collectionPayment.vue 19 KB

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