linkList.vue 18 KB

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