index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <script setup lang="tsx">
  2. import { nextTick, ref, useTemplateRef } from 'vue';
  3. import {
  4. fetchGetFailPointsList,
  5. fetchGetPointsList,
  6. fetchGetPointsOutList,
  7. fetchImportPoints
  8. } from '@/service/api/government/points';
  9. import { fetchGetLoginUserList } from '@/service/api/common';
  10. import { useAuth } from '@/hooks/business/auth';
  11. import { commonExport } from '@/utils/common';
  12. import { useTable } from '@/components/zt/Table/hooks/useTable';
  13. import { useModal } from '@/components/zt/Modal/hooks/useModal';
  14. import type { FormSchema } from '@/components/zt/Form/types/form';
  15. import SVGIcon from '@/components/custom/svg-icon.vue';
  16. const importTemplateRef = useTemplateRef('importTemplateRef');
  17. const loading = ref(false);
  18. const ModalColumns: NaiveUI.TableColumn<Api.government.PointsRecharge>[] = [
  19. {
  20. key: 'channelName',
  21. title: '所属企业',
  22. align: 'center'
  23. },
  24. {
  25. key: 'userName',
  26. title: '员工姓名',
  27. align: 'center'
  28. },
  29. {
  30. key: 'userPhone',
  31. title: '员工手机号',
  32. align: 'center'
  33. },
  34. {
  35. key: 'points',
  36. title: '充值积分',
  37. align: 'center'
  38. },
  39. {
  40. key: 'expiryDate',
  41. title: '过期日期',
  42. align: 'center'
  43. },
  44. {
  45. key: 'createTime',
  46. title: '创建时间',
  47. align: 'center'
  48. }
  49. ];
  50. const outColumns: NaiveUI.TableColumn<Api.government.PointsRechargeVO>[] = [
  51. {
  52. key: 'channelName',
  53. title: '所属企业',
  54. align: 'center'
  55. },
  56. {
  57. key: 'totalPoints',
  58. title: '总充值积分',
  59. align: 'center'
  60. },
  61. {
  62. key: 'totalUserCount',
  63. title: '总充值人次',
  64. align: 'center'
  65. },
  66. {
  67. key: 'createTime',
  68. title: '操作时间',
  69. align: 'center'
  70. }
  71. ];
  72. const searchSchemas: FormSchema[] = [
  73. {
  74. field: 'channelNoList',
  75. label: '所属企业',
  76. component: 'ApiSelect',
  77. componentProps: {
  78. api: fetchGetLoginUserList,
  79. labelFeild: 'channelName',
  80. valueFeild: 'channelNo',
  81. multiple: true,
  82. onUpdateValue: () => {
  83. nextTick(() => {
  84. handleSearch();
  85. });
  86. },
  87. getOptions: async (options: any) => {
  88. await setSearchForm({ channelNoList: [options[0].channelNo] });
  89. handleSearch();
  90. }
  91. }
  92. },
  93. {
  94. field: 'userAttrType',
  95. label: '人员属性',
  96. component: 'dictSelect',
  97. componentProps: {
  98. dictCode: 'user_attr_type',
  99. immediate: true
  100. },
  101. show: useAuth().hasAuth('user:attr:type')
  102. },
  103. {
  104. field: 'userPhone',
  105. label: '员工手机号',
  106. component: 'NInput'
  107. },
  108. {
  109. field: 'userName',
  110. label: '员工姓名',
  111. component: 'NInput'
  112. },
  113. {
  114. label: '创建时间',
  115. component: 'NDatePicker',
  116. field: 'createTime',
  117. componentProps: {
  118. type: 'datetimerange',
  119. defaultTime: ['00:00:00', '23:59:59']
  120. }
  121. }
  122. ];
  123. const failColumns: NaiveUI.TableColumn<Api.government.PointsFailureRecordVO>[] = [
  124. {
  125. key: 'index',
  126. title: '序号',
  127. align: 'center',
  128. render(_, rowIndex) {
  129. return rowIndex + 1;
  130. }
  131. },
  132. {
  133. key: 'name',
  134. title: '任务名称',
  135. align: 'center'
  136. },
  137. {
  138. key: 'createTime',
  139. title: '时间',
  140. align: 'center',
  141. render(row) {
  142. return (
  143. <div>
  144. <div>创建时间:{row.createTime}</div>
  145. <div>完成时间:{row.createTime}</div>
  146. </div>
  147. );
  148. }
  149. },
  150. {
  151. key: 'totalUserCount',
  152. title: '操作人',
  153. align: 'center',
  154. render(row) {
  155. return (
  156. <div>
  157. <div>{row.createByRole}</div>
  158. <div>({row.createByName})</div>
  159. </div>
  160. );
  161. }
  162. },
  163. {
  164. key: 'successStatus',
  165. title: '状态',
  166. align: 'center',
  167. width: 240,
  168. render(row) {
  169. return (
  170. <div class={'flex items-center'}>
  171. 共{Number(row.successStatus) + Number(row.failureStatus)}条,成功:{row.successStatus},
  172. <span class={'flex items-center text-red-500'}>
  173. 失败:
  174. {row.failureStatus}
  175. {row.failureStatus != 0 && (
  176. <div onClick={() => hanleExportFailure(row.code)}>
  177. <SVGIcon
  178. icon={'tdesign:download'}
  179. class={'ml-1 cursor-pointer text-20px'}
  180. style={'color:var(--n-color)'}
  181. ></SVGIcon>
  182. </div>
  183. )}
  184. </span>
  185. </div>
  186. );
  187. }
  188. }
  189. ];
  190. const failData = ref<Api.government.PointsFailureRecordVO[]>([]);
  191. const [registerTable, { refresh, setFieldsValue: setSearchValues }] = useTable({
  192. searchFormConfig: {
  193. schemas: [
  194. {
  195. field: 'channelNoList',
  196. label: '所属企业',
  197. component: 'ApiSelect',
  198. componentProps: {
  199. api: fetchGetLoginUserList,
  200. labelFeild: 'channelName',
  201. valueFeild: 'channelNo',
  202. multiple: true,
  203. onUpdateValue: () => {
  204. nextTick(() => {
  205. listHandleSearch();
  206. });
  207. },
  208. getOptions: async (options: any) => {
  209. await setSearchValues({ channelNoList: [options[0].channelNo] });
  210. listHandleSearch();
  211. }
  212. }
  213. },
  214. {
  215. field: 'userAttrType',
  216. label: '人员属性',
  217. component: 'dictSelect',
  218. componentProps: {
  219. dictCode: 'user_attr_type',
  220. immediate: true
  221. },
  222. show: useAuth().hasAuth('user:attr:type')
  223. }
  224. ],
  225. inline: false,
  226. size: 'small',
  227. labelPlacement: 'left',
  228. isFull: false
  229. },
  230. tableConfig: {
  231. keyField: 'id',
  232. title: '充值积分',
  233. showAddButton: false,
  234. defaultParamsNotReset: 'channelIdList'
  235. }
  236. });
  237. const [registerModalTable, { refresh: refreshModal, setFieldsValue, getSeachForm, setTableLoading, getTableData }] =
  238. useTable({
  239. searchFormConfig: {
  240. schemas: searchSchemas,
  241. inline: false,
  242. size: 'small',
  243. labelPlacement: 'left',
  244. isFull: false
  245. },
  246. tableConfig: {
  247. keyField: 'id',
  248. title: '积分列表',
  249. showAddButton: false,
  250. minHeight: 400,
  251. defaultParamsNotReset: 'channelIdList',
  252. fieldMapToTime: [['createTime', ['createTimeStart', 'createTimeEnd']]]
  253. }
  254. });
  255. const [registerModal, { openModal }] = useModal({
  256. title: '充值积分',
  257. height: 800,
  258. showFooter: false,
  259. width: 1200
  260. });
  261. const [registerModalFail, { openModal: openModalFail }] = useModal({
  262. title: '导入记录',
  263. height: 400,
  264. showFooter: false
  265. });
  266. async function handleSubmitImport(file: File) {
  267. const { error } = await fetchImportPoints(file);
  268. if (!error) {
  269. importTemplateRef.value?.closeModal();
  270. refreshModal();
  271. } else {
  272. importTemplateRef.value?.setSubLoading(false);
  273. }
  274. }
  275. function handleOpenPoints() {
  276. importTemplateRef.value?.openModal();
  277. }
  278. async function openImportModal() {
  279. openModalFail();
  280. const { data } = await fetchGetFailPointsList();
  281. failData.value = data as Api.government.PointsFailureRecordVO[];
  282. }
  283. async function hanleExportFailure(code: string) {
  284. if (loading.value) {
  285. window.$message?.error('正在导出,请勿重复点击');
  286. return;
  287. }
  288. loading.value = true;
  289. try {
  290. await commonExport('/smqjh-system/api/v1/pointsFailureRecord/export', { code }, '失败的记录.xlsx');
  291. } finally {
  292. loading.value = false;
  293. }
  294. }
  295. async function exportIntegral() {
  296. setTableLoading(true);
  297. try {
  298. await commonExport('/smqjh-system/api/v1/pointsRecharge/export', getSeachForm(), '积分列表.xlsx');
  299. } finally {
  300. setTableLoading(false);
  301. }
  302. }
  303. function handleSearch() {
  304. refreshModal();
  305. }
  306. function listHandleSearch() {
  307. refresh();
  308. }
  309. async function setSearchForm(value: Recordable) {
  310. await setFieldsValue(value);
  311. }
  312. </script>
  313. <template>
  314. <LayoutTable>
  315. <ZTable :columns="outColumns" :immediate="false" :api="fetchGetPointsOutList" @register="registerTable">
  316. <template #prefix>
  317. <NButton size="small" @click="openModal">充值积分</NButton>
  318. </template>
  319. </ZTable>
  320. <BasicModal @register="registerModal" @after-leave="refresh">
  321. <LayoutTable>
  322. <ZTable
  323. :immediate="false"
  324. :show-table-action="false"
  325. :columns="ModalColumns"
  326. :api="fetchGetPointsList"
  327. @register="registerModalTable"
  328. >
  329. <template #prefix="{ loading: tabloading }">
  330. <NButton
  331. v-if="useAuth().hasAuth('points:user:export')"
  332. size="small"
  333. :loading="tabloading"
  334. :disabled="getTableData().length == 0"
  335. @click="exportIntegral"
  336. >
  337. 导出
  338. </NButton>
  339. <NButton v-if="useAuth().hasAuth('points:user:import')" size="small" @click="handleOpenPoints">
  340. 导入积分
  341. </NButton>
  342. <NButton v-if="useAuth().hasAuth('points:user:import-record')" size="small" @click="openImportModal">
  343. 导入记录
  344. </NButton>
  345. </template>
  346. </ZTable>
  347. </LayoutTable>
  348. </BasicModal>
  349. <BasicModal @register="registerModalFail">
  350. <NDataTable :columns="failColumns" :data="failData" size="small" remote class="sm:h-full" />
  351. </BasicModal>
  352. <ZImportTemplate
  353. ref="importTemplateRef"
  354. url="/smqjh-system/api/v1/pointsRecharge/exportTemplate"
  355. template-text="导入积分模版.xlsx"
  356. modal-text="导入积分"
  357. @submit="handleSubmitImport"
  358. ></ZImportTemplate>
  359. </LayoutTable>
  360. </template>
  361. <style scoped></style>