AddOrEdit.vue 8.8 KB
Newer Older
D
dingzhiwei 已提交
1 2 3 4 5 6 7 8 9
<template>
  <a-drawer
    :title=" isAdd ? '新增操作员' : '修改操作员' "
    placement="right"
    :closable="true"
    @ok="handleOkFunc"
    :visible="isShow"
    width="600"
    @close="onClose"
10
    :maskClosable="false">
D
dingzhiwei 已提交
11 12
    <!-- <a-modal :confirmLoading="confirmLoading"> -->

13 14 15
    <a-form-model
      ref="infoFormModel"
      :model="saveObject"
16 17 18 19 20 21 22 23 24 25
      :rules="rules"
      style="padding-bottom:50px"
      layout="vertical"
    >
      <a-row justify="space-between" type="flex">
        <a-col :span="10">
          <a-form-model-item label="用户登录名:" prop="loginUsername">
            <a-input v-model="saveObject.loginUsername" :disabled="!isAdd" />
          </a-form-model-item>
        </a-col>
D
dingzhiwei 已提交
26

27 28 29 30 31
        <a-col :span="10">
          <a-form-model-item label="用户姓名:" prop="realname">
            <a-input v-model="saveObject.realname" />
          </a-form-model-item>
        </a-col>
D
dingzhiwei 已提交
32

33 34 35 36 37
        <a-col :span="10">
          <a-form-model-item label="手机号:" prop="telphone">
            <a-input v-model="saveObject.telphone" />
          </a-form-model-item>
        </a-col>
D
dingzhiwei 已提交
38

39 40 41 42 43
        <a-col :span="10">
          <a-form-model-item label="编号:" prop="userNo">
            <a-input v-model="saveObject.userNo" />
          </a-form-model-item>
        </a-col>
D
dingzhiwei 已提交
44

45 46 47 48 49 50 51 52
        <a-col :span="10">
          <a-form-model-item label="请选择性别:" prop="sex">
            <a-radio-group v-model="saveObject.sex">
              <a-radio :value="1"></a-radio>
              <a-radio :value="2"></a-radio>
            </a-radio-group>
          </a-form-model-item>
        </a-col>
D
dingzhiwei 已提交
53

54 55 56 57 58 59 60 61 62
        <a-col :span="10">
          <a-form-model-item label="状态:" prop="state">
            <a-radio-group v-model="saveObject.state">
              <a-radio :value="1">启用</a-radio>
              <a-radio :value="0">停用</a-radio>
            </a-radio-group>
          </a-form-model-item>
        </a-col>
      </a-row>
63 64 65 66 67 68
      <a-divider orientation="left" v-if="resetIsShow">
        <a-tag color="#FF4B33">
          账户安全
        </a-tag>
      </a-divider>

69 70 71 72 73
      <div style="display:flex;flex-direction:row;">
        <a-row justify="space-between" type="flex" style="width:100%">
          <a-col :span="10">
            <a-form-model-item label="" v-if="resetIsShow">
              重置密码:<a-checkbox v-model="sysPassword.resetPass"></a-checkbox>
74
            </a-form-model-item>
75 76 77 78
          </a-col>
          <a-col :span="10">
            <a-form-model-item label="" v-if="sysPassword.resetPass">
              恢复默认密码:<a-checkbox v-model="sysPassword.defaultPass" @click="isResetPass"></a-checkbox>
79
            </a-form-model-item>
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
          </a-col>
        </a-row>
      </div>

      <div v-if="sysPassword.resetPass">
        <div v-show="!this.sysPassword.defaultPass">
          <a-row justify="space-between" type="flex">
            <a-col :span="10">
              <a-form-model-item label="新密码:" prop="newPwd">
                <a-input-password
                  autocomplete="new-password"
                  v-model="sysPassword.newPwd"
                  :disabled="sysPassword.defaultPass" />
              </a-form-model-item>
            </a-col>
            <a-col :span="10">
              <a-form-model-item label="确认新密码:" prop="confirmPwd">
                <a-input-password
                  autocomplete="new-password"
                  v-model="sysPassword.confirmPwd"
                  :disabled="sysPassword.defaultPass" />
              </a-form-model-item>
            </a-col>
          </a-row>
104 105 106
        </div>
      </div>

D
dingzhiwei 已提交
107 108 109 110 111 112 113 114 115 116
      <div class="drawer-btn-center">
        <a-button :style="{ marginRight: '8px' }" @click="onClose" icon="close">取消</a-button>
        <a-button type="primary" @click="handleOkFunc" icon="check" :loading="confirmLoading">保存</a-button>
      </div>

    </a-form-model>
  </a-drawer>
</template>

<script>
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
	import {
		req,
		API_URL_SYS_USER_LIST
	} from '@/api/manage'

	export default {

		props: {
			callbackFunc: {
				type: Function,
				default: () => ({})
			}
		},

		data () {
			return {
				resetIsShow: false, // 重置密码是否展现
				sysPassword: {
					resetPass: false, // 重置密码
					defaultPass: true, // 使用默认密码
					newPwd: '', //  新密码
					confirmPwd: '' //  确认密码
				},
				loading: false, // 按钮上的loading
				value: 1, // 单选框默认的值
				confirmLoading: false, // 显示确定按钮loading图标
				isAdd: true, // 新增 or 修改页面标识
				isShow: false, // 是否显示弹层/抽屉
				saveObject: {}, // 数据对象
				recordId: null, // 更新对象ID
				rules: {
					realname: [{
						required: true,
						message: '请输入用户姓名',
						trigger: 'blur'
					}],
					telphone: [{
						required: true,
						pattern: /^[1][0-9]{10}$/,
						message: '请输入正确的手机号码',
						trigger: 'blur'
					}],
					userNo: [{
						required: true,
						message: '请输入编号',
						trigger: 'blur'
					}],
					loginUsername: [],
					newPwd: [{
						required: false,
						trigger: 'blur'
					}, {
						validator: (rule, value, callBack) => {
							if (!this.sysPassword.defaultPass) {
								if (this.sysPassword.newPwd.length < 6 || this.sysPassword.newPwd.length >
									12) {
									callBack('请输入6-12位新密码')
								}
							}
							callBack()
						}
					}], // 新密码
					confirmPwd: [{
						required: false,
						trigger: 'blur'
					}, {
						validator: (rule, value, callBack) => {
							if (!this.sysPassword.defaultPass) {
								this.sysPassword.newPwd === this.sysPassword.confirmPwd ? callBack()
									: callBack('新密码与确认密码不一致')
							} else {
								callBack()
							}
						}
					}] // 确认新密码
				}
			}
		},
		created () {},
		methods: {
			show (recordId) { // 弹层打开事件
				if (this.$refs.infoFormModel !== undefined) {
					this.$refs.infoFormModel.resetFields()
				}

				this.isAdd = !recordId
				// 数据恢复为默认数据
				this.saveObject = {
					state: 1,
					sex: 1
				}
				this.rules.loginUsername = []
				this.confirmLoading = false // 关闭loading

				if (this.isAdd) {
					this.rules.loginUsername.push({
						required: true,
						pattern: /^[a-zA-Z][a-zA-Z0-9]{5,17}$/,
						message: '请输入字母开头,长度为6-18位的登录名',
						trigger: 'blur'
					})
				}

				const that = this
				if (!this.isAdd) { // 修改信息 延迟展示弹层
					that.resetIsShow = true // 展示重置密码板块
					that.recordId = recordId
					req.getById(API_URL_SYS_USER_LIST, recordId).then(res => {
						that.saveObject = res
					})
					this.isShow = true
				} else {
					that.isShow = true // 立马展示弹层信息
				}
			},
			handleOkFunc: function () { // 点击【确认】按钮事件
				const that = this
				this.$refs.infoFormModel.validate(valid => {
					if (valid) { // 验证通过
						// 请求接口
						that.loading = true // 打开按钮上的 loading
						that.confirmLoading = true // 显示loading
						if (that.isAdd) {
							req.add(API_URL_SYS_USER_LIST, that.saveObject).then(res => {
								that.$message.success('新增成功')
								that.isShow = false
								that.loading = false
								that.callbackFunc() // 刷新列表
							}).catch((res) => {
								that.confirmLoading = false
							})
						} else {
							Object.assign(that.saveObject, that.sysPassword) // 拼接对象
							req.updateById(API_URL_SYS_USER_LIST, that.recordId, that.saveObject).then(res => {
								that.$message.success('修改成功')
								that.isShow = false
								that.callbackFunc() // 刷新列表
								that.resetIsShow = false // 取消展示
								that.sysPassword.resetPass = false
256 257
								that.sysPassword.defaultPass = true	// 是否使用默认密码默认为true
								that.resetPassEmpty(that) // 清空密码
258 259 260 261
							}).catch(res => {
								that.confirmLoading = false
								that.resetIsShow = false // 取消展示
								that.sysPassword.resetPass = false
262 263
								that.sysPassword.defaultPass = true	// 是否使用默认密码默认为true
								that.resetPassEmpty(that) // 清空密码
264 265 266 267 268 269 270 271 272
							})
						}
					}
				})
			},
			// 点击遮罩层关闭抽屉
			onClose () {
				this.isShow = false
				this.resetIsShow = false // 取消重置密码板块展示
273 274 275
				this.resetPassEmpty(this) // 清空密码
				this.sysPassword.resetPass = false // 关闭密码输入
				this.sysPassword.defaultPass = true	// 是否使用默认密码默认为true
276 277 278 279 280 281 282
			},
			// 使用默认密码重置是否为true
			isResetPass () {
				if (!this.sysPassword.defaultPass) {
					this.sysPassword.newPwd = ''
					this.sysPassword.confirmPwd = ''
				}
283 284 285 286 287
			},
			// 保存后清空密码
			resetPassEmpty (that) {
				that.sysPassword.newPwd = ''
				that.sysPassword.confirmPwd = ''
288 289 290
			}
		}
	}
D
dingzhiwei 已提交
291
</script>