linkList.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. <template>
  2. <cwg-page-wrapper class="create-page" :isHeaderFixed="true">
  3. <cwg-header :title="t('Ib.Index.CreateLink')" />
  4. <view class="account-section">
  5. <view class="add-link" @click="addLink">
  6. <view class="add-link-content" @click="addLink">
  7. <cwg-icon name="icon_add" :size="18" color="#fff"></cwg-icon>
  8. {{ t('Ib.Index.CreateLink') }}
  9. </view>
  10. </view>
  11. <cwg-tabel ref="tableRef" :columns="columns" :mobilePrimaryFields="mobilePrimaryFields"
  12. :api="listApi" :show-operation="false" :showPagination="true" isPages pagesToDetail @goPages="openDetail">
  13. <template #link="{ row }">
  14. <view class="link-cell">
  15. <uni-easyinput class="read-input" disabled v-model.trim="row.link"></uni-easyinput>
  16. <view class="qr-code-icon" @click.stop="showQrCodeDialog(row.link)">
  17. <svg style="width: 18px; height: 18px; fill: #409eff; vertical-align: middle;" viewBox="0 0 24 24"
  18. xmlns="http://www.w3.org/2000/svg">
  19. <path
  20. d="M3 3h8v8H3V3zm2 2v4h4V5H5zm8-2h8v8h-8V3zm2 2v4h4V5h-4zM3 13h8v8H3v-8zm2 2v4h4v-4H5zm13-2h3v2h-3v-2zm0 4h3v2h-3v-2zm-4-4h2v6h-2v-6zm4-8h2v2h-2V3zm0 4h2v2h-2V7zm-4 0h2v2h-2V7z" />
  21. </svg>
  22. </view>
  23. <view class="copy" @click.stop="CopyLink(row.link)">
  24. {{ t('Ib.Index.Copy') }}
  25. </view>
  26. </view>
  27. </template>
  28. <template #linkValue="{ row }">
  29. <view class="link-cell">
  30. <uni-easyinput class="read-input" disabled v-model.trim="row.linkValue"></uni-easyinput>
  31. <view class="copy" @click.stop="CopyLink(row.linkValue)">
  32. {{ t('Ib.Index.Copy') }}
  33. </view>
  34. </view>
  35. </template>
  36. </cwg-tabel>
  37. <!--详情-->
  38. <link-detail-dialog :visible="datailVisible" @close="closeDetail" :detail="detail"
  39. @showQrCode="showQrCodeDialog" />
  40. <cwg-popup ref="linkPopup" :visible="dialogLink" type="center" :title="t('Ib.Index.CreateLink')" showFooterLine
  41. @close="dialogLink = false" @confirm="saveLink">
  42. <view class="dia-content">
  43. <view class="content" style="font-size: 14px; text-align: left">
  44. <view class="label">{{ t('Ib.Custom.NameLabelColon') }}</view>
  45. <uni-easyinput
  46. v-model="linkName"
  47. :placeholder="t('Ib.Custom.NameLabel')"
  48. />
  49. <view class="label-tit">{{ t('Ib.Index.Spread5') }} :</view>
  50. <!--标准账户-->
  51. <view class="label">{{ t('AccountType.StandardAccount') }} :</view>
  52. <cwg-combox
  53. v-model:value="accountTypeSettings.standard.selectedIndex"
  54. :options="getAvailableSpreads('7')"
  55. @change="(val)=>handleAccountTypeChange('standard', '7',val)"
  56. :placeholder="t('placeholder.choose')"
  57. />
  58. <view class="label">{{ t('AccountType.SeniorAccount') }}</view>
  59. <cwg-combox
  60. v-model:value="accountTypeSettings.ecn.selectedIndex"
  61. :options="getAvailableSpreads('2')"
  62. @change="(val)=>handleAccountTypeChange('ecn', '2',val)"
  63. :placeholder="t('placeholder.choose')"
  64. />
  65. <view class="label">{{ t('AccountType.CentAccount') }}</view>
  66. <cwg-combox
  67. v-model:value="accountTypeSettings.cent.selectedIndex"
  68. :options="getAvailableSpreads('8')"
  69. @change="(val)=>handleAccountTypeChange('cent', '8',val)"
  70. :placeholder="t('placeholder.choose')"
  71. />
  72. <view class="btn">
  73. <button
  74. class="crm-cursor"
  75. @click="CreateLink"
  76. >{{ t('Ib.Index.CreateLink') }}
  77. </button>
  78. </view>
  79. <view class="link qrCode" v-if="link">
  80. <QrCode
  81. ref="qrCode"
  82. :text="link"
  83. :width="200"
  84. :height="200"
  85. />
  86. <view class="btn">
  87. <button
  88. class="crm-cursor"
  89. @click="downloadQrCode()"
  90. >{{ t('Btn.item9') }}
  91. </button>
  92. </view>
  93. </view>
  94. <view class="link" v-if="link">
  95. <uni-easyinput
  96. disabled
  97. v-model="link"
  98. />
  99. <button class="btn" @click="CopyLink(link)">
  100. {{ t('Ib.Index.Copy') }}
  101. </button>
  102. </view>
  103. </view>
  104. </view>
  105. </cwg-popup>
  106. <cwg-popup :visible="qrCodeDialogVisible" type="center" :title="t('Ib.Index.QrCode')" showFooterLine
  107. @singleClick="qrCodeDialogVisible = false" :singleBtnText="t('Btn.Cancel')" :footerType="'single'"
  108. @close="qrCodeDialogVisible = false">
  109. <view class="qr-code-dialog-content">
  110. <QrCode
  111. ref="dialogQrCode"
  112. v-if="currentQrCodeLink"
  113. :text="currentQrCodeLink"
  114. :width="300"
  115. :height="300"
  116. ></QrCode>
  117. <view v-if="currentQrCodeLink" class="qr-code-btn">
  118. <button @click="downloadDialogQrCode">
  119. {{ t('Btn.item9') }}
  120. </button>
  121. </view>
  122. </view>
  123. </cwg-popup>
  124. </view>
  125. </cwg-page-wrapper>
  126. </template>
  127. <script setup lang="ts">
  128. import { ref, reactive, computed, onMounted, onUnmounted, watch } from 'vue'
  129. import { onLoad } from '@dcloudio/uni-app'
  130. import { useI18n } from 'vue-i18n' // uni-app 中已集成,但需配置
  131. import { customApi } from '@/service/custom'
  132. import { financialApi } from '@/service/financial'
  133. import Config from '@/config/index'
  134. import PaymentMethodsList from './components/PaymentMethodsList.vue'
  135. import { ibApi } from '@/service/ib'
  136. import useUserStore from '@/stores/use-user-store'
  137. import QrCode from '@/components/QrCode.vue'
  138. import LinkDetailDialog from '@/pages/ib/components/linkDetailDialog.vue'
  139. const { Code, Host80 } = Config
  140. const { t, locale } = useI18n()
  141. // 列表数据
  142. const tableData = ref([])
  143. const loading = ref(false)
  144. const listApi = ref(null)
  145. const currentQrCodeLink = ref('')
  146. const qrCodeDialogVisible = ref(false)
  147. const datailVisible = ref(false)
  148. const detail = ref({})
  149. // 按账户类型分组的数据
  150. const accountTypeData = ref({
  151. ecn: [], // loginType = 2
  152. standard: [], // loginType = 7
  153. cent: [], // loginType = 8
  154. })
  155. const tableRef = ref(null)
  156. // 弹窗中的二维码组件
  157. const dialogQrCode = ref(null)
  158. const excludeList = ref([])
  159. const excludeLists = ref([])
  160. const excludeListVN = ref([])
  161. const excludeShowLoginTypes = ref([])
  162. // 账户类型设置:每个账户类型对应一个点差设置
  163. const accountTypeSettings = ref({
  164. // ECN账户,存储选中的完整对象
  165. ecn: { selectedIndex: null, selectedItem: null, loginType: '2' },
  166. // 标准账户
  167. standard: { selectedIndex: null, selectedItem: null, loginType: '7' },
  168. // 美分账户
  169. cent: { selectedIndex: null, selectedItem: null, loginType: '8' },
  170. })
  171. const selectedSpreadId = ref('')
  172. const linkName = ref('')
  173. const loginTypes = ref('')
  174. const link = ref('')
  175. const linkValue = ref('')
  176. const ibInvalid = ref('B0')
  177. const dialogLink = ref(false)
  178. const qrCode = ref(null)
  179. const { userInfo } = useUserStore()
  180. const country = computed(() => {
  181. return userInfo.customInfo.country
  182. })
  183. const agentAccountSetting = computed(() => {
  184. return userInfo.ibInfo.agentAccountSetting ||
  185. 0
  186. })
  187. const getInfoId = computed(() => {
  188. console.log(userInfo.ibInfo.id, 'userInfo.ibInfo.id')
  189. return userInfo.ibInfo.id ||
  190. 0
  191. })
  192. listApi.value = ibApi.customLinkSearchList
  193. const columns = ref([
  194. {
  195. prop: 'name',
  196. label: t('Ib.Custom.NameLabel'),
  197. align: 'center',
  198. },
  199. {
  200. prop: 'link',
  201. label: t('Ib.Index.Link'),
  202. align: 'center',
  203. slot: 'link',
  204. width: 480,
  205. },
  206. {
  207. prop: 'linkValue',
  208. label: t('Ib.Index.LinkValue'),
  209. align: 'center',
  210. slot: 'linkValue',
  211. width: 200,
  212. },
  213. {
  214. prop: 'customNum',
  215. label: t('Ib.Index.CustomNum'),
  216. align: 'center',
  217. },
  218. {
  219. prop: 'comPoint',
  220. label: t('AccountType.StandardAccount'),
  221. align: 'center',
  222. formatter: ({ row }) => getGroupNameByLoginType(row.loginConfig, 7),
  223. },
  224. {
  225. prop: 'hide',
  226. label: 'ECN',
  227. align: 'center',
  228. formatter: ({ row }) => getGroupNameByLoginType(row.loginConfig, 2),
  229. },
  230. {
  231. prop: 'loginTypes',
  232. label: t('AccountType.CentAccount'),
  233. align: 'center',
  234. formatter: ({ row }) => getGroupNameByLoginType(row.loginConfig, 8),
  235. },
  236. ])
  237. const mobilePrimaryFields = ref([
  238. {
  239. prop: 'name',
  240. label: t('Ib.Custom.NameLabel'),
  241. align: 'center',
  242. },
  243. {
  244. prop: 'customNum',
  245. label: t('Ib.Index.CustomNum'),
  246. align: 'center',
  247. },
  248. {
  249. prop: 'more',
  250. type: 'more',
  251. width: 20,
  252. align: 'right',
  253. },
  254. ])
  255. const getGroupNameByLoginType = (loginConfig, loginType) => {
  256. if (!loginConfig) return '--'
  257. // 如果 loginConfig 是字符串,尝试解析为数组
  258. let config = loginConfig
  259. if (typeof loginConfig === 'string') {
  260. try {
  261. config = JSON.parse(loginConfig)
  262. } catch (e) {
  263. return '--'
  264. }
  265. }
  266. // 确保是数组
  267. if (!Array.isArray(config)) {
  268. return '--'
  269. }
  270. // 查找匹配的 loginType
  271. const matchedItem = config.find(item => {
  272. // 支持数字和字符串类型的比较
  273. return item.loginType === loginType ||
  274. item.loginType === String(loginType) ||
  275. String(item.loginType) === String(loginType)
  276. })
  277. return matchedItem ? (matchedItem.groupName || '--') : '--'
  278. }
  279. const CopyLink = (link) => {
  280. uni.setClipboardData({
  281. data: link,
  282. success: () => {
  283. uni.showToast({
  284. title: t('card.Msg.m8'),
  285. icon: 'success',
  286. })
  287. },
  288. })
  289. }
  290. const showQrCodeDialog = (link) => {
  291. if (!link) return
  292. currentQrCodeLink.value = link
  293. qrCodeDialogVisible.value = true
  294. }
  295. // 获取开户链接账户类型列表
  296. const getCustomLinkTypes = async () => {
  297. let res = await ibApi.customLinkTypes()
  298. if (res.code == Code.StatusOK) {
  299. // 按 loginType 分组数据
  300. const data = res.data || []
  301. console.log(data, '123')
  302. accountTypeData.value = {
  303. ecn: data.filter(item => item.loginType === 2 || item.loginType === '2'),
  304. standard: data.filter(item => item.loginType === 7 || item.loginType === '7'),
  305. cent: data.filter(item => item.loginType === 8 || item.loginType === '8'),
  306. }
  307. } else {
  308. uni.showToast({
  309. title: res.msg,
  310. icon: 'none',
  311. })
  312. accountTypeData.value = {
  313. ecn: [],
  314. standard: [],
  315. cent: [],
  316. }
  317. }
  318. }
  319. // 获取账户类型设置
  320. const getAgentAccountSetting = () => {
  321. // 如果是越南账户,显示标准账户、美分账户和ECN账户
  322. if (country.value === 'VN') {
  323. const standardAccount = excludeLists.value.find(
  324. (item) => item.value === '7',
  325. )
  326. const centAccount = excludeLists.value.find(
  327. (item) => item.value === '8',
  328. )
  329. const ecnAccount = excludeLists.value.find(
  330. (item) => item.value === '2',
  331. )
  332. excludeListVN.value = [standardAccount, centAccount, ecnAccount].filter(
  333. Boolean,
  334. )
  335. excludeShowLoginTypes.value = []
  336. } else {
  337. if (agentAccountSetting.value == 0) {
  338. const excludeValues = userInfo
  339. .customInfo.excludeShowLoginTypes
  340. try {
  341. const excludeList = excludeLists.value.filter(
  342. (item) => !excludeValues.includes(item.value),
  343. )
  344. excludeList.value = excludeList
  345. excludeShowLoginTypes.value = []
  346. } catch (error) {
  347. excludeShowLoginTypes.value = []
  348. excludeList.value = excludeLists.value
  349. }
  350. } else {
  351. excludeShowLoginTypes.value = []
  352. excludeList.value = excludeLists.value
  353. }
  354. }
  355. }
  356. // add
  357. const addLink = async () => {
  358. console.log(getInfoId.value, 'getInfo.id')
  359. await getCustomLinkTypes()
  360. getAgentAccountSetting()
  361. // 重置所有表单字段
  362. selectedSpreadId.value = ''
  363. linkName.value = ''
  364. loginTypes.value = ''
  365. linkValue.value = ''
  366. // 重置账户类型设置
  367. accountTypeSettings.value = {
  368. ecn: { selectedIndex: null, selectedItem: null, loginType: '2' },
  369. standard: { selectedIndex: null, selectedItem: null, loginType: '7' },
  370. cent: { selectedIndex: null, selectedItem: null, loginType: '8' },
  371. }
  372. dialogLink.value = true
  373. }
  374. const onNameChange = (e) => {
  375. console.log(e)
  376. }
  377. // 账户类型选择变化处理
  378. const handleAccountTypeChange = (type, loginType, val) => {
  379. console.log(type, loginType, val, '221')
  380. const setting = accountTypeSettings.value[type]
  381. const availableSpreads = getAvailableSpreads(loginType)
  382. if (setting.selectedIndex !== null && setting.selectedIndex !== undefined) {
  383. accountTypeSettings.value[type].selectedItem = availableSpreads[setting.selectedIndex] || null
  384. } else {
  385. accountTypeSettings.value[type].selectedItem = null
  386. }
  387. }
  388. // 获取指定账户类型可用的点差设置
  389. const getAvailableSpreads = (loginType) => {
  390. // 根据 loginType 返回对应的数据
  391. if (loginType === '2') {
  392. return accountTypeData.value.ecn?.map((item, index) => ({ ...item, value: index, text: item.groupName })) || []
  393. } else if (loginType === '7') {
  394. return accountTypeData.value.standard?.map((item, index) => ({
  395. ...item,
  396. value: index,
  397. text: item.groupName,
  398. })) || []
  399. } else if (loginType === '8') {
  400. return accountTypeData.value.cent?.map((item, index) => ({ ...item, value: index, text: item.groupName })) || []
  401. }
  402. return []
  403. }
  404. // 获取链接值
  405. const getLink1 = async () => {
  406. // 收集所有选中的账户类型和对应的点差设置
  407. const selectedAccountTypes = []
  408. const loginConfig = []
  409. // 检查每个账户类型是否已选择点差设置
  410. Object.keys(accountTypeSettings.value).forEach((key) => {
  411. const setting = accountTypeSettings.value[key]
  412. if (setting.selectedItem) {
  413. selectedAccountTypes.push(setting.loginType)
  414. // 将选中的整个对象添加到 loginConfig 数组
  415. loginConfig.push(setting.selectedItem)
  416. }
  417. })
  418. if (selectedAccountTypes.length === 0) {
  419. uni.showToast({
  420. title: t('Ib.Index.Spread5'),
  421. icon: 'none',
  422. })
  423. link.value = ''
  424. return
  425. }
  426. // 构建请求参数
  427. const validList = {
  428. loginConfig: loginConfig,
  429. }
  430. // 直接调用接口生成链接
  431. const res = await ibApi.customLinkCode(validList)
  432. if (res.code === Code.StatusOK) {
  433. uni.showToast({
  434. title: res.msg,
  435. icon: 'none',
  436. })
  437. return res.data
  438. } else {
  439. uni.showToast({
  440. title: res.msg,
  441. icon: 'error',
  442. })
  443. return ''
  444. }
  445. }
  446. const saveLink = async () => {
  447. if (!linkName.value) {
  448. uni.showToast({
  449. title: t('Ib.Custom.NameLabel'),
  450. icon: 'none',
  451. })
  452. return
  453. }
  454. if (!link.value) {
  455. uni.showToast({
  456. title: t('Ib.Index.CreateLink'),
  457. icon: 'none',
  458. })
  459. return
  460. }
  461. // 收集所有选中的账户类型配置
  462. const loginConfig = []
  463. Object.keys(accountTypeSettings.value).forEach((key) => {
  464. const setting = accountTypeSettings.value[key]
  465. if (setting.selectedItem) {
  466. // 将选中的整个对象添加到 loginConfig 数组
  467. loginConfig.push(setting.selectedItem)
  468. }
  469. })
  470. if (loginConfig.length === 0) {
  471. uni.showToast({
  472. title: t('Ib.Index.Spread5'),
  473. icon: 'none',
  474. })
  475. return
  476. }
  477. // 调用保存接口
  478. const res = await ibApi.customLinkAdd({
  479. name: linkName.value,
  480. link: link.value,
  481. linkValue: linkValue.value,
  482. loginConfig: loginConfig,
  483. })
  484. if (res.code === Code.StatusOK) {
  485. uni.showToast({
  486. title: res.msg,
  487. icon: 'none',
  488. })
  489. dialogLink.value = false
  490. // 重置表单
  491. linkName.value = ''
  492. link.value = ''
  493. linkValue.value = ''
  494. excludeShowLoginTypes.value = []
  495. selectedSpreadId.value = ''
  496. accountTypeSettings.value = {
  497. ecn: { selectedIndex: null, selectedItem: null, loginType: '2' },
  498. standard: { selectedIndex: null, selectedItem: null, loginType: '7' },
  499. cent: { selectedIndex: null, selectedItem: null, loginType: '8' },
  500. }
  501. tableRef.value.refreshTable()
  502. } else {
  503. uni.showToast({
  504. title: res.msg,
  505. icon: 'error',
  506. })
  507. }
  508. }
  509. watch(() => dialogLink.value, (val) => {
  510. // 关闭弹窗清空
  511. if (!val) {
  512. link.value = ''
  513. }
  514. })
  515. // 生成链接(不保存)
  516. const CreateLink = async () => {
  517. console.log(linkName.value)
  518. if (!linkName.value) {
  519. uni.showToast({
  520. title: t('Ib.Custom.NameLabel'),
  521. icon: 'none',
  522. })
  523. return
  524. }
  525. const value = await getLink1()
  526. if (!value) return
  527. linkValue.value = value
  528. link.value = `${Host80}/#/signup/${getInfoId.value}/${value}/${ibInvalid.value}`
  529. }
  530. const downloadQrCode = (type = 0) => {
  531. qrCode.value.download()
  532. }
  533. // 下载弹窗中的二维码
  534. const downloadDialogQrCode = (type = 0) => {
  535. dialogQrCode.value.download()
  536. }
  537. // 打开详情弹窗
  538. const openDetail = (row) => {
  539. datailVisible.value = true
  540. detail.value = row
  541. }
  542. // 关闭详情弹窗
  543. const closeDetail = () => {
  544. datailVisible.value = false
  545. detail.value = {}
  546. }
  547. </script>
  548. <style lang="scss" scoped>
  549. @import "@/uni.scss";
  550. .add-link {
  551. width: 100%;
  552. display: flex;
  553. align-items: center;
  554. justify-content: flex-end;
  555. .add-link-content {
  556. cursor: pointer;
  557. display: flex;
  558. align-items: center;
  559. color: #fff;
  560. padding: 0 px2rpx(10);
  561. background-color: #ffde02;
  562. font-size: px2rpx(16);
  563. font-weight: bold;
  564. line-height: px2rpx(26);
  565. border-radius: px2rpx(5);
  566. }
  567. }
  568. .link-cell {
  569. width: 100%;
  570. display: inline-flex;
  571. align-items: center;
  572. justify-content: flex-start;
  573. gap: 5px;
  574. white-space: nowrap;
  575. .read-input {
  576. max-width: px2rpx(360);
  577. white-space: nowrap;
  578. overflow: hidden;
  579. text-overflow: ellipsis;
  580. flex: 1;
  581. }
  582. .copy {
  583. cursor: pointer;
  584. line-height: px2rpx(28);
  585. }
  586. }
  587. .qr-code-icon {
  588. cursor: pointer;
  589. user-select: none;
  590. transition: opacity 0.3s;
  591. white-space: nowrap;
  592. line-height: 28px;
  593. display: flex;
  594. align-items: center;
  595. padding: 0 8px;
  596. &:hover {
  597. opacity: 0.7;
  598. }
  599. }
  600. .dia-content {
  601. padding: 20rpx;
  602. }
  603. .content {
  604. display: flex;
  605. flex-direction: column;
  606. gap: 20rpx;
  607. }
  608. .label-tit {
  609. font-weight: 500;
  610. margin-bottom: 8rpx;
  611. }
  612. .label {
  613. font-weight: 400;
  614. margin-bottom: 8rpx;
  615. }
  616. .btn {
  617. margin-top: px2rpx(16);
  618. text-align: center;
  619. }
  620. .link {
  621. display: flex;
  622. margin-top: px2rpx(20);
  623. .btn {
  624. display: flex;
  625. align-items: center;
  626. justify-content: center;
  627. height: px2rpx(35);
  628. margin: 0 px2rpx(10);
  629. }
  630. }
  631. .qrCode {
  632. display: flex;
  633. flex-direction: column;
  634. align-items: center;
  635. gap: px2rpx(16);
  636. }
  637. .qr-code-dialog-content {
  638. display: flex;
  639. flex-direction: column;
  640. justify-content: center;
  641. align-items: center;
  642. padding: px2rpx(20) 0;
  643. .qr-code-btn {
  644. margin-top: px2rpx(16);
  645. }
  646. }
  647. </style>