subsList.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <template>
  2. <cwg-page-wrapper class="create-page" :isHeaderFixed="true">
  3. <cwg-header :title="t('Ib.Custom.Manage2')" />
  4. <view class="account-content">
  5. <!-- 移动端:按钮在筛选上方 -->
  6. <cwg-match-media :max-width="991">
  7. <view class="search-content mobile-search-content">
  8. <view class="search-bar mobile-add-btn-wrap">
  9. <button type="primary" class="search-button" @click="addSub">
  10. <cwg-icon name="icon_add" :size="18" color="#fff"></cwg-icon>
  11. {{ t('Ib.Report.Title5') }}
  12. </button>
  13. </view>
  14. <view class="search-bar">
  15. <cwg-complex-search :fields="filterFields" v-model="searchParams" @search="handleSearch"
  16. @reset="handleReset" />
  17. </view>
  18. </view>
  19. </cwg-match-media>
  20. <!-- PC端:按钮和筛选在同一行 -->
  21. <cwg-match-media :min-width="991">
  22. <view class="search-content pc-search-content">
  23. <view class="search-bar">
  24. <cwg-complex-search :fields="filterFields" v-model="searchParams" @search="handleSearch"
  25. @reset="handleReset" />
  26. </view>
  27. <view class="search-bar">
  28. <button type="primary" class="search-button" @click="addSub">
  29. <cwg-icon name="icon_add" :size="18" color="#fff"></cwg-icon>
  30. {{ t('Ib.Report.Title5') }}
  31. </button>
  32. </view>
  33. </view>
  34. </cwg-match-media>
  35. <cwg-tabel
  36. ref="tableRef"
  37. :columns="columns"
  38. :mobilePrimaryFields="mobilePrimaryFields"
  39. :queryParams="search"
  40. :api="listApi"
  41. :show-operation="true"
  42. :showPagination="true"
  43. >
  44. </cwg-tabel>
  45. </view>
  46. <ApplyIbDialog ref="applyIbDialogRef" :visible="applyVisible" @close="closeApplyIb" @confirm="confirmApply"
  47. :title="formDia?'Ib.Report.Title5':'Ib.Custom.Commit3'" :isFormApplyIb="formDia"
  48. :paramsType="applyType" :detail="applyDetail" />
  49. <cwg-popup
  50. :visible="exclusiveVisible"
  51. :title="t('Ib.Custom.Commit5')"
  52. :cancelText="t('Btn.Cancel')"
  53. :confirmText="t('Btn.Confirm')"
  54. @close="cancelExclusiveCommission"
  55. @confirm="confirmExclusiveCommission"
  56. >
  57. <view class="dia-content">
  58. <uni-forms ref="exclusiveCommissionFormRef" labelWidth="240">
  59. <uni-forms-item :label="t('Ib.Custom.Commit5')" prop="selectedPoint">
  60. <cwg-combox
  61. v-model:value="exclusiveCommissionForm.selectedPoint"
  62. :options="exclusiveCommissionForm.pointOptions"
  63. :placeholder="t('placeholder.choose')"
  64. />
  65. </uni-forms-item>
  66. </uni-forms>
  67. </view>
  68. </cwg-popup>
  69. </cwg-page-wrapper>
  70. </template>
  71. <script setup lang="ts">
  72. // 代理管理
  73. import { ref, reactive, computed, onMounted, onUnmounted } from 'vue'
  74. import { onLoad } from '@dcloudio/uni-app'
  75. import { useI18n } from 'vue-i18n' // uni-app 中已集成,但需配置
  76. import { customApi } from '@/service/custom'
  77. import { financialApi } from '@/service/financial'
  78. import Config from '@/config/index'
  79. import { ibApi } from '@/service/ib'
  80. import { useFilters } from '@/composables/useFilters'
  81. import ApplyIbDialog from '@/pages/ib/components/applyIbDialog.vue'
  82. import { nextTick } from 'vue'
  83. const { numberFormat, numberDecimal } = useFilters()
  84. const { t, locale } = useI18n()
  85. const { Code } = Config
  86. const searchParams = ref({})
  87. const search = ref({
  88. ibNo: '',
  89. name: '',
  90. cId: '',
  91. startDate: '',
  92. endDate: '',
  93. })
  94. const filterFields = [
  95. { key: 'ibNo', type: 'input', label: t('Label.IbAccount'), placeholder: t('Label.IbAccount'), defaultValue: '' },
  96. {
  97. key: 'name',
  98. type: 'input',
  99. label: t('Ib.Custom.NameLabel'),
  100. placeholder: t('Ib.Custom.NameLabel'),
  101. defaultValue: '',
  102. },
  103. { key: 'cId', type: 'input', label: 'CID', placeholder: 'CID', defaultValue: '' },
  104. { key: 'date', label: t('placeholder.Start') + ' - ' + t('placeholder.End'), type: 'daterange' },
  105. ]
  106. const tableRef = ref(null)
  107. const applyIbDialogRef = ref(null)
  108. const applyVisible = ref(false)
  109. const applyType = ref('')
  110. const applyDetail = ref()
  111. const formDia = ref(false)
  112. const exclusiveVisible = ref(false)
  113. const exclusiveCommissionFormRef = ref(null)
  114. const exclusiveCommissionForm = ref({
  115. agentId: '',
  116. selectedPoint: '',
  117. pointOptions: [],
  118. })
  119. const exclusiveRow = ref<any>(null)
  120. // 表格列配置
  121. const columns = computed(() => [
  122. {
  123. prop: 'cId',
  124. label: t('Label.CidAccount'),
  125. align: 'center',
  126. },
  127. {
  128. prop: 'ibNo',
  129. label: t('Label.IbAccount'),
  130. align: 'center',
  131. },
  132. {
  133. prop: 'name',
  134. label: t('Ib.Custom.NameLabel'),
  135. align: 'center',
  136. },
  137. {
  138. prop: 'agentNum',
  139. label: t('Ib.Custom.AgentNum'),
  140. align: 'center',
  141. },
  142. {
  143. prop: 'customNum',
  144. label: t('Ib.Custom.CustomerNum'),
  145. align: 'center',
  146. },
  147. {
  148. prop: 'addTime',
  149. label: t('Label.ApplyTime'),
  150. align: 'center',
  151. },
  152. {
  153. prop: 'lastTime',
  154. label: t('Ib.Custom.LastActiveTime'),
  155. align: 'center',
  156. },
  157. {
  158. prop: 'action',
  159. label: t('Label.Action'),
  160. type: 'action',
  161. align: 'center',
  162. menuList: [
  163. {
  164. label: t('Ib.Custom.Commit3'),
  165. type: 'vietnamDistribution',
  166. btnClick: (row) => handleMenuClick({ type: 'vietnamDistribution', row }),
  167. show: true,
  168. },
  169. {
  170. label: t('Ib.Custom.Commit5'),
  171. type: 'exclusiveCommission',
  172. btnClick: (row) => handleMenuClick({ type: 'exclusiveCommission', row }),
  173. show: (row) => row.exclusiveCommissionOptions?.length > 0,
  174. },
  175. ]
  176. },
  177. ])
  178. const mobilePrimaryFields = computed(() => [
  179. {
  180. prop: 'cId',
  181. label: t('Label.CidAccount'),
  182. align: 'center',
  183. },
  184. {
  185. prop: 'ibNo',
  186. label: t('Label.IbAccount'),
  187. align: 'center',
  188. },
  189. {
  190. prop: 'name',
  191. label: t('Ib.Custom.NameLabel'),
  192. align: 'center',
  193. },
  194. {
  195. prop: 'more',
  196. type: 'more',
  197. width: 20,
  198. align: 'right',
  199. },
  200. ])
  201. const listApi = ref(ibApi.IbSubs)
  202. const handleSearch = (params: any) => {
  203. // 拦截处理 daterange,将 date 拆分为 startDate 和 endDate
  204. const payload = { ...params }
  205. if (payload.date && payload.date.length === 2) {
  206. payload.startDate = payload.date[0]
  207. payload.endDate = payload.date[1]
  208. } else {
  209. payload.startDate = ''
  210. payload.endDate = ''
  211. }
  212. delete payload.date
  213. search.value = payload
  214. nextTick(() => {
  215. tableRef.value.refreshTable()
  216. })
  217. }
  218. const handleReset = () => {
  219. search.value = {
  220. ibNo: '',
  221. name: '',
  222. cId: '',
  223. startDate: '',
  224. endDate: '',
  225. }
  226. nextTick(() => {
  227. tableRef.value.refreshTable()
  228. })
  229. }
  230. onMounted(() => {
  231. // applyVisible.value = true
  232. })
  233. const handleMenuClick = (item) => {
  234. if (item.type == 'vietnamDistribution') {
  235. const { agentId, id } = item.row
  236. applyDetail.value = {
  237. id: id || agentId,
  238. }
  239. formDia.value = false
  240. applyType.value = 'vietnam'
  241. applyVisible.value = true
  242. } else if (item.type == 'exclusiveCommission') {
  243. openExclusiveCommission(item.row)
  244. }
  245. }
  246. const addSub = () => {
  247. formDia.value = true
  248. applyVisible.value = true
  249. }
  250. const closeApplyIb = () => {
  251. applyVisible.value = false
  252. }
  253. const confirmApply = (data) => {
  254. tableRef.value.refreshTable()
  255. }
  256. const normalizePointOptions = (options: any[]) => {
  257. if (!Array.isArray(options)) return []
  258. return options.map((o: any) => ({
  259. text: o.label ?? o.text ?? o.name ?? String(o.value ?? ''),
  260. value: o.value,
  261. }))
  262. }
  263. const openExclusiveCommission = async (row: any) => {
  264. exclusiveCommissionForm.value.agentId = row.id
  265. exclusiveCommissionForm.value.selectedPoint = ''
  266. exclusiveCommissionForm.value.pointOptions = normalizePointOptions(row?.exclusiveCommissionOptions || [])
  267. exclusiveVisible.value = true
  268. }
  269. const cancelExclusiveCommission = () => {
  270. exclusiveVisible.value = false
  271. exclusiveCommissionForm.value.selectedPoint = ''
  272. exclusiveCommissionForm.value.pointOptions = []
  273. }
  274. const confirmExclusiveCommission = async () => {
  275. try {
  276. const res = await ibApi.agentHiddenPointAdd({
  277. agentId: exclusiveCommissionForm.value.agentId,
  278. point: [{ value: exclusiveCommissionForm.value.selectedPoint }],
  279. })
  280. if (res.code == Code.StatusOK) {
  281. cancelExclusiveCommission()
  282. tableRef.value?.refreshTable?.()
  283. }
  284. } catch (e) {
  285. }
  286. }
  287. </script>
  288. <style lang="scss" scoped>
  289. @import "@/uni.scss";
  290. .search-content {
  291. display: flex;
  292. }
  293. /* PC 端对齐方式 */
  294. .pc-search-content {
  295. justify-content: space-between;
  296. align-items: flex-start;
  297. margin-bottom: px2rpx(10);
  298. }
  299. /* 移动端排版方式 */
  300. .mobile-search-content {
  301. flex-direction: column;
  302. margin-bottom: px2rpx(10);
  303. .mobile-add-btn-wrap {
  304. display: flex;
  305. justify-content: flex-end;
  306. width: 100%;
  307. margin-bottom: px2rpx(10);
  308. .search-button {
  309. background-color: var(--color-error);
  310. margin: 0 0 0 auto; /* 强制按钮靠右且消除其它 margin */
  311. }
  312. }
  313. }
  314. .search-button {
  315. display: flex;
  316. align-items: center;
  317. background-color: var(--color-error);
  318. line-height: px2rpx(36);
  319. min-width: px2rpx(120);
  320. }
  321. </style>