index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <!-- 客户管理-用户管理 -->
  2. <template>
  3. <div class="customer-management">
  4. <!-- 搜索条件区 -->
  5. <div class="search-section">
  6. <a-form :model="searchForm" layout="inline">
  7. <a-form-item field="customerName" :label="$t('customer.customerName')">
  8. <a-input v-model="searchForm.customerName" :placeholder="$t('customer.enterCustomerName')"
  9. allow-clear />
  10. </a-form-item>
  11. <a-form-item field="operatorType" :label="$t('customer.operatorType')">
  12. <a-select v-model="searchForm.operatorType" :placeholder="$t('customer.selectOperatorType')"
  13. allow-clear style="width: 160px">
  14. <a-option v-for="op in operatorTypeOptions" :key="op.value" :value="op.value">
  15. {{ $t(`customer.operatorTypes.${op.value}`) }}
  16. </a-option>
  17. </a-select>
  18. </a-form-item>
  19. <a-form-item>
  20. <a-button type="primary" @click="handleSearch">{{ $t('global.common.search') }}</a-button>
  21. </a-form-item>
  22. <a-form-item>
  23. <a-button @click="resetSearch">{{ $t('global.common.reset') }}</a-button>
  24. </a-form-item>
  25. </a-form>
  26. </div>
  27. <!-- 顶部操作区 -->
  28. <div class="top-actions">
  29. <a-space>
  30. <a-button type="primary" @click="showNewCustomerForm">{{ $t('customer.addCustomer') }}</a-button>
  31. <a-button @click="handleBatchDelete">{{ $t('customer.batchDelete') }}</a-button>
  32. </a-space>
  33. </div>
  34. <!-- 数据表格 -->
  35. <a-table row-key="id" :columns="columns" :data="tableData" :pagination="pagination" :scroll="{ x: 'auto' }"
  36. :row-selection="{ type: 'checkbox', showCheckedAll: true }" @page-change="onPageChange">
  37. <template #state="{ record }">
  38. <a-tag :color="getStatusColor(record.state)">
  39. {{ $t(`customer.status.${getStatusText(record.state)}`) }}
  40. </a-tag>
  41. </template>
  42. <template #operation="{ record }">
  43. <a-space>
  44. <a-button type="text" size="small" @click="handleRecharge(record)">{{ $t('customer.recharge')
  45. }}</a-button>
  46. <a-button type="text" size="small" @click="handlePackageManagement(record)">{{
  47. $t('customer.packageManagement') }}</a-button>
  48. <a-button type="text" size="small" @click="handleEdit(record)">{{ $t('global.common.edit')
  49. }}</a-button>
  50. </a-space>
  51. </template>
  52. </a-table>
  53. <!-- 新客户表单对话框 -->
  54. <new-customer-form v-model:visible="newCustomerFormVisible" :editMode="editMode" :editData="editData"
  55. :loading="loading" @submit="handleNewCustomerSubmit" />
  56. </div>
  57. </template>
  58. <script setup>
  59. import { ref, reactive, computed, onMounted } from 'vue';
  60. import { Message } from '@arco-design/web-vue';
  61. import { useI18n } from 'vue-i18n';
  62. import NewCustomerForm from './NewCustomerForm.vue';
  63. import { getCustomerList, addCustomer, getCustomer, updateCustomer } from '@/api/customer';
  64. const { t } = useI18n();
  65. const loading = ref(false);
  66. const columns = computed(() => [
  67. { title: t('customer.id'), dataIndex: 'id' },
  68. { title: t('customer.customerCode'), dataIndex: 'customerCode' },
  69. { title: t('customer.customerName'), dataIndex: 'customerName' },
  70. { title: t('customer.accountNumber'), dataIndex: 'accountNumber' },
  71. { title: t('customer.accountBalance'), dataIndex: 'accountBalance' },
  72. { title: t('customer.paymentMethodName'), dataIndex: 'paymentMethod' },
  73. { title: t('customer.customerStatus'), slotName: 'state' },
  74. { title: t('customer.validPeriod'), dataIndex: 'validPeriod' },
  75. { title: t('customer.activeCards'), dataIndex: 'activeCards' },
  76. { title: t('customer.updateTime'), dataIndex: 'updateTime' },
  77. { title: t('global.common.operations'), slotName: 'operation', width: 250 },
  78. ]);
  79. onMounted(() => {
  80. // fetchCustomerList();
  81. });
  82. const tableData = ref([
  83. {
  84. id: "1", customerCode: "8",
  85. customerName: "泰国景和",
  86. accountBalance: "TS001",
  87. paymentMethod: "预付费",
  88. state: "1",
  89. validPeriod: "2024-12-54",
  90. activeCards: "0/0",
  91. updateTime: "2024-09-20 08:05:54"
  92. },
  93. {
  94. id: "2", customerCode: "9",
  95. customerName: "泰国景和",
  96. accountBalance: "TS001",
  97. paymentMethod: "后付费",
  98. state: "1",
  99. validPeriod: "2024-12-54",
  100. activeCards: "0/0",
  101. updateTime: "2024-09-20 08:05:54"
  102. },
  103. {
  104. id: "3", customerCode: "10",
  105. customerName: "泰国景和",
  106. accountBalance: "TS001",
  107. paymentMethod: "后付费",
  108. state: "1",
  109. validPeriod: "2024-12-54",
  110. activeCards: "0/0",
  111. updateTime: "2024-09-20 08:05:54"
  112. },
  113. {
  114. id: "4", customerCode: "11",
  115. customerName: "泰国景和",
  116. accountBalance: "TS001",
  117. paymentMethod: "后付费",
  118. state: "1",
  119. validPeriod: "2024-12-54",
  120. activeCards: "0/0",
  121. updateTime: "2024-09-20 08:05:54"
  122. },
  123. ]);
  124. // const pagination = reactive({
  125. // // total: 100,
  126. // current: 1,
  127. // pageSize: 10,
  128. // });
  129. const pagination = { pageSize: 10 }
  130. const fetchCustomerList = async () => {
  131. try {
  132. const response = await getCustomerList({
  133. current: pagination.current,
  134. pageSize: pagination.pageSize,
  135. customerName: searchForm.customerName,
  136. operatorType: searchForm.operatorType,
  137. });
  138. if (response.code === 200 && response.data) {
  139. tableData.value = response.data.records;
  140. pagination.total = response.data.total;
  141. pagination.current = response.data.current;
  142. pagination.pageSize = response.data.size;
  143. } else {
  144. Message.error(response.message || 'Failed to fetch customer list');
  145. }
  146. } catch (error) {
  147. Message.error('Failed to fetch customer list');
  148. console.error(error);
  149. }
  150. };
  151. const onPageChange = (page) => {
  152. pagination.current = page;
  153. fetchCustomerList();
  154. };
  155. const newCustomerFormVisible = ref(false);
  156. const editMode = ref(false);
  157. const editData = ref(null);
  158. const searchForm = reactive({
  159. customerName: '',
  160. operatorType: '',
  161. });
  162. const operatorTypeOptions = [
  163. { value: 'domestic', label: t('customer.operatorTypes.domestic') },
  164. { value: 'international', label: t('customer.operatorTypes.international') },
  165. ];
  166. const showNewCustomerForm = () => {
  167. editMode.value = false;
  168. editData.value = null;
  169. newCustomerFormVisible.value = true;
  170. };
  171. const handleEdit = async (record) => {
  172. try {
  173. loading.value = true;
  174. const response = await getCustomer({ id: record.id });
  175. if (response.code === 200) {
  176. // 处理返回的数据,确保数据结构匹配表单
  177. const formattedData = {
  178. userInfo: {
  179. ...response.data.userInfo,
  180. password: '', // 清空密码字段
  181. passwordState: true // 添加密码状态控制
  182. },
  183. customerInfo: {
  184. ...response.data.customerInfo,
  185. // 确保日期格式正确
  186. exTime: response.data.customerInfo.exTime ? new Date(response.data.customerInfo.exTime) : null
  187. },
  188. customerProperty: {
  189. ...response.data.customerProperty,
  190. // 确保数值类型正确
  191. amount: Number(response.data.customerProperty?.amount || 0),
  192. rechargeLimit: Number(response.data.customerProperty?.rechargeLimit || 0),
  193. lineOfCredit: Number(response.data.customerProperty?.lineOfCredit || 0),
  194. smsUnitPrice: Number(response.data.customerProperty?.smsUnitPrice || 0),
  195. iotSmsUnitPrice: Number(response.data.customerProperty?.iotSmsUnitPrice || 0),
  196. paymentMethod: response.data.customerProperty?.paymentMethod || 'prepaid'
  197. },
  198. customerInvoice: {
  199. ...response.data.customerInvoice,
  200. // 处理文件列表
  201. businessLicenseFile: response.data.customerInvoice?.businessLicenseFile ? [response.data.customerInvoice.businessLicenseFile] : [],
  202. taxRegistrationFile: response.data.customerInvoice?.taxRegistrationFile ? [response.data.customerInvoice.taxRegistrationFile] : [],
  203. generalTaxpayerFile: response.data.customerInvoice?.generalTaxpayerFile ? [response.data.customerInvoice.generalTaxpayerFile] : []
  204. },
  205. customerCardQualification: {
  206. ...response.data.customerCardQualification,
  207. // 处理图片和文件字段
  208. blImg: response.data.customerCardQualification?.blImg || null,
  209. legalPersonIdCardImgUp: response.data.customerCardQualification?.legalPersonIdCardImgUp || null,
  210. legalPersonIdCardImgDown: response.data.customerCardQualification?.legalPersonIdCardImgDown || null,
  211. iotImg: response.data.customerCardQualification?.iotImg || null,
  212. contractImg: response.data.customerCardQualification?.contractImg || null,
  213. commitmentImg: response.data.customerCardQualification?.commitmentImg || null,
  214. customerForm: response.data.customerCardQualification?.customerForm || null,
  215. phoneForm: response.data.customerCardQualification?.phoneForm || null,
  216. otherFile: response.data.customerCardQualification?.otherFile || null
  217. },
  218. customerWarningParameter: {
  219. ...response.data.customerWarningParameter,
  220. // 确保数值类型正确
  221. accountBalanceWarning: Number(response.data.customerWarningParameter?.accountBalanceWarning || 0),
  222. reachWarning: Number(response.data.customerWarningParameter?.reachWarning || 0),
  223. stopSending: Number(response.data.customerWarningParameter?.stopSending || 0),
  224. networkDisconnection: Number(response.data.customerWarningParameter?.networkDisconnection || 0),
  225. // 设置默认值
  226. stopSendingAction: response.data.customerWarningParameter?.stopSendingAction || 'noRecovery',
  227. networkDisconnectionAction: response.data.customerWarningParameter?.networkDisconnectionAction || 'noRecovery'
  228. },
  229. customerInterfaceParams: {
  230. ...(response.data.customerInterfaceParams || {}),
  231. // 设置默认值
  232. smsStatusReportUrl: response.data.customerInterfaceParams?.smsStatusReportUrl || '',
  233. reportIp: response.data.customerInterfaceParams?.reportIp || '',
  234. deliveryPriority: response.data.customerInterfaceParams?.deliveryPriority || '',
  235. dataReportUrl: response.data.customerInterfaceParams?.dataReportUrl || ''
  236. }
  237. };
  238. editMode.value = true;
  239. editData.value = formattedData;
  240. newCustomerFormVisible.value = true;
  241. } else {
  242. Message.error(response.message || t('customer.fetchFailed'));
  243. }
  244. } catch (error) {
  245. console.error('获取客户详情时发生错误:', error);
  246. Message.error(t('customer.fetchError'));
  247. } finally {
  248. loading.value = false;
  249. }
  250. };
  251. const handleRecharge = (record) => {
  252. Message.success(`为客户 ${record.customerName} 充值`);
  253. };
  254. const handlePackageManagement = (record) => {
  255. Message.success(`管理客户 ${record.customerName} 的套餐`);
  256. };
  257. const handleNewCustomerSubmit = async (formData) => {
  258. try {
  259. loading.value = true;
  260. let response;
  261. if (editMode.value) {
  262. response = await updateCustomer(formData);
  263. } else {
  264. response = await addCustomer(formData);
  265. }
  266. if (response.code === 200) {
  267. Message.success(editMode.value ? t('customer.updateSuccess') : t('customer.addSuccess'));
  268. newCustomerFormVisible.value = false;
  269. fetchCustomerList();
  270. } else {
  271. Message.error(response.message || (editMode.value ? t('customer.updateFailed') : t('customer.addFailed')));
  272. }
  273. } catch (error) {
  274. console.error(editMode.value ? '更新客户时发生错误:' : '添加客户时发生错误:', error);
  275. Message.error(editMode.value ? t('customer.updateError') : t('customer.addError'));
  276. } finally {
  277. loading.value = false;
  278. }
  279. };
  280. const handleSearch = () => {
  281. pagination.current = 1;
  282. fetchCustomerList();
  283. };
  284. const resetSearch = () => {
  285. Object.keys(searchForm).forEach(key => {
  286. searchForm[key] = '';
  287. });
  288. pagination.current = 1;
  289. fetchCustomerList();
  290. };
  291. const handleBatchDelete = () => {
  292. Message.warning(t('customer.batchDeleteWarning'));
  293. };
  294. const getStatusColor = (state) => {
  295. const stateColors = {
  296. '1': 'green', // 正常 - 绿色
  297. '2': 'red', // 禁用 - 红色
  298. '3': 'orange', // 待审 - 橙色
  299. '4': 'gray' // 暂停 - 灰色
  300. };
  301. return stateColors[state] || 'default';
  302. };
  303. const getStatusText = (state) => {
  304. const stateTexts = {
  305. '1': 'normal', // 正常
  306. '2': 'disabled', // 禁用
  307. '3': 'pending', // 待审
  308. '4': 'suspended' // 暂停
  309. };
  310. return stateTexts[state] || 'undefined';
  311. };
  312. </script>
  313. <style scoped>
  314. .customer-management {
  315. padding: 20px !important;
  316. }
  317. .top-actions {
  318. margin-bottom: 20px;
  319. }
  320. .search-section {
  321. margin-bottom: 20px;
  322. }
  323. .customer-management .arco-table-th {
  324. white-space: nowrap;
  325. }
  326. </style>