k94314517
2023-08-11 d52b2bdc62a5722a96d3999a9ed96640f3945f91
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
<template>
  <GlobalWindow
    :title="title"
    :visible.sync="visible"
    :confirm-working="isWorking"
    @confirm="confirm"
  >
    <el-form :model="form" ref="form" :rules="rules">
      <el-form-item label="计划生产数量:" prop="planNum">
        <el-input v-model="form.planNum" placeholder="请输入" v-trim/>
      </el-form-item>
      <el-form-item label="计划开工日期:" prop="planDate">
        <el-date-picker
          v-model="form.planDate"
          value-format="yyyy-MM-dd"
          type="date"
          :picker-options="pickerOptions"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="生产设备:" prop="proGroupId">
        <el-select
          v-model="form.proGroupId"
          clearable
          filterable
          placeholder="请选择生产设备"
          @change="selectDevice"
        >
          <el-option
            v-for="(item, index) in device"
            :key="index"
            :label="'【' + item.code + '】' +item.name "
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="生产人员:" prop="proUserList">
        <el-select 
          v-model="form.proUserList" 
          :disabled="!form.proGroupId" 
          multiple 
          clearable
          filterable
          placeholder="请选择生产人员" 
          @change="selectUser"
        >
          <el-option
            v-for="(item, index) in user"
            :key="index"
            :label="index==0?'全部':(item.umodel.name  + ' - ' + (item.tmodel && item.tmodel.name))"
            :value="item.userId">
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </GlobalWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
import { findAll } from '@/api/ext/userDeviceExt'
// import { getUserDevice } from '@/api/ext/userDeviceExt'
import { distributeById } from '@/api/ext/plansExt'
import { getDeviceByCondition } from '@/api/ext/deviceExt'
export default {
  name: 'OrderDistrubution',
  extends: BaseOpera,
  components: { GlobalWindow },
  data () {
    return {
      // 表单数据
      form: {
        planId: null,
        planNum: null,
        planDate: null,
        proGroupId: '',
        proUserList: []
      },
      parent: [],
      isShow: false,
      device: [],
      user: [],
      index: null,
      pickerOptions: {},
      // 验证规则
      rules: {
        planNum: [
          { required: true, message: '请输入计划生产数量', trigger: 'blur' }
        ],
        planDate: [
          { required: true, message: '请选择计划生产日期', trigger: 'change' }
        ],
        proUserId: [
          { required: true, message: '请选择生产人员/设备', trigger: 'change' }
        ]
      }
    }
  },
  methods: {
    open (title, target) {
      this.title = title
      this.visible = true
      // 编辑
      this.$nextTick(() => {
        for (const key in this.form) {
          this.form[key] = target[key]
        }
        this.form.planDate = new Date()
        this.form.planId = target.id
        this.form.planNum = target.num - target.distributNum
        getDeviceByCondition({})
          .then(res => {
            this.device = res
          })
          .catch(err => {
            console.log(err)
          })
        })
    },
    selectDevice (v) {
      this.getUser(v)
    },
    getUser (deviceId) {
      findAll({ 
        // dmodelProcedureId: target.procedureId
        deviceId,
        planId: this.form.planId
      })
        .then(res => {
          this.form.proUserList = []
          this.user = res
          if (res.length > 0) {
            this.user = [{userId:'all'} ,...res]
            // if (res[0].userList.length > 0) {
            //   let tempUserId = res.userList[0].userId
            //   for (const item of res) {
            //     if (item.userId === tempUserId) {
            //       this.form.proUserList.push(item.userId)
            //     }
            //   }
            // }
          }
          console.log(this.user)
        })
        .catch(err => {
          console.log(err)
        })
    },
    // changeModel (v) {
    //   // console.log('选择了', v)
    //   const item = this.user[v]
    //   this.form.userDeivceId = item.id
    // },
    selectUser (v) {
      console.log(v);
      if (v.indexOf('all') != -1) {
        console.log('all');
        let all = this.user.map(item=> item.userId)
        this.form.proUserList = all.filter(item => item!='all')
      }
    },
    __confirmCreate () {
      this.$refs.form.validate((valid) => {
        if (!valid) {
          return
        }
        // 调用新建接口
        this.isWorking = true
        // let form = JSON.parse(JSON.stringify(this.form))
        // form.proUserList = this.form.proUserList.join(',')
        distributeById(this.form)
          .then(() => {
            this.visible = false
            this.$tip.apiSuccess('分配成功')
            this.$emit('success')
          })
          .catch(e => {
            this.$tip.apiFailed(e)
          })
          .finally(() => {
            this.isWorking = false
          })
      })
    },
    compairDate (data) {
      let date1 = new Date(data);
      let date2 = new Date();
      console.log(date1, date2);
      if (date1 > date2) {
        return date1
      } else {
        return date2
      }
    },
    // pickerOptions(data) {
    //   let time = new Date(data);
    //   let tempTime = 3600 * 1000 * 24 
    //   return {
    //    disabledDate: time.getTime() < new Date(data)-tempTime
    //   }
    // }
  },
  created () {
    this.config({
      api: '/ext/categoryExt',
      'field.id': 'id'
    })
    this.pickerOptions.disabledDate = (time) => {
        // 一天
      let tempTime = 3600 * 1000 * 24 
      return time.getTime() < new Date()-tempTime
    }
  }
}
 
</script>