zhouwx
2024-06-27 ae43feac8c6b2372f5a061ead68e71027e8877e1
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
<template>
  <el-dialog
    :title="dialogStatus==='add'?'新增':'编辑'"
    :visible.sync="dialogVisible"
    :modal-append-to-body="false"
    :close-on-click-modal="false"
    width="500px"
    :before-close="handleClose"
  >
    <el-form ref="dataForm" :model="dataForm"  :rules="rules" label-position="right" label-width="150px" style="padding-right: 50px" element-loading-text="保存中...">
      <el-form-item label="平台名称:" prop="institutionalName">
        <el-input v-model.trim="dataForm.institutionalName"/>
      </el-form-item>
<!--      <el-form-item label="AccessKey:" prop="AccessKey">-->
<!--        <el-input  v-model.trim="dataForm.AccessKey"/>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="SecretKey:" prop="SecretKey">-->
<!--        <el-input v-model.trim="dataForm.SecretKey"/>-->
<!--      </el-form-item>-->
      <el-form-item label="联系人:" prop="contacts">
        <el-input v-model.trim="dataForm.contacts"/>
      </el-form-item>
      <el-form-item label="联系电话:" prop="phone">
        <el-input v-model.trim="dataForm.phone" :maxlength="11" />
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="onSubmit">确 定</el-button>
    </span>
  </el-dialog>
</template>
 
<script >
import { addPlat, updatePlat } from '@/api/onlineEducation/plat'
 
export default {
  name: 'addUser',
  components: {
  },
  data() {
    return {
      dialogVisible: false,
      dialogStatus: '',
      rules: {
        institutionalName: [{ required: true, message: '请输入平台名称', trigger: 'blur' }],
        contacts: [{ required: true, message: '请输入联系人', trigger: 'blur' }],
        phone: [
          { required: true,
            pattern: /^1[0-9]{10}$/,
            message: '手机号格式不正确',
            trigger: 'blur'
          }
        ],
      },
      dataForm: {}
    }
  },
  created() {
 
  },
  methods: {
    openDialog (type, data) {
      this.resetDataForm();
      this.dialogVisible = true;
      this.dialogStatus = type;
      if(this.dialogStatus == 'edit') {
        this.dataForm = data;
      }
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
 
 
    handleClose() {
      this.dialogVisible = false;
      this.$emit("getList");
    },
    onSubmit() {
      this.$refs["dataForm"].validate( async valid => {
        if (valid) {
          if(this.dialogStatus == 'add'){
            console.log("this.dataForm",this.dataForm)
            const res = await addPlat(this.dataForm);
            if(res.code == 200) {
              this.$emit("getList");
              this.dialogVisible = false;
              this.$message({
                type:'success',
                message: '新增成功'
              })
            }else{
              this.$message({
                type:'warning',
                message: res.msg
              })
            }
          }else {
            const res = await updatePlat(this.dataForm);
            if(res.code == 200) {
              this.$emit("getList");
              this.dialogVisible = false;
              this.$message({
                type:'success',
                message: '编辑成功'
              })
            }else{
              this.$message({
                type:'warning',
                message: res.msg
              })
            }
          }
        }
      })
 
    },
    resetDataForm() {
      this.dataForm = {
      }
    },
  }
}
 
</script>
<style scoped>
 
</style>