yangfeng
2024-01-26 eb30bab79870f892cf11774d8a09684381074640
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
<template>
  <div class="add-quotation">
    <el-dialog
      :title="editConfig.title + '用户'"
      :visible.sync="isvisible"
      :width="dialogWidth"
      :before-close="handleClose"
      append-to-body
      custom-class="iframe-dialog"
    >
      <div class="drawerContent" style="overflow: auto">
        <el-form ref="form" :rules="rules" :model="editConfig.form" label-position="right" label-width="100px">
          <el-form-item label="用户名:" prop="userName">
            <el-input
              v-model="editConfig.form.userName"
              :placeholder="editConfig.title == '添加' ? '请输入用户名' : '--'"
              :disabled="editConfig.title == '添加' ? false : true"
            ></el-input>
          </el-form-item>
          <el-form-item v-if="editConfig.title == '添加'" label="密码:" prop="passWord">
            <el-input v-model="editConfig.form.passWord" :placeholder="'请输入密码'"></el-input>
          </el-form-item>
          <el-form-item v-else label="密码:" prop="password">
            <el-input v-model="editConfig.form.passsord" :placeholder="'******'" disabled></el-input>
          </el-form-item>
          <el-form-item label="手机号:" prop="phone">
            <el-input
              v-model="editConfig.form.phone"
              :placeholder="editConfig.title == '添加' ? '请输入手机号' : '--'"
              :disabled="editConfig.title == '添加' ? false : true"
            ></el-input>
          </el-form-item>
          <el-form-item label="公司名称:" prop="companyName">
            <el-input
              v-model="editConfig.form.company"
              :placeholder="editConfig.title == '添加' ? '请输入公司名称' : '--'"
              :disabled="editConfig.title == '添加' ? false : true"
            ></el-input>
          </el-form-item>
          <el-form-item label="联系人名称:" prop="companyContact">
            <el-input
              v-model="editConfig.form.companyContact"
              :placeholder="editConfig.title == '添加' ? '请输入联系人名称' : '--'"
              :disabled="editConfig.title == '添加' ? false : true"
            ></el-input>
          </el-form-item>
          <el-form-item label="邮箱:" prop="companyEmail">
            <el-input
              v-model="editConfig.form.email"
              :placeholder="editConfig.title == '添加' ? '请输入邮箱' : '--'"
              :disabled="editConfig.title == '添加' ? false : true"
            ></el-input>
          </el-form-item>
          <el-form-item label="行业:" prop="companyTrade">
            <el-input
              v-model="editConfig.form.companyTrade"
              :placeholder="editConfig.title == '添加' ? '请输入行业' : '--'"
              :disabled="editConfig.title == '添加' ? false : true"
            ></el-input>
          </el-form-item>
          <el-form-item label="地区:" prop="companyProvince">
            <el-input
              v-model="editConfig.form.companyProvince"
              :placeholder="editConfig.title == '添加' ? '请输入地区' : '--'"
              :disabled="editConfig.title == '添加' ? false : true"
            ></el-input>
          </el-form-item>
          <el-form-item label="用户等级:" prop="roleIDs">
            <el-checkbox-group v-model="editConfig.form.roleIDs" :disabled="editConfig.title == '查看' ? true : false">
              <el-checkbox v-for="role in roleList" :label="role.id" :key="role.id">{{ role.name }}</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button v-if="editConfig.title == '查看' ? false : true" type="primary" @click="onSubmit('form')"
          >确定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import { getRoleIDs, setUser, register } from "@/api/unifiedManage/userManage"
export default {
  name: "EditUserInfo",
  props: {
    editCommonConfig: {
      type: Object,
      default: () => {
        return {
          visible: false,
          title: "新建",
          form: {
            roleIDs: []
          }
        }
      }
    }
  },
  components: {},
  computed: {},
  data() {
    return {
      dialogWidth: "30%",
      isvisible: false,
      editConfig: this.editCommonConfig,
      // form: {},
      rules: {
        userName: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        passWord: [{ required: true, message: "请输入密码", trigger: "blur" }],
        phone: [{ required: true, message: "请输入手机号", trigger: "blur" }],
        // companyName: [{ required: true, message: "请输入公司名称", trigger: "blur" }],
        companyContact: [{ required: true, message: "请输入联系人名称", trigger: "blur" }],
        roleIDs: [{ required: true, message: "请选择用户等级", trigger: "change" }]
      },
      roleList: [] // 用户等级
    }
  },
  watch: {
    isvisible(val) {
      console.log("ssss")
      if (val) {
        // this.formInfo()
        console.log(val)
        // this.$refs.form.resetFields()
      }
    }
  },
  created() {
    this.getDataInfo()
  },
  methods: {
    handleClose() {
      this.isvisible = false
    },
    // 获取等级信息
    async getDataInfo() {
      const rsp = await getRoleIDs({ useType: 1 })
      if (rsp.code == 200) {
        this.roleList = rsp.data ? rsp.data : []
      }
    },
    // 确定
    onSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        console.log(valid)
        if (valid) {
          let requestUrl = this.editConfig.title == "添加" ? register : setUser
          let param = this.saveParams()
          requestUrl(param).then((reply) => {
            if (reply && reply.code === 200) {
              this.$message.success("保存成功")
              this.handleClose()
              this.$parent.getData()
            }
          })
        }
      })
    },
    saveParams() {
      let params = {
        userName: this.editConfig.form.userName || "",
        passWord: this.editConfig.form.passWord || "",
        dutyIDs: this.editConfig.form.dutyIDs,
        id: this.editConfig.form.id,
        nickName: this.editConfig.form.nickName || "",
        phone: this.editConfig.form.phone || "",
        roleIDs: this.editConfig.form.roleIDs,
        companyCity: this.editConfig.form.companyCity || "",
        companyContact: this.editConfig.form.companyContact || "",
        companyEmail: this.editConfig.form.companyEmail || "",
        companyName: this.editConfig.form.companyName || "",
        companyProvince: this.editConfig.form.companyProvince || "",
        companyTrade: this.editConfig.form.companyTrade || ""
      }
      return params
    }
  }
}
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
::v-deep {
  .iframe-dialog .el-dialog__body {
    .drawerContent {
      width: 80%;
      padding: 20px 0;
      margin: auto;
      overflow: hidden;
      margin-top: 15px;
      // 溢出隐藏滚动条
      scrollbar-width: none; /* firefox */
      -ms-overflow-style: none; /* IE 10+ */
    }
  }
  .el-dialog__footer {
    background-color: #f5f5f5;
    height: 55px;
    line-height: 55px;
    text-align: right;
    padding-right: 20px;
  }
  .el-input__inner {
    text-align: left;
  }
}
</style>