index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <script setup lang="tsx">
  2. import { ref, useTemplateRef } from 'vue';
  3. import {
  4. fetchGetFailPointsList,
  5. fetchGetPointsList,
  6. fetchGetPointsOutList,
  7. fetchImportPoints
  8. } from '@/service/api/government/points';
  9. import { useTable } from '@/components/zt/Table/hooks/useTable';
  10. import { useModal } from '@/components/zt/Modal/hooks/useModal';
  11. import type { FormSchema } from '@/components/zt/Form/types/form';
  12. import SVGIcon from '@/components/custom/svg-icon.vue';
  13. const importTemplateRef = useTemplateRef('importTemplateRef');
  14. const ModalColumns: NaiveUI.TableColumn<Api.government.PointsRecharge>[] = [
  15. {
  16. key: 'channelName',
  17. title: '所属企业',
  18. align: 'center'
  19. },
  20. {
  21. key: 'userName',
  22. title: '员工姓名',
  23. align: 'center'
  24. },
  25. {
  26. key: 'userPhone',
  27. title: '员工手机号',
  28. align: 'center'
  29. },
  30. {
  31. key: 'points',
  32. title: '充值积分',
  33. align: 'center'
  34. },
  35. {
  36. key: 'expiryDate',
  37. title: '过期日期',
  38. align: 'center'
  39. },
  40. {
  41. key: 'createTime',
  42. title: '创建时间',
  43. align: 'center'
  44. }
  45. ];
  46. const outColumns: NaiveUI.TableColumn<Api.government.PointsRechargeVO>[] = [
  47. {
  48. key: 'channelName',
  49. title: '所属企业',
  50. align: 'center'
  51. },
  52. {
  53. key: 'totalPoints',
  54. title: '总充值积分',
  55. align: 'center'
  56. },
  57. {
  58. key: 'totalUserCount',
  59. title: '总充值人次',
  60. align: 'center'
  61. },
  62. {
  63. key: 'createTime',
  64. title: '操作时间',
  65. align: 'center'
  66. }
  67. ];
  68. const searchSchemas: FormSchema[] = [
  69. {
  70. field: 'channelName',
  71. label: '企业名称',
  72. component: 'NInput'
  73. },
  74. {
  75. field: 'userPhone',
  76. label: '员工手机号',
  77. component: 'NInput'
  78. }
  79. ];
  80. const failColumns: NaiveUI.TableColumn<Api.government.PointsFailureRecordVO>[] = [
  81. {
  82. key: 'index',
  83. title: '序号',
  84. align: 'center',
  85. render(_, rowIndex) {
  86. return rowIndex + 1;
  87. }
  88. },
  89. {
  90. key: 'name',
  91. title: '任务名称',
  92. align: 'center'
  93. },
  94. {
  95. key: 'createTime',
  96. title: '时间',
  97. align: 'center',
  98. render(row) {
  99. return (
  100. <div>
  101. <div>创建时间:{row.createTime}</div>
  102. <div>完成时间:{row.createTime}</div>
  103. </div>
  104. );
  105. }
  106. },
  107. {
  108. key: 'totalUserCount',
  109. title: '操作人',
  110. align: 'center',
  111. render(row) {
  112. return (
  113. <div>
  114. <div>{row.createByRole}</div>
  115. <div>({row.createByName})</div>
  116. </div>
  117. );
  118. }
  119. },
  120. {
  121. key: 'successStatus',
  122. title: '状态',
  123. align: 'center',
  124. width: 240,
  125. render(row) {
  126. return (
  127. <div class={'flex items-center'}>
  128. 共{Number(row.successStatus) + Number(row.failureStatus)}条,成功:{row.successStatus},
  129. <span class={'flex items-center text-red-500'}>
  130. 失败:
  131. {row.failureStatus}
  132. {row.failureStatus != 0 && (
  133. <div onClick={() => hanleExportFailure(row.code)}>
  134. <SVGIcon
  135. icon={'tdesign:download'}
  136. class={'ml-1 cursor-pointer text-20px'}
  137. style={'color:var(--n-color)'}
  138. ></SVGIcon>
  139. </div>
  140. )}
  141. </span>
  142. </div>
  143. );
  144. }
  145. }
  146. ];
  147. const failData = ref<Api.government.PointsFailureRecordVO[]>([]);
  148. const [registerTable, { refresh }] = useTable({
  149. searchFormConfig: {
  150. schemas: searchSchemas.slice(0, 1),
  151. inline: false,
  152. size: 'small',
  153. labelPlacement: 'left',
  154. isFull: false
  155. },
  156. tableConfig: {
  157. keyField: 'id',
  158. title: '充值积分',
  159. showAddButton: false
  160. }
  161. });
  162. const [registerModalTable, { refresh: refreshModal }] = useTable({
  163. searchFormConfig: {
  164. schemas: searchSchemas,
  165. inline: false,
  166. size: 'small',
  167. labelPlacement: 'left',
  168. isFull: false
  169. },
  170. tableConfig: {
  171. keyField: 'id',
  172. title: '积分列表',
  173. showAddButton: false,
  174. minHeight: 400
  175. }
  176. });
  177. const [registerModal, { openModal }] = useModal({
  178. title: '充值积分',
  179. height: 800,
  180. showFooter: false,
  181. width: 1200
  182. });
  183. const [registerModalFail, { openModal: openModalFail }] = useModal({
  184. title: '导入记录',
  185. height: 400,
  186. showFooter: false
  187. });
  188. async function handleSubmitImport(file: File) {
  189. const { error } = await fetchImportPoints(file);
  190. if (!error) {
  191. importTemplateRef.value?.closeModal();
  192. refreshModal();
  193. } else {
  194. importTemplateRef.value?.setSubLoading(false);
  195. }
  196. }
  197. function handleOpenPoints() {
  198. importTemplateRef.value?.openModal();
  199. }
  200. async function openImportModal() {
  201. openModalFail();
  202. const { data } = await fetchGetFailPointsList();
  203. failData.value = data as Api.government.PointsFailureRecordVO[];
  204. }
  205. function hanleExportFailure(code: string) {
  206. window.open(`${import.meta.env.VITE_SERVICE_BASE_URL}/platform/pointsFailureRecord/export?code=${code}`, '_blank');
  207. }
  208. </script>
  209. <template>
  210. <LayoutTable>
  211. <ZTable :show-table-action="false" :columns="outColumns" :api="fetchGetPointsOutList" @register="registerTable">
  212. <template #prefix>
  213. <NButton size="small" @click="openModal">充值积分</NButton>
  214. </template>
  215. </ZTable>
  216. <BasicModal @register="registerModal" @after-leave="refresh">
  217. <LayoutTable>
  218. <ZTable
  219. :show-table-action="false"
  220. :columns="ModalColumns"
  221. :api="fetchGetPointsList"
  222. @register="registerModalTable"
  223. >
  224. <template #prefix>
  225. <NButton size="small" @click="handleOpenPoints">导入积分</NButton>
  226. <NButton size="small" @click="openImportModal">导入记录</NButton>
  227. </template>
  228. </ZTable>
  229. </LayoutTable>
  230. </BasicModal>
  231. <BasicModal @register="registerModalFail">
  232. <NDataTable :columns="failColumns" :data="failData" size="small" remote class="sm:h-full" />
  233. </BasicModal>
  234. <ZImportTemplate
  235. ref="importTemplateRef"
  236. url="/platform/pointsRecharge/exportTemplate"
  237. template-text="导入积分模版.xlsx"
  238. modal-text="导入积分"
  239. @submit="handleSubmitImport"
  240. ></ZImportTemplate>
  241. </LayoutTable>
  242. </template>
  243. <style scoped></style>