index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <template>
  2. <div class="p-2">
  3. <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
  4. <div v-show="showSearch" class="mb-[10px]">
  5. <el-card shadow="hover">
  6. <el-form ref="queryFormRef" :model="queryParams" :inline="true">
  7. <el-form-item label="对账单号" prop="statementOrderNo">
  8. <el-input v-model="queryParams.statementOrderNo" placeholder="请输入对账单号" clearable @keyup.enter="handleQuery" />
  9. </el-form-item>
  10. <el-form-item label="对账日期" prop="statementDate">
  11. <el-date-picker
  12. v-model="dateRange"
  13. type="daterange"
  14. range-separator="至"
  15. start-placeholder="开始时间"
  16. end-placeholder="结束时间"
  17. value-format="YYYY-MM-DD"
  18. />
  19. </el-form-item>
  20. <el-form-item label="客户名称" prop="customerName">
  21. <el-input v-model="queryParams.customerName" placeholder="请输入客户名称" clearable @keyup.enter="handleQuery" />
  22. </el-form-item>
  23. <!-- <el-form-item label="订单编号" prop="orderNo">
  24. <el-input v-model="queryParams.orderNo" placeholder="请输入客户名称" clearable @keyup.enter="handleQuery" />
  25. </el-form-item> -->
  26. <el-form-item label="对账状态" prop="statementStatus">
  27. <el-select v-model="queryParams.statementStatus" placeholder="请选择对账状态" clearable>
  28. <el-option v-for="dict in statement_status" :key="dict.value" :label="dict.label" :value="dict.value" />
  29. </el-select>
  30. </el-form-item>
  31. <el-form-item label="支付状态" prop="isPaymentStatus">
  32. <el-select v-model="queryParams.isPaymentStatus" placeholder="请选择付款状态" clearable>
  33. <el-option v-for="dict in payment_status" :key="dict.value" :label="dict.label" :value="dict.value" />
  34. </el-select>
  35. </el-form-item>
  36. <el-form-item>
  37. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  38. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  39. </el-form-item>
  40. </el-form>
  41. </el-card>
  42. </div>
  43. </transition>
  44. <el-card shadow="never">
  45. <template #header>
  46. <el-row :gutter="10" class="mb8">
  47. <el-col :span="22"> 对账管理信息列表 </el-col>
  48. <el-col :span="1.5">
  49. <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['bill:statementOrder:add']">新增</el-button>
  50. </el-col>
  51. </el-row>
  52. </template>
  53. <el-table v-loading="loading" border :data="statementOrderList" @selection-change="handleSelectionChange">
  54. <el-table-column type="selection" width="55" align="center" />
  55. <el-table-column label="对账单号" align="center" prop="statementOrderNo" />
  56. <el-table-column label="对账日期" align="center" prop="statementDate" width="180">
  57. <template #default="scope">
  58. <span>{{ parseTime(scope.row.statementDate, '{y}-{m}-{d}') }}</span>
  59. </template>
  60. </el-table-column>
  61. <el-table-column label="对账金额" align="center" prop="amount" />
  62. <el-table-column label="客户编号" align="center" prop="customerNo" />
  63. <el-table-column label="客户名称" align="center" prop="customerName" />
  64. <el-table-column label="对账状态" align="center" prop="statementStatus">
  65. <template #default="scope">
  66. <dict-tag :options="statement_status" :value="scope.row.statementStatus" />
  67. </template>
  68. </el-table-column>
  69. <el-table-column label="开票状态" align="center" prop="isInvoiceStatus">
  70. <template #default="scope">
  71. <dict-tag :options="invoice_issuance_status" :value="scope.row.isInvoiceStatus" />
  72. </template>
  73. </el-table-column>
  74. <el-table-column label="支付状态" align="center" prop="isPaymentStatus">
  75. <template #default="scope">
  76. <dict-tag :options="payment_status" :value="scope.row.isPaymentStatus" />
  77. </template>
  78. </el-table-column>
  79. <el-table-column label="操作" align="center" width="300" fixed="right">
  80. <template #default="scope">
  81. <template v-for="btn in getAvailableButtons(scope.row.statementStatus)" :key="btn.action">
  82. <el-button link type="primary" @click="btn.handler(scope.row)" v-hasPermi="[btn.permission]">
  83. {{ btn.label }}
  84. </el-button>
  85. </template>
  86. </template>
  87. </el-table-column>
  88. </el-table>
  89. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  90. </el-card>
  91. <!--新增对账的抽屉 -->
  92. <add-drawer ref="addDrawerRef" @success="getList" />
  93. <!--查看对账的抽屉 -->
  94. <detail-drawer ref="detailDrawerRef" @success="getList" />
  95. </div>
  96. </template>
  97. <script setup name="StatementOrder" lang="ts">
  98. import { listStatementOrder, getStatementOrder, changeStatus } from '@/api/bill/statementOrder';
  99. import { StatementOrderVO, StatementOrderQuery, StatementOrderForm } from '@/api/bill/statementOrder/types';
  100. import AddDrawer from './addDrawer.vue';
  101. import DetailDrawer from './detailDrawer.vue';
  102. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  103. const { statement_status, statement_order_type, invoice_issuance_status, payment_status } = toRefs<any>(
  104. proxy?.useDict('statement_status', 'statement_order_type', 'invoice_issuance_status', 'payment_status')
  105. );
  106. const statementOrderList = ref<StatementOrderVO[]>([]);
  107. const buttonLoading = ref(false);
  108. const loading = ref(true);
  109. const showSearch = ref(true);
  110. const ids = ref<Array<string | number>>([]);
  111. const single = ref(true);
  112. const multiple = ref(true);
  113. const total = ref(0);
  114. const addDrawerRef = ref<InstanceType<typeof AddDrawer>>();
  115. const detailDrawerRef = ref<InstanceType<typeof DetailDrawer>>();
  116. const queryFormRef = ref<ElFormInstance>();
  117. const statementOrderFormRef = ref<ElFormInstance>();
  118. const dateRange = ref<[DateModelType, DateModelType]>(['', '']);
  119. const dialog = reactive<DialogOption>({
  120. visible: false,
  121. title: ''
  122. });
  123. const initFormData: StatementOrderForm = {
  124. id: undefined,
  125. statementOrderNo: undefined,
  126. customerId: undefined,
  127. customerNo: undefined,
  128. customerName: undefined,
  129. amount: undefined,
  130. statementSelf: undefined,
  131. statementSelfPhone: undefined,
  132. statementStatus: undefined,
  133. isPaymentStatus: undefined,
  134. isInvoiceStatus: undefined,
  135. statementDate: undefined,
  136. annexAddress: undefined,
  137. rejectRemark: undefined,
  138. remark: undefined,
  139. detailList: [],
  140. productList: []
  141. };
  142. const data = reactive<PageData<StatementOrderForm, StatementOrderQuery>>({
  143. form: { ...initFormData },
  144. queryParams: {
  145. pageNum: 1,
  146. pageSize: 10,
  147. statementOrderNo: undefined,
  148. customerId: undefined,
  149. customerNo: undefined,
  150. customerName: undefined,
  151. amount: undefined,
  152. statementSelf: undefined,
  153. statementSelfPhone: undefined,
  154. statementStatus: undefined,
  155. isPaymentStatus: undefined,
  156. isInvoiceStatus: undefined,
  157. statementDate: undefined,
  158. annexAddress: undefined,
  159. rejectRemark: undefined,
  160. platformCode: undefined,
  161. params: {}
  162. },
  163. rules: {}
  164. });
  165. const { queryParams, form, rules } = toRefs(data);
  166. // 对账单状态枚举
  167. enum StatementStatus {
  168. DRAFT = 0, // 待确认
  169. PENDING = 1, // 待对账
  170. CONFIRMED = 2, // 已对账
  171. REJECTED = 3, // 已驳回
  172. OBSOLETE = 4 // 已作废
  173. }
  174. // 按钮配置类型
  175. interface ActionButton {
  176. action: string;
  177. label: string;
  178. handler: (row: StatementOrderVO) => void;
  179. permission: string;
  180. }
  181. /** 查询对账单主列表 */
  182. const getList = async () => {
  183. loading.value = true;
  184. const res = await listStatementOrder(proxy?.addDateRange(queryParams.value, dateRange.value));
  185. statementOrderList.value = res.rows;
  186. total.value = res.total;
  187. loading.value = false;
  188. };
  189. /** 表单重置 */
  190. const reset = () => {
  191. form.value = { ...initFormData };
  192. statementOrderFormRef.value?.resetFields();
  193. };
  194. /** 搜索按钮操作 */
  195. const handleQuery = () => {
  196. queryParams.value.pageNum = 1;
  197. getList();
  198. };
  199. /** 重置按钮操作 */
  200. const resetQuery = () => {
  201. dateRange.value = ['', ''];
  202. queryFormRef.value?.resetFields();
  203. handleQuery();
  204. };
  205. /** 多选框选中数据 */
  206. const handleSelectionChange = (selection: StatementOrderVO[]) => {
  207. ids.value = selection.map((item) => item.id);
  208. single.value = selection.length != 1;
  209. multiple.value = !selection.length;
  210. };
  211. /** 新增按钮操作 */
  212. const handleAdd = () => {
  213. reset();
  214. // 打开抽屉
  215. addDrawerRef.value?.open();
  216. };
  217. /** 修改按钮操作 */
  218. const handleUpdate = async (row?: StatementOrderVO) => {
  219. const _id = row?.id || ids.value[0];
  220. const res = await getStatementOrder(_id);
  221. // 打开抽屉,传递id和数据
  222. addDrawerRef.value?.open(_id, res.data);
  223. };
  224. /** 查看按钮操作 */
  225. const handleDetail = async (row?: StatementOrderVO) => {
  226. const _id = row?.id || ids.value[0];
  227. const res = await getStatementOrder(_id);
  228. // 打开抽屉,传递id和数据
  229. detailDrawerRef.value?.open(_id, res.data);
  230. };
  231. /** 发送按钮操作 */
  232. const handleSend = async (row?: StatementOrderVO) => {
  233. const _no = row?.statementOrderNo;
  234. const _ids = row?.id;
  235. const oldValue = row.statementStatus; // 保存旧值
  236. await proxy?.$modal.confirm('是否发送当前账单编号【' + _no + '】吗?').finally(() => (loading.value = false));
  237. //todo 发送
  238. try {
  239. await changeStatus(_ids, '1'); // 传新值 1 待确认
  240. } catch (e) {
  241. // 恢复旧值
  242. row.statementStatus = oldValue;
  243. }
  244. proxy?.$modal.msgSuccess('发送成功');
  245. await getList();
  246. };
  247. /** 撤回按钮操作 */
  248. const handleWithdraw = async (row?: StatementOrderVO) => {
  249. const _no = row?.statementOrderNo;
  250. const _ids = row?.id;
  251. const oldValue = row.statementStatus; // 保存旧值
  252. await proxy?.$modal.confirm('是否撤回当前账单编号【' + _no + '】吗?').finally(() => (loading.value = false));
  253. //todo 撤回
  254. try {
  255. await changeStatus(_ids, '0'); // 传新值 0 待确认
  256. } catch (e) {
  257. // 恢复旧值
  258. row.statementStatus = oldValue;
  259. }
  260. proxy?.$modal.msgSuccess('撤回成功');
  261. await getList();
  262. };
  263. /** 作废按钮操作 */
  264. const handleObsolete = async (row?: StatementOrderVO) => {
  265. const _no = row?.statementOrderNo;
  266. const oldValue = row.statementStatus; // 保存旧值
  267. await proxy?.$modal.confirm('是否作废当前账单编号【' + _no + '】吗?').finally(() => (loading.value = false));
  268. await changeStatus(row.id, '4'); // 传新值 4 - 作废
  269. proxy?.$modal.msgSuccess('作废成功');
  270. await getList();
  271. };
  272. /** 导出按钮操作 */
  273. const handleExport = () => {
  274. proxy?.download(
  275. 'bill/statementOrder/export',
  276. {
  277. ...queryParams.value
  278. },
  279. `statementOrder_${new Date().getTime()}.xlsx`
  280. );
  281. };
  282. // 按钮配置映射:状态 -> 可用按钮列表
  283. const buttonConfigMap: Record<number, ActionButton[]> = {
  284. [StatementStatus.DRAFT]: [
  285. { action: 'detail', label: '查看', handler: handleDetail, permission: 'bill:statementOrder:edit' },
  286. { action: 'edit', label: '编辑', handler: handleUpdate, permission: 'bill:statementOrder:edit' },
  287. { action: 'send', label: '发送对账单', handler: handleSend, permission: 'bill:statementOrder:edit' },
  288. { action: 'withdraw', label: '撤回', handler: handleWithdraw, permission: 'bill:statementOrder:edit' },
  289. { action: 'obsolete', label: '作废', handler: handleObsolete, permission: 'bill:statementOrder:remove' }
  290. ],
  291. [StatementStatus.PENDING]: [
  292. { action: 'detail', label: '查看', handler: handleDetail, permission: 'bill:statementOrder:edit' },
  293. { action: 'edit', label: '编辑', handler: handleUpdate, permission: 'bill:statementOrder:edit' },
  294. { action: 'withdraw', label: '撤回', handler: handleWithdraw, permission: 'bill:statementOrder:edit' },
  295. { action: 'obsolete', label: '作废', handler: handleObsolete, permission: 'bill:statementOrder:remove' }
  296. ],
  297. [StatementStatus.CONFIRMED]: [
  298. { action: 'detail', label: '查看', handler: handleDetail, permission: 'bill:statementOrder:edit' },
  299. { action: 'obsolete', label: '作废', handler: handleObsolete, permission: 'bill:statementOrder:remove' }
  300. ],
  301. [StatementStatus.REJECTED]: [
  302. { action: 'detail', label: '查看', handler: handleDetail, permission: 'bill:statementOrder:edit' },
  303. { action: 'edit', label: '编辑', handler: handleUpdate, permission: 'bill:statementOrder:edit' },
  304. { action: 'send', label: '发送对账单', handler: handleSend, permission: 'bill:statementOrder:edit' },
  305. { action: 'obsolete', label: '作废', handler: handleObsolete, permission: 'bill:statementOrder:remove' }
  306. ],
  307. [StatementStatus.OBSOLETE]: [{ action: 'detail', label: '查看', handler: handleDetail, permission: 'bill:statementOrder:edit' }]
  308. };
  309. /**
  310. * 根据对账单状态获取可用按钮列表
  311. * @param status 对账单状态
  312. * @returns 可用按钮配置数组
  313. */
  314. const getAvailableButtons = (status: number): ActionButton[] => {
  315. return buttonConfigMap[status] || [{ action: 'detail', label: '查看', handler: handleDetail, permission: 'bill:statementOrder:edit' }];
  316. };
  317. onMounted(() => {
  318. getList();
  319. });
  320. </script>