liuying
2024-05-09 f4078b75fe80f03e58af3217bf642d0de118d1c9
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
<template>
  <a-modal
    title="新增叫料"
    width="90vw"
    :visible="visible"
    dialogClass="zero-modal"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <div class="ex-warehouse1-modal-content">
        <div class="form-view">
          <a-form :form="form">
            <a-row>
              <a-col :md="8" :sm="24">
                <a-form-item label="单据号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input disabled v-decorator="['OrderNo',{rules:[{required:true,message:'单据号不可为空!'}]}]" />
                </a-form-item>
              </a-col>
             <!-- <a-col :md="8" :sm="24">
                <a-form-item label="工程号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input allowClear placeholder="请输入..." v-decorator="['engineeringNo',{rules:[{required:true,message:'请输入工程号!'}]}]" />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="计划号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input allowClear placeholder="请输入..." v-decorator="['planNo',{rules:[{required:true,message:'请输入计划号!'}]}]" />
                </a-form-item>
              </a-col> -->
              <a-col :md="8" :sm="24">
                <a-form-item label="叫料站点" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input v-show="false" v-decorator="['takeMaterialsSiteId',{rules:[{required:true,message:'请选择叫料站点!'}]}]" />
                  <station-select v-model="stationArr" :get-lines="getLines" :get-stations="getStations" @change="onChangeStation" />
                </a-form-item>
              </a-col>
              <!-- <a-col :md="8" :sm="24">
                <a-form-item label="班组" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input allowClear placeholder="请输入..." v-decorator="['teamName',{rules:[{required:true,message:'请输入班组!'}]}]" />
                </a-form-item>
              </a-col> -->
            </a-row>
          </a-form>
        </div>
        <div class="action-view">
          <a-button type="primary" icon="plus" @click="openChoose">
            添加物料
          </a-button>
        </div>
        <div class="list-view" ref="listWrapper">
          <!-- 注意scroll.x的值 -->
          <a-table v-if="th" :data-source="list" :columns="columns" rowKey="id" :pagination="false" :scroll="{x:1100,y:th}">
            <template slot="index" slot-scope="text,record,index">{{index+1}}</template>
            <template slot="action" slot-scope="text,record,index">
              <a-button type="danger" size="small" @click.stop="cancelListItem(index)">删除</a-button>
            </template>
          </a-table> 
        </div>
      </div>
    </a-spin>
    
    <choose-modal :visible.sync="chooseVisible" @callback="chooseBack" />
    
    <template slot="footer">
      <a-button key="back" @click="handleCancel">取消</a-button>
      <a-button key="submit" type="primary" :loading="confirmLoading" @click="handleSubmit" :disabled="!list.length">确认</a-button>
    </template>
  </a-modal>
</template>
 
<script>
  import ChooseModal from './chooseMaterials.vue'
  import { CncTakeMaterialsAdd,GetBillNumber,GetLines,GetStations } from '@/api/modular/main/ExWarehouseManage1'
  import StationSelect from '@/components/StationSelect.vue'
  export default {
    components:{ChooseModal,StationSelect},
    data () {
      return {
        getLines:GetLines,
        getStations:GetStations,
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 18 }
        },
        visible: false,
        confirmLoading: false,
        lines:[],
        stations:[],
        stationArr:[],
        th:0,
        list:[],
        columns:[
          { title: '序号', key: 'index', width: 70, align:'center', fixed:"left", scopedSlots: { customRender: 'index' }},
          { title: '物料编码', dataIndex: 'materialNo', key: 'materialNo', width: 150 },
          { title: '图号', dataIndex: 'drawingNo', key: 'drawingNo' },
          { title: '尺寸', dataIndex: 'materialSpec', key: 'materialSpec', width: 150 },
          { title: '库区', dataIndex: 'areaName', key: 'areaName', width: 120 },
          { title: '库位', dataIndex: 'placeCode', key: 'placeCode', width: 150 },
          { title: '托盘号', dataIndex: 'containerCode', key: 'containerCode', width: 120 },
          { title: '数量', dataIndex: 'stockNumber', key: 'stockNumber', width: 100 },
          { title: '操作', key: 'action', width: 80, align:'center', fixed:"right", scopedSlots: { customRender: 'action' }}
        ],
        chooseVisible:false
      }
    },
    beforeCreate(){
      this.form = this.$form.createForm(this)
    },
    methods: {
      // 初始化方法
      add (record) {
        this.visible = true
        this.$nextTick(() => {
          this.th = this.$refs.listWrapper.clientHeight - 60
          this.getInitData()
        });
      },
      getInitData(){
        this.confirmLoading = true;
        GetBillNumber().then((d1)=>{
          this.form.setFieldsValue({OrderNo:(d1.data.takeMaterialsNo || '')})
          this.confirmLoading = false;
        }).catch(()=>{
          this.confirmLoading = false;
        })
      },
      onChangeStation(arr){
        this.form.setFieldsValue({takeMaterialsSiteId:arr[1]})
      },
      chooseBack(arr){
        let newArr = [], reCount = 0;
        arr.forEach((item)=>{
          let f = false;
          for (let i=0;i<this.list.length;i++) {
            if (this.list[i].id === item.id) {
              reCount++;
              f = true
              break;
            }
          }
          if (!f) {
            newArr.push(item)
          }
        })
        this.list = [].concat(this.list,newArr)
        if (reCount) {
          this.$message.warning(`${reCount}笔数据已存在,未添加!`);
        }
      },
      cancelListItem(index){
        this.list.splice(index,1)
      },
      /**
       * 提交表单
       */
      handleSubmit () {
        this.form.validateFields((errors, values) => {
          if (!errors) {
            this.confirmLoading = true
            let params = {...values,...{WmsAssembleOrderDetails:this.list}}
            CncTakeMaterialsAdd(params).then(()=>{
              this.confirmLoading = false
              this.handleCancel()
              this.$emit('ok')
            }).catch(()=>{
              this.confirmLoading = false
            })
          } 
        })
      },
      handleCancel () {
        this.form.resetFields()
        this.visible = false
        this.th = 0
        this.list = []
        this.chooseVisible = false
      },
      openChoose(){
        this.chooseVisible = true
      }
    }
  }
</script>
<style lang="less" scoped>
.ex-warehouse1-modal-content{
  height: 70vh;
  display: flex;
  flex-direction: column;
  .form-view,.action-view{
    flex-shrink: 0;
  }
  .form-view{
    background-color: #F3F7FA;
    padding-top: 20px;
  }
  .action-view{
    padding: 8px 16px;
  }
  .list-view{
    flex-grow: 1;
    padding: 0 16px;
    overflow: auto;
  }
}
</style>