collectionPayment.vue 17 KB

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