<template>
|
<el-dialog
|
custom-class="sy-modal"
|
|
title="订货号选择"
|
width="90%"
|
append-to-body
|
:before-close="close"
|
>
|
<div class="sy-default-choose-table-modal-content" v-loading="loading">
|
<div v-if="!choosenVisible">
|
<search-bar @search="onSearch" @reset="onReset">
|
<el-form :inline="true" class="search-form">
|
<el-form-item label="订货号">
|
<el-input placeholder="请输入..." clearable class="default-form-width" v-model.trim="query.orderNo"></el-input>
|
</el-form-item>
|
</el-form>
|
</search-bar>
|
|
<el-table :data="list" ref="list" border stripe @select="handleSingelSelect" @select-all="handleAllSelect">
|
<el-table-column type="selection" width="55" fixed align="center" />
|
<el-table-column width="80" label="序号" fixed align="center">
|
<template #default="scope">{{(queried.page-1)*queried.pageSize+(scope.$index+1)}}</template>
|
</el-table-column>
|
<el-table-column prop="OrderNo" label="订货号" />
|
<el-table-column prop="MaterialModel" label="型号" />
|
<el-table-column prop="Qty" label="库存数" />
|
</el-table>
|
|
<div class="pagination-row">
|
<el-pagination :pager-count="5" layout="total, prev, pager, next, jumper" :total="total" @current-change="onPageList" />
|
</div>
|
</div>
|
|
<div v-else>
|
<el-table :data="choosen" border stripe>
|
<el-table-column width="55" label="序号" fixed>
|
<template #default="scope">{{scope.$index+1}}</template>
|
</el-table-column>
|
<el-table-column prop="OrderNo" label="订货号" />
|
<el-table-column prop="MaterialModel" label="型号" />
|
<el-table-column prop="Qty" label="库存数" />
|
<el-table-column label="操作" width="80" align="center">
|
<template #default="scope">
|
<el-button type="danger" size="small">删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
</div>
|
|
</div>
|
<template #footer>
|
<span class="dialog-footer">
|
<el-button @click="onClose">取 消</el-button>
|
<el-button @click="onChangeChoosenVisible" :type="choosenVisible?'':'primary'">已选择物料<span v-if="choosen.length>0">({{choosen.length}})</span></el-button>
|
<el-button @click="onConfirm" type="primary">确 定</el-button>
|
</span>
|
</template>
|
</el-dialog>
|
</template>
|
|
<script>
|
import SearchBar from '@/components/SearchBar.vue'
|
const defaultQuery = {
|
orderNo:'',
|
orderNo_FilterMode:'1'
|
}
|
export default {
|
name:'statisticsOfInventoryOrderChooseModalCompontent',
|
components:{SearchBar},
|
emits:['submitCallback','update:visible'],
|
props:{
|
visible:{
|
type:Boolean,
|
default:false
|
}
|
},
|
data(){
|
return {
|
loading:false,
|
list:[],
|
total:100,
|
query:{...defaultQuery},
|
queried:{...this.$config.pagination},
|
choosen:[],
|
shortChoosen:[],
|
pageChecked:[],
|
choosenVisible:false
|
}
|
},
|
watch:{
|
visible(newVal,oldVal){
|
if (newVal!==oldVal) {
|
if (newVal) {
|
this.initModal();
|
}
|
}
|
}
|
},
|
methods:{
|
initModal(){
|
this.emptyChoosen();
|
this.choosenVisible = false;
|
this.reset();
|
},
|
close(){
|
this.$emit('update:visible',false)
|
},
|
onClose(){
|
this.close();
|
},
|
onSelect(row){
|
this.$emit('submitCallback',row)
|
this.close();
|
},
|
/* 搜索按钮 */
|
onSearch(){
|
this.newList()
|
},
|
/* 重置按钮 */
|
onReset(){
|
this.reset();
|
},
|
reset(needLoading=true,callback){
|
this.query = {...defaultQuery}
|
this.newList(needLoading,callback)
|
},
|
/* 翻页功能 */
|
onPageList(page){
|
this.queried.page = page;
|
this.getList();
|
},
|
/* 表格刷新至首页 */
|
newList(needLoading=true,callback){
|
this.queried = {...this.query,...this.$config.pagination}
|
this.getList(callback,needLoading)
|
},
|
/* 更新数据表 */
|
getList(callback,needLoading=true){
|
if (needLoading) {
|
this.loading = true;
|
}
|
this.$api.post('GetStoreByOrderNo',this.queried,{block:'store'}).then((d)=>{
|
this.total = d.total;
|
this.list = (d.list || []).map((currentItem)=>{
|
currentItem.tempCompare = currentItem.OrderNo+'&'+currentItem.MaterialModel
|
return currentItem
|
})
|
this.setTablePageChecked()
|
if (needLoading) {
|
this.loading = false;
|
}
|
callback && callback(true)
|
}).catch((err)=>{
|
if (needLoading) {
|
this.loading = false;
|
}
|
callback && callback(false)
|
})
|
},
|
setTablePageChecked(){
|
let tempArr = [];
|
this.$nextTick(()=>{
|
this.list.forEach((item)=>{
|
if (this.shortChoosen.indexOf(item.tempCompare)>=0) {
|
tempArr.push(item)
|
this.$refs.list.toggleRowSelection(item,undefined)
|
}
|
})
|
})
|
this.pageChecked = tempArr;
|
},
|
handleAllSelect(selection){
|
this.setMultipleChoosen(selection)
|
},
|
handleSingelSelect(selection,row){
|
if (this.$utils.getObjectArrayIndex(selection,row,'tempCompare')<0) {
|
console.log('reduce')
|
this.reduceChoosen(row)
|
} else {
|
console.log('plus')
|
this.addChoosen(row)
|
}
|
},
|
addChoosen(row){
|
this.shortChoosen.push(row.tempCompare)
|
this.choosen.push(row)
|
console.log(this.shortChoosen)
|
},
|
reduceChoosen(row){
|
let i = this.shortChoosen.indexOf(row.tempCompare);
|
if (i<0) return false;
|
this.shortChoosen.splice(i,1)
|
this.choosen.splice(i,1)
|
console.log(this.shortChoosen)
|
},
|
setMultipleChoosen(selection){
|
if (selection && selection.length>0) {
|
selection.forEach((item)=>{
|
if (this.shortChoosen.indexOf(item.tempCompare)<0){
|
this.shortChoosen.push(item.tempCompare)
|
this.choosen.push(item)
|
}
|
})
|
} else {
|
this.emptyChoosen();
|
}
|
},
|
emptyChoosen(){
|
this.choosen = [];
|
this.shortChoosen = [];
|
this.pageChecked = [];
|
},
|
onChangeChoosenVisible(){
|
this.choosenVisible = !this.choosenVisible
|
if (!this.choosenVisible) {
|
this.setTablePageChecked()
|
/* 注意,切换显示的时候,勾选会被移除,所以得再给加上 */
|
}
|
},
|
onChoosenCancel(index){
|
this.shortChoosen.splice(index,1)
|
this.choosen.splice(index,1)
|
},
|
onConfirm(){
|
if (this.choosen.length>0){
|
this.$emit('submitCallback',this.choosen)
|
}
|
this.close()
|
}
|
}
|
}
|
</script>
|
|
<style scoped lang="scss">
|
</style>
|