confrontModal.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. <template>
  2. <a-modal
  3. v-model="opened"
  4. :title="title"
  5. centered
  6. :maskClosable="false"
  7. width="80%"
  8. :footer="null"
  9. @cancel="cancel"
  10. >
  11. <a-spin :spinning="spinning" tip="Loading...">
  12. <a-card size="small" :bordered="false" class="searchBoxNormal">
  13. <!-- 搜索条件 -->
  14. <div ref="tableSearch" class="table-page-search-wrapper">
  15. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  16. <a-row :gutter="15">
  17. <a-col :md="6" :sm="24">
  18. <a-form-item label="时间">
  19. <rangeDate id="conFrontModal-rangeDate" ref="rangeDate" :value="creatDate" @change="dateChange" />
  20. </a-form-item>
  21. </a-col>
  22. <a-col :md="4" :sm="24">
  23. <a-form-item label="业务单号">
  24. <a-input id="conFrontModal-bizNo" v-model.trim="queryParam.bizNo" allowClear placeholder="请输入业务单号"/>
  25. </a-form-item>
  26. </a-col>
  27. <a-col :md="4" :sm="24">
  28. <a-form-item label="借贷类型">
  29. <v-select
  30. v-model="queryParam.changeType"
  31. ref="changeType"
  32. id="conFrontModal-changeType"
  33. code="VERIFY_ACCOUNT_CHANGE_TYPE"
  34. placeholder="请选择状态"
  35. allowClear></v-select>
  36. </a-form-item>
  37. </a-col>
  38. <a-col :md="4" :sm="24">
  39. <a-form-item label="业务类型">
  40. <v-select
  41. v-model="queryParam.bizType"
  42. ref="bizType"
  43. id="conFrontModal-bizType"
  44. code="VERIFY_ACCOUNT_BIZ_TYPE"
  45. placeholder="请选择业务类型"
  46. allowClear></v-select>
  47. </a-form-item>
  48. </a-col>
  49. <a-col :md="6" :sm="24">
  50. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="conFrontModal-search">查询</a-button>
  51. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="conFrontModal-reset">重置</a-button>
  52. <a-button
  53. style="margin-left: 10px"
  54. type="primary"
  55. v-if="$hasPermissions('B_as_detail_export')"
  56. id="conFrontModal-export"
  57. class="button-warning"
  58. @click="handleExport"
  59. :disabled="disabled"
  60. :loading="exportLoading"
  61. >导出</a-button>
  62. </a-col>
  63. </a-row>
  64. </a-form>
  65. </div>
  66. </a-card>
  67. <a-card size="small" :bordered="false" class="conFrontModal-wrap">
  68. <div class="action-bar">
  69. 列显示
  70. <a-popover title="勾选显示列" trigger="click">
  71. <template slot="content">
  72. <div style="width:150px;">
  73. <a-checkbox-group v-model="showCols">
  74. <a-row>
  75. <a-col :span="24" v-for="item in showColsOptions" :key="item.value">
  76. <a-checkbox v-show="item.show" :value="item.value">{{ item.label }}</a-checkbox>
  77. </a-col>
  78. </a-row>
  79. </a-checkbox-group>
  80. </div>
  81. </template>
  82. <a-button type="link" size="small">
  83. 设置 <a-icon type="setting" />
  84. </a-button>
  85. </a-popover>
  86. </div>
  87. <!-- 列表 -->
  88. <s-table
  89. class="sTable"
  90. ref="table"
  91. size="small"
  92. :rowKey="(record) => record.id"
  93. :columns="columns"
  94. :data="loadData"
  95. :showPagination="false"
  96. :defaultLoadData="false"
  97. bordered>
  98. </s-table>
  99. <div class="conFrontModal-info" v-if="detailData">
  100. 备注:{{ detailData.remarks }}
  101. </div>
  102. <div class="conFrontModal-flex" v-if="detailData">
  103. <div class="conFrontModal-subTitle">
  104. <div><span>公司名称:</span> 东莞市箭冠汽车配件制造有限公司</div>
  105. <div><span>签名:</span>{{ detailData.signName }}</div>
  106. <div><span>盖章</span></div>
  107. </div>
  108. <div class="conFrontModal-subTitle">
  109. <div><span>公司名称:</span>{{ dealear.dealerAlias }}</div>
  110. <div><span>签名:</span></div>
  111. <div><span>盖章</span></div>
  112. </div>
  113. </div>
  114. <div class="conFrontModal-footer-bar" v-if="detailData">
  115. <a-button @click="cancel" style="margin-right: 15px" id="conFrontModal-btn-back">取消</a-button>
  116. <a-button type="primary" v-if="orderType==1" :loading="confirmLoading" @click="handleSubmit" id="conFrontModal-btn-submit">对单</a-button>
  117. </div>
  118. </a-card>
  119. </a-spin>
  120. </a-modal>
  121. </template>
  122. <script>
  123. import { commonMixin } from '@/utils/mixin'
  124. import XLSX from 'xlsx-js-style'
  125. import moment from 'moment'
  126. import { STable, VSelect } from '@/components'
  127. import rangeDate from '@/views/common/rangeDate.vue'
  128. import {
  129. verifyAcountBillDetailQueryList,
  130. verifyAcountBillDetail,
  131. verifyAcountBillConfirmCheck,
  132. verifyAcountBillConfirm
  133. } from '@/api/verifyAccount'
  134. export default {
  135. name: 'ConFrontModal',
  136. mixins: [commonMixin],
  137. components: { STable, VSelect, rangeDate },
  138. props: {
  139. show: [Boolean]
  140. },
  141. data () {
  142. return {
  143. opened: this.show,
  144. spinning: false,
  145. disabled: false,
  146. confirmLoading: false,
  147. title: '',
  148. exportLoading: false,
  149. queryParam: {
  150. beginDate: '',
  151. endDate: '',
  152. bizNo: '',
  153. changeType: undefined,
  154. bizType: undefined
  155. },
  156. creatDate: [],
  157. // 加载数据方法 必须为 Promise 对象
  158. loadData: parameter => {
  159. this.disabled = true
  160. this.spinning = true
  161. const params = Object.assign(parameter, this.queryParam)
  162. params.verifyAccountBillSn = this.verifyAccountBillSn
  163. return verifyAcountBillDetailQueryList(params).then(res => {
  164. let data
  165. if (res.status == 200) {
  166. data = res.data
  167. const no = 0
  168. let prevTotalAmount = 0
  169. for (var i = 0; i < data.length; i++) {
  170. data[i].no = no + i + 1
  171. const dates = data[i].bizDate.split('-')
  172. data[i].year = dates[0]
  173. data[i].month = dates[1]
  174. data[i].day = dates[2].split(' ')[0]
  175. // 正为借方, 负数为贷方
  176. if (data[i].bizAmount > 0) {
  177. data[i].debitAmount = Number(data[i].bizAmount).toFixed(2)
  178. } else {
  179. data[i].creditorAmount = Number(data[i].bizAmount * -1).toFixed(2)
  180. }
  181. data[i].totalAmount = Number(Number(prevTotalAmount || 0) + Number(data[i].debitAmount || 0) - Number(data[i].creditorAmount || 0)).toFixed(2)
  182. prevTotalAmount = data[i].totalAmount
  183. }
  184. this.total = data.length || 0 + 1
  185. this.disabled = false
  186. }
  187. this.spinning = false
  188. return data
  189. })
  190. },
  191. total: 0, // 合计
  192. detailData: null,
  193. dealear: null,
  194. verifyAccountBillSn: undefined,
  195. orderType: 0,
  196. showCols: []
  197. }
  198. },
  199. computed: {
  200. showColsOptions () {
  201. return [
  202. { label: '序号', value: 'no', show: false },
  203. { label: '年', value: 'year', show: false },
  204. { label: '月', value: 'month', show: false },
  205. { label: '日', value: 'day', show: false },
  206. { label: '业务单号', value: 'bizNo', show: false },
  207. { label: '业务类型', value: 'bizTypeDictValue', show: false },
  208. { label: '费用/调拨类型', value: 'expenseAllocateType', show: true },
  209. { label: '摘要', value: 'digestInfo', show: true },
  210. { label: '客诉索赔编码', value: 'productCode', show: true },
  211. { label: '借方金额', value: 'debitAmount', show: false },
  212. { label: '贷方金额', value: 'creditorAmount', show: false },
  213. { label: '余额', value: 'totalAmount', show: true },
  214. { label: '备注', value: 'remarks', show: true }
  215. ]
  216. },
  217. columns () {
  218. const renderContent = (value, row, index) => {
  219. const obj = {
  220. children: value || '--',
  221. attrs: {}
  222. }
  223. return obj
  224. }
  225. return [
  226. {
  227. title: '箭冠汽配 应收账款明细表',
  228. children: [
  229. {
  230. title: '营业执照名称',
  231. children: [
  232. {
  233. title: '财务编码',
  234. children: [
  235. { title: '序号',
  236. dataIndex: 'no',
  237. width: '4%',
  238. align: 'center',
  239. customRender: renderContent
  240. },
  241. { title: '年', dataIndex: 'year', width: '4%', align: 'center', customRender: renderContent },
  242. { title: '月', dataIndex: 'month', width: '4%', align: 'center', customRender: renderContent },
  243. { title: '日', dataIndex: 'day', width: '4%', align: 'center', customRender: renderContent },
  244. { title: '业务单号', dataIndex: 'bizNo', width: '8%', align: 'center', customRender: renderContent }
  245. ].filter(item => this.showCols.includes(item.dataIndex))
  246. }
  247. ]
  248. },
  249. {
  250. title: this.dealear ? this.dealear.dealerAlias : '--',
  251. children: [
  252. {
  253. title: this.dealear ? this.dealear.kdMidCustomerFnumber : '--',
  254. children: [
  255. { title: '业务类型', dataIndex: 'bizTypeDictValue', width: '8%', align: 'center', customRender: renderContent },
  256. { title: '费用/调拨类型',
  257. dataIndex: 'expenseAllocateType',
  258. width: '8%',
  259. align: 'center',
  260. customRender: renderContent
  261. }
  262. ].filter(item => this.showCols.includes(item.dataIndex))
  263. }
  264. ]
  265. },
  266. {
  267. title: '系统名称',
  268. children: [
  269. {
  270. title: '',
  271. children: [
  272. { title: '摘要', dataIndex: 'digestInfo', width: '10%', align: 'center', customRender: renderContent },
  273. { title: '客诉索赔编码', dataIndex: 'productCode', width: '8%', align: 'center', customRender: renderContent },
  274. { title: '借方', dataIndex: 'debitAmount', width: '6%', align: 'right', customRender: renderContent }
  275. ].filter(item => this.showCols.includes(item.dataIndex))
  276. }
  277. ]
  278. },
  279. {
  280. title: this.dealear ? this.dealear.dealerName : '--',
  281. children: [
  282. {
  283. title: '',
  284. children: [
  285. { title: '贷方', dataIndex: 'creditorAmount', width: '6%', align: 'right', customRender: renderContent },
  286. { title: '余额', dataIndex: 'totalAmount', width: '6%', align: 'right', customRender: renderContent },
  287. { title: '备注', dataIndex: 'remarks', width: '15%', align: 'center', customRender: renderContent }
  288. ].filter(item => this.showCols.includes(item.dataIndex))
  289. }
  290. ]
  291. }
  292. ]
  293. }
  294. ]
  295. }
  296. },
  297. methods: {
  298. // 创建时间 change
  299. dateChange (date) {
  300. this.queryParam.beginDate = date[0] ? date[0] : ''
  301. this.queryParam.endDate = date[1] ? date[1] : ''
  302. },
  303. // 重置
  304. resetSearchForm () {
  305. this.creatDate = []
  306. if (this.$refs.rangeDate) {
  307. this.$refs.rangeDate.resetDate(this.creatDate)
  308. }
  309. this.queryParam.beginDate = ''
  310. this.queryParam.endDate = ''
  311. this.queryParam.bizNo = ''
  312. this.queryParam.changeType = undefined
  313. this.queryParam.bizType = undefined
  314. this.$refs.table.refresh(true)
  315. },
  316. // 详情
  317. getDetail () {
  318. this.spinning = true
  319. verifyAcountBillDetail({ sn: this.verifyAccountBillSn }).then(res => {
  320. this.detailData = res.data
  321. this.spinning = false
  322. this.resetSearchForm()
  323. })
  324. },
  325. // 关闭弹框
  326. cancel () {
  327. this.opened = false
  328. this.$emit('cancel')
  329. },
  330. appendSplitMergedRow (ws, firstValue, secondValue) {
  331. const colsLen = this.showCols.length
  332. const s = Math.floor((colsLen % 2 == 0) ? (colsLen / 2) : ((colsLen - 1) / 2))
  333. // 1. 获取当前数据范围
  334. const range = XLSX.utils.decode_range(ws['!ref'])
  335. const newRowNum = range.e.r + 1
  336. // 2. 填充基础数据(仅设置有效单元格)
  337. ws[XLSX.utils.encode_cell({ r: newRowNum, c: 0 })] = { v: firstValue, t: 's' } // 前7列合并值
  338. ws[XLSX.utils.encode_cell({ r: newRowNum, c: s + 1 })] = { v: secondValue, t: 's' } // 后6列合并值
  339. // 3. 设置合并区域
  340. if (!ws['!merges']) ws['!merges'] = []
  341. // 前7列合并(0-6列)
  342. ws['!merges'].push(XLSX.utils.decode_range(
  343. `${XLSX.utils.encode_cell({ r: newRowNum, c: 0 })}:${XLSX.utils.encode_cell({ r: newRowNum, c: s })}`
  344. ))
  345. // 后6列合并(7-12列)
  346. ws['!merges'].push(XLSX.utils.decode_range(
  347. `${XLSX.utils.encode_cell({ r: newRowNum, c: s + 1 })}:${XLSX.utils.encode_cell({ r: newRowNum, c: colsLen - 1 })}`
  348. ))
  349. // 4. 更新数据范围
  350. range.e.r = newRowNum
  351. ws['!ref'] = XLSX.utils.encode_range(range)
  352. return ws
  353. },
  354. // 导出表格excel,dom 表格对象,title 导出表格名称
  355. exportTable (dom, title) {
  356. var ws = XLSX.utils.table_to_sheet(dom)
  357. // console.log(ws)
  358. // 4. 设置列宽
  359. const colsLen = this.showCols.length
  360. ws['!cols'] = Array(colsLen).fill().map((item, index) => ({ wch: index < 4 ? 6 : 20 }))
  361. // 追加备注
  362. const range = XLSX.utils.decode_range(ws['!ref'])
  363. const newRowNum = range.e.r + 1
  364. // 填充数据(首列填值,其余留空)
  365. const mergedValue = '备注:' + this.detailData.remarks
  366. for (let col = 0; col < colsLen; col++) {
  367. const cellRef = XLSX.utils.encode_cell({ r: newRowNum, c: col })
  368. ws[cellRef] = { v: col === 0 ? mergedValue : '', t: 's' }
  369. }
  370. // 设置全列合并(0-12列)
  371. if (!ws['!merges']) ws['!merges'] = []
  372. ws['!merges'].push(XLSX.utils.decode_range(
  373. `${XLSX.utils.encode_cell({ r: newRowNum, c: 0 })}:${XLSX.utils.encode_cell({ r: newRowNum, c: colsLen - 1 })}`
  374. ))
  375. // 4. 更新数据范围
  376. range.e.r = newRowNum
  377. ws['!ref'] = XLSX.utils.encode_range(range)
  378. ws['!rows'][0] = { hpt: 30 }
  379. ws['!rows'][newRowNum] = { hpt: 30 }
  380. // 追加表尾
  381. const newWs = this.appendSplitMergedRow(ws, '公司名称:东莞市箭冠汽车配件制造有限公司', '公司名称:' + (this.dealear.dealerAlias || ''))
  382. const newWs1 = this.appendSplitMergedRow(newWs, '签名:' + (this.detailData.signName || ''), '签名:')
  383. const newWs2 = this.appendSplitMergedRow(newWs1, '盖章:', '盖章:')
  384. // 设置单元格样式
  385. Object.keys(newWs2).forEach(cell => {
  386. if (!cell.startsWith('!')) {
  387. const rowNum = parseInt(cell.match(/\d+/)[0])
  388. newWs2[cell].s = cell === 'A1' ? {
  389. font: { bold: true, color: { rgb: '000000' } },
  390. alignment: { horizontal: 'center', vertical: 'center' }
  391. } : rowNum === 4 ? {
  392. font: { bold: true },
  393. fill: { fgColor: { rgb: 'ffdd8d' } },
  394. alignment: { horizontal: rowNum < newRowNum + 1 ? 'center' : 'left', vertical: 'center' }
  395. } : {
  396. alignment: { horizontal: rowNum < newRowNum + 1 ? 'center' : 'left', vertical: 'center' }
  397. }
  398. }
  399. })
  400. // 创建工作簿并导出
  401. var wb = XLSX.utils.book_new()
  402. // 5. 写入文件
  403. XLSX.utils.book_append_sheet(wb, newWs2, 'Sheet1')
  404. const timeStr = moment().format('YYYYMMDDHHmmss')
  405. XLSX.writeFile(wb, title + '-' + timeStr + '.xlsx')
  406. },
  407. // 点击导出
  408. handleExport () {
  409. const excelTitle = '(' + this.detailData.dealerName + ')应收账款明细表'
  410. this.exportTable(this.$refs.table.$el.querySelector('table'), excelTitle)
  411. },
  412. // 对单
  413. async handleSubmit () {
  414. const _this = this
  415. this.confirmLoading = true
  416. const ret = await verifyAcountBillConfirmCheck({ sn: this.verifyAccountBillSn })
  417. this.confirmLoading = false
  418. console.log(ret)
  419. const snList = ret.data.length ? ret.data.map(item => item.bizNo) : []
  420. if (snList.length) {
  421. this.$info({
  422. title: '提示(' + _this.dealear.dealerName + ')',
  423. content: <div style="font-size:14px;">{snList.toString()}不可对单</div>,
  424. centered: true,
  425. closable: true,
  426. onOk () {
  427. }
  428. })
  429. } else {
  430. this.confirmLoading = true
  431. verifyAcountBillConfirm({ sn: this.verifyAccountBillSn }).then(res => {
  432. this.confirmLoading = false
  433. this.$message.success('对单成功')
  434. this.$emit('confirm')
  435. this.cancel()
  436. })
  437. }
  438. },
  439. // 初始化
  440. async pageInit (row, dealear, type) {
  441. // console.log(row, dealear, type)
  442. this.orderType = type
  443. this.verifyAccountBillSn = row.verifyAccountBillSn
  444. this.dealear = dealear
  445. this.title = type ? '对单' : '单据详情' + `(对账单号:${row.verifyAccountBillNo} 客户名称:${row.dealerName})`
  446. this.getDetail()
  447. }
  448. },
  449. watch: {
  450. show (newValue, oldValue) {
  451. this.opened = newValue
  452. if (newValue) {
  453. this.showCols = ['no', 'year', 'month', 'day', 'bizNo', 'bizTypeDictValue', 'expenseAllocateType', 'digestInfo', 'productCode', 'debitAmount', 'creditorAmount', 'totalAmount', 'remarks']
  454. }
  455. }
  456. }
  457. }
  458. </script>
  459. <style lang="less">
  460. .conFrontModal-title{
  461. font-size: 16px;
  462. font-weight: bold;
  463. text-align: center;
  464. margin-bottom: 10px;
  465. }
  466. .action-bar{
  467. text-align: right;
  468. }
  469. .conFrontModal-flex{
  470. display: flex;
  471. justify-content: space-between;
  472. align-items: center;
  473. flex-wrap: wrap;
  474. }
  475. .conFrontModal-subTitle{
  476. width: 50%;
  477. padding: 5px;
  478. > span{
  479. display: block;
  480. font-size: 14px;
  481. width: 100px;
  482. }
  483. > div{
  484. display: block;
  485. font-size: 14px;
  486. width: 100%;
  487. word-break: break-all;
  488. margin: 5px 0;
  489. }
  490. }
  491. .conFrontModal-info{
  492. font-size: 14px;
  493. padding: 15px 5px 10px;
  494. line-height: 20px;
  495. color: #333;
  496. }
  497. .conFrontModal-footer-bar{
  498. text-align: center;
  499. padding: 30px 0 20px;
  500. }
  501. </style>