123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- <template>
- <el-dialog
- :title="title"
- :visible.sync="dialogVisible"
- width="33%"
- :before-close="handleClose"
- v-loading.fullscreen.lock="fullscreenLoading"
- >
- <el-form ref="form" :model="form" label-width="100px" :rules="rules">
- <el-form-item prop="account">
- <template slot="label" class="status"
- ><span>账  号</span>:</template
- >
- <el-input placeholder="请输入" v-model.trim="form.account"></el-input>
- </el-form-item>
- <el-form-item prop="name">
- <template slot="label" class="status"
- ><span>姓  名</span>:</template
- >
- <el-input placeholder="请输入" v-model.trim="form.name"></el-input>
- </el-form-item>
- <el-form-item prop="password">
- <template slot="label" class="status"
- ><span>密  码</span>:</template
- >
- <el-input placeholder="请输入" v-model.trim="form.password"></el-input>
- </el-form-item>
- <el-form-item label>
- <template slot="label" class="status"
- ><span>状  态</span>:</template
- >
- <el-radio-group v-model="form.status">
- <el-radio :label="1">启用</el-radio>
- <el-radio :label="0">禁用</el-radio>
- </el-radio-group>
- </el-form-item>
- </el-form>
- <span slot="footer" class="dialog-footer">
- <el-button size="small" @click="handleClose">取 消</el-button>
- <el-button
- size="small"
- style="margin-left: 60px"
- type="primary"
- @click="addList('form')"
- >确 定</el-button
- >
- </span>
- </el-dialog>
- </template>
- <script>
- import * as api from '@/api/api'
- export default {
- data() {
- const validatePass = (rule, value, callback) => {
- if (value.length < 6 || value.length > 18) {
- callback(new Error('密码不能小于6位,大于18位'))
- } else {
- callback()
- }
- }
- return {
- fullscreenLoading:false,
- dialogVisible: false,
- radio: '',
- title: '',
- form: {
- account: '',
- name: '',
- password: '',
- status: 0,
- userId: ''
- },
- userString: {},
- rules: {
- account: [{ required: true, message: '请输入账号', trigger: 'blur' }],
- name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
- password: [{ required: true, trigger: 'blur', validator: validatePass }]
- }
- }
- },
- methods: {
- handleClose() {
- this.dialogVisible = false
- this.$parent.search()
- this.form = {
- account: '',
- name: '',
- password: '',
- status: '',
- userId: ''
- }
- this.$refs['form'].resetFields()
- },
- openClose(val) {
- this.title = val.title
- if (val) {
- this.userString = val
- if (val.id) {
- this.detail()
- }
- }
- this.dialogVisible = true
- },
- /**
- * @method 用户确定
- * **/
- addList(formName) {
- this.$refs[formName].validate(valid => {
- if (valid) {
- this.fullscreenLoading = true
- let code = {
- account: this.form.account,
- name: this.form.name,
- password: this.form.password,
- status: this.form.status
- }
- this.userString.show
- ? this.addListData(code)
- : this.editListData(code)
- }
- })
- },
- /**
- * @method 详情
- * **/
- detail() {
- const code = {
- id: this.userString.id
- }
- api.GET('/user/detail', code).then(data => {
- if (data.code == 0) {
- this.form = data.data
- }
- })
- },
- /**
- * @method 新增
- * **/
- addListData(val) {
- api.POST('/user/add', val).then(data => {
- if (data.code == 0) {
- this.handleClose()
- this.$message.success(data.message)
- this.fullscreenLoading = false
- }
- }).catch(()=>{
- this.fullscreenLoading = false
- })
- },
- /**
- * @method 编辑
- * **/
- editListData(val) {
- val.userId = this.form.userId
- api.POST('/user/update', val).then(data => {
- if (data.code == 0) {
- this.handleClose()
- this.$message.success(data.message)
- this.fullscreenLoading = false
- }
- }).catch(()=>{
- this.fullscreenLoading = false
- })
- }
- }
- }
- </script>
- <style lang="less" scoped>
- .status {
- padding: 0 12px 0 0;
- }
- .status::before {
- content: '*';
- color: #f56c6c;
- margin-right: 4px;
- }
- </style>
|