collectionPayment.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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 60px;color: #000;font-size: 16px;font-weight: 600;">客户:{{ $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 { hdPrint } from '@/libs/JGPrint'
  186. export default {
  187. name: 'CollectionPaymentDetail',
  188. components: { STable, VSelect, chooseBillModal, Print, settleAccount },
  189. mixins: [commonMixin],
  190. data () {
  191. this.amountSettledChange = debounce(this.amountSettledChange, 800)
  192. this.amountSettledTotalChange = debounce(this.amountSettledTotalChange, 800)
  193. const _this = this
  194. return {
  195. spinning: false,
  196. loading: false, // 表格加载中
  197. chooseQueryParam: {
  198. productCode: '',
  199. productName: ''
  200. },
  201. // 表头
  202. chooseColumns: [
  203. { title: '序号', scopedSlots: { customRender: 'no' }, width: '5%', align: 'center' },
  204. { title: '单据号', dataIndex: 'bizNo', width: '20%', align: 'center', customRender: function (text) { return text || '--' } },
  205. { title: '单据类型', dataIndex: 'bizTypeDictValue', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  206. { title: '审核时间', dataIndex: 'auditTime', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  207. { title: '金额', dataIndex: 'totalAmount', width: '10%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
  208. { title: '余额', dataIndex: 'unsettleAmount', width: '10%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
  209. { title: '本次结算金额', scopedSlots: { customRender: 'settleAmount' }, width: '15%', align: 'center' },
  210. { title: '操作', scopedSlots: { customRender: 'action' }, width: '10%', align: 'center' }
  211. ],
  212. chooseLoadData: [],
  213. formItemLayout: {
  214. labelCol: { span: 6 },
  215. wrapperCol: { span: 16 }
  216. },
  217. form: {
  218. amountSettled: 0,
  219. discountAmount: 0, // 折让金额
  220. settleStyleSn: undefined,
  221. settleClientName: '',
  222. settleAccountSn: undefined,
  223. settleAccountName: undefined,
  224. remark: ''
  225. },
  226. rules: {
  227. amountSettled: [{ required: true, message: '请输入本次结算金额,系统将自动分配到已选单据上', trigger: 'change' }],
  228. discountAmount: [{ required: true, message: '请输入折让金额', trigger: 'blur' }],
  229. settleStyleSn: [{ required: true, message: '请选择结算方式', trigger: 'change' }],
  230. settleAccountSn: [{ required: true, message: '请选择结算账户', trigger: 'change' }]
  231. },
  232. openModal: false, // 弹框
  233. isPositive: true, // 是否是正值
  234. isChangeAs: false,
  235. maxAmountSettled: 0,
  236. enableFundAccount: false
  237. }
  238. },
  239. computed: {
  240. // 本次结算金额合计
  241. currentTotalBalance () {
  242. let val = 0
  243. this.chooseLoadData.map(item => {
  244. val += (Number(item.settleAmount) * 1000)
  245. })
  246. return val / 1000
  247. },
  248. // 金额合计
  249. totalAmount () {
  250. let val = 0
  251. this.chooseLoadData.map(item => {
  252. val += (Number(item.totalAmount) * 1000)
  253. })
  254. return val / 1000
  255. },
  256. // 余额合计
  257. totalBalance () {
  258. let val = 0
  259. this.chooseLoadData.map(item => {
  260. val += (Number(item.unsettleAmount) * 1000)
  261. })
  262. return val / 1000
  263. },
  264. // 实结算金额
  265. actualSettlementAmount () {
  266. const val = (this.form.amountSettled * 1000 - this.form.discountAmount * 1000) / 1000
  267. return val
  268. }
  269. },
  270. methods: {
  271. ...mapActions(['GetSettleAccountState']),
  272. // 打印预览/快捷打印
  273. handlePrint (type, printerType) {
  274. const _this = this
  275. const params = _this.getParams()
  276. _this.spinning = true
  277. let url = settleUnitPrint
  278. if (type == 'export') { // 导出
  279. url = settleUnitExport
  280. }
  281. // 打印或导出
  282. hdPrint(printerType, type, url, params, '单位应收应付', function () {
  283. _this.spinning = false
  284. })
  285. },
  286. // 选择结算方式
  287. settleStyleChange (v, name) {
  288. this.form.settleStyleName = name.dispName
  289. if (this.form.settleAccountSn) {
  290. this.form.settleAccountSn = undefined
  291. }
  292. },
  293. settleAccountChange (v, name) {
  294. this.form.settleAccountName = name
  295. },
  296. // 应结算金额
  297. amountSettledChange () {
  298. console.log(this.isChangeAs)
  299. if (!this.isChangeAs) {
  300. let val = 0
  301. this.chooseLoadData.map(item => {
  302. val += (Number(item.settleAmount) * 1000)
  303. })
  304. val = val / 1000
  305. this.isPositive = val > 0
  306. this.form.amountSettled = Math.abs(val)
  307. this.maxAmountSettled = Math.abs(val)
  308. }
  309. },
  310. // 修改本次结算金额,自动分配
  311. amountSettledTotalChange (v) {
  312. console.log(this.isChangeAs, v, this.totalBalance, this.isPositive)
  313. if (v <= Math.abs(this.totalBalance)) {
  314. this.isChangeAs = true
  315. const sa = v
  316. const list = this.chooseLoadData
  317. // 恢复初始值
  318. list.map((item, index) => {
  319. item.settleAmount = item.unsettleAmount
  320. })
  321. this.maxAmountSettled = Math.abs(this.totalBalance)
  322. // 开始计算
  323. let temp = 0
  324. let ti = 0
  325. for (let i = 0; i < list.length; i++) {
  326. temp = temp + list[i].settleAmount * (this.isPositive ? 1 : -1)
  327. if (temp >= sa) {
  328. ti = i
  329. break
  330. }
  331. }
  332. console.log(ti, temp, sa)
  333. list[ti].settleAmount = (list[ti].settleAmount - (temp - sa) * (this.isPositive ? 1 : -1)).toFixed(2)
  334. // ti 之后的都改成0
  335. for (let i = ti + 1; i < list.length; i++) {
  336. list[i].settleAmount = 0
  337. }
  338. list.splice()
  339. this.isChangeAs = false
  340. }
  341. },
  342. // 选择单据
  343. handleChoose () {
  344. this.openModal = true
  345. },
  346. // 移除
  347. handleDel (record) {
  348. const ind = this.chooseLoadData.findIndex(item => item.id == record.id)
  349. this.chooseLoadData.splice(ind, 1)
  350. this.amountSettledChange()
  351. },
  352. getParams () {
  353. const _this = this
  354. const form = _this.form
  355. form.settleClientName = _this.$route.params.name
  356. form.settleClientSn = _this.$route.params.sn || undefined
  357. form.settleClientType = _this.chooseLoadData[0].settleClientType
  358. form.settleType = _this.isPositive ? 'R' : 'P'
  359. form.settleAmount = _this.form.amountSettled
  360. form.realSettleAmount = _this.actualSettlementAmount
  361. form.detailList = []
  362. _this.chooseLoadData.map(item => {
  363. form.detailList.push({
  364. bizSn: item.bizSn,
  365. settleAmount: item.settleAmount,
  366. prFlag: item.prFlag
  367. })
  368. })
  369. return form
  370. },
  371. // 提交
  372. handleSubmit () {
  373. const _this = this
  374. if (_this.chooseLoadData.length == 0) {
  375. _this.$message.warning('请选择单据后再提交信息')
  376. return
  377. }
  378. this.$refs.ruleForm.validate(valid => {
  379. if (valid) {
  380. _this.spinning = true
  381. const form = this.getParams()
  382. settleUnitSave(form).then(res => {
  383. if (res.status == 200) {
  384. _this.$message.success(res.message)
  385. _this.handleBack()
  386. _this.spinning = false
  387. } else {
  388. _this.spinning = false
  389. }
  390. })
  391. } else {
  392. console.log('error submit!!')
  393. return false
  394. }
  395. })
  396. },
  397. handleOk (selectedRows) {
  398. this.chooseLoadData = selectedRows.sort((a, b) => {
  399. const at = new Date(a.auditTime).getTime()
  400. const bt = new Date(b.auditTime).getTime()
  401. return bt - at
  402. })
  403. this.amountSettledChange()
  404. },
  405. // 返回列表
  406. handleBack () {
  407. this.$router.push({ path: `/financialManagement/companyReceivablePayable/list` })
  408. },
  409. // 关闭
  410. handleClose () {
  411. this.openModal = false
  412. },
  413. // 默认获取所有单据
  414. getsettleInfoAllList () {
  415. settleInfoAllList({ settleClientSn: this.$route.params.sn, settleClientType: this.$route.params.type, notEqZero: 1 }).then(res => {
  416. res.data.map(item => {
  417. item.settleAmount = item.unsettleAmount
  418. })
  419. this.chooseLoadData = res.data || []
  420. this.amountSettledChange()
  421. })
  422. },
  423. pageInit () {
  424. this.chooseLoadData = []
  425. this.getsettleInfoAllList()
  426. }
  427. },
  428. mounted () {
  429. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  430. this.pageInit()
  431. }
  432. },
  433. activated () {
  434. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  435. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  436. this.pageInit()
  437. }
  438. // 结算账户状态查询
  439. if (this.$hasPermissions('M_fundAccountList') && this.$hasPermissions('B_fundAccountEnable')) {
  440. this.GetSettleAccountState().then(res => {
  441. if (res.status == 200) {
  442. this.enableFundAccount = res.data.functionEnableFlag == 1
  443. }
  444. })
  445. }
  446. },
  447. beforeRouteEnter (to, from, next) {
  448. next(vm => {})
  449. }
  450. }
  451. </script>
  452. <style lang="less">
  453. .collectionPayment-wrap{
  454. position: relative;
  455. height: 100%;
  456. padding-bottom: 51px;
  457. box-sizing: border-box;
  458. >.ant-spin-nested-loading{
  459. overflow-y: auto;
  460. height: 100%;
  461. }
  462. .collectionPayment-cont{
  463. margin-top: 10px;
  464. .green{
  465. color: #19be6b;
  466. }
  467. .red{
  468. color: #ed1c24;
  469. }
  470. }
  471. }
  472. </style>