Blame view

src/views/system/information/base-set.vue 4.1 KB
xiaomiao committed
1 2 3 4 5 6 7 8
<template>
  <div class="content">
    <div class="user-info">
      <el-form
        ref="form"
        label-width="100px"
        :model="form"
        class="form-wrapper"
xiaomiao committed
9
        :rules="rules">
xiaomiao committed
10 11 12 13 14 15 16 17 18 19 20
        <el-form-item label="用户名:" required>
          <el-input v-model="form.loginName" clearable disabled />
        </el-form-item>
        <el-form-item label="姓名:">
          <el-input v-model="form.name" clearable />
        </el-form-item>
        <el-form-item label="性别:">
          <el-radio-group v-model="form.sex">
            <el-radio
              v-for="(item, index) in sexList"
              :key="index"
xiaomiao committed
21
              :label="item.value">{{ item.name }}</el-radio>
xiaomiao committed
22 23 24 25 26 27
          </el-radio-group>
        </el-form-item>
        <el-form-item label="身份证号:" prop="idCard">
          <el-input v-model="form.idCard" clearable />
        </el-form-item>
        <el-form-item label="手机号码:" prop="mobilePhone">
28
          <el-input v-model="form.mobilePhone" clearable />
xiaomiao committed
29
        </el-form-item>
xiaomiao committed
30
        <el-form-item label="办公电话:">
xiaomiao committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44
          <el-input v-model="form.telephone" clearable />
        </el-form-item>
        <el-form-item label="办公地址:">
          <el-input v-model="form.address" clearable />
        </el-form-item>
      </el-form>
      <div class="bottom-wrapper">
        <el-button type="primary" @click="updateInfo">更新信息</el-button>
      </div>
    </div>
  </div>
</template>

<script>
xiaomiao committed
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
  import { api, getAction, putAction, getDictItems } from '@/api/manageApi'
  export default {
    props: {
      userInfo: {
        type: Object,
        default: null
      }
    },
    data () {
      return {
        form: {},
        sexList: [],
        rules: {
          mobilePhone: [
            {
              pattern:
                /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/,
              message: '手机号码格式有误',
              trigger: 'blur'
            }
          ],
          idCard: [
            {
              pattern: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/,
              message: '身份证号格式有误',
              trigger: 'blur'
            }
          ]
        }
      }
    },
    watch: {
      userInfo: {
        handler: function (val) {
          if (val) {
xiaomiao committed
80
            this.getUserdata(val.id)
xiaomiao committed
81 82 83 84 85
          }
        }
      }
    },
    mounted () {
xiaomiao committed
86
      if (this.userInfo) {
xiaomiao committed
87
        this.getUserdata(this.userInfo)
xiaomiao committed
88
      }
xiaomiao committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102
      this.sexList = [
        {
          "name": "男",
          "value": "0",
        },
        {

          "name": "女",
          "value": "1",
        },

        {
          "name": "保密",
          "value": "2",
xiaomiao committed
103

xiaomiao committed
104 105
        }
      ]
106
    },
xiaomiao committed
107
    methods: {
xiaomiao committed
108
      getUserdata (p) {
xiaomiao committed
109
        getAction(`${api.users}/${p.id}`).then((res) => {
xiaomiao committed
110 111 112 113 114 115 116 117 118 119 120 121 122
          if (res.status === 1) {
            this.form = res.content
          } else {
            this.$message.error({ message: res.message, showClose: true })
          }
        })
      },
      updateInfo () {
        this.$refs.form.validate((valid) => {
          if (valid) {
            putAction(`${api.users}/${this.form.id}`, this.form).then((res) => {
              if (res.status === 1) {
                this.$message.success({ message: res.message, showClose: true })
xiaomiao committed
123
                this.getUserdata(this.form.id)
xiaomiao committed
124 125 126 127 128 129 130 131 132
              } else {
                this.$message.error({ message: res.message, showClose: true })
              }
            })
          }
        })
      }
    }
  }
xiaomiao committed
133 134 135
</script>

<style scoped lang="scss">
xiaomiao committed
136 137 138 139 140
  .user-info {
    margin: 0.1875rem 1.0417rem;
    background: #ffffff;
    overflow-y: auto;
    .form-wrapper {
xiaomiao committed
141
      padding: 0px 120px 0px;
xiaomiao committed
142
      .el-form-item {
143 144
        /deep/.el-form-item__label {
          color: #ffffff;
xiaomiao committed
145 146 147 148 149 150 151
        }
        ::v-deep .el-input .el-input__inner {
          padding: 0 8px;
          height: 40px;
          line-height: 40px;
          border: 1px solid #6bc1fc;
        }
xiaomiao committed
152
      }
xiaomiao committed
153 154 155
      .el-form-item--small.el-form-item {
        margin-bottom: 16px;
      }
xiaomiao committed
156
    }
xiaomiao committed
157
    .bottom-wrapper {
xiaomiao committed
158
      padding: 0px 120px 0px;
xiaomiao committed
159 160
      text-align: right;
    }
xiaomiao committed
161 162
  }
</style>