|
|
|
@ -32,12 +32,18 @@ |
|
|
|
<!-- 物料table --> |
|
|
|
<view class="lf-p-32 lf-p-t-30 lf-p-b-30 lf-w-100 lf-h-maxcontent lf-border-box"> |
|
|
|
<view class="lf-font-32 lf-font-bold">物资明细</view> |
|
|
|
<view v-for="(value, key) in material_list" :key="key" class="lf-m-t-20"> |
|
|
|
<view v-for="(value, key) in render_material_list" :key="key" class="lf-m-t-20"> |
|
|
|
<view class="lf-m-b-10 lf-row-between"> |
|
|
|
<text>{{ value.supplier_name }}</text> |
|
|
|
<text @click="removeSupplier(key)">删除</text> |
|
|
|
</view> |
|
|
|
<wyb-table :headers="value.headers" :contents="value.material_list" contentBgColor="#ecfaf5" :first-line-fixed="true" @onInputChange="onInputChange" width="max-content" height="800rpx"></wyb-table> |
|
|
|
<wyb-table :headers="value.headers" |
|
|
|
:contents="value.material_list" |
|
|
|
contentBgColor="#ecfaf5" |
|
|
|
:first-line-fixed="true" |
|
|
|
@onInputChange="onInputChange" |
|
|
|
width="max-content" height="800rpx" |
|
|
|
@onButtonClick="onButtonClick"></wyb-table> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
<!-- 操作按钮 --> |
|
|
|
@ -59,22 +65,20 @@ |
|
|
|
data(){ |
|
|
|
return { |
|
|
|
date: this.$shared.recordTime(new Date(), '-', 'date'), // 选择时间 |
|
|
|
material_list: {}, // 供应商,物资列表 |
|
|
|
show_material: false, |
|
|
|
render_material_list: [] |
|
|
|
material_list: {}, // 供应商,物资列表,不被渲染,在底层逻辑运作 |
|
|
|
show_material: false, // 是否显示采购清单按钮 |
|
|
|
render_material_list: {} // 渲染出来的物资列表 |
|
|
|
} |
|
|
|
}, |
|
|
|
onLoad(){ |
|
|
|
// todo 验证table有没有问题,因为它是从对象转为数组的 |
|
|
|
// todo 选择供应商但未选择物资,点进去选择物资,选完回到当前页面,table没有显示 |
|
|
|
|
|
|
|
// 监听MaterialList被操作 |
|
|
|
uni.$on('addMaterialList', res => { |
|
|
|
this.material_list = res; |
|
|
|
}) |
|
|
|
}, |
|
|
|
onShow(){ |
|
|
|
let material_list = this.material_list; |
|
|
|
let material_list = JSON.stringify(this.material_list); |
|
|
|
material_list = JSON.parse(material_list); |
|
|
|
for(let i in material_list){ |
|
|
|
// table 标题处理 |
|
|
|
material_list[i].headers = [{ |
|
|
|
@ -84,28 +88,60 @@ |
|
|
|
key: 'spec_name', |
|
|
|
label: '规格' |
|
|
|
},{ |
|
|
|
key: 'purchase_number', |
|
|
|
label: '采购数量' |
|
|
|
key: 'unit', |
|
|
|
label: '单位' |
|
|
|
},{ |
|
|
|
key: 'brand', |
|
|
|
label: '品牌' |
|
|
|
},{ |
|
|
|
key: 'tax_price', |
|
|
|
label: '税前价' |
|
|
|
label: '含税价' |
|
|
|
},{ |
|
|
|
key: 'non_tax_price', |
|
|
|
label: '税后价' |
|
|
|
label: '不含税价' |
|
|
|
},{ |
|
|
|
key: 'purchase_number', |
|
|
|
label: '数量' |
|
|
|
},{ |
|
|
|
key: 'operation', |
|
|
|
label: '操作' |
|
|
|
}]; |
|
|
|
// table 内容处理 |
|
|
|
let list_arr = []; |
|
|
|
for(let j in material_list[i].material_list){ |
|
|
|
material_list[i].material_list[j].purchase_number = {edit: true, value: ''}; |
|
|
|
material_list[i].material_list[j].operation = {button: true, key: 'delete', value: '删除'}; |
|
|
|
list_arr.push(material_list[i].material_list[j]); |
|
|
|
} |
|
|
|
material_list[i].material_list = list_arr; |
|
|
|
} |
|
|
|
this.material_list = material_list; |
|
|
|
this.render_material_list = material_list; |
|
|
|
this.show_material = Object.keys(this.material_list).length > 0; |
|
|
|
console.log("show..material_list", this.material_list); |
|
|
|
console.log("show...render_material_list", this.render_material_list) |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
// table-input值被改变 todo |
|
|
|
// table-input值被改变 |
|
|
|
onInputChange(event){ |
|
|
|
console.log("检测到table input被更改", event); |
|
|
|
// this.contents[event.contentIndex][event.key].value = event.detailValue; |
|
|
|
let supplier_id = event.lineData.supplier_id; // 取出第一层,供应商id |
|
|
|
let material_index = event.contentIndex; // 取出第二层,物资下标 |
|
|
|
let detailValue = event.detailValue; // 取出table input被输入的值 |
|
|
|
let supplier_item = this.render_material_list[supplier_id]; // 取出所在供应商 |
|
|
|
let material_item = supplier_item.material_list[material_index]; // 取出物资 |
|
|
|
material_item.purchase_number.value = detailValue; // 将输入的值赋值给物资 |
|
|
|
console.log("render_material_list_change", this.render_material_list); |
|
|
|
}, |
|
|
|
// table 操作按钮被点击 |
|
|
|
onButtonClick(event){ |
|
|
|
console.log("event", event); |
|
|
|
if(event.content.key == 'delete'){ |
|
|
|
let supplier_id = event.lineData.supplier_id; // 取出第一层,供应商id |
|
|
|
let material_id = event.lineData.material_id; // 取出第二层,物资id |
|
|
|
let material_index = event.lineData.contentIndex; // 取出第二层,物资下标 |
|
|
|
this.render_material_list[supplier_id].material_list.splice(material_index, 1); |
|
|
|
delete this.material_list[supplier_id].material_list[material_id]; |
|
|
|
} |
|
|
|
}, |
|
|
|
// 时间选择 |
|
|
|
pickerChange(event){ |
|
|
|
@ -113,29 +149,45 @@ |
|
|
|
}, |
|
|
|
// 移除供应商 |
|
|
|
removeSupplier(key){ |
|
|
|
let material_list = {...this.material_list}; |
|
|
|
delete material_list[key]; |
|
|
|
this.material_list = material_list; |
|
|
|
// 移除render_material_list |
|
|
|
let render_material_list = {...this.render_material_list}; |
|
|
|
delete render_material_list[key]; |
|
|
|
this.render_material_list = render_material_list; |
|
|
|
// 移除material_list |
|
|
|
delete this.material_list[key]; |
|
|
|
// 校验还有没有供应商,没有则不能显示选择物资按钮 |
|
|
|
this.show_material = Object.keys(this.material_list).length > 0; |
|
|
|
}, |
|
|
|
// 保存并发单 |
|
|
|
save(_t){ |
|
|
|
let material_list = this.material_list; |
|
|
|
let material_list = this.render_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 |
|
|
|
}); |
|
|
|
} |
|
|
|
// 数组写法 |
|
|
|
let arr = material.map(item => { |
|
|
|
return { |
|
|
|
m_id: item.material_id, |
|
|
|
m_spec_id: item.spec_id, |
|
|
|
tax_price: item.tax_price, |
|
|
|
non_tax_price: item.non_tax_price, |
|
|
|
purchase_number: item.purchase_number.value || 0 |
|
|
|
} |
|
|
|
}); |
|
|
|
// 对象写法: |
|
|
|
// 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 |
|
|
|
|