tj
2025-06-05 bba272999cc546f65781bf3d20245a3f819af67f
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<template>
  <div class="container">
    <div class="title" v-if="!editId">
      新建供应商 <span class="back" @click="back"> <i class="iconfont icon-fanhui"></i> 返回 </span>
    </div>
    <div class="title" v-else>
      <span>修改供应商</span> <span class="back" @click="back"> <i class="iconfont icon-fanhui"></i> 返回 </span>
    </div>
 
    <div class="wrap">
      <el-row>
        <el-col :lg="16" :md="20" :sm="24" :xs="24">
          <el-form :model="contact" status-icon ref="form" label-width="auto" @submit.prevent :rules="rules">
            <el-form-item label="姓名" prop="name">
              <el-input v-model="contact.name" placeholder="请填写姓名"></el-input>
            </el-form-item>
 
            <el-form-item label="供应商" prop="company_id">
              <el-select v-model="contact.company_id" placeholder="请选择供应商" clearable>
                <el-option v-for="item in companyArr" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>
            </el-form-item>
 
            <el-form-item label="参与项目" prop="project_list">
              <el-select
                v-model="contact.project_list"
                placeholder="所属项目"
                clearable
                filterable
                class="selectClass"
                multiple
              >
                <el-option v-for="item in projectInfoArr" :key="item.id" :label="item.project_name" :value="item.id" />
              </el-select>
            </el-form-item>
 
            <el-form-item label="擅长" prop="skill_list">
              <el-select
                v-model="contact.skill_list"
                placeholder="所属项目"
                clearable
                filterable
                class="selectClass"
                multiple
              >
                <el-option v-for="item in skillTypeArr" :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
 
            <el-form-item label="职务/角色" prop="title">
              <el-input v-model="contact.title" placeholder="请填写职务/角色"></el-input>
            </el-form-item>
 
            <el-form-item label="性别" prop="sex">
              <el-select v-model="contact.sex" placeholder="请填写性别" clearable>
                <el-option v-for="item in sexArr" :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
 
            <el-form-item label="电话" prop="phone">
              <el-input v-model="contact.phone" placeholder="请填写电话"></el-input>
            </el-form-item>
 
            <el-form-item label="邮箱" prop="email_address">
              <el-input v-model="contact.email_address" placeholder="请填写邮箱"></el-input>
            </el-form-item>
 
            <el-form-item label="地址" prop="address">
              <el-input v-model="contact.address" placeholder="请填写地址"></el-input>
            </el-form-item>
 
            <el-form-item label="备注" prop="remark">
              <el-input
                type="textarea"
                :autosize="{ minRows: 4, maxRows: 8 }"
                placeholder="请输入备注"
                v-model="contact.remark"
              >
              </el-input>
            </el-form-item>
 
            <el-form-item class="submit">
              <el-button type="primary" @click="submitForm">保 存</el-button>
              <el-button @click="resetForm">重 置</el-button>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
    </div>
  </div>
</template>
 
<script>
import { reactive, ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
 
import ProjectInfo from '@/model/projectInfo'
import ContactInfo from '@/model/supplierContactInfo'
import CompanyInfo from '@/model/supplierCompanyInfo'
import sysDictItemModel from '@/model/sysDictItem'
 
export default {
  props: {
    editId: {
      type: String,
      default: null,
    },
  },
  setup(props, context) {
    const form = ref(null)
    const loading = ref(false)
    const contact = reactive({
      id: props.editId,
      name: '',
      company_id: '',
      title: '',
      sex: '0',
      phone: '',
      email_address: '',
      address: '',
      remark: '',
      project_list: '',
      skill_list: '',
    })
 
    const companyArr = ref([])
    const projectInfoArr = ref([])
    const skillTypeArr = ref([])
    const sexArr = ref([])
 
    const listAssign = (a, b) => Object.keys(a).forEach(key => {
      a[key] = b[key] || a[key]
    })
 
    /**
     * 表单规则验证
     */
    const { rules } = getRules()
 
    onMounted(() => {
      if (props.editId) {
        getCompany()
      }
      loadDictDitems()
    })
 
    // 根据字典类型查询字典
    const loadDictDitems = async () => {
      companyArr.value = await CompanyInfo.getCompanyInfoList(null)
      sexArr.value = await sysDictItemModel.getSysDictItemListByType('sex')
      projectInfoArr.value = await ProjectInfo.getProjectInfoList('')
      skillTypeArr.value = await sysDictItemModel.getSysDictItemListByType('skill_type')
    }
 
    const getCompany = async () => {
      loading.value = true
      const res = await ContactInfo.getContactInfo(props.editId)
      listAssign(contact, res)
      contact.sex = String(res.sex)
      loading.value = false
    }
 
    // 重置表单
    const resetForm = () => {
      form.value.resetFields()
    }
 
    const submitForm = async formName => {
      form.value.validate(async valid => {
        if (valid) {
          let res = {}
          if (props.editId) {
            res = await ContactInfo.editContactInfo(props.editId, contact)
            context.emit('editClose')
          } else {
            res = await ContactInfo.createContactInfo(contact)
            resetForm(formName)
          }
          if (res.code < window.MAX_SUCCESS_CODE) {
            ElMessage.success(`${res.message}`)
          }
        } else {
          console.error('error submit!!')
          ElMessage.error('请将信息填写完整')
        }
      })
    }
 
    const back = () => {
      context.emit('editClose')
    }
 
    return {
      // 字典项加载
      sexArr,
      companyArr,
      projectInfoArr,
      skillTypeArr,
 
      back,
      contact,
      form,
      rules,
      resetForm,
      submitForm,
    }
  },
}
 
/**
 * 表单验证规则
 */
function getRules() {
  /**
   * 验证回调函数
   */
  const checkInfo = (rule, value, callback) => {
    if (!value) {
      callback(new Error('信息不能为空'))
    }
    callback()
  }
  const rules = {
    name: [{ validator: checkInfo, trigger: 'blur', required: true }],
    company_id: [{ validator: checkInfo, trigger: 'blur', required: true }],
    // title: [{ validator: checkInfo, trigger: 'blur', required: true }],
    // sex: [{ validator: checkInfo, trigger: 'blur', required: true }],
    // phone: [
    //   { validator: checkInfo, trigger: 'blur', required: true },
    //   {
    //     validator: (rule, value, callback) => {
    //       const phonePattern = /^1[0-9]{10}$/; // 手机号码的正则表达式
    //       if (!phonePattern.test(value)) {
    //         callback(new Error('请输入有效的手机号码'));
    //       } else {
    //         callback();
    //       }
    //     },
    //     trigger: 'blur'
    //   }
    // ],
    // email_address:[
    //   { type: 'email', message: '请输入正确的邮箱地址或者不填', trigger: ['blur', 'change'] , required: true}
    // ],
    // address: [{ validator: checkInfo, trigger: 'blur', required: true }],
  }
  return { rules }
}
</script>
 
<style lang="scss" scoped>
.container {
  .title {
    height: 59px;
    line-height: 59px;
    color: $parent-title-color;
    font-size: 16px;
    font-weight: 500;
    text-indent: 40px;
    border-bottom: 1px solid #dae1ec;
 
    .back {
      float: right;
      margin-right: 40px;
      cursor: pointer;
    }
  }
 
  .wrap {
    padding: 20px;
  }
 
  .submit {
    float: left;
  }
}
</style>