              <template>
                <div class="app-container calendar-list-container">
                  <el-form :rules="rules" ref="addForm" :model="JlAdminUser" label-position="left" label-width="80px"
                            style='width: 80% ;margin-left:20px'>
                          <el-row :gutter="16" style="margin-bottom: 15px;" align="center">
                            <el-col :span="8">
                              <div class="grid-content bg-purple" style="width: 300px;">
                                <el-form-item  :label="$t('usermanager.name')" prop="name" style="width: 310px;">
                                  <div class="block">
                                <el-input  v-model="JlAdminUser.name"> </el-input>
                                  </div>
                                </el-form-item>
                              </div>
                            </el-col>
                            <el-col :span="8">
                              <div class="grid-content bg-purple"  style="width: 300px;">
                                <el-form-item  :label="$t('usermanager.phone')" prop="phone" style="width: 310px;">
                                  <div class="block">
                                <el-input  v-model="JlAdminUser.phone"> </el-input>
                                  </div>
                                </el-form-item>
                              </div>
                            </el-col>
                          </el-row>
                          <el-row :gutter="16" style="margin-bottom: 15px;" align="center">
                            <el-col :span="8">
                              <div class="grid-content bg-purple" style="width: 300px;">
                                <el-form-item  :label="$t('usermanager.password')" prop="password" style="width: 310px;">
                                  <div class="block">
                                <el-input  v-model="JlAdminUser.password"> </el-input>
                                  </div>
                                </el-form-item>
                              </div>
                            </el-col>
                            <el-col :span="8">
                              <div class="grid-content bg-purple" style="width: 300px;">
                                <el-form-item  :label="$t('usermanager.role')" style="width: 310px;">
                                  <div class="block">
                                <el-select class="filter-item" v-model="JlAdminUser.role" prop="role" style="width: 230px;">
                                  <el-option v-for="item in adminroles" :key="item.id" :label="item.jr_rolename" :value="item.id">
                                  </el-option>
                                </el-select>
                                  </div>
                                </el-form-item>
                              </div>
                            </el-col>
                          </el-row>
                          <el-row :gutter="16" style="margin-bottom: 15px;" align="center">
                            <el-col :span="8">
                              <div class="grid-content bg-purple" style="width: 300px;">
                                <el-form-item  :label="$t('usermanager.city')" prop="city" style="width: 310px;">
                                  <div class="block">
                                <el-select class="filter-item" v-model="JlAdminUser.city"  style="width: 230px;">
                                  <el-option v-for="item in branches" :key="item.branche_code" :label="item.branche_name" :value="item.branche_code">
                                  </el-option>
                                </el-select>
                                  </div>
                                </el-form-item>
                              </div>
                            </el-col>
                            <el-col :span="8">
                              <div class="grid-content bg-purple" style="width: 300px;">
                                <el-form-item  :label="$t('usermanager.status')" style="width: 310px;">
                                  <div class="block">
                                <el-select class="filter-item" v-model="JlAdminUser.status"  style="width: 230px;">
                                  <el-option v-for="item in statusOptions" :key="item.value" :label="item.label" :value="item.value">
                                  </el-option>
                                </el-select>
                                  </div>
                                </el-form-item>
                              </div>
                            </el-col>
                          </el-row>
                          <el-row :gutter="24" style="margin-bottom: 15px;">
                          <el-col :span="6"><div>&nbsp;</div></el-col>
                          <el-col :span="12">
                            <div >
                              <el-button  type="primary" @click="updateUser">{{$t('table.confirm')}}</el-button>
                              <el-button @click="handleref()">{{$t('navbar.reset')}}</el-button>
                            </div>
                          </el-col>
                          <el-col :span="6"><div>&nbsp;</div></el-col>
                        </el-row>
                      </el-form>
                  <el-dialog title="Reading statistics" :visible.sync="dialogPvVisible">
                    <el-table :data="pvData" border fit highlight-current-row style="width: 100%">
                      <el-table-column prop="key" label="Channel"></el-table-column>
                      <el-table-column prop="pv" label="Pv"></el-table-column>
                    </el-table>
                    <span slot="footer" class="dialog-footer" >
                      <el-button type="primary" @click="dialogPvVisible = false">{{$t('table.confirm')}}</el-button>
                    </span>
                  </el-dialog>
                </div>
              </template>
              <script>
                import waves from '@/directive/waves' // 水波纹指令
                import { parseTime } from '@/utils'
                import { JlAdminGetOne, getMktBranches, getAdminRoles, updateAdminUser } from '@/api/manager'
                import crypto from 'crypto'
                import regex from '@/utils/regex'
                // arr to obj ,such as { CN : "China", US : "USA" }
                export default {
                  name: 'useredit1222333',
                  directives: {
                    waves
                  },
                  data() {
                    return {
                      tableKey: 0,
                      listLoading: true,
                      JlAdminUser: {
                        id: null,
                        username: null,
                        name: null,
                        password: null,
                        role: null,
                        city: null,
                        stauts: null,
                        phone: null
                      },
                      JlAdminUserCancel: {
                        id: null,
                        username: null,
                        name: null,
                        password: null,
                        role: null,
                        city: null,
                        stauts: null,
                        phone: null
                      },
                      jlQueryUser: {
                        id: undefined
                      },
                      rules: {
                        username: [{ required: true, min: 1, max: 20, message: '请正确录入用户名', trigger: 'blur' },
                          { pattern: /^[a-zA-Z0-9_-]{4,16}$/, message: '用户名格式错误！', trigger: 'blur' }],
                        name: [{ required: true, min: 1, max: 20, message: '请正确录入姓名', trigger: 'blur' }],
                        password: [{ required: true, min: 1, max: 20, message: '请正确录入密码', trigger: 'blur' }],
                        role: [{ required: true, message: '请正确选择角色', trigger: 'blur' }],
                        phone: [{ required: true, message: '请输入手机号码', trigger: 'blur' },
                          { pattern: regex.REPHONE, message: '手机号格式错误', trigger: 'blur' }],
                        city: [{ required: true, message: '请正确选择所属门店', trigger: 'blur' }]
                      },
                      adminroles: [],
                      branches: [],
                      statusOptions: [{ label: '正常', value: '1' }, { label: '停用', value: '0' }],
                      sortOptions: [{ label: 'ID Ascending', key: '+id' }, { label: 'ID Descending', key: '-id' }],
                      showReviewer: false,
                      ethnicgroupptions: '',
                      provinceoptions: '',
                      dialogFormVisible: false,
                      dialogStatus: '',
                      dialogPvVisible: false,
                      pvData: [],
                      downloadLoading: false,
                      view: {
                        name: undefined,
                        path: undefined,
                        title: undefined
                      }
                    }
                  },
                  destroyed() {
                    this.view.name = 'useredit'
                    this.view.path = '/user/user_edit'
                    this.view.title = 'useredit'
                    this.$store.dispatch('delVisitedViews', this.view)
                  },
                  created() {
                    this.jlQueryUser.id = this.$route.params.userId
                    JlAdminGetOne(this.jlQueryUser).then(response => {
                      this.JlAdminUser.id = response.data.id
                      this.JlAdminUser.username = response.data.username
                      this.JlAdminUser.name = response.data.name
                      this.JlAdminUser.role = String(response.data.role)
                      this.JlAdminUser.city = response.data.city
                      this.JlAdminUser.status = String(response.data.status)
                      this.JlAdminUser.phone = response.data.phone
                      this.JlAdminUserCancel.id = response.data.id
                      this.JlAdminUserCancel.phone = response.data.phone
                      this.JlAdminUserCancel.username = response.data.username
                      this.JlAdminUserCancel.name = response.data.name
                      this.JlAdminUserCancel.role = String(response.data.role)
                      this.JlAdminUserCancel.city = response.data.city
                      this.JlAdminUserCancel.status = String(response.data.status)
                    })
                    getAdminRoles().then(response3 => {
                      this.adminroles = response3.data
                    })
                    getMktBranches().then(response4 => {
                      this.branches = response4.data
                    })
                  },
                  methods: {
                    updateUser() {
                      this.$refs['addForm'].validate((valid) => {
                        if (valid) {
                          if (this.JlAdminUser.password !== null) {
                            var md5 = crypto.createHash('md5')
                            md5.update(this.JlAdminUser.password)
                            this.JlAdminUser.password = md5.digest('hex')
                          }
                          updateAdminUser(this.JlAdminUser).then(response => {
                            if (response.data === 1) {
                              this.$notify({
                                title: '成功',
                                message: '更新成功！',
                                type: 'success',
                                duration: 2000
                              })
                            } else {
                              this.$notify({
                                title: '失败',
                                message: '更新失败！',
                                type: 'warning',
                                duration: 2000
                              })
                            }
                            this.JlAdminUser.password = ''
                          })
                        }
                      })
                    },
                    handleref() {
                      this.JlAdminUser.username = this.JlAdminUserCancel.username
                      this.JlAdminUser.name = this.JlAdminUserCancel.name
                      this.JlAdminUser.role = this.JlAdminUserCancel.role
                      this.JlAdminUser.city = this.JlAdminUserCancel.city
                      this.JlAdminUser.status = this.JlAdminUserCancel.status
                      this.JlAdminUser.phone = this.JlAdminUserCancel.phone
                    },
                    formatJson(filterVal, jsonData) {
                      return jsonData.map(v => filterVal.map(j => {
                        if (j === 'timestamp') {
                          return parseTime(v[j])
                        } else {
                          return v[j]
                        }
                      }))
                    }
                  }
                }
              </script>
              <style>
              .el-form--label-left .el-form-item__label{
                text-align:right
              }
              .el-rate{
                line-height: 0;
                margin-top:8px;
              }
              .el-checkbox.el-checkbox {
                  margin-left: 30px;
              }
              </style>