collectionPayment.vue 19 KB

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