collectionPayment.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. <template>
  2. <div class="jg-page-wrap collectionPaymentNew-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" class="collectionPaymentNew-back" >
  5. <!-- 自定义的二级文字标题 -->
  6. <template slot="subTitle">
  7. <span style="margin-right:30px;color: #000;font-size: 14px;font-weight: 600;">客户:{{ $route.params.name!='undefined'?$route.params.name: '--' }}</span>
  8. <a-button id="collectionPayEdit-back-btn" type="link" @click="handleBack" class="button-default"> <a-icon type="rollback" /> 返回列表</a-button>
  9. </template>
  10. <template slot="extra" v-if="$hasPermissions('B_cPayment_printAndExport')">
  11. <div style="margin-top: 5px;">
  12. <PrintPanel ref="printBox" @handlePrint="handlePrint">
  13. <div style="padding:10px;" slot="extendCons">
  14. <a-checkbox v-model="remarksFlag" id="salesQuery-remarksFlag">打印备注</a-checkbox>
  15. <!-- <a-checkbox v-model="printTotalKs" :checked="printTotalKs" id="salesQuery-printTotalKs">打印总款数</a-checkbox> -->
  16. <!-- <a-checkbox v-model="printTotalNums" :checked="printTotalNums" id="salesQuery-printTotalNums">打印总数量</a-checkbox> -->
  17. </div>
  18. </PrintPanel>
  19. <a-divider type="vertical" />
  20. <a-button id="scollectionPayEdit-del-btn" class="button-default" type="link" @click="handleOk([])"><a-icon type="close" />清空单据</a-button>
  21. <a-divider type="vertical" />
  22. <a-button id="scollectionPayEdit-add-btn" type="link" @click="openModal=true"><a-icon type="plus" />选择单据</a-button>
  23. </div>
  24. </template>
  25. </a-page-header>
  26. <!-- 已选单据 -->
  27. <a-card size="small" :bordered="false" class="collectionPaymentNew-cont">
  28. <div class="table-operator">
  29. <div class="alert-message">
  30. 共 <strong>{{ chooseLoadData.length }}</strong>条明细 ,
  31. 金额合计<strong>{{ toThousands(totalAmount) }}</strong> ,
  32. 余额合计<strong>{{ toThousands(totalBalance) }}</strong> ,
  33. 本次结算金额合计<strong>{{ toThousands(currentTotalBalance) }}</strong>
  34. </div>
  35. </div>
  36. <!-- 列表 -->
  37. <a-table
  38. class="sTable"
  39. ref="chooseTable"
  40. size="small"
  41. :rowKey="(record) => record.id"
  42. :columns="chooseColumns"
  43. :dataSource="chooseLoadData"
  44. :scroll="{ y: 300 }"
  45. :loading="loading"
  46. :locale="{emptyText: '请先选择单据'}"
  47. :pagination="false"
  48. bordered>
  49. <!-- 序号 -->
  50. <template slot="no" slot-scope="text, record, index">
  51. {{ index+1 }}
  52. </template>
  53. <!-- 本次结算金额 -->
  54. <template slot="settleAmount" slot-scope="text, record">
  55. <a-input-number
  56. :id="'collectionPaymentNew-settleAmount-'+record.id"
  57. v-model="record.settleAmount"
  58. :precision="2"
  59. :min="record.unsettleAmount<0 ? record.unsettleAmount : 0"
  60. :max="record.unsettleAmount<0 ? 0 : record.unsettleAmount"
  61. @change="amountSettledChange"
  62. size="small"
  63. placeholder="请输入"
  64. style="width: 100%;" />
  65. </template>
  66. <!-- 操作 -->
  67. <template slot="action" slot-scope="text, record">
  68. <a-button size="small" type="link" class="button-error" @click="handleDel(record)" :id="'collectionPaymentNew-del-'+record.id">移除</a-button>
  69. </template>
  70. </a-table>
  71. </a-card>
  72. <a-card size="small" :bordered="false" class="collectionPaymentNew-cont">
  73. <a-collapse :activeKey="['1']">
  74. <a-collapse-panel key="1" header="收付款信息">
  75. <a-form-model
  76. id="collectionPaymentNew-form"
  77. ref="ruleForm"
  78. :model="form"
  79. :rules="rules"
  80. :label-col="formItemLayout.labelCol"
  81. :wrapper-col="formItemLayout.wrapperCol">
  82. <a-row :gutter="20">
  83. <a-col span="12">
  84. <a-form-model-item prop="amountSettled">
  85. <template slot="label">
  86. 本次结算金额(<span :class="isPositive ? 'green':'red'">{{ isPositive ? '收款' : '付款' }}</span>)
  87. </template>
  88. <a-input-number
  89. id="collectionPaymentNew-amountSettled"
  90. v-model="form.amountSettled"
  91. @change="amountSettledTotalChange"
  92. :precision="2"
  93. placeholder=""
  94. :max="maxAmountSettled"
  95. style="width: 100%;" />
  96. </a-form-model-item>
  97. </a-col>
  98. <a-col span="12">
  99. <a-form-model-item label="折让金额" prop="discountAmount">
  100. <a-input-number
  101. id="collectionPaymentNew-discountAmount"
  102. v-model="form.discountAmount"
  103. :precision="2"
  104. :min="0"
  105. :max="form.amountSettled"
  106. placeholder="请输入"
  107. style="width: 100%;"
  108. allowClear />
  109. </a-form-model-item>
  110. </a-col>
  111. <a-col span="12">
  112. <a-form-model-item prop="actualSettlementAmount">
  113. <template slot="label">
  114. 本次实际结算金额(<span :class="isPositive ? 'green':'red'">{{ isPositive ? '收款' : '付款' }}</span>)
  115. </template>
  116. <a-input-number
  117. id="collectionPaymentNew-actualSettlementAmount"
  118. v-model="actualSettlementAmount"
  119. disabled
  120. :precision="2"
  121. placeholder=""
  122. style="width: 100%;" />
  123. </a-form-model-item>
  124. </a-col>
  125. <a-col span="12">
  126. <a-form-model-item label="结算方式" prop="settleStyleSn">
  127. <v-select
  128. code="SETTLE_STYLE"
  129. id="collectionPaymentNew-settleStyleSn"
  130. v-model="form.settleStyleSn"
  131. @change="settleStyleChange"
  132. allowClear
  133. placeholder="请选择结算方式"
  134. ></v-select>
  135. </a-form-model-item>
  136. </a-col>
  137. <a-col span="12">
  138. <a-form-model-item v-if="enableFundAccount" label="结算账户" prop="settleAccountSn">
  139. <settleAccount
  140. id="collectionPaymentNew-settleAccountSn"
  141. v-model="form.settleAccountSn"
  142. :settleStyleSn="form.settleStyleSn"
  143. @change="settleAccountChange"
  144. placeholder="请选择结算账户">
  145. </settleAccount>
  146. </a-form-model-item>
  147. </a-col>
  148. <a-col span="24">
  149. <a-form-model-item label="备注" prop="remark" :label-col="{ span: 3 }" :wrapper-col="{ span: 20 }">
  150. <a-textarea id="collectionPaymentNew-remark" :maxLength="100" v-model="form.remark" placeholder="请输入备注(最多100个字符)" allowClear />
  151. </a-form-model-item>
  152. </a-col>
  153. </a-row>
  154. </a-form-model>
  155. </a-collapse-panel>
  156. </a-collapse>
  157. </a-card>
  158. </a-spin>
  159. <div class="affix-cont">
  160. <a-button
  161. type="primary"
  162. id="collectionPaymentNew-submit"
  163. size="large"
  164. :disabled="spinning"
  165. class="button-primary"
  166. @click="handleSubmit"
  167. style="padding: 0 60px;">提交</a-button>
  168. </div>
  169. <!-- 单据选择 -->
  170. <choose-bill-modal
  171. ref="chooseBillModal"
  172. :openModal="openModal"
  173. :nowChoose="chooseLoadData"
  174. :settleClientType="$route.params.type"
  175. :settleClientSn="$route.params.sn"
  176. @ok="handleOk"
  177. @close="handleClose" />
  178. </div>
  179. </template>
  180. <script>
  181. import { commonMixin } from '@/utils/mixin'
  182. import { mapActions } from 'vuex'
  183. import debounce from 'lodash/debounce'
  184. import { STable, VSelect } from '@/components'
  185. import chooseBillModal from './chooseBillModal.vue'
  186. import { settleUnitSave, settleUnitPrint, settleUnitExport, settleInfoAllList } from '@/api/settle'
  187. import Print from '@/views/common/print.vue'
  188. import settleAccount from '@/views/common/settleAccount'
  189. import rangeDate from '@/views/common/rangeDate.vue'
  190. import { hdPrint } from '@/libs/JGPrint'
  191. import PrintPanel from '@/views/common/printPanel.vue'
  192. export default {
  193. name: 'CollectionPaymentDetail',
  194. components: { STable, VSelect, chooseBillModal, Print, settleAccount, rangeDate, PrintPanel },
  195. mixins: [commonMixin],
  196. data () {
  197. this.amountSettledChange = debounce(this.amountSettledChange, 800)
  198. this.amountSettledTotalChange = debounce(this.amountSettledTotalChange, 800)
  199. const _this = this
  200. return {
  201. disabled: false,
  202. spinning: false,
  203. loading: false, // 表格加载中
  204. chooseQueryParam: {
  205. productCode: '', // 产品编码
  206. productName: '' // 产品名称
  207. },
  208. // 表头
  209. chooseColumns: [
  210. { title: '序号', scopedSlots: { customRender: 'no' }, width: '5%', align: 'center' },
  211. { title: '单据号', dataIndex: 'bizNo', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  212. { title: '单据类型', dataIndex: 'bizTypeDictValue', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  213. { title: '关联单据创建时间', dataIndex: 'bizCreateDate', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  214. { title: '审核时间', dataIndex: 'auditTime', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  215. { title: '总款数', dataIndex: 'bizTotalCategory', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  216. { title: '总数量', dataIndex: 'bizTotalQty', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  217. { title: '金额', dataIndex: 'totalAmount', width: '10%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
  218. { title: '余额', dataIndex: 'unsettleAmount', width: '10%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
  219. { title: '本次结算金额', scopedSlots: { customRender: 'settleAmount' }, width: '12%', align: 'center' },
  220. { title: '操作', scopedSlots: { customRender: 'action' }, width: '10%', align: 'center' }
  221. ],
  222. chooseLoadData: [],
  223. formItemLayout: {
  224. labelCol: { span: 6 },
  225. wrapperCol: { span: 16 }
  226. },
  227. form: {
  228. amountSettled: 0, // 本次结算金额
  229. discountAmount: 0, // 折让金额
  230. settleStyleSn: undefined, // 结算方式sn
  231. settleClientName: '', // 客户名称
  232. settleAccountSn: undefined, // 结算账户sn
  233. settleAccountName: undefined, // 结算账户名称
  234. remark: '' // 备注
  235. },
  236. rules: {
  237. amountSettled: [{ required: true, message: '请输入本次结算金额,系统将自动分配到已选单据上', trigger: 'change' }],
  238. discountAmount: [{ required: true, message: '请输入折让金额', trigger: 'blur' }],
  239. settleStyleSn: [{ required: true, message: '请选择结算方式', trigger: 'change' }],
  240. settleAccountSn: [{ required: true, message: '请选择结算账户', trigger: 'change' }]
  241. },
  242. openModal: false, // 弹框
  243. isPositive: true, // 是否是正值
  244. isChangeAs: false, // 防止重复计算
  245. maxAmountSettled: 0, // 结算金额最大值
  246. enableFundAccount: false, // 结算账户是否开启
  247. printTotalKs: false, // 打印原创编码
  248. printTotalNums: false, // 打印全部名称
  249. remarksFlag: false // 打印备注
  250. }
  251. },
  252. computed: {
  253. // 本次结算金额合计
  254. currentTotalBalance () {
  255. let val = 0
  256. this.chooseLoadData.map(item => {
  257. val += (Number(item.settleAmount) * 1000)
  258. })
  259. return val / 1000
  260. },
  261. // 金额合计
  262. totalAmount () {
  263. let val = 0
  264. this.chooseLoadData.map(item => {
  265. val += (Number(item.totalAmount) * 1000)
  266. })
  267. return val / 1000
  268. },
  269. // 余额合计
  270. totalBalance () {
  271. let val = 0
  272. this.chooseLoadData.map(item => {
  273. val += (Number(item.unsettleAmount) * 1000)
  274. })
  275. return val / 1000
  276. },
  277. // 实结算金额
  278. actualSettlementAmount () {
  279. const val = (this.form.amountSettled * 1000 - this.form.discountAmount * 1000) / 1000
  280. return val
  281. }
  282. },
  283. methods: {
  284. ...mapActions(['GetSettleAccountState']),
  285. // 打印预览/快捷打印
  286. handlePrint (type, printerType) {
  287. const _this = this
  288. const params = _this.getParams()
  289. _this.spinning = true
  290. let url = ''
  291. if (type == 'export') { // 导出
  292. url = settleUnitExport
  293. } else {
  294. url = settleUnitPrint
  295. // 打印
  296. // params.printTotalKs = params.printTotalKs ? 1 : 0
  297. // params.printTotalNums = params.printTotalNums ? 1 : 0
  298. params.remarksFlag = this.remarksFlag ? 1 : 0
  299. }
  300. // 打印或导出
  301. hdPrint(printerType, type, url, params, '单位应收应付', function () {
  302. _this.spinning = false
  303. })
  304. },
  305. // 选择结算方式
  306. settleStyleChange (v, name) {
  307. this.form.settleStyleName = name.dispName
  308. if (this.form.settleAccountSn) {
  309. this.form.settleAccountSn = undefined
  310. }
  311. },
  312. // 选择结算账户
  313. settleAccountChange (v, name) {
  314. this.form.settleAccountName = name
  315. },
  316. // 应结算金额
  317. amountSettledChange () {
  318. console.log(this.isChangeAs)
  319. if (!this.isChangeAs) {
  320. let val = 0
  321. this.chooseLoadData.map(item => {
  322. val += (Number(item.settleAmount) * 1000)
  323. })
  324. val = val / 1000
  325. this.isPositive = val > 0
  326. this.form.amountSettled = Math.abs(val)
  327. this.maxAmountSettled = Math.abs(val)
  328. }
  329. },
  330. // 修改本次结算金额,自动分配
  331. amountSettledTotalChange (v) {
  332. if (v <= Math.abs(this.totalBalance)) {
  333. this.isChangeAs = true
  334. const sa = v
  335. const list = this.chooseLoadData
  336. // 恢复初始值
  337. list.map((item, index) => {
  338. item.settleAmount = item.unsettleAmount
  339. })
  340. this.maxAmountSettled = Math.abs(this.totalBalance)
  341. // 开始计算
  342. let temp = 0
  343. let ti = 0
  344. for (let i = 0; i < list.length; i++) {
  345. temp = temp + list[i].settleAmount * (this.isPositive ? 1 : -1)
  346. if (temp >= sa) {
  347. ti = i
  348. break
  349. }
  350. }
  351. list[ti].settleAmount = (list[ti].settleAmount - (temp - sa) * (this.isPositive ? 1 : -1)).toFixed(2)
  352. // ti 之后的都改成0
  353. for (let i = ti + 1; i < list.length; i++) {
  354. list[i].settleAmount = 0
  355. }
  356. list.splice()
  357. this.isChangeAs = false
  358. }
  359. },
  360. // 选择单据
  361. handleChoose () {
  362. this.openModal = true
  363. },
  364. // 移除
  365. handleDel (record) {
  366. const ind = this.chooseLoadData.findIndex(item => item.id == record.id)
  367. this.chooseLoadData.splice(ind, 1)
  368. this.amountSettledChange()
  369. },
  370. // 获取格式化后的提交参数
  371. getParams () {
  372. const _this = this
  373. const form = _this.form
  374. form.settleClientName = _this.$route.params.name
  375. form.settleClientSn = _this.$route.params.sn || undefined
  376. form.settleClientType = _this.chooseLoadData[0].settleClientType
  377. form.settleType = _this.isPositive ? 'R' : 'P'
  378. form.settleAmount = _this.form.amountSettled
  379. form.realSettleAmount = _this.actualSettlementAmount
  380. form.detailList = []
  381. _this.chooseLoadData.map(item => {
  382. form.detailList.push({
  383. bizSn: item.bizSn,
  384. settleAmount: item.settleAmount,
  385. prFlag: item.prFlag
  386. })
  387. })
  388. return form
  389. },
  390. // 提交
  391. handleSubmit () {
  392. const _this = this
  393. if (_this.chooseLoadData.length == 0) {
  394. _this.$message.warning('请选择单据后再提交信息')
  395. return
  396. }
  397. this.$refs.ruleForm.validate(valid => {
  398. if (valid) {
  399. _this.spinning = true
  400. const form = this.getParams()
  401. settleUnitSave(form).then(res => {
  402. if (res.status == 200) {
  403. _this.$message.success(res.message)
  404. _this.handleBack()
  405. _this.spinning = false
  406. } else {
  407. _this.spinning = false
  408. }
  409. })
  410. } else {
  411. console.log('error submit!!')
  412. return false
  413. }
  414. })
  415. },
  416. // 选择单据成功
  417. handleOk (selectedRows) {
  418. if (selectedRows.length) {
  419. this.chooseLoadData = this.chooseLoadData.concat(selectedRows).sort((a, b) => {
  420. const at = new Date(a.auditTime).getTime()
  421. const bt = new Date(b.auditTime).getTime()
  422. return at - bt
  423. })
  424. } else {
  425. this.chooseLoadData = selectedRows
  426. }
  427. // 计算结算金额
  428. this.amountSettledChange()
  429. },
  430. // 返回列表
  431. handleBack () {
  432. this.$router.push({ name: `companyReceivablePayableNewList` })
  433. },
  434. // 关闭
  435. handleClose () {
  436. this.openModal = false
  437. },
  438. // 默认获取所有单据
  439. getsettleInfoAllList () {
  440. this.loading = true
  441. this.disabled = true
  442. settleInfoAllList({ settleClientSn: this.$route.params.sn, settleClientType: this.$route.params.type, notEqZero: 1 }).then(res => {
  443. res.data.map(item => {
  444. item.settleAmount = item.unsettleAmount
  445. })
  446. this.chooseLoadData = res.data || []
  447. this.loading = false
  448. this.disabled = false
  449. this.amountSettledChange()
  450. })
  451. },
  452. // 初始化页面
  453. pageInit () {
  454. const vm = this
  455. vm.$nextTick(() => {
  456. vm.chooseLoadData = []
  457. vm.getsettleInfoAllList()
  458. })
  459. },
  460. // 重置
  461. resetSearchForm () {
  462. this.getsettleInfoAllList()
  463. }
  464. },
  465. mounted () {
  466. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  467. this.pageInit()
  468. }
  469. },
  470. activated () {
  471. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  472. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  473. this.pageInit()
  474. }
  475. // 结算账户状态查询
  476. if (this.$hasPermissions('M_fundAccountList') && this.$hasPermissions('B_fundAccountEnable')) {
  477. this.GetSettleAccountState().then(res => {
  478. if (res.status == 200) {
  479. this.enableFundAccount = res.data.functionEnableFlag == 1
  480. }
  481. })
  482. }
  483. },
  484. beforeRouteEnter (to, from, next) {
  485. next(vm => {})
  486. }
  487. }
  488. </script>
  489. <style lang="less" scoped>
  490. .collectionPaymentNew-wrap{
  491. position: relative;
  492. height: 100%;
  493. padding-bottom: 51px;
  494. box-sizing: border-box;
  495. >.ant-spin-nested-loading{
  496. overflow-y: auto;
  497. height: 100%;
  498. }
  499. .collectionPaymentNew-cont{
  500. margin-top: 6px;
  501. .green{
  502. color: #19be6b;
  503. }
  504. .red{
  505. color: #ed1c24;
  506. }
  507. }
  508. }
  509. </style>