schangxiang@126.com
2024-08-16 65bd2dc1d4c1fb136af853c7ede93a338431be29
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
<template>
  <a-modal
    :title="type=='add'?'新增生产计划':'编辑生产计划'"
    :width="600"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-form-item label="计划类型" has-feedback>
          <a-select
            disabled
            allow-clear
            style="width: 100%"
            placeholder="请选择计划类型"
            v-decorator="['planType']"
          >
            <a-select-option :value="1"> 班组计划 </a-select-option>
            <a-select-option :value="2"> 月份计划 </a-select-option>
          </a-select>
        </a-form-item>
 
        <a-form-item label="计划时间" has-feedback>
          <a-date-picker
            v-if="planType == 1"
            style="width: 100%"
            format="YYYY-MM-DD"
            placeholder="请选择计划时间"
            v-decorator="['planTime', { rules: [{ required: true, message: '请选择计划时间!' }] }]"
          />
          <a-month-picker
            v-else
            style="width: 100%"
            format="YYYY-MM"
            placeholder="请选择计划时间"
            v-decorator="['planTime', { rules: [{ required: true, message: '请选择计划时间!' }] }]"
          />
        </a-form-item>
 
        <a-form-item label="班组类型" has-feedback v-if="planType == 1">
          <a-select
            allow-clear
            style="width: 100%"
            v-decorator="['teamType', { rules: [{ required: true, message: '请选择班组类型!' }] }]"
            placeholder="请选择班组类型"
          >
            <a-select-option value="白班"> 白班 </a-select-option>
            <a-select-option value="晚班"> 晚班 </a-select-option>
          </a-select>
        </a-form-item>
 
        <a-form-item label="计划产量" has-feedback>
          <a-input-number
            :min="0"
            style="width: 100%"
            placeholder="请输入计划产量"
            v-decorator="['planProductionNum', { rules: [{ required: true, message: '请输入计划产量!' }] }]"
          />
        </a-form-item>
 
        <a-form-item label="备注" has-feedback>
          <a-input allow-clear="" placeholder="请输入备注" v-decorator="['remarks']" />
        </a-form-item>
 
        <a-form-item label="id" has-feedback v-show="false">
          <a-input v-decorator="['id']" />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>
 
  <script>
import moment from 'moment'
import { addProductionPlaninfo, editProductionPlaninfo } from '@/api/modular/main/YieldMaintenanceManage'
export default {
  name: 'EditForm',
  data() {
    return {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 15 }
      },
      confirmLoading: false,
      visible: false,
      form: this.$form.createForm(this),
      id: '',
      type: '',
      planType: 0,
      endOpen: false
    }
  },
  methods: {
    // 显示对话框
    showModal(type, planType, record = {}) {
      this.visible = true
      this.type = type
      this.planType = planType
      let planTime = ''
      if (this.planType == 1) {
        planTime = moment(record.planTime, 'YYYY-MM-DD')
      } else {
        planTime = moment(record.planTime, 'YYYY-MM')
      }
      const option = {
            id: record.id + '',
            planType: record.planType + '',
            planTime,
            planProductionNum: record.planProductionNum,
            remarks: record.remarks + ''
      }
      if (this.planType == 1) {
        option.teamType = record.teamType + ''
      }
 
      if (this.type == 'edit') {
        this.$nextTick(() => {
          this.form.setFieldsValue(option)
        })
      } else {
        this.$nextTick(() => {
          this.form.setFieldsValue({
            planType: this.planType
          })
        })
      }
    },
    // 确定
    handleSubmit() {
      const {
        form: { validateFields }
      } = this
      validateFields(async (errors, values) => {
        if (values.planType == 1) {
          values.planTime = moment(values.planTime).format('YYYY-MM-DD')
        } else {
          values.planTime = moment(values.planTime).format('YYYY-MM')
        }
        if (!errors) {
          this.confirmLoading = true
            try {
                if (values.id) {
                    // 编辑
                    await editProductionPlaninfo(values)
                    this.$message.success('编辑成功')
                    this.$emit('reflesh')
                } else {
                    // 新增
                    await addProductionPlaninfo(values)
                    this.$message.success('新增成功')
                    this.$emit('reflesh', 1)
                }
                this.confirmLoading = false
                this.handleCancel()
            } catch (error) {
                console.log(error)
                this.confirmLoading = false
            }
        }
      })
    },
    // 取消
    handleCancel() {
      this.visible = false
      this.form.resetFields()
    }
  }
}
</script>
 
  <style></style>