collectionPayment.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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: 14px;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="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="salesNewOrderEdit-del-btn" class="button-default" type="link" @click="handleOk([])"><a-icon type="close" />清空单据</a-button>
  21. <a-divider type="vertical" />
  22. <a-button id="salesNewOrderEdit-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="collectionPayment-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="collectionPayment-settleAmount"
  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="collectionPayment-del-btn">移除</a-button>
  69. </template>
  70. </a-table>
  71. </a-card>
  72. <a-card size="small" :bordered="false" class="collectionPayment-cont">
  73. <a-collapse :activeKey="['1']">
  74. <a-collapse-panel key="1" header="收付款信息">
  75. <a-form-model
  76. id="collectionPayment-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="collectionPayment-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="collectionPayment-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="collectionPayment-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="collectionPayment-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="collectionPayment-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="collectionPayment-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="collectionPayment-submit"
  163. size="large"
  164. :disabled="spinning"
  165. class="button-primary"
  166. @click="handleSubmit"
  167. style="padding: 0 60px;">提交</a-button>
  168. </div>
  169. <choose-bill-modal
  170. ref="chooseBillModal"
  171. :openModal="openModal"
  172. :nowChoose="chooseLoadData"
  173. :settleClientType="$route.params.type"
  174. :settleClientSn="$route.params.sn"
  175. @ok="handleOk"
  176. @close="handleClose" />
  177. </div>
  178. </template>
  179. <script>
  180. import { commonMixin } from '@/utils/mixin'
  181. import { mapActions } from 'vuex'
  182. import debounce from 'lodash/debounce'
  183. import { STable, VSelect } from '@/components'
  184. import chooseBillModal from './chooseBillModal.vue'
  185. import { settleUnitSave, settleUnitPrint, settleUnitExport, settleInfoAllList } from '@/api/settle'
  186. import Print from '@/views/common/print.vue'
  187. import settleAccount from '@/views/common/settleAccount'
  188. import rangeDate from '@/views/common/rangeDate.vue'
  189. import { hdPrint } from '@/libs/JGPrint'
  190. import PrintPanel from '@/views/common/printPanel.vue'
  191. export default {
  192. name: 'CollectionPaymentDetail',
  193. components: { STable, VSelect, chooseBillModal, Print, settleAccount, rangeDate, PrintPanel },
  194. mixins: [commonMixin],
  195. data () {
  196. this.amountSettledChange = debounce(this.amountSettledChange, 800)
  197. this.amountSettledTotalChange = debounce(this.amountSettledTotalChange, 800)
  198. const _this = this
  199. return {
  200. disabled: false,
  201. spinning: false,
  202. loading: false, // 表格加载中
  203. chooseQueryParam: {
  204. productCode: '',
  205. productName: ''
  206. },
  207. // 表头
  208. chooseColumns: [
  209. { title: '序号', scopedSlots: { customRender: 'no' }, width: '5%', align: 'center' },
  210. { title: '单据号', dataIndex: 'bizNo', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  211. { title: '单据类型', dataIndex: 'bizTypeDictValue', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  212. { title: '关联单据创建时间', dataIndex: 'bizCreateDate', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  213. { title: '审核时间', dataIndex: 'auditTime', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  214. { title: '总款数', dataIndex: 'bizTotalCategory', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  215. { title: '总数量', dataIndex: 'bizTotalQty', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? 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: '12%', 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. printTotalKs: false, // 打印原创编码
  247. printTotalNums: false, // 打印全部名称
  248. remarksFlag: false // 打印备注
  249. }
  250. },
  251. computed: {
  252. // 本次结算金额合计
  253. currentTotalBalance () {
  254. let val = 0
  255. this.chooseLoadData.map(item => {
  256. val += (Number(item.settleAmount) * 1000)
  257. })
  258. return val / 1000
  259. },
  260. // 金额合计
  261. totalAmount () {
  262. let val = 0
  263. this.chooseLoadData.map(item => {
  264. val += (Number(item.totalAmount) * 1000)
  265. })
  266. return val / 1000
  267. },
  268. // 余额合计
  269. totalBalance () {
  270. let val = 0
  271. this.chooseLoadData.map(item => {
  272. val += (Number(item.unsettleAmount) * 1000)
  273. })
  274. return val / 1000
  275. },
  276. // 实结算金额
  277. actualSettlementAmount () {
  278. const val = (this.form.amountSettled * 1000 - this.form.discountAmount * 1000) / 1000
  279. return val
  280. }
  281. },
  282. methods: {
  283. ...mapActions(['GetSettleAccountState']),
  284. // 打印预览/快捷打印
  285. handlePrint (type, printerType) {
  286. const _this = this
  287. const params = _this.getParams()
  288. _this.spinning = true
  289. let url = ''
  290. if (type == 'export') { // 导出
  291. url = settleUnitExport
  292. } else {
  293. url = settleUnitPrint
  294. // 打印
  295. // params.printTotalKs = params.printTotalKs ? 1 : 0
  296. // params.printTotalNums = params.printTotalNums ? 1 : 0
  297. params.remarksFlag = this.remarksFlag ? 1 : 0
  298. }
  299. // 打印或导出
  300. hdPrint(printerType, type, url, params, '单位应收应付', function () {
  301. _this.spinning = false
  302. })
  303. },
  304. // 选择结算方式
  305. settleStyleChange (v, name) {
  306. this.form.settleStyleName = name.dispName
  307. if (this.form.settleAccountSn) {
  308. this.form.settleAccountSn = undefined
  309. }
  310. },
  311. settleAccountChange (v, name) {
  312. this.form.settleAccountName = name
  313. },
  314. // 应结算金额
  315. amountSettledChange () {
  316. console.log(this.isChangeAs)
  317. if (!this.isChangeAs) {
  318. let val = 0
  319. this.chooseLoadData.map(item => {
  320. val += (Number(item.settleAmount) * 1000)
  321. })
  322. val = val / 1000
  323. this.isPositive = val > 0
  324. this.form.amountSettled = Math.abs(val)
  325. this.maxAmountSettled = Math.abs(val)
  326. }
  327. },
  328. // 修改本次结算金额,自动分配
  329. amountSettledTotalChange (v) {
  330. console.log(this.isChangeAs, v, this.totalBalance, this.isPositive)
  331. if (v <= Math.abs(this.totalBalance)) {
  332. this.isChangeAs = true
  333. const sa = v
  334. const list = this.chooseLoadData
  335. // 恢复初始值
  336. list.map((item, index) => {
  337. item.settleAmount = item.unsettleAmount
  338. })
  339. this.maxAmountSettled = Math.abs(this.totalBalance)
  340. // 开始计算
  341. let temp = 0
  342. let ti = 0
  343. for (let i = 0; i < list.length; i++) {
  344. temp = temp + list[i].settleAmount * (this.isPositive ? 1 : -1)
  345. if (temp >= sa) {
  346. ti = i
  347. break
  348. }
  349. }
  350. console.log(ti, temp, sa)
  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. getParams () {
  371. const _this = this
  372. const form = _this.form
  373. form.settleClientName = _this.$route.params.name
  374. form.settleClientSn = _this.$route.params.sn || undefined
  375. form.settleClientType = _this.chooseLoadData[0].settleClientType
  376. form.settleType = _this.isPositive ? 'R' : 'P'
  377. form.settleAmount = _this.form.amountSettled
  378. form.realSettleAmount = _this.actualSettlementAmount
  379. form.detailList = []
  380. _this.chooseLoadData.map(item => {
  381. form.detailList.push({
  382. bizSn: item.bizSn,
  383. settleAmount: item.settleAmount,
  384. prFlag: item.prFlag
  385. })
  386. })
  387. return form
  388. },
  389. // 提交
  390. handleSubmit () {
  391. const _this = this
  392. if (_this.chooseLoadData.length == 0) {
  393. _this.$message.warning('请选择单据后再提交信息')
  394. return
  395. }
  396. this.$refs.ruleForm.validate(valid => {
  397. if (valid) {
  398. _this.spinning = true
  399. const form = this.getParams()
  400. settleUnitSave(form).then(res => {
  401. if (res.status == 200) {
  402. _this.$message.success(res.message)
  403. _this.handleBack()
  404. _this.spinning = false
  405. } else {
  406. _this.spinning = false
  407. }
  408. })
  409. } else {
  410. console.log('error submit!!')
  411. return false
  412. }
  413. })
  414. },
  415. handleOk (selectedRows) {
  416. if (selectedRows.length) {
  417. this.chooseLoadData = this.chooseLoadData.concat(selectedRows).sort((a, b) => {
  418. const at = new Date(a.auditTime).getTime()
  419. const bt = new Date(b.auditTime).getTime()
  420. return at - bt
  421. })
  422. } else {
  423. this.chooseLoadData = selectedRows
  424. }
  425. this.amountSettledChange()
  426. },
  427. // 返回列表
  428. handleBack () {
  429. this.$router.push({ path: `/financialManagement/companyReceivablePayableNew/list` })
  430. },
  431. // 关闭
  432. handleClose () {
  433. this.openModal = false
  434. },
  435. // 默认获取所有单据
  436. getsettleInfoAllList () {
  437. this.loading = true
  438. this.disabled = true
  439. settleInfoAllList({ settleClientSn: this.$route.params.sn, settleClientType: this.$route.params.type, notEqZero: 1 }).then(res => {
  440. res.data.map(item => {
  441. item.settleAmount = item.unsettleAmount
  442. })
  443. this.chooseLoadData = res.data || []
  444. this.loading = false
  445. this.disabled = false
  446. this.amountSettledChange()
  447. })
  448. },
  449. pageInit () {
  450. const vm = this
  451. vm.$nextTick(() => {
  452. vm.chooseLoadData = []
  453. vm.getsettleInfoAllList()
  454. })
  455. },
  456. // 重置
  457. resetSearchForm () {
  458. this.getsettleInfoAllList()
  459. }
  460. },
  461. mounted () {
  462. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  463. this.pageInit()
  464. }
  465. },
  466. activated () {
  467. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  468. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  469. this.pageInit()
  470. }
  471. // 结算账户状态查询
  472. if (this.$hasPermissions('M_fundAccountList') && this.$hasPermissions('B_fundAccountEnable')) {
  473. this.GetSettleAccountState().then(res => {
  474. if (res.status == 200) {
  475. this.enableFundAccount = res.data.functionEnableFlag == 1
  476. }
  477. })
  478. }
  479. },
  480. beforeRouteEnter (to, from, next) {
  481. next(vm => {})
  482. }
  483. }
  484. </script>
  485. <style lang="less" scoped>
  486. .collectionPayment-wrap{
  487. position: relative;
  488. height: 100%;
  489. padding-bottom: 51px;
  490. box-sizing: border-box;
  491. >.ant-spin-nested-loading{
  492. overflow-y: auto;
  493. height: 100%;
  494. }
  495. .collectionPayment-cont{
  496. margin-top: 6px;
  497. .green{
  498. color: #19be6b;
  499. }
  500. .red{
  501. color: #ed1c24;
  502. }
  503. }
  504. }
  505. </style>