ke_junjie
2025-06-04 84620534eb627e95811b971a4b552b6a177829bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<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">取&nbsp;消</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">确&nbsp;定</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>