index.vue 14 KB

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