index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <template>
  2. <div class="page-container">
  3. <PageTitle title="对账单管理" />
  4. <!-- 搜索条件区域 -->
  5. <div class="search-area">
  6. <el-form :model="searchForm" inline>
  7. <el-form-item label="对账编号">
  8. <el-input v-model="searchForm.keyword" placeholder="请输入对账编号" clearable @clear="handleSearch" />
  9. </el-form-item>
  10. <el-form-item label="对账日期">
  11. <el-date-picker
  12. v-model="searchForm.dateRange"
  13. type="daterange"
  14. range-separator="至"
  15. start-placeholder="开始日期"
  16. end-placeholder="结束日期"
  17. value-format="YYYY-MM-DD"
  18. @change="handleSearch"
  19. />
  20. </el-form-item>
  21. <el-form-item label="对账状态">
  22. <el-select v-model="searchForm.billStatus" placeholder="请选择对账状态" clearable @change="handleSearch">
  23. <el-option v-for="item in billStatusOptions" :key="item.value" :label="item.label" :value="item.value" />
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item label="开票状态">
  27. <el-select v-model="searchForm.invoiceStatus" placeholder="请选择开票状态" clearable @change="handleSearch">
  28. <el-option v-for="item in invoiceStatusOptions" :key="item.value" :label="item.label" :value="item.value" />
  29. </el-select>
  30. </el-form-item>
  31. <el-form-item label="支付状态">
  32. <el-select v-model="searchForm.payStatus" placeholder="请选择支付状态" clearable @change="handleSearch">
  33. <el-option v-for="item in payStatusOptions" :key="item.value" :label="item.label" :value="item.value" />
  34. </el-select>
  35. </el-form-item>
  36. <el-form-item>
  37. <el-button type="primary" @click="handleSearch">搜索</el-button>
  38. <el-button @click="handleReset">重置</el-button>
  39. </el-form-item>
  40. </el-form>
  41. </div>
  42. <el-table
  43. v-loading="loading"
  44. :data="tableData"
  45. border
  46. style="width: 100%"
  47. @selection-change="handleSelectionChange"
  48. @select="handleSelect"
  49. @select-all="handleSelectAll"
  50. ref="tableRef"
  51. >
  52. <el-table-column type="selection" width="55" align="center" />
  53. <el-table-column prop="billNo" label="对账编号" min-width="130" align="center" />
  54. <el-table-column prop="billDate" label="对账日期" min-width="110" align="center">
  55. <template #default="{ row }">{{ parseTime(row.billDate, '{y}-{m}-{d}') }}</template>
  56. </el-table-column>
  57. <el-table-column prop="amount" label="对账单金额" min-width="110" align="center">
  58. <template #default="{ row }">¥{{ row.amount.toFixed(2) }}</template>
  59. </el-table-column>
  60. <el-table-column prop="billStatus" label="对账状态" min-width="90" align="center">
  61. <template #default="{ row }">
  62. {{ getDictLabel(statement_status, row.billStatus) }}
  63. </template>
  64. </el-table-column>
  65. <el-table-column prop="invoiceStatus" label="开票状态" min-width="90" align="center">
  66. <template #default="{ row }">
  67. <span :style="{ color: row.invoiceStatus === '0' ? '#e60012' : '' }">
  68. {{ getDictLabel(invoice_issuance_status, row.invoiceStatus) }}
  69. </span>
  70. </template>
  71. </el-table-column>
  72. <el-table-column prop="payStatus" label="支付状态" min-width="90" align="center">
  73. <template #default="{ row }">
  74. {{ getDictLabel(payment_status, row.payStatus) }}
  75. </template>
  76. </el-table-column>
  77. <el-table-column label="操作" width="100" align="center">
  78. <template #default="{ row }">
  79. <el-button type="primary" link size="small" @click="handleView(row)">查看</el-button>
  80. <el-button type="danger" link size="small" @click="handleConfirm(row)" v-if="row.billStatus == '1'">确认</el-button>
  81. </template>
  82. </el-table-column>
  83. </el-table>
  84. <div class="bottom-bar">
  85. <div class="summary">
  86. <span
  87. >已选择 <em>{{ selectedCount }}</em> 个对账单</span
  88. >
  89. <span class="total"
  90. >合计金额 <em>¥{{ totalAmount.toFixed(2) }}</em></span
  91. >
  92. <el-button type="primary" :disabled="selectedCount === 0" @click="handleApplyInvoice">申请开票</el-button>
  93. </div>
  94. </div>
  95. <div class="pagination-wrapper">
  96. <TablePagination v-model:page="pagination.page" v-model:pageSize="pagination.pageSize" :total="pagination.total" />
  97. </div>
  98. </div>
  99. </template>
  100. <script setup lang="ts">
  101. import { reactive, ref, onMounted, watch, computed, getCurrentInstance, toRefs } from 'vue';
  102. import { useRouter } from 'vue-router';
  103. import { ElMessage, ElMessageBox } from 'element-plus';
  104. import { PageTitle, TablePagination } from '@/components';
  105. import { getStatementList, getStatementInfo, confirmStatement, applyForInvoice } from '@/api/pc/enterprise/statement';
  106. import type { StatementOrder } from '@/api/pc/enterprise/statementTypes';
  107. const router = useRouter();
  108. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  109. const { invoice_issuance_status, statement_status, payment_status } = toRefs<any>(
  110. proxy?.useDict('invoice_issuance_status', 'statement_status', 'payment_status')
  111. );
  112. const searchForm = reactive({
  113. keyword: '', // 对账编号
  114. dateRange: [],
  115. billStatus: '',
  116. invoiceStatus: '',
  117. payStatus: ''
  118. });
  119. // 从字典生成选项,添加"全部"选项
  120. const billStatusOptions = computed(() => [{ label: '全部', value: '' }, ...(statement_status.value || [])]);
  121. const invoiceStatusOptions = computed(() => [{ label: '全部', value: '' }, ...(invoice_issuance_status.value || [])]);
  122. const payStatusOptions = computed(() => [{ label: '全部', value: '' }, ...(payment_status.value || [])]);
  123. const pagination = reactive({ page: 1, pageSize: 5, total: 0 });
  124. const tableData = ref<any[]>([]);
  125. const loading = ref(false);
  126. const selectedRows = ref<any[]>([]);
  127. const tableRef = ref();
  128. const form = reactive({
  129. statementOrderIds: []
  130. });
  131. // 加载对账单列表
  132. const loadStatementList = async () => {
  133. try {
  134. loading.value = true;
  135. const queryParams = {
  136. pageNum: pagination.page,
  137. pageSize: pagination.pageSize,
  138. statementOrderNo: searchForm.keyword,
  139. statementStatus: searchForm.billStatus,
  140. isInvoiceStatus: searchForm.invoiceStatus,
  141. isPaymentStatus: searchForm.payStatus,
  142. params: {} as any
  143. };
  144. // 添加日期范围参数
  145. if (searchForm.dateRange && searchForm.dateRange.length === 2) {
  146. queryParams.params.beginTime = searchForm.dateRange[0];
  147. queryParams.params.endTime = searchForm.dateRange[1];
  148. }
  149. const res = await getStatementList(queryParams);
  150. if (res.code === 200 && res.rows) {
  151. tableData.value = res.rows.map((item: StatementOrder) => ({
  152. id: item.id,
  153. billNo: item.statementOrderNo,
  154. billDate: item.statementDate,
  155. amount: parseFloat(item.amount as any) || 0,
  156. billStatus: item.statementStatus,
  157. invoiceStatus: item.isInvoiceStatus,
  158. payStatus: item.isPaymentStatus
  159. }));
  160. pagination.total = res.total || 0;
  161. }
  162. } catch (error) {
  163. console.error('加载对账单列表失败:', error);
  164. ElMessage.error('加载对账单列表失败');
  165. } finally {
  166. loading.value = false;
  167. }
  168. };
  169. // 处理单个选择
  170. const handleSelect = (selection: any[], row: any) => {
  171. // 判断是选中还是取消选中
  172. const isSelected = selection.some((item) => item.id === row.id);
  173. if (isSelected && row.billStatus !== '2') {
  174. ElMessage.warning('该账单未对账,不可申请开票');
  175. // 取消选中状态
  176. tableRef.value?.toggleRowSelection(row, false);
  177. return;
  178. }
  179. };
  180. // 处理全选
  181. const handleSelectAll = (selection: any[]) => {
  182. // 如果有选中的行,过滤掉 billStatus !== '2' 的行
  183. const invalidRows = selection.filter((row) => row.billStatus !== '2');
  184. if (invalidRows.length > 0) {
  185. ElMessage.warning('部分账单未对账,已自动过滤');
  186. // 取消这些行的选中状态
  187. invalidRows.forEach((row) => {
  188. tableRef.value?.toggleRowSelection(row, false);
  189. });
  190. }
  191. };
  192. // 处理选择变化
  193. const handleSelectionChange = (selection: any[]) => {
  194. selectedRows.value = selection.filter((row) => row.billStatus === '2');
  195. };
  196. // 计算选中数量
  197. const selectedCount = computed(() => selectedRows.value.length);
  198. // 计算总金额
  199. const totalAmount = computed(() => {
  200. return selectedRows.value.reduce((sum, item) => sum + item.amount, 0);
  201. });
  202. // 监听分页变化
  203. watch(
  204. () => [pagination.page, pagination.pageSize],
  205. () => {
  206. loadStatementList();
  207. }
  208. );
  209. // 监听搜索条件变化
  210. watch(
  211. () => [searchForm.keyword, searchForm.dateRange, searchForm.billStatus, searchForm.invoiceStatus, searchForm.payStatus],
  212. () => {
  213. pagination.page = 1;
  214. loadStatementList();
  215. }
  216. );
  217. const getDictLabel = (dictOptions: any[], value: string) => {
  218. if (!dictOptions || !value) return value;
  219. const dict = dictOptions.find((item) => item.value === value);
  220. return dict ? dict.label : value;
  221. };
  222. // 页面加载时获取数据
  223. onMounted(() => {
  224. loadStatementList();
  225. });
  226. const handleView = (row: any) => {
  227. router.push(`/reconciliation/billManage/detail?id=${row.id}`);
  228. };
  229. const handleConfirm = async (row: any) => {
  230. try {
  231. await ElMessageBox.confirm(`确定要确认对账单"${row.billNo}"吗?`, '提示', {
  232. confirmButtonText: '确定',
  233. cancelButtonText: '取消',
  234. type: 'warning'
  235. });
  236. await confirmStatement({ id: row.id });
  237. row.billStatus = '2';
  238. ElMessage.success('确认成功');
  239. loadStatementList();
  240. } catch (error) {
  241. if (error !== 'cancel') {
  242. console.error('确认对账单失败:', error);
  243. ElMessage.error('确认对账单失败');
  244. }
  245. }
  246. };
  247. const handleApplyInvoice = async () => {
  248. try {
  249. form.statementOrderIds = selectedRows.value.map((row) => row.id);
  250. if (!form.statementOrderIds) {
  251. ElMessage.warning('请选择要申请的对账单');
  252. return;
  253. }
  254. const billNos = selectedRows.value.map((row) => row.billNo).join('、');
  255. await ElMessageBox.confirm(`确定要为以下对账单申请开票吗?\n${billNos}`, '提示', {
  256. confirmButtonText: '确定',
  257. cancelButtonText: '取消',
  258. type: 'warning'
  259. });
  260. // TODO: 调用申请开票接口
  261. await applyForInvoice(form);
  262. ElMessage.success('申请开票成功');
  263. loadStatementList();
  264. } catch (error) {
  265. if (error !== 'cancel') {
  266. console.error('申请开票失败:', error);
  267. ElMessage.error('申请开票失败');
  268. }
  269. }
  270. };
  271. // 搜索
  272. const handleSearch = () => {
  273. pagination.page = 1;
  274. loadStatementList();
  275. };
  276. // 重置
  277. const handleReset = () => {
  278. searchForm.keyword = '';
  279. searchForm.dateRange = [];
  280. searchForm.billStatus = '';
  281. searchForm.invoiceStatus = '';
  282. searchForm.payStatus = '';
  283. pagination.page = 1;
  284. loadStatementList();
  285. };
  286. </script>
  287. <style scoped>
  288. .search-area {
  289. margin-bottom: 16px;
  290. padding: 16px;
  291. background: #fff;
  292. border: 1px solid #e4e7ed;
  293. border-radius: 4px;
  294. }
  295. .search-area .el-form {
  296. display: flex;
  297. flex-wrap: wrap;
  298. gap: 16px;
  299. align-items: flex-end;
  300. }
  301. .search-area .el-form-item {
  302. margin-bottom: 0;
  303. margin-right: 0;
  304. }
  305. .search-area .el-input,
  306. .search-area .el-select,
  307. .search-area .el-date-picker {
  308. width: 200px;
  309. }
  310. .pagination-wrapper {
  311. margin-top: 16px;
  312. display: flex;
  313. justify-content: flex-end;
  314. }
  315. .bottom-bar {
  316. margin-top: 16px;
  317. padding: 16px;
  318. background: #fafafa;
  319. border: 1px solid #eee;
  320. border-radius: 4px;
  321. display: flex;
  322. justify-content: flex-end;
  323. }
  324. .summary {
  325. display: flex;
  326. align-items: center;
  327. gap: 20px;
  328. }
  329. .summary span {
  330. font-size: 14px;
  331. color: #666;
  332. }
  333. .summary em {
  334. color: #e60012;
  335. font-style: normal;
  336. font-weight: bold;
  337. }
  338. .summary .total em {
  339. font-size: 16px;
  340. }
  341. </style>