collectionPayment.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  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. <choose-bill-modal
  167. ref="chooseBillModal"
  168. :openModal="openModal"
  169. :nowChoose="chooseLoadData"
  170. :settleClientType="$route.params.type"
  171. :settleClientSn="$route.params.sn"
  172. @ok="handleOk"
  173. @close="handleClose" />
  174. </div>
  175. </template>
  176. <script>
  177. import { commonMixin } from '@/utils/mixin'
  178. import { mapActions } from 'vuex'
  179. import debounce from 'lodash/debounce'
  180. import { STable, VSelect } from '@/components'
  181. import chooseBillModal from './chooseBillModal.vue'
  182. import { settleUnitSave, settleUnitPrint, settleUnitExport, settleInfoAllList } from '@/api/settle'
  183. import Print from '@/views/common/print.vue'
  184. import settleAccount from '@/views/common/settleAccount'
  185. import rangeDate from '@/views/common/rangeDate.vue'
  186. import { hdPrint } from '@/libs/JGPrint'
  187. export default {
  188. name: 'CollectionPaymentDetail',
  189. components: { STable, VSelect, chooseBillModal, Print, settleAccount, rangeDate },
  190. mixins: [commonMixin],
  191. data () {
  192. this.amountSettledChange = debounce(this.amountSettledChange, 800)
  193. this.amountSettledTotalChange = debounce(this.amountSettledTotalChange, 800)
  194. const _this = this
  195. return {
  196. disabled: false,
  197. spinning: false,
  198. loading: false, // 表格加载中
  199. chooseQueryParam: {
  200. productCode: '',
  201. productName: ''
  202. },
  203. // 表头
  204. chooseColumns: [
  205. { title: '序号', scopedSlots: { customRender: 'no' }, width: '5%', align: 'center' },
  206. { title: '单据号', dataIndex: 'bizNo', width: '20%', align: 'center', customRender: function (text) { return text || '--' } },
  207. { title: '单据类型', dataIndex: 'bizTypeDictValue', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  208. { title: '关联单据创建时间', dataIndex: 'bizCreateDate', width: '20%', align: 'center', customRender: function (text) { return text || '--' } },
  209. { title: '审核时间', dataIndex: 'auditTime', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  210. { title: '金额', dataIndex: 'totalAmount', width: '10%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
  211. { title: '余额', dataIndex: 'unsettleAmount', width: '10%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
  212. { title: '本次结算金额', scopedSlots: { customRender: 'settleAmount' }, width: '15%', align: 'center' },
  213. { title: '操作', scopedSlots: { customRender: 'action' }, width: '10%', align: 'center' }
  214. ],
  215. chooseLoadData: [],
  216. formItemLayout: {
  217. labelCol: { span: 6 },
  218. wrapperCol: { span: 16 }
  219. },
  220. form: {
  221. amountSettled: 0,
  222. discountAmount: 0, // 折让金额
  223. settleStyleSn: undefined,
  224. settleClientName: '',
  225. settleAccountSn: undefined,
  226. settleAccountName: undefined,
  227. remark: ''
  228. },
  229. rules: {
  230. amountSettled: [{ required: true, message: '请输入本次结算金额,系统将自动分配到已选单据上', trigger: 'change' }],
  231. discountAmount: [{ required: true, message: '请输入折让金额', trigger: 'blur' }],
  232. settleStyleSn: [{ required: true, message: '请选择结算方式', trigger: 'change' }],
  233. settleAccountSn: [{ required: true, message: '请选择结算账户', trigger: 'change' }]
  234. },
  235. openModal: false, // 弹框
  236. isPositive: true, // 是否是正值
  237. isChangeAs: false,
  238. maxAmountSettled: 0,
  239. enableFundAccount: false
  240. }
  241. },
  242. computed: {
  243. // 本次结算金额合计
  244. currentTotalBalance () {
  245. let val = 0
  246. this.chooseLoadData.map(item => {
  247. val += (Number(item.settleAmount) * 1000)
  248. })
  249. return val / 1000
  250. },
  251. // 金额合计
  252. totalAmount () {
  253. let val = 0
  254. this.chooseLoadData.map(item => {
  255. val += (Number(item.totalAmount) * 1000)
  256. })
  257. return val / 1000
  258. },
  259. // 余额合计
  260. totalBalance () {
  261. let val = 0
  262. this.chooseLoadData.map(item => {
  263. val += (Number(item.unsettleAmount) * 1000)
  264. })
  265. return val / 1000
  266. },
  267. // 实结算金额
  268. actualSettlementAmount () {
  269. const val = (this.form.amountSettled * 1000 - this.form.discountAmount * 1000) / 1000
  270. return val
  271. }
  272. },
  273. methods: {
  274. ...mapActions(['GetSettleAccountState']),
  275. // 打印预览/快捷打印
  276. handlePrint (type, printerType) {
  277. const _this = this
  278. const params = _this.getParams()
  279. _this.spinning = true
  280. let url = settleUnitPrint
  281. if (type == 'export') { // 导出
  282. url = settleUnitExport
  283. }
  284. // 打印或导出
  285. hdPrint(printerType, type, url, params, '单位应收应付', function () {
  286. _this.spinning = false
  287. })
  288. },
  289. // 选择结算方式
  290. settleStyleChange (v, name) {
  291. this.form.settleStyleName = name.dispName
  292. if (this.form.settleAccountSn) {
  293. this.form.settleAccountSn = undefined
  294. }
  295. },
  296. settleAccountChange (v, name) {
  297. this.form.settleAccountName = name
  298. },
  299. // 应结算金额
  300. amountSettledChange () {
  301. console.log(this.isChangeAs)
  302. if (!this.isChangeAs) {
  303. let val = 0
  304. this.chooseLoadData.map(item => {
  305. val += (Number(item.settleAmount) * 1000)
  306. })
  307. val = val / 1000
  308. this.isPositive = val > 0
  309. this.form.amountSettled = Math.abs(val)
  310. this.maxAmountSettled = Math.abs(val)
  311. }
  312. },
  313. // 修改本次结算金额,自动分配
  314. amountSettledTotalChange (v) {
  315. console.log(this.isChangeAs, v, this.totalBalance, this.isPositive)
  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. console.log(ti, temp, sa)
  336. list[ti].settleAmount = (list[ti].settleAmount - (temp - sa) * (this.isPositive ? 1 : -1)).toFixed(2)
  337. // ti 之后的都改成0
  338. for (let i = ti + 1; i < list.length; i++) {
  339. list[i].settleAmount = 0
  340. }
  341. list.splice()
  342. this.isChangeAs = false
  343. }
  344. },
  345. // 选择单据
  346. handleChoose () {
  347. this.openModal = true
  348. },
  349. // 移除
  350. handleDel (record) {
  351. const ind = this.chooseLoadData.findIndex(item => item.id == record.id)
  352. this.chooseLoadData.splice(ind, 1)
  353. this.amountSettledChange()
  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. console.log('error submit!!')
  396. return false
  397. }
  398. })
  399. },
  400. handleOk (selectedRows) {
  401. this.chooseLoadData = selectedRows.sort((a, b) => {
  402. const at = new Date(a.auditTime).getTime()
  403. const bt = new Date(b.auditTime).getTime()
  404. return at - bt
  405. })
  406. // this.chooseLoadData = selectedRows.reverse()
  407. this.amountSettledChange()
  408. },
  409. // 返回列表
  410. handleBack () {
  411. this.$router.push({ path: `/financialManagement/companyReceivablePayable/list` })
  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. this.amountSettledChange()
  429. })
  430. },
  431. pageInit () {
  432. this.chooseLoadData = []
  433. this.getsettleInfoAllList()
  434. },
  435. // 重置
  436. resetSearchForm () {
  437. this.getsettleInfoAllList()
  438. }
  439. },
  440. mounted () {
  441. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  442. this.pageInit()
  443. }
  444. },
  445. activated () {
  446. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  447. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  448. this.pageInit()
  449. }
  450. // 结算账户状态查询
  451. if (this.$hasPermissions('M_fundAccountList') && this.$hasPermissions('B_fundAccountEnable')) {
  452. this.GetSettleAccountState().then(res => {
  453. if (res.status == 200) {
  454. this.enableFundAccount = res.data.functionEnableFlag == 1
  455. }
  456. })
  457. }
  458. },
  459. beforeRouteEnter (to, from, next) {
  460. next(vm => {})
  461. }
  462. }
  463. </script>
  464. <style lang="less">
  465. .collectionPayment-wrap{
  466. position: relative;
  467. height: 100%;
  468. padding-bottom: 51px;
  469. box-sizing: border-box;
  470. >.ant-spin-nested-loading{
  471. overflow-y: auto;
  472. height: 100%;
  473. }
  474. .collectionPayment-cont{
  475. margin-top: 6px;
  476. .green{
  477. color: #19be6b;
  478. }
  479. .red{
  480. color: #ed1c24;
  481. }
  482. }
  483. }
  484. </style>