const Constants = require('@/utils/Constants.js'); const util = require('@/utils/util.js') const mixins = require('@/mixins/index.js') Page({ mixins: [mixins], /** * 页面的初始数据 */ data: { returnTotalAmount: 0, allChecked: false, // 路由 routeObjName: 'inbound', tableData: [], choooseInboundItemList: [], buttonSaveList: [{ code: 'add', title: mixins.$t('confirm'), width: '120rpx', }], contentSaveList: [{ code: 'need', title: '退货总额', type: 'str' }, { code: 'amount', content: 0, type: 'number' }], }, /** * @desc : 加载数据源 * @date : 2024/2/1 15:49 * @author : 于继渤 */ getData(params) { return this.excute(this.data.service, this.data.service.selectInboundAndItem, params); }, /** * @desc : 加载数据源 * @date : 2024/2/1 15:49 * @author : 于继渤 */ handleSearchData(tableData) { console.log('handleSearchData', tableData) if (tableData && tableData.length > 0) { tableData.forEach(res => { if (res.inboundItemList && res.inboundItemList.length > 0) { res.inboundItemList.forEach(item => { //处理图片 if (item.skuImages) { item['imagesUrl'] = item.skuImages.length > 0 ? item.skuImages[0].url : null } }) } }) } this.setData({ tableData:tableData, contentSaveList: [{ code: 'need', title: '退货总额', type: 'str' }, { code: 'amount', content: 0, type: 'number' }] }) }, /** * @desc : 设置查询参数 * @date : 2024/2/1 15:49 * @author : 于继渤 */ setSearchParams(params) { params.intoType = Constants.intoType.pur params.intoStatus = Constants.intoStatus.inBounded params.fromId = this.data.id return params }, /** * @desc : 父级商品信息选择 * @date : 2024/2/1 15:49 * @author : 于继渤 */ onListItemChange(e) { let tableData = this.data.tableData let index = e.currentTarget.dataset.index tableData.forEach(item => { item.checked = false item.inboundItemList.forEach(it => { it.checked = false }) }) tableData[index].checked = e.detail let inboundItemList = tableData[index].inboundItemList if (inboundItemList && inboundItemList.length > 0) { inboundItemList.forEach(res => { res.checked = tableData[index].checked }) } //商品不能跨入库单选择 this.setData({ tableData: tableData }) this.calculateTotal() }, /** * @desc : 子级商品信息选择 * @date : 2024/2/1 15:49 * @author : 于继渤 */ onChangeItemCheckbox(e) { let tableData = this.data.tableData let index = e.currentTarget.dataset.index let index_ = e.currentTarget.dataset.index_ // tableData.forEach(item => { // item.checked = false // item.inboundItemList.forEach(it => { // it.checked = false // }) // }) tableData[index].inboundItemList[index_].checked = e.detail this.setData({ tableData: tableData }) this.calculateTotal() }, /** * @desc : 全退 * @date : 2024/2/1 15:49 * @author : 于继渤 */ onCheckboxChange(e) { let checked = e.detail.checked let tableData = this.data.tableData tableData.forEach(res => { res.checked = checked if (res.inboundItemList && res.inboundItemList.length > 0) { res.inboundItemList.forEach(item => { item.checked = checked }) } }) this.setData({ tableData: tableData }) this.calculateTotal() }, /** * @desc : 计算金额/过滤出已选数据 * @date : 2024/2/1 15:49 * @author : 于继渤 */ calculateTotal() { let tableData = this.data.tableData let contentSaveList = this.data.contentSaveList let choooseInboundItemList = [] let returnTotalAmount = Number(0) //过滤出已选数据 tableData.forEach(res => { if (res.inboundItemList && res.inboundItemList.length > 0) { res.inboundItemList.forEach(item => { if (item.checked) { // item.itemQty = Number(item.canReturnQty ) // item.itemQtyMin = Number(item.canReturnQty) // item.itemQtyMax = Number(-1) // item.itemAmt = Number(item.canReturnQty * item.priceInto) choooseInboundItemList.push(item) } }) } }) if (choooseInboundItemList && choooseInboundItemList.length > 0) { choooseInboundItemList.forEach(res => { returnTotalAmount += Number(res.intoingQty * res.priceInto) }) } contentSaveList[1]['content'] = returnTotalAmount.toFixed(2) this.setData({ returnTotalAmount: returnTotalAmount, choooseInboundItemList: choooseInboundItemList, contentSaveList: contentSaveList, }) }, /** * @desc : 跳转退货页 * @date : 2024/2/1 15:49 * @author : 于继渤 */ toAdd() { let choooseInboundItemList = this.data.choooseInboundItemList let fromNo = [] choooseInboundItemList.forEach(res => { if (fromNo.indexOf(res.intoNo) == -1) { fromNo.push(res.intoNo) } res.sPurId = res.fromId res.sPurItemId = res.fromItemId res.fromId = res.intoId res.fromItemId = res.intoItemId res.sIntoId = res.intoId res.sIntoItemId = res.intoItemId res.intoingQty = res.decimalPlaces ? res.intoingQty.toFixed(res.decimalPlaces) : res.intoingQty res.returnQty = null res.returnAmt = null delete res['itemId'] }) let that = this let formData = that.data.formData let item = that.data.item item.choooseInboundItemList = choooseInboundItemList item.fromNo = fromNo item.fromId = choooseInboundItemList[0].intoId item.sPurId = item.purId if (this.data.id) { wx.navigateTo({ url: this.data.route.addReturn.url, success: function (res) { // 通过eventChannel向被打开页面传送数据 TODO 测试例子url是写死的,实际中,需要从route中读取 res.eventChannel.emit('params', { formMode: 'add', item: JSON.stringify(item) }) } }) } else { const eventChannel = this.getOpenerEventChannel(); eventChannel.emit('bindData', { data: { itemList: choooseInboundItemList, beforeSumAmount: that.data.returnTotalAmount * -1 } }) wx.navigateBack({ data: 1 }) } }, /** * 生命周期函数--监听页面加载 */ loadInit() { this.setData({ searchText: this.data.item.purNo }) }, })