JIALDemo/target/classes/backend/page/member/add.html

222 lines
7.0 KiB
HTML
Raw Normal View History

2023-11-28 08:43:15 +08:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- 引入样式 -->
<link rel="stylesheet" href="../../plugins/element-ui/index.css" />
<link rel="stylesheet" href="../../styles/common.css" />
<link rel="stylesheet" href="../../styles/page.css" />
</head>
<body>
<div class="addBrand-container" id="member-add-app">
<div class="container">
<el-form
ref="ruleForm"
:model="ruleForm"
:rules="rules"
:inline="false"
label-width="180px"
class="demo-ruleForm"
>
2023-11-28 20:46:55 +08:00
<el-form-item label="工号:" prop="username">
<el-input v-model="ruleForm.username" placeholder="请输入工号" maxlength="20"/>
2023-11-28 08:43:15 +08:00
</el-form-item>
<el-form-item
2023-11-28 20:46:55 +08:00
label="姓名:"
2023-11-28 08:43:15 +08:00
prop="name"
>
<el-input
v-model="ruleForm.name"
2023-11-28 20:46:55 +08:00
placeholder="请输入姓名"
2023-11-28 08:43:15 +08:00
maxlength="20"
/>
</el-form-item>
<el-form-item
label="手机号:"
prop="phone"
>
<el-input
v-model="ruleForm.phone"
placeholder="请输入手机号"
maxlength="20"
/>
</el-form-item>
<el-form-item
2023-11-28 23:49:50 +08:00
label="是否为管理员账号:"
prop="admin"
2023-11-28 08:43:15 +08:00
>
2023-11-28 23:49:50 +08:00
<el-radio-group v-model="ruleForm.admin">
<el-radio label="是"></el-radio>
<el-radio label="否"></el-radio>
2023-11-28 08:43:15 +08:00
</el-radio-group>
</el-form-item>
<el-form-item
2023-11-28 20:46:55 +08:00
label="密码:"
prop="password"
2023-11-28 08:43:15 +08:00
>
<el-input
2023-11-28 20:46:55 +08:00
v-model="ruleForm.password"
placeholder="请输入密码"
2023-11-28 08:43:15 +08:00
maxlength="20"
/>
</el-form-item>
<div class="subBox address">
<el-form-item>
<el-button @click="goBack()">
取消
</el-button>
<el-button
type="primary"
@click="submitForm('ruleForm', false)"
>
保存
</el-button>
<el-button
v-if="actionType == 'add'"
type="primary"
class="continue"
@click="submitForm('ruleForm', true)"
>
保存并继续添加
</el-button>
</el-form-item>
</div>
</el-form>
</div>
</div>
<!-- 开发环境版本,包含了有帮助的命令行警告 -->
<script src="../../plugins/vue/vue.js"></script>
<!-- 引入组件库 -->
<script src="../../plugins/element-ui/index.js"></script>
<!-- 引入axios -->
<script src="../../plugins/axios/axios.min.js"></script>
<script src="../../js/request.js"></script>
<script src="../../api/member.js"></script>
<script src="../../js/validate.js"></script>
<script src="../../js/index.js"></script>
<script>
new Vue({
el: '#member-add-app',
data() {
return {
id: '',
actionType : '',
ruleForm : {
'name': '',
'phone': '',
2023-11-28 23:49:50 +08:00
'admin': '是',
2023-11-28 20:46:55 +08:00
'password': '',
2023-11-28 08:43:15 +08:00
username: ''
}
}
},
computed: {
rules () {
return {
//账号
username: [
{
required: true, 'validator': checkUserName, trigger: 'blur'
}
],
//姓名
name: [{ required: true, 'validator': checkName, 'trigger': 'blur' }],
'phone': [{ 'required': true, 'validator': checkPhone, 'trigger': 'blur' }],
2023-11-28 20:46:55 +08:00
'password': [{ 'required': true, 'validator': checkPassword, 'trigger': 'blur' }]
2023-11-28 08:43:15 +08:00
}
}
},
created() {
this.id = requestUrlParam('id')
this.actionType = this.id ? 'edit' : 'add'
if (this.id) {
this.init()
}
},
mounted() {
},
methods: {
async init () {
queryEmployeeById(this.id).then(res => {
if (String(res.code) === '1') {
console.log(res.data)
this.ruleForm = res.data
2023-11-28 23:49:50 +08:00
this.ruleForm.admin = res.data.admin === '0' ? '否' : '是'
2023-11-28 08:43:15 +08:00
// this.ruleForm.password = ''
} else {
this.$message.error(res.msg || '操作失败')
}
})
},
submitForm (formName, st) {
this.$refs[formName].validate((valid) => {
if (valid) {
if (this.actionType === 'add') {
const params = {
...this.ruleForm,
2023-11-28 23:49:50 +08:00
admin: this.ruleForm.admin === '否' ? '0' : '1'
2023-11-28 08:43:15 +08:00
}
addEmployee(params).then(res => {
if (res.code === 1) {
2023-11-28 23:49:50 +08:00
console.log("添加成功")
2023-11-28 08:43:15 +08:00
this.$message.success('员工添加成功!')
if (!st) {
this.goBack()
} else {
this.ruleForm = {
username: '',
'name': '',
'phone': '',
// 'password': '',
// 'rePassword': '',/
2023-11-28 23:49:50 +08:00
'admin': '是',
2023-11-28 20:46:55 +08:00
'password': ''
2023-11-28 08:43:15 +08:00
}
}
} else {
this.$message.error(res.msg || '操作失败')
}
}).catch(err => {
this.$message.error('请求出错了:' + err)
})
} else {
const params = {
...this.ruleForm,
2023-11-28 23:49:50 +08:00
admin: this.ruleForm.admin === '否' ? '0' : '1'
2023-11-28 08:43:15 +08:00
}
editEmployee(params).then(res => {
2023-11-28 23:49:50 +08:00
console.log(res.toString());
2023-11-28 08:43:15 +08:00
if (res.code === 1) {
2023-11-28 23:49:50 +08:00
var vm = this;
Vue.prototype.$message.success('员工信息修改成功!')
console.log("修改成功");
2023-11-28 08:43:15 +08:00
this.goBack()
} else {
this.$message.error(res.msg || '操作失败')
}
}).catch(err => {
this.$message.error('请求出错了:' + err)
})
}
} else {
console.log('error submit!!')
return false
}
})
},
goBack(){
window.parent.menuHandle({
2023-11-29 21:17:35 +08:00
id: '6',
2023-11-28 08:43:15 +08:00
url: '/backend/page/member/list.html',
name: '员工管理'
},false)
}
}
})
</script>
</body>
</html>