diff --git a/common/mixin.js b/common/mixin.js index d5146e8..74f1728 100644 --- a/common/mixin.js +++ b/common/mixin.js @@ -112,7 +112,7 @@ export default{ let pages = getCurrentPages(); // 当前页 let beforePage = pages[pages.length - (page + 1)]; // 上个页面 if(beforePage && beforePage.route){ - uni.navigateBack(); + uni.navigateBack({delta: page}); }else{ let path_url = '/pages/'+ this.$getPageType() +'/index/index'; this.$url(path_url, {type: 'launch'}); diff --git a/components/wyb-table/wyb-table.vue b/components/wyb-table/wyb-table.vue index 97e347e..8361850 100644 --- a/components/wyb-table/wyb-table.vue +++ b/components/wyb-table/wyb-table.vue @@ -205,7 +205,7 @@ bottomComputed: [], colorList: [], bgColorList: [], - contentsSort: this.contents.slice(), + contentsSort: this.toArray(), oContentsSort: [], sortWay: 0, sortKeys: [], @@ -535,7 +535,7 @@ } }, contents: { - type: Array, + type: [Array, Object], default() { return [{ name: '张三', @@ -754,6 +754,19 @@ } }, methods: { + // 校验数据格式,如果不是数组则转为数组 + toArray(){ + if(Array.isArray(this.contents)){ + return this.contents.slice(); + }else{ + let contents = {...this.$props.contents}; + let arr = []; + for(let i in contents){ + arr.push(contents[i]); + } + return arr; + } + }, inputBlur(cIndex, hIndex, event){ let event_obj = {}; let value = event.detail.value; diff --git a/pages/canteen/classification/material.vue b/pages/canteen/classification/material.vue index 9e9f0b8..0cb6c10 100644 --- a/pages/canteen/classification/material.vue +++ b/pages/canteen/classification/material.vue @@ -24,7 +24,8 @@ - + + @@ -41,13 +42,18 @@ checked_list: {}, is_search_ing: false, // 是否处于搜索中 request_count: 0, // 请求次数 + type: 0 } }, - onLoad(){ + onLoad(options){ this.windowHeight = uni.getSystemInfoSync().windowHeight; - let pages = getCurrentPages(); - let prevPage = pages[pages.length - 3]; // 上上一页 + let page_num = 3; // 上上一页 + this.type = options.type || this.type; + if(options.type && options.type == 1){ + page_num = 2; + } + let prevPage = pages[pages.length - page_num]; if(!prevPage){ let path_url = '/pages/canteen/index/index'; this.$msg('页面异常, 即将跳转').then(result => { @@ -56,89 +62,6 @@ return; } this.checked_list = prevPage.$data.material_list; - - /* - this.checked_list = { - "1": { - address: "广西南宁市青秀区青秀万达店", - admin_uid: 1, - area_id: 2165, - checked: true, - city_id: 2163, - corporate_account: "6214456799861234", - corporate_account_name: "刘淑怡粮油店", - corporate_bank: "招商银行", - corporate_bank_sub: "青秀区支行", - corporate_name: "法人", - corporate_phone: "15699896658", - created_at: "2021-07-17 11:34:50", - created_uid: 1, - ctl_man: "刘淑怡", - ctl_phone: "13397706896", - deleted_at: null, - deleted_uid: 0, - id: 1, - license_number: "11559896646", - license_pic: "admin_images/5bbbc1e4f96bc5566c43bb006d36cc37.jpg", - logo: "admin_images/83e16f0d0c9dd01f1bfd62ddf150607e.jpeg", - material_list: {}, - private_account: "", - private_account_name: "", - private_bank: "", - private_bank_sub: "", - province_id: 2162, - qualification_pic: "", - remark: "测试备注,我只改个备注", - s_cate_id: 1, - state: "启用", - subject_name: "主体名称", - subject_type: "公司", - supplier_name: "供应商001", - updated_at: "2021-07-17 16:25:58", - updated_uid: 1 - }, - "2": { - address: "F座6楼", - admin_uid: 3, - area_id: 2165, - checked: true, - city_id: 2163, - corporate_account: "", - corporate_account_name: "", - corporate_bank: "", - corporate_bank_sub: "", - corporate_name: "", - corporate_phone: "", - created_at: "2021-07-17 20:28:17", - created_uid: 1, - ctl_man: "芳芳", - ctl_phone: "13397706896", - deleted_at: null, - deleted_uid: 0, - id: 2, - license_number: "", - license_pic: "", - logo: "admin_images/skyshareimg.jpeg", - material_list: {}, - private_account: "", - private_account_name: "", - private_bank: "", - private_bank_sub: "", - province_id: 2162, - qualification_pic: "", - remark: "", - s_cate_id: 2, - state: "启用", - subject_name: "", - subject_type: "公司", - supplier_name: "供应商002", - updated_at: "2021-07-27 12:00:01", - updated_uid: 1 - } - }; - */ - - this.getData(); }, methods: { @@ -241,7 +164,11 @@ // todo关闭所有页面跳转 // this.$url('/pages/canteen/purchase/launch', {type: 'launch'}) - // this.$toBack(2); // 跳回前两个页面 + let page_num = 2; // 默认跳回前两个页面 + if(this.type == 1){ + page_num = 1; + } + this.$toBack(page_num); }, // 上一步 prev(){ diff --git a/pages/canteen/purchase/launch.vue b/pages/canteen/purchase/launch.vue index ea93329..0e1d278 100644 --- a/pages/canteen/purchase/launch.vue +++ b/pages/canteen/purchase/launch.vue @@ -9,10 +9,10 @@ - + 采购清单 - + @@ -32,20 +32,19 @@ 物资明细 - - + - 我是供应商 - 删除 + {{ value.supplier_name }} + 删除 - + - - + + @@ -59,25 +58,15 @@ }, data(){ return { - headers: [{ - label: '菜品名称', - key: 'name' - },{ - label: '规格', - key: 'spec' - },{ - label: '税前价', - key: 'pre_tax_price' - },{ - label: '税后价', - key: 'after_tax_price' - }], - contents: [], date: this.$shared.recordTime(new Date(), '-', 'date'), // 选择时间 - material_list: {} // 供应商,物资列表 + material_list: {}, // 供应商,物资列表 + show_material: false, + render_material_list: [] } }, onLoad(){ + // todo 验证table有没有问题,因为它是从对象转为数组的 + // todo 选择供应商但未选择物资,点进去选择物资,选完回到当前页面,table没有显示 // 监听MaterialList被操作 uni.$on('addMaterialList', res => { @@ -85,28 +74,34 @@ }) }, onShow(){ - console.log("material_list", this.material_list) + let material_list = this.material_list; + for(let i in material_list){ + // table 标题处理 + material_list[i].headers = [{ + key: 'material_name', + label: '菜品名称' + },{ + key: 'spec_name', + label: '规格' + },{ + key: 'purchase_number', + label: '采购数量' + },{ + key: 'tax_price', + label: '税前价' + },{ + key: 'non_tax_price', + label: '税后价' + }]; + // table 内容处理 + for(let j in material_list[i].material_list){ + material_list[i].material_list[j].purchase_number = {edit: true, value: ''}; + } + } + this.material_list = material_list; + this.show_material = Object.keys(this.material_list).length > 0; }, methods: { - // 改接口废弃 - getMaterialList(){ - this.$http(this.API.API_CANTEEN_MATERIALLIST, { - // category_id: 1 // 分类id 不传则显示默认分类 - }).then(res => { - let list = res.data.material || []; - let contents = list.map(item => { - return { - name: item.material.m_name, - spec: item.name, - pre_tax_price: {edit: true, value: item.tax_standard_price}, - after_tax_price: {edit: true, value: item.non_tax_standard_price}, - spec_id: item.id, - material_id: item.material.id - } - }) - this.contents = contents; - }) - }, // table-input值被改变 todo onInputChange(event){ console.log("检测到table input被更改", event); @@ -116,24 +111,47 @@ pickerChange(event){ this.date = event.detail.value; }, + // 移除供应商 + removeSupplier(key){ + let material_list = {...this.material_list}; + delete material_list[key]; + this.material_list = material_list; + }, // 保存并发单 - save(){ - // todo - console.log("dddddd", this.contents) - - - return; - - let list = this.contents.map(item => { - return { - m_id: item.material_id, - m_spec_id: item.spec_id, - tax_price: item.pre_tax_price.value, - non_tax_price: item.after_tax_price.value + save(_t){ + let material_list = this.material_list; + let list = []; + let is_empty = true; // 物资数据是否为空 + for(let i in material_list){ + if(Object.keys(material_list[i].material_list).length){ + is_empty = false; + let material = material_list[i].material_list; + let arr = []; + for(let j in material){ + arr.push({ + m_id: material[j].material_id, + m_spec_id: material[j].spec_id, + tax_price: material[j].tax_price, + non_tax_price: material[j].non_tax_price, + purchase_number: material[j].purchase_number.value || 0 + }); + } + list.push({ + supplier_id: material_list[i].id, + material: arr + }) } - }); + } + + console.log("list", list) + if(is_empty){ + this.$msg('您未选择物资'); + return; + } + let state = ['待发单', '待审核'][_t]; this.$http(this.API.API_CANTEEN_PURCHASEAPPLY, { - data: list + order: list, + state: state }).then(res => { console.log("save", res); this.$msg('操作成功');