|
|
@@ -0,0 +1,449 @@
|
|
|
+/*******************************************************************************
|
|
|
+ * Copyright(c) 2022 dongke All rights reserved. / Confidential
|
|
|
+ * 类的信息:
|
|
|
+ * 1.程序名称: 新建收款单
|
|
|
+ * 编辑履历:
|
|
|
+ * 作者 日期 版本 修改内容
|
|
|
+ * 姜永辉 2024-03-22 1.00
|
|
|
+ *******************************************************************************/
|
|
|
+const mixins = require('@/mixins/index.js')
|
|
|
+const Constants = require('@/utils/Constants.js');
|
|
|
+const app = getApp();
|
|
|
+Page({
|
|
|
+ mixins: [mixins],
|
|
|
+ /**
|
|
|
+ * 页面的初始数据
|
|
|
+ */
|
|
|
+ data: {
|
|
|
+ cardList: [
|
|
|
+ { name: 'main' },
|
|
|
+ { name: 'bill', title: '应收', chooseFlag: true, chooseTitle: '选应收', urlKey: 'selectBill' },
|
|
|
+ { name: 'file' }],
|
|
|
+ contentObj: {
|
|
|
+ main: [
|
|
|
+ {
|
|
|
+ code: 'accDate',
|
|
|
+ name: 'accDate',
|
|
|
+ type: 'date',
|
|
|
+ required: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ code: 'staffId',
|
|
|
+ name: 'staffName',
|
|
|
+ required: true,
|
|
|
+ title: '收款人',
|
|
|
+ type: 'choose',
|
|
|
+ urlKey: 'chooseStaff'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ code: 'orgId',
|
|
|
+ name: 'orgName',
|
|
|
+ required: true,
|
|
|
+ type: 'choose',
|
|
|
+ urlKey: 'chooseOrg'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ code: 'sumAmtRec',
|
|
|
+ type: 'number',
|
|
|
+ title: '本次收款',
|
|
|
+ required: true
|
|
|
+ },
|
|
|
+
|
|
|
+ ],
|
|
|
+ bill: [
|
|
|
+ { code: 'cancelAmount', type: 'cancel', title: '核销应收', bill: 0, amount: 0 },
|
|
|
+ { code: 'receivableResidue', type: 'number', title: '待核销金额', readonly: true, },
|
|
|
+ { code: 'receiptResidue', type: 'number', title: '使用预存', readonly: true, },
|
|
|
+ { code: 'sumWaiveAmt', type: 'number', title: '优惠金额', },
|
|
|
+ { code: 'currentReceivableResidue', type: 'number', title: '本次核销', required: true },
|
|
|
+ ],
|
|
|
+ file: [{
|
|
|
+ code: 'remarks', type: 'textarea', title: '备注'
|
|
|
+ },
|
|
|
+ { code: 'file', type: 'uploader', title: '附件' }]
|
|
|
+ },
|
|
|
+ // 弹出按钮
|
|
|
+ buttonList: [{
|
|
|
+ name: 'merge',
|
|
|
+ title: mixins.$t('collection')
|
|
|
+ }],
|
|
|
+ contentList: [{
|
|
|
+ code: 'need',
|
|
|
+ title: mixins.$t('totalAmount'),
|
|
|
+ type: 'str'
|
|
|
+ }, {
|
|
|
+ code: 'amount',
|
|
|
+ content: 0,
|
|
|
+ type: 'number'
|
|
|
+ }],
|
|
|
+ btnFormData: null,
|
|
|
+ routeObjName: 'receiptPayment',
|
|
|
+ accountService: app.globalData['accountService'],
|
|
|
+ receivableResidue: 0,
|
|
|
+ receiptResidue: 0,
|
|
|
+ bill: 0,
|
|
|
+ objInfo: {},
|
|
|
+ table: Constants.tables.recPay,
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * @desc : 页面加载数据方法
|
|
|
+ * @date : 2024/2/1 15:49
|
|
|
+ * @author : 姜永辉
|
|
|
+ */
|
|
|
+ loadInit() {
|
|
|
+ console.log(this.data.item, this.data.formMode);
|
|
|
+ if (this.data.formMode == Constants.formMode.edit) {
|
|
|
+ wx.setNavigationBarTitle({
|
|
|
+ title: mixins.$t('receiptReturnOrderEdit'),
|
|
|
+ })
|
|
|
+
|
|
|
+ } else {
|
|
|
+ wx.setNavigationBarTitle({
|
|
|
+ title: mixins.$t('receiptReturnOrderAdd'),
|
|
|
+ })
|
|
|
+ // 新增
|
|
|
+ if (this.data.formData == '{}') {
|
|
|
+ this.setData({
|
|
|
+ formData: JSON.stringify({ accDate: new Date().toDateStr() })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 给表单赋值
|
|
|
+ * @date : 2024/2/1 15:49
|
|
|
+ * @author : 姜永辉
|
|
|
+ */
|
|
|
+ setValuesByEdit(data) {
|
|
|
+
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 绑定数据-选择页面返回的逻辑处理
|
|
|
+ * @author : 姜永辉
|
|
|
+ * @date : 2024年3月12日
|
|
|
+ */
|
|
|
+ chooseData(e) {
|
|
|
+ console.log("chooseData", e, this.data.formData);
|
|
|
+ let formData = JSON.parse(this.data.formData)
|
|
|
+ let cardList_ = this.data.cardList
|
|
|
+ let contentObj = this.data.contentObj
|
|
|
+ let code = e.detail.code
|
|
|
+ let data = e.detail.data.data
|
|
|
+ if (code == "supId") { //供应商
|
|
|
+ formData.supId = data.id
|
|
|
+ formData.supName = data.name
|
|
|
+ }
|
|
|
+ if (code == "staffId") { //员工
|
|
|
+ formData.staffId = data.id
|
|
|
+ formData.staffName = data.name
|
|
|
+ }
|
|
|
+ if (code == "orgId") { //部门
|
|
|
+ formData.orgId = data.id
|
|
|
+ formData.orgName = data.name
|
|
|
+ }
|
|
|
+ if (code == "bill") { //选取应收的返回值
|
|
|
+ formData.receivableList = data.receivableList
|
|
|
+ this.setData({
|
|
|
+ receivableList: data.receivableList,
|
|
|
+ objInfo: data.objInfo,
|
|
|
+ receivableResidue: data.receivableResidue,
|
|
|
+ receiptResidue: data.receiptResidue,
|
|
|
+ bill: data.receivableList.length,
|
|
|
+ })
|
|
|
+ this.setForm(formData, contentObj, data.receivableResidue, data.receiptResidue, data.receivableList.length)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ cardList: cardList_,
|
|
|
+ formData: JSON.stringify(formData)
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 选择客户后的回调
|
|
|
+ * @date : 2024/2/1 15:49
|
|
|
+ * @author : 姜永辉
|
|
|
+ */
|
|
|
+ chooseObjTypeData(e) {
|
|
|
+ let _this = this
|
|
|
+ console.log("chooseObjTypeData", e, this.data.formData);
|
|
|
+ let formData = JSON.parse(this.data.formData)
|
|
|
+ let contentObj = this.data.contentObj
|
|
|
+ let objInfo = e.detail.data.objInfo
|
|
|
+ let cusId = e.detail.data.cusId
|
|
|
+ let params = {
|
|
|
+ objectId: cusId,
|
|
|
+ accItemType: '账款类型-应收',
|
|
|
+ amtResidueFlg: true,
|
|
|
+ }
|
|
|
+ this.excute(this.data.accountService, this.data.accountService.getReceivableAccountItem, params).then(res => {
|
|
|
+ console.log("getReceivableAccountItem", res);
|
|
|
+ formData.cancelAmount = true
|
|
|
+ formData.receivableList = res.data.data
|
|
|
+ _this.setForm(formData, contentObj, objInfo.receivableResidue,
|
|
|
+ objInfo.receiptResidue, res.data.data.length)
|
|
|
+ _this.setData({
|
|
|
+ objInfo,
|
|
|
+ receivableList: res.data.data,
|
|
|
+ receivableResidue: objInfo.receivableResidue,
|
|
|
+ receiptResidue: objInfo.receiptResidue,
|
|
|
+ bill: res.data.data.length
|
|
|
+ })
|
|
|
+
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 设置表单的数据
|
|
|
+ * @date : 2024/2/1 15:49
|
|
|
+ * @author : 姜永辉
|
|
|
+ */
|
|
|
+ onCheckChange(e) {
|
|
|
+ let cancelAmount = e.detail.data.cancelAmount
|
|
|
+ let formData = JSON.parse(this.data.formData)
|
|
|
+ let contentObj = this.data.contentObj
|
|
|
+ if (cancelAmount) {
|
|
|
+ formData.receivableList = this.data.receivableList
|
|
|
+ this.setForm(formData, contentObj, this.data.receivableResidue, this.data.receiptResidue, this.data.bill)
|
|
|
+ } else {
|
|
|
+ formData.receivableList = []
|
|
|
+ this.setForm(formData, contentObj, 0, 0, 0)
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 设置表单的数据
|
|
|
+ * @date : 2024/2/1 15:49
|
|
|
+ * @author : 姜永辉
|
|
|
+ */
|
|
|
+ changeNumber(e) {
|
|
|
+ let formData = JSON.parse(this.data.formData)
|
|
|
+ let code = e.detail.code
|
|
|
+ let data = e.detail.data
|
|
|
+ console.log(code, data, e);
|
|
|
+ // 本次收款金额
|
|
|
+ if (code == "sumAmtRec") {
|
|
|
+ formData.sumAmtRec = data
|
|
|
+ formData.sumAmount = data
|
|
|
+ let contentList = this.data.contentList
|
|
|
+ contentList.forEach(it => {
|
|
|
+ if (it.type == 'number') {
|
|
|
+ it.content = data
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ contentList,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ // 本次核销金额
|
|
|
+ if (code == "currentReceivableResidue") {
|
|
|
+ formData.currentReceivableResidue = data
|
|
|
+ }
|
|
|
+ // 优惠金额
|
|
|
+ if (code == "sumWaiveAmt") {
|
|
|
+ formData.sumWaiveAmt = data
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ formData: JSON.stringify(formData)
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 设置表单的数据
|
|
|
+ * @date : 2024/2/1 15:49
|
|
|
+ * @author : 姜永辉
|
|
|
+ */
|
|
|
+ setForm(formData, contentObj, receivableResidue, receiptResidue, bill) {
|
|
|
+ if (receivableResidue == null) {
|
|
|
+ receivableResidue = 0
|
|
|
+ }
|
|
|
+ if (receiptResidue == null) {
|
|
|
+ receiptResidue = 0
|
|
|
+ }
|
|
|
+ if (bill == null) {
|
|
|
+ bill = 0
|
|
|
+ }
|
|
|
+ formData.receivableResidue = receivableResidue // 总剩余应收
|
|
|
+ formData.currentReceivableResidue = receivableResidue // 总剩余应收
|
|
|
+ if (receivableResidue > receiptResidue) {
|
|
|
+ formData.receiptResidue = receiptResidue // 预存
|
|
|
+ } else {
|
|
|
+ formData.receiptResidue = receivableResidue // 预存 (用总剩余应收来负值)
|
|
|
+ }
|
|
|
+ if (formData.staffId == null) {
|
|
|
+ formData.staffId = app.globalData.user.staffId
|
|
|
+ formData.orgId = app.globalData.user.orgId
|
|
|
+ formData.staffName = app.globalData.user.staffName
|
|
|
+ formData.orgName = app.globalData.user.orgName
|
|
|
+ }
|
|
|
+ contentObj['bill'].forEach(itcard => {
|
|
|
+ if (itcard.code === 'cancelAmount') {
|
|
|
+ //单数和金额
|
|
|
+ itcard.bill = bill
|
|
|
+ itcard.amount = receivableResidue //总应收
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ contentObj,
|
|
|
+ formData: JSON.stringify(formData)
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 保存数据服务--校验
|
|
|
+ * @date : 2024/2/1 15:49
|
|
|
+ * @author : 姜永辉
|
|
|
+ */
|
|
|
+ validData() {
|
|
|
+ let msgError = null
|
|
|
+ let formData = JSON.parse(this.data.formData)
|
|
|
+ // 本次核销不能大于待核销金额
|
|
|
+ if (Number(formData.currentReceivableResidue)
|
|
|
+ > Number(formData.receivableResidue)) {
|
|
|
+ msgError = '本次核销不能大于待核销金额'
|
|
|
+ }
|
|
|
+ if (Number(formData.currentReceivableResidue) == 0
|
|
|
+ && Number(formData.sumAmtRec) == 0) {
|
|
|
+ msgError = '本次核销金额和本次收款不能同时为0'
|
|
|
+ }
|
|
|
+ // 预存+本次收款》= 本次核销
|
|
|
+ if (Number(formData.sumAmtRec) + Number(formData.receiptResidue)
|
|
|
+ < Number(formData.currentReceivableResidue)) {
|
|
|
+ msgError = '本次核销金额不能大于收款和预存金额之和'
|
|
|
+ }
|
|
|
+
|
|
|
+ if (msgError != null) {
|
|
|
+ wx.showToast({
|
|
|
+ title: msgError,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ return true
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 保存的參數設置
|
|
|
+ * @date : 2024/2/1 15:49
|
|
|
+ * @author : 姜永辉
|
|
|
+ */
|
|
|
+ setParams(params) {
|
|
|
+ let formData = JSON.parse(this.data.formData)
|
|
|
+ if (Number(formData.sumAmtRec) != 0) {
|
|
|
+ return params
|
|
|
+ }
|
|
|
+ //收付款类型-收款的查询参数
|
|
|
+ params.rpType = Constants.rpType.receipt
|
|
|
+ params.orgId = formData.orgId //组织部门
|
|
|
+ params.staffId = formData.staffId // 员工
|
|
|
+ // // 供应商1 客户2 所有 传空
|
|
|
+ params.objectId = this.data.objInfo.cusId // 客户
|
|
|
+ // 收款金额 - 本次收款
|
|
|
+ params.sumAmtRec = formData.sumAmtRec
|
|
|
+ // 合计应收冲抵金额
|
|
|
+ params.sumAmtReceivableHandle = formData.currentReceivableResidue
|
|
|
+ // 合计优惠金额
|
|
|
+ params.sumWaiveAmt = formData.sumWaiveAmt
|
|
|
+ // 预存的使用
|
|
|
+ params.receiptResidue = formData.receiptResidue
|
|
|
+ params.annexPaths = formData.annexPaths || [] //附件
|
|
|
+ // params.biznisType = null
|
|
|
+ // params.biznisId = null
|
|
|
+ // params.biznisNo = null
|
|
|
+ params.accDate = formData.accDate //
|
|
|
+ params.remarks = formData.remarks // 备注
|
|
|
+ params.makeStaff = app.globalData.user.staffId // 制单人
|
|
|
+
|
|
|
+ params.itemList = [] //明细
|
|
|
+ let rlsit = this.setReturnReceivableList(formData.receivableList || [], formData.sumWaiveAmt, formData.currentReceivableResidue, formData.receivableResidue)
|
|
|
+ params.receivableList = rlsit //应收收款的明细
|
|
|
+
|
|
|
+ return params
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 将优惠和本次核销的金额分摊到应收单据的明细里
|
|
|
+ * @date : 2024/2/1 15:49
|
|
|
+ * @author : 姜永辉
|
|
|
+ */
|
|
|
+ setReturnReceivableList(list, sumWaiveAmt, currentReceivableResidue, totalAmount) {
|
|
|
+ let retList = []
|
|
|
+ if (sumWaiveAmt == null || sumWaiveAmt == undefined) {
|
|
|
+ sumWaiveAmt = 0
|
|
|
+ }
|
|
|
+ if (currentReceivableResidue == null || currentReceivableResidue == null) {
|
|
|
+ currentReceivableResidue = 0
|
|
|
+ }
|
|
|
+ if (currentReceivableResidue == 0 && sumWaiveAmt == 0 || list == null) {
|
|
|
+ return retList
|
|
|
+ }
|
|
|
+ let finalAmout = currentReceivableResidue
|
|
|
+ let finalSumWaiveAmt = sumWaiveAmt
|
|
|
+ for (let index = 0; index < list.length; index++) {
|
|
|
+ const element = list[index];
|
|
|
+ // 应收冲抵金额 == 明细的剩余金额 默认
|
|
|
+ let amtReceivableHandle = (finalAmout < element.amtResidue ? finalAmout : element.amtResidue)
|
|
|
+ let amtWaive = Number(parseFloat(element.amtResidue / totalAmount * sumWaiveAmt).toFixed(2))
|
|
|
+ finalAmout -= amtReceivableHandle
|
|
|
+ finalSumWaiveAmt -= amtWaive
|
|
|
+
|
|
|
+ retList.push({
|
|
|
+ accDate: list.accDate,
|
|
|
+ accItemId: element.accItemId,
|
|
|
+ // 应收冲抵金额
|
|
|
+ amtReceivableHandle: amtReceivableHandle,
|
|
|
+ // 优惠金额-分摊之后 最后一条的数据取剩余的值
|
|
|
+ amtWaive: (index == list.length - 1 ? finalSumWaiveAmt : amtWaive),
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ return retList
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 保存数据服务
|
|
|
+ * @date : 2024/2/1 15:49
|
|
|
+ * @author : 姜永辉
|
|
|
+ */
|
|
|
+ saveData() {
|
|
|
+ let formData = JSON.parse(this.data.formData)
|
|
|
+ // 本次收款金额大于0 进入收款页面否则 直接保存
|
|
|
+ if (formData.sumAmtRec == 0) {
|
|
|
+ return this.excute(this.data.service, this.data.service.insertReceivableReceipt, this.data.params)
|
|
|
+ } else {
|
|
|
+ this.open()
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 保存数据服务-跳转收款页面
|
|
|
+ * @date : 2024/2/1 15:49
|
|
|
+ * @author : 姜永辉
|
|
|
+ */
|
|
|
+ open(e) {
|
|
|
+ let _this = this
|
|
|
+ wx.navigateTo({
|
|
|
+ url: '/package-base-select/pages/select-collection_confirm/select-collection_confirm',
|
|
|
+ events: {
|
|
|
+ // 回调后
|
|
|
+ bindData: function (data) {
|
|
|
+ // 保存成功后 回调
|
|
|
+ wx.navigateBack({
|
|
|
+ data: 1
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ success: function (res) {
|
|
|
+ // 通过eventChannel向被打开页面传送数据
|
|
|
+ res.eventChannel.emit('params', { item: _this.data.formData, formType: 1 })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+})
|