index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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="remoteSearchPartner"
  28. :loading="customerLoading"
  29. clearable
  30. style="width: 100%"
  31. @change="handlePartnerChange"
  32. >
  33. <el-option v-for="item in partnerOptions" :key="item.id" :label="item.partnerName" :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 { getListByPartnerName } from '@/api/partner/merchant';
  107. import { PartnerMerchantVO } from '@/api/partner/merchant/types';
  108. import AddDrawer from './addDrawer.vue';
  109. import DetailDrawer from './detailDrawer.vue';
  110. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  111. const { invoice_status } = toRefs<any>(proxy?.useDict('invoice_status'));
  112. const addDrawerRef = ref<InstanceType<typeof AddDrawer>>();
  113. const detailDrawerRef = ref<InstanceType<typeof DetailDrawer>>();
  114. const statementInvoiceList = ref<StatementInvoiceVO[]>([]);
  115. const buttonLoading = ref(false);
  116. const loading = ref(true);
  117. const showSearch = ref(true);
  118. const ids = ref<Array<string | number>>([]);
  119. const single = ref(true);
  120. const multiple = ref(true);
  121. const total = ref(0);
  122. const dateRange = ref<[DateModelType, DateModelType]>(['', '']);
  123. const queryFormRef = ref<ElFormInstance>();
  124. const statementInvoiceFormRef = ref<ElFormInstance>();
  125. const customerLoading = ref(false);
  126. const customerOptions = ref<CustomerInfoVO[]>([]);
  127. const partnerOptions = ref<PartnerMerchantVO[]>([]);
  128. const dialog = reactive<DialogOption>({
  129. visible: false,
  130. title: ''
  131. });
  132. // 发票单状态枚举
  133. enum InvoiceStatus {
  134. DRAFT = 0, // 待确认
  135. PENDING = 1, // 待对账
  136. CONFIRMED = 2, // 已对账
  137. OBSOLETE = 3 // 已作废
  138. }
  139. // 按钮配置类型
  140. interface ActionButton {
  141. action: string;
  142. label: string;
  143. handler: (row: StatementInvoiceVO) => void;
  144. permission: string;
  145. }
  146. const initFormData: StatementInvoiceForm = {
  147. id: undefined,
  148. statementInvoiceNo: undefined,
  149. customerId: undefined,
  150. customerNo: undefined,
  151. customerName: undefined,
  152. invoiceAmount: undefined,
  153. invoiceStatus: undefined,
  154. invoiceTime: undefined,
  155. rejectRemark: undefined,
  156. remark: undefined
  157. };
  158. const data = reactive<PageData<StatementInvoiceForm, StatementInvoiceQuery>>({
  159. form: { ...initFormData },
  160. queryParams: {
  161. pageNum: 1,
  162. pageSize: 10,
  163. statementInvoiceNo: undefined,
  164. customerId: undefined,
  165. customerNo: undefined,
  166. customerName: undefined,
  167. invoiceAmount: undefined,
  168. invoiceStatus: undefined,
  169. invoiceTime: undefined,
  170. rejectRemark: undefined,
  171. platformCode: undefined,
  172. params: {}
  173. },
  174. rules: {}
  175. });
  176. const { queryParams, form, rules } = toRefs(data);
  177. /** 查询销售发票主列表 */
  178. const getList = async () => {
  179. loading.value = true;
  180. const res = await listStatementInvoice(proxy?.addDateRange(queryParams.value, dateRange.value));
  181. statementInvoiceList.value = res.rows;
  182. total.value = res.total;
  183. loading.value = false;
  184. };
  185. /** 远程搜索客户 */
  186. const remoteSearchCustomer = async (query: string) => {
  187. if (query) {
  188. customerLoading.value = true;
  189. try {
  190. const res = await getListBycustomerName(query);
  191. customerOptions.value = res.data;
  192. } catch (error) {
  193. console.error(error);
  194. } finally {
  195. customerLoading.value = false;
  196. }
  197. } else {
  198. customerOptions.value = [];
  199. }
  200. };
  201. /** 客户变更 */
  202. const handleCustomerChange = async (customerId: string | number) => {
  203. if (customerId) {
  204. const customer = customerOptions.value.find((item) => item.id === customerId);
  205. if (customer) {
  206. form.value.customerName = customer.customerName;
  207. form.value.customerNo = customer.customerNo;
  208. }
  209. } else {
  210. form.value.customerName = undefined;
  211. form.value.customerNo = undefined;
  212. }
  213. };
  214. /** 远程搜索伙伴商 */
  215. const remoteSearchPartner = async (query: string) => {
  216. if (query) {
  217. customerLoading.value = true;
  218. try {
  219. const res = await getListByPartnerName(query);
  220. partnerOptions.value = res.data;
  221. } catch (error) {
  222. console.error(error);
  223. } finally {
  224. customerLoading.value = false;
  225. }
  226. } else {
  227. customerOptions.value = [];
  228. }
  229. };
  230. /** 伙伴商变更 */
  231. const handlePartnerChange = async (customerId: string | number) => {
  232. if (customerId) {
  233. const partner = partnerOptions.value.find((item) => item.id === customerId);
  234. if (partner) {
  235. form.value.customerName = partner.partnerName;
  236. form.value.customerNo = partner.partnerNo;
  237. }
  238. // 预加载订单列表
  239. } else {
  240. form.value.customerName = undefined;
  241. form.value.customerNo = undefined;
  242. }
  243. };
  244. /** 表单重置 */
  245. const reset = () => {
  246. form.value = { ...initFormData };
  247. statementInvoiceFormRef.value?.resetFields();
  248. };
  249. /** 搜索按钮操作 */
  250. const handleQuery = () => {
  251. queryParams.value.pageNum = 1;
  252. getList();
  253. };
  254. /** 重置按钮操作 */
  255. const resetQuery = () => {
  256. dateRange.value = ['', ''];
  257. queryFormRef.value?.resetFields();
  258. handleQuery();
  259. };
  260. /** 多选框选中数据 */
  261. const handleSelectionChange = (selection: StatementInvoiceVO[]) => {
  262. ids.value = selection.map((item) => item.id);
  263. single.value = selection.length != 1;
  264. multiple.value = !selection.length;
  265. };
  266. /** 新增按钮操作 */
  267. const handleAdd = () => {
  268. reset();
  269. // 打开抽屉
  270. addDrawerRef.value?.open();
  271. };
  272. /** 修改按钮操作 */
  273. const handleUpdate = async (row?: StatementInvoiceVO) => {
  274. const _id = row?.id || ids.value[0];
  275. const res = await getStatementInvoice(_id);
  276. // 打开抽屉,传递id和数据
  277. addDrawerRef.value?.open(_id, res.data);
  278. };
  279. /** 查看按钮操作 */
  280. const handleDetail = async (row?: StatementInvoiceVO) => {
  281. const _id = row?.id || ids.value[0];
  282. const res = await getStatementInvoice(_id);
  283. // 打开抽屉,传递id和数据
  284. detailDrawerRef.value?.open(_id, res.data);
  285. };
  286. /** 发送按钮操作 */
  287. const handleSend = async (row?: StatementInvoiceVO) => {
  288. const _no = row?.statementInvoiceNo;
  289. const _ids = row?.id || ids.value;
  290. const oldValue = row.invoiceStatus; // 保存旧值
  291. await proxy?.$modal.confirm('是否确认当前发票编号【' + _no + '】吗?').finally(() => (loading.value = false));
  292. //todo 发送
  293. try {
  294. await changeStatus(row.id, '2'); // 传新值 1 待开票
  295. } catch (e) {
  296. // 恢复旧值
  297. row.invoiceStatus = oldValue;
  298. }
  299. proxy?.$modal.msgSuccess('发送成功');
  300. await getList();
  301. };
  302. /** 撤回按钮操作 */
  303. const handleWithdraw = async (row?: StatementInvoiceVO) => {
  304. const _no = row?.statementInvoiceNo;
  305. const _ids = row?.id;
  306. const oldValue = row.invoiceStatus; // 保存旧值
  307. await proxy?.$modal.confirm('是否撤回当前发票编号【' + _no + '】吗?').finally(() => (loading.value = false));
  308. //todo 撤回
  309. try {
  310. await changeStatus(_ids, '0'); // 传新值 0 待确认
  311. } catch (e) {
  312. // 恢复旧值
  313. row.invoiceStatus = oldValue;
  314. }
  315. proxy?.$modal.msgSuccess('撤回成功');
  316. await getList();
  317. };
  318. /** 作废按钮操作 */
  319. const handleObsolete = async (row?: StatementInvoiceVO) => {
  320. const _no = row?.statementInvoiceNo;
  321. const oldValue = row.invoiceStatus; // 保存旧值
  322. await proxy?.$modal.confirm('是否作废当前发票编号【' + _no + '】吗?').finally(() => (loading.value = false));
  323. await changeStatus(row.id, '3'); // 传新值 3 - 作废
  324. proxy?.$modal.msgSuccess('作废成功');
  325. await getList();
  326. };
  327. // 按钮配置映射:状态 -> 可用按钮列表
  328. const buttonConfigMap: Record<number, ActionButton[]> = {
  329. [InvoiceStatus.DRAFT]: [
  330. { action: 'detail', label: '查看', handler: handleDetail, permission: 'bill:statementInvoice:edit' },
  331. { action: 'edit', label: '编辑', handler: handleUpdate, permission: 'bill:statementInvoice:edit' },
  332. { action: 'send', label: '确认', handler: handleSend, permission: 'bill:statementInvoice:edit' },
  333. { action: 'withdraw', label: '撤回', handler: handleWithdraw, permission: 'bill:statementInvoice:edit' },
  334. { action: 'obsolete', label: '作废', handler: handleObsolete, permission: 'bill:statementInvoice:remove' }
  335. ],
  336. [InvoiceStatus.PENDING]: [
  337. { action: 'detail', label: '查看', handler: handleDetail, permission: 'bill:statementInvoice:edit' },
  338. { action: 'edit', label: '编辑', handler: handleUpdate, permission: 'bill:statementInvoice:edit' },
  339. { action: 'withdraw', label: '撤回', handler: handleWithdraw, permission: 'bill:statementInvoice:edit' },
  340. { action: 'obsolete', label: '作废', handler: handleObsolete, permission: 'bill:statementInvoice:remove' }
  341. ],
  342. [InvoiceStatus.CONFIRMED]: [
  343. { action: 'detail', label: '查看', handler: handleDetail, permission: 'bill:statementInvoice:edit' },
  344. { action: 'obsolete', label: '作废', handler: handleObsolete, permission: 'bill:statementInvoice:remove' }
  345. ],
  346. [InvoiceStatus.OBSOLETE]: [{ action: 'detail', label: '查看', handler: handleDetail, permission: 'bill:statementInvoice:edit' }]
  347. };
  348. /**
  349. * 根据对发票状态获取可用按钮列表
  350. * @param status 发票单状态
  351. * @returns 可用按钮配置数组
  352. */
  353. const getAvailableButtons = (status: number): ActionButton[] => {
  354. return buttonConfigMap[status] || [{ action: 'detail', label: '查看', handler: handleDetail, permission: 'bill:statementInvoice:edit' }];
  355. };
  356. /** 导出按钮操作 */
  357. const handleExport = () => {
  358. proxy?.download(
  359. 'bill/statementInvoice/export',
  360. {
  361. ...queryParams.value
  362. },
  363. `statementInvoice_${new Date().getTime()}.xlsx`
  364. );
  365. };
  366. onMounted(() => {
  367. getList();
  368. });
  369. </script>