liuying
2024-04-25 ca3d7079ea8d06599ff322daac616ea60ed6329d
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
<template>
  <a-modal
    title="物料选择"
    width="85vw"
    :visible="innerVisible"
    dialogClass="zero-modal"
    @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="loading">
      <div class="purchase-receive-choose-modal-content">
        <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="unitTyleSlot" slot-scope="text">{{ 'unit_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="unitTyleSlot" slot-scope="text">{{ 'unit_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 { GetCouldReceiveMaterials } from '@/api/modular/main/PurchaseReceiveOrderManage'
const pagination = {
  PageNo:1,
  PageSize:10
export default {
  emits:['update:visible','callback'],
  props:{
    visible:{
      type:Boolean,
      default:false
    },
    queryOrderNo:{
      type:String,
      default:''
    }
  },
  data(){
    return {
      innerVisible:false,
      loading:false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 18 }
      },
      queried:{...pagination},
      tableKey:'materialNo',
      listTotal:0,
      list:[],
      listColumns:[
        { title: '序号', key: 'index', width: 70, align:'center', fixed:"left", scopedSlots: { customRender: 'index' }},
        { title: '物料编码', dataIndex: 'materialNo', key: 'materialNo' },
        { title: '物料名称', dataIndex: 'materialName', key: 'materialName' },
        { title: '规格', dataIndex: 'materialSpec', key: 'materialSpec' },
        { title: '单位类型', dataIndex: 'basicUnit', key: 'basicUnit', width: 120, scopedSlots: { customRender: 'unitTyleSlot' }},
        { title: '送货数', dataIndex: 'deliverQuantity', key: 'deliverQuantity', width: 180 }
      ],
      selectedRowKeys:[],
      choosen:[],
      choosenColumns:[
        { title: '物料编码', dataIndex: 'materialNo', key: 'materialNo' },
        { title: '物料名称', dataIndex: 'materialName', key: 'materialName' },
        { title: '规格', dataIndex: 'materialSpec', key: 'materialSpec' },
        { title: '单位类型', dataIndex: 'basicUnit', key: 'basicUnit', width: 120, scopedSlots: { customRender: 'unitTyleSlot' }},
        { title: '送货数', dataIndex: 'deliverQuantity', key: 'deliverQuantity', width: 180 },
        { 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
  },
  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.newQuery()
      });
    },
    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}
    },
    newQuery(){
      this.queried = {...pagination}
      this.queried.purchaseOrderNo = this.queryOrderNo
      this.queryChooseDataSource()
    },
    queryChooseDataSource(){
      this.loading = true;
      GetCouldReceiveMaterials(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>
.purchase-receive-choose-modal-content{
  height: 50vh;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  padding: 16px 16px 0 16px;
  .table-box{
    height: 100%;
  }
}
</style>