collectionPayment.vue 18 KB

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