| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- 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 : 于继渤
- */
- 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.rejectQty * -1)
- item.itemQtyMin = Number(item.rejectQty * -1)
- item.itemQtyMax = Number(-1)
- item.priceReturn = Number(item.priceInto * -1)
- item.itemAmt = Number(item.rejectQty * item.priceInto * -1)
- choooseInboundItemList.push(item)
- }
- })
- }
- })
- if (choooseInboundItemList && choooseInboundItemList.length > 0) {
- choooseInboundItemList.forEach(res => {
- returnTotalAmount += Number(res.rejectQty * 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)
- }
-
- })
- let that = this
- let formData = that.data.formData
- let item = that.data.item
- item.fromNo = fromNo
- 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',
- choooseInboundItemList: choooseInboundItemList,
- beforeSumAmount: that.data.returnTotalAmount * -1,
- 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
- })
- },
- })
|