cuijian
2025-06-26 694d882c7a27bc276d37f1c06d0c67a03146e086
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
<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
    wrapClassName="ant-modal-cust-warp"
    style="top:5%;height: 85%;overflow-y: hidden">
 
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form"  v-bind="layout"  :model="model" :rules="validatorRules">
        <a-form-model-item label="班组编码" required prop="groupCode">
          <a-input v-model="model.groupCode" :disabled="roleDisabled"  placeholder="请输入班组编码"/>
        </a-form-model-item>
        <a-form-model-item label="班组名称" required prop="groupName">
          <a-input v-model="model.groupName" placeholder="请输入班组名称"/>
        </a-form-model-item>
         <a-form-model-item label="班组长" prop="groupManager">
          <j-dict-select-tag
                type="list"
                v-model="model.groupManager"
                :trigger-change="true"
                dictCode="sys_user,realname,id"
                placeholder="请选择班组长"
              />
        </a-form-model-item>
         <a-form-model-item label="产线" prop="factoryId">
          <j-dict-select-tag
                type="list"
                v-model="model.factoryId"
                :trigger-change="true"
                dictCode="base_factory,factory_name,id"
                placeholder="请选择产线"
              />
        </a-form-model-item>
         <a-form-model-item label="班次" prop="shiftId">
          <j-dict-select-tag
                type="list"
                v-model="model.shiftId"
                :trigger-change="true"
                dictCode="base_shift,shift_name,id"
                placeholder="请选择班次"
              />
        </a-form-model-item>
        <a-form-model-item label="备注" prop="remark">
          <a-textarea :rows="5" v-model="model.remark" placeholder="请输入备注"/>
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>
 
<script>
  import {duplicateCheck } from '@/api/api'
  import {postAction,requestPut} from '@/api/manage'
  import JDictSelectTag from '@/components/dict/JDictSelectTag'
  export default {
    name: "GroupModal",
    components: {
    JDictSelectTag,
  },
    data () {
      return {
        title:"操作",
        visible: false,
        roleDisabled: false,
        model: {},
        layout: {
          labelCol: { span: 3 },
          wrapperCol: { span: 14 },
        },
        confirmLoading: false,
        validatorRules:{
          groupName: [
            { required: true, message: '请输入班组名称!' },
            { min: 2, max: 30, message: '长度在 2 到 30 个字符', trigger: 'blur' }
          ],
          groupCode: [
            { required: true, message: '请输入班组名称!'},
            { min: 0, max: 64, message: '长度不超过 64 个字符', trigger: 'blur' },
            { validator: this.validategroupCode}
          ],
          remark: [
            { min: 0, max: 126, message: '长度不超过 126 个字符', trigger: 'blur' }
          ]
        },
        url: {
          add: "/base/shiftGroup/add",
          edit: "/base/shiftGroup/edit",
        }
      }
    },
    created () {
      //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      close () {
        this.$refs.form.clearValidate();
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let obj;
            if(!this.model.id){
              obj=postAction(this.url.add, this.model)
            }else{
              obj=requestPut(this.url.edit, this.model, {
                    id: this.model.id
                  })
            }
            obj.then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }else{
            return false;
          }
        })
      },
      handleCancel () {
        this.close()
      },
      validategroupCode(rule, value, callback){
        if(/[\u4E00-\u9FA5]/g.test(value)){
          callback("班组编码不可输入汉字!");
        }else{
          let params = {
            tableName: "base_shift_group",
            fieldName: "group_code",
            fieldVal: value,
            dataId: this.model.id,
          };
          duplicateCheck(params).then((res)=>{
            if(res.success){
              callback();
            }else{
              callback(res.message);
            }
          });
        }
      }
    }
  }
</script>
 
<style scoped>
 
</style>