payne
2024-04-26 3946fe3c23ff022b7e1d27c2a29041496ef6d529
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<template>
  <a-modal
    title="盘点计划明细选择"
    width="85vw"
    :visible="innerVisible"
    dialogClass="zero-modal"
    @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="loading">
      <div class="inventory-plan-choose-modal-content">
        <div class="choose-bar">
          <div class="choose-form-view">
            <a-form layout="inline">
              <a-row>
                <a-col :md="8" :sm="24">
                  <a-form-item label="物料编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-input v-model.trim="query.MaterialName" placeholder="请输入..." allowClear />
                  </a-form-item>
                </a-col>
                <a-col :md="8" :sm="24">
                  <a-form-item label="物料名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-input v-model.trim="query.MaterialCode" placeholder="请输入..." allowClear />
                  </a-form-item>
                </a-col>
                <a-col :md="8" :sm="24">
                  <a-form-item label="物料类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-select style="width: 100%" v-model="query.MaterialType" placeholder="请选择..." allowClear>
                      <a-select-option v-for="(item,index) in types" :value="item.code" :key="'types-sel-'+index">{{item.name}}</a-select-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col :md="8" :sm="24">
                  <a-form-item label="容器编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-input v-model.trim="query.ContainerCode" placeholder="请输入..." allowClear />
                  </a-form-item>
                </a-col>
                <a-col :md="8" :sm="24">
                  <a-form-item label="库位编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-input v-model.trim="query.PlaceCode" placeholder="请输入..." allowClear />
                  </a-form-item>
                </a-col>
              </a-row>
            </a-form>
          </div>
          <div class="choose-btns-view">
            <a-button type="primary" style="margin-bottom:6px;" @click.stop="onQuery">查询</a-button>
            <a-button @click.stop="onReset">重置</a-button>
          </div>
        </div>
        <div class="table-box" ref="listWrapper">
          <div class="action-view" v-if="showType===1">
            <a-table v-if="th1" :data-source="list" :columns="listColumns" 
              :pagination="{current:queried.PageNo,pageSize:queried.PageSize,total:listTotal}" 
              :rowKey="tableKey" :row-selection="{onChange:rowSelectionsChange,selectedRowKeys:selectedRowKeys}" :scroll="{y:th1}"
              @change="chooseTablePageChange">
              <template slot="index" slot-scope="text,record,index">{{(queried.PageNo-1)*queried.PageSize+(index+1)}}</template>
              <span slot="materialTyleSlot" slot-scope="text">{{ 'material_type' | dictType(text) }}</span>
            </a-table>
          </div>
          <div class="choosen-view" v-else>
            <a-table v-if="th2" :data-source="choosen" :columns="choosenColumns" :rowKey="tableKey" :pagination="false" :scroll="{y:th2}">
              <template slot="action" slot-scope="text,record,index">
                <a-button type="danger" size="small" @click.stop="cancelChoosen(index)">删除</a-button>
              </template>
              <span slot="materialTyleSlot" slot-scope="text">{{ 'material_type' | dictType(text) }}</span>
            </a-table>
          </div>
        </div>
      </div>
    </a-spin>
    <template slot="footer">
      <a-button key="back" @click="handleCancel">取消</a-button>
      <a-button key="choosen" type="primary" @click="changeShowType">所选物料<span v-if="choosen.length>0">({{choosen.length}})</span></a-button>
      <a-button key="submit" type="primary" :loading="loading" @click="handleSubmit" :disabled="!choosen.length">确认</a-button>
    </template>
  </a-modal>
</template>
 
<script>
import { GetCouldOuts } from '@/api/modular/main/InventoryPlanManage'
const defaultQuery = {
  MaterialType:undefined,
  ContainerCode:'',
  MaterialCode:'',
  MaterialName:'',
  PlaceCode:''
}
const pagination = {
  PageNo:1,
  PageSize:10
export default {
  emits:['update:visible','callback'],
  props:{
    visible:{
      type:Boolean,
      default:false
    }
  },
  data(){
    return {
      innerVisible:false,
      loading:false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 18 }
      },
      types:[],
      query:{...defaultQuery},
      queried:{...pagination},
      tableKey:'containerCode',
      listTotal:0,
      list:[],
      listColumns:[
        { title: '序号', key: 'index', width: 70, align:'center', fixed:"left", scopedSlots: { customRender: 'index' }},
        { title: '容器编号', dataIndex: 'containerCode', key: 'containerCode' },
        { title: '库位编号', dataIndex: 'placeCode', key: 'placeCode' },
        { title: '物料编码', dataIndex: 'materialCode', key: 'materialCode' },
        { title: '物料名称', dataIndex: 'materialName', key: 'materialName' },
        { title: '物料类型', dataIndex: 'materialType', key: 'materialType', width: 120, scopedSlots: { customRender: 'materialTyleSlot' }},
        { title: '数量', dataIndex: 'stockNumber', key: 'stockNumber' }
      ],
      selectedRowKeys:[],
      choosen:[],
      choosenColumns:[
        { title: '容器编号', dataIndex: 'containerCode', key: 'containerCode' },
        { title: '库位编号', dataIndex: 'placeCode', key: 'placeCode' },
        { title: '物料编码', dataIndex: 'materialCode', key: 'materialCode' },
        { title: '物料名称', dataIndex: 'materialName', key: 'materialName' },
        { title: '物料类型', dataIndex: 'materialType', key: 'materialType', width: 120, scopedSlots: { customRender: 'materialTyleSlot' }},
        { title: '数量', dataIndex: 'stockNumber', key: 'stockNumber' },
        { title: '操作', key: 'action', width: 80, align:'center', fixed:"right", scopedSlots: { customRender: 'action' }}
      ],
      showType:1,   //1显示查询页面; 2显示已选数据
      th1:0,
      th2:0
    }
  },
  created(){
    this.innerVisible = this.visible
    this.types = this.$options.filters['dictData']('material_type')
  },
  watch:{
    visible(newVal){
      if (newVal!==this.innerVisible) {
        this.innerVisible = newVal
      }
    },
    innerVisible(newVal,oldVal){
      if (newVal!==this.visible) {
        this.$emit('update:visible',newVal)
      }
      if (newVal!==oldVal) {
        if (newVal) {
          this.init()
        }
      }
    }
  },
  methods:{
    init(){
      this.$nextTick(() => {
        let h = this.$refs.listWrapper.clientHeight
        this.th1 = h - 120
        this.th2= h - 60
        this.resetQuery()
      });
    },
    handleSubmit(){
      this.$emit('callback',this.choosen)
      this.handleCancel()
    },
    handleCancel(){
      this.innerVisible = false;
      this.showType = 1
      this.list = []
      this.choosen = []
      this.loading = false
      this.queried = {...pagination}
    },
    onQuery(){
      this.newQuery()
    },
    onReset(){
      this.resetQuery()
    },
    resetQuery(){
      this.query = {...defaultQuery}
      this.newQuery()
    },
    newQuery(){
     this.queried = {...this.query,...pagination}
      this.queryChooseDataSource()
    },
    queryChooseDataSource(){
      this.loading = true;
      GetCouldOuts(this.queried).then((d)=>{
        this.list = d.data.rows || []
        this.listTotal = d.data.totalRows || 0
        this.setSelectedRowKeys()
        this.loading = false;
      }).catch(()=>{
        this.loading = false;
      })
    },
    rowSelectionsChange(selectedRowKeys, selectedRows){
      let reduces = [], adds = []
      /* 计算需要被移出choosen的内容 */
      this.selectedRowKeys.forEach((val)=>{
        let f1 = false;
        for (let i=0;i<selectedRowKeys.length;i++) {
          if (selectedRowKeys[i] === val) {
            f1 = true;
            break;
          }
        }
        if (!f1) {
          reduces.push(val)
        }
      })
      /* 计算需要被加入choosen的内容 */
      selectedRowKeys.forEach((val)=>{
        let f2 = false;
        for (let i=0;i<this.choosen.length;i++) {
          if (this.choosen[i][this.tableKey] === val) {
            f2 = true;
            break;
          }
        }
        if (!f2) {
          adds.push(val)
        }
      })
      /* 执行实际数据处理,先减后加,减少处理时间 */
      this.selectedRowKeys = selectedRowKeys
      this.reduceChoosen(reduces)
      this.addChosen(adds)
    },
    chooseTablePageChange(pagination){
      this.queried.PageNo = pagination.current
      this.queryChooseDataSource()
    },
    reduceChoosen(arr){
      arr.forEach((val)=>{
        let reduceIndex = -1;
        for (let i=0;this.choosen.length;i++) {
          if (this.choosen[i][this.tableKey] === val) {
            reduceIndex = i
            break;
          }
        }
        if (reduceIndex>=0) {
          this.choosen.splice(reduceIndex,1)
        }
      })
    },
    cancelChoosen(index){
      this.choosen.splice(index,1)
    },
    addChosen(arr){
      arr.forEach((val)=>{
        for (let i=0;this.list.length;i++) {
          if (this.list[i][this.tableKey] === val) {
            let obj = {...this.list[i]}
            this.choosen.push(obj)
            break;
          }
        }
      })
    },
    setSelectedRowKeys(){
      let arr = []
      this.choosen.forEach((item)=>{
        for (let i=0;i<this.list.length;i++) {
          if (this.list[i][this.tableKey] === item[this.tableKey]) {
            arr.push(item[this.tableKey])
            break;
          }
        }
      })
      this.selectedRowKeys = arr
    },
    changeShowType(){
      if (this.showType===1) {
        this.showType = 2
      } else {
        this.showType = 1
        this.setSelectedRowKeys()
      }
    }
  }
}
</script>
 
<style lang="less" scoped>
.inventory-plan-choose-modal-content{
  height: 70vh;
  display: flex;
  flex-direction: column;
  .choose-bar{
    flex-shrink: 0;
    padding: 8px 4px;
    display: flex;
    .choose-form-view{
      flex-grow: 1;
    }
    .choose-btns-view{
      flex-shrink: 0;
      display: flex;
      flex-direction: column;
      justify-content: center;
    }
  }
  .table-box{
    flex-grow: 1;
    padding: 0 16px;
    overflow: auto;
  }
  .ant-form-inline{
    .ant-form-item {
      margin-right: 0;
      width: 100%;
    }
  }
}
</style>