<template>
  <el-form ref="form" status-icon :model="formItem" label-width="150px" label-suffix=" : ">
    <ec-line :title="'用户信息'" />
    <el-row>
      <el-col :span="12">
        <el-form-item
          :label="$t('ec.user.realName')"
          prop="sysrUser.realName"
          :rules="[{ required: true, message: $t('ec.user.realName') + $t('ec.table.emptyError'), trigger: 'blur'}]"
        >
          <span v-if="method==='view'">{{ formItem.sysrUser.realName }}</span>
          <el-input v-else v-model="formItem.sysrUser.realName" maxlength="64" type="text" :placeholder="$t('ec.user.realName')" />
        </el-form-item>
      </el-col>

      <el-col :span="12">
        <el-form-item
          :label="$t('ec.user.userName')"
          prop="sysrUser.username"
          :rules="[{ required: true, message: $t('ec.user.userName') + $t('ec.table.emptyError'), trigger: 'blur'}, { validator: validateAccount, trigger: 'blur'}]"
        >
          <span v-if="method === 'view'">{{ formItem.sysrUser.username }}</span>
          <el-input
            v-else
            v-model="formItem.sysrUser.username"
            type="text"
            :placeholder="$t('ec.user.userName')"
            maxlength="16"
          />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row v-if="method !== 'view'">
      <el-col :span="12">
        <el-form-item
          :label="$t('ec.login.password')"
          prop="sysrUser.loginPwd"
          :rules="method === 'edit' ? [{ validator: validateEditPassword, trigger: 'blur'}] : [{ required: true, message: $t('ec.login.password') + $t('ec.table.emptyError'), trigger: 'blur'},
                                                                                               { validator: validateNewPassword, trigger: 'blur'}]"
        >
          <el-input v-model="formItem.sysrUser.loginPwd" type="password" :placeholder="$t('ec.login.password')" maxlength="64" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item
          :label="$t('ec.login.pwd.confirm')"
          prop="sysrUser.confirm"
          :rules="method === 'edit' ? [{validator: validateConfirm, trigger: 'blur'}] :
            [{ required: true, message: $t('ec.login.pwd.confirm') + $t('ec.table.emptyError'), trigger: 'blur'},
             {validator: validateConfirm, trigger: 'blur'}]"
        >
          <el-input v-model="formItem.sysrUser.confirm" type="password" :placeholder="$t('ec.login.pwd.confirm')" maxlength="64" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item :label="$t('ec.user.sex')" prop="sysrUser.sex">
          <ec-radio-group v-model="formItem.sysrUser.sex" dict-type="sex" :readonly="method==='view'" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item
          label="直接上级"
          prop="sysrUser.superior"
        >
          <ec-user-modal v-model="formItem.sysrUser.superior" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item v-if="superAdmin && enableTenant===true" :label="$t('ec.user.tenant')" prop="sysrUser.tenantId">
          <ec-tenant v-model="formItem.sysrUser.tenantId" :readonly="method==='view'" />
        </el-form-item>
      </el-col>
      <el-col v-if="formItem.sysrUser.tenantId" :span="12">
        <el-form-item :label="$t('ec.user.org')" prop="orgIdList" :rules="[{ validator: validateOrgs, trigger: 'change'}]">
          <ec-org-big-tenant
            ref="orgSelect"
            v-model="formItem.orgIdList"
            :data="{ tenantId: formItem.sysrUser.tenantId }"
            multiple
            check-strictly
            filterable
            default-expand-all
            ban-root
            :readonly="method==='view'"
          />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item v-if="superAdmin" :label="$t('ec.app.app')" prop="sysrUser.appId">
          <ec-register-app v-model="formItem.sysrUser.appId" :tenant-id="formItem.sysrUser.tenantId" :readonly="method==='view'" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item prop="sysrUser.deptId" :label="$t('ec.user.dept')" :rules="[{ validator: validateDepts, trigger: 'change'}]">
          <ec-app-dept-select
            ref="appDeptSelect"
            v-model="formItem.sysrUser.deptId"
            multiple
            ban-root
            check-strictly
            :readonly="method==='view'"
          />
        </el-form-item>
      </el-col>
    </el-row>

    <el-form-item v-if="method==='view'" :label="$t('ec.user.accessibleApp')" prop="sysrUser.accessibleAppIds">
      <template v-for="item in accessibleAppList">
        <span v-if="formItem.sysrUser.accessibleAppIds.indexOf(item.appId) > -1" :key="item.appId">
          {{ item.appName }}{{ formItem.sysrUser.accessibleAppIds.indexOf(item.appId)===formItem.sysrUser.accessibleAppIds.length-1 ? '': '、' }}
        </span>
      </template>
    </el-form-item>
    <el-form-item
      v-if="method==='view' && formItem.sysrUser.accessibleAppIds && formItem.sysrUser.accessibleAppIds.length > 0"
      :label="$t('ec.user.role')"
      prop="sysrUser.roleIds"
    >
      <template v-for="item in roleList">
        <span v-if="formItem.sysrUser.roleIds.indexOf(item.id) > -1" :key="item.id">
          {{ item.roleName }}{{ formItem.sysrUser.roleIds.indexOf(item.id)===formItem.sysrUser.roleIds.length-1 ? '': '、' }}
        </span>
      </template>
    </el-form-item>
    <el-row>
      <el-col :span="12">
        <el-form-item :label="$t('ec.user.birthday')" prop="sysrUser.birthday">
          <span v-if="method==='view'">{{ formItem.sysrUser.birthday }}</span>
          <ec-date v-else v-model="formItem.sysrUser.birthday" format="yyyy-MM-dd HH:mm:ss" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item :label="$t('ec.user.age')" prop="sysrUser.age" :rules="[]">
          <span v-if="method==='view'">{{ formItem.sysrUser.age }}</span>
          <el-input v-else v-model="formItem.sysrUser.age" type="number" :placeholder="$t('ec.user.age')" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item
          :label="$t('ec.sms.phone')"
          prop="sysrUser.phone"
          :rules="[
            { required: userPhoneRequired || getUserPageOptionsSwitch('phoneRequired'), message: $t('ec.login.phoneEmpty'), trigger: 'blur'},
            { validator: validator.mobilePhoneNumber, trigger: 'blur' }
          ]"
        >
          <span v-if="method==='view'">{{ formItem.sysrUser.phone }}</span>
          <el-input v-else v-model="formItem.sysrUser.phone" type="text" :placeholder="$t('ec.sms.phone')" maxlength="16" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item
          :label="$t('ec.user.officePhone')"
          prop="sysrUser.officeTel"
          :rules="[
            // { required: false, validator: validator.mobilePhoneOrPhone, trigger: 'blur' }
          ]"
        >
          <span v-if="method==='view'">{{ formItem.sysrUser.officeTel }}</span>
          <el-input v-else v-model="formItem.sysrUser.officeTel" type="text" :placeholder="$t('ec.user.officePhone')" maxlength="16" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item :label="$t('ec.email.address')" prop="sysrUser.email">
          <span v-if="method==='view'">{{ formItem.sysrUser.email }}</span>
          <el-input v-else v-model="formItem.sysrUser.email" type="text" :placeholder="$t('ec.email.address')" maxlength="64" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item :label="$t('ec.user.entryDate')" prop="sysrUser.entryDate" :rules="[]">
          <span v-if="method==='view'">{{ formItem.sysrUser.entryDate }}</span>
          <ec-date v-else v-model="formItem.sysrUser.entryDate" format="yyyy-MM-dd HH:mm:ss" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col v-if="getUserPageOptionsSwitch('showUserCert')" :span="12">
        <el-form-item :label="$t('ec.user.certType')" prop="sysrUser.typeCert">
          <ec-select v-model="formItem.sysrUser.typeCert" dict-type="typeCert" :readonly="method==='view'" />
        </el-form-item>
      </el-col>
      <el-col v-if="getUserPageOptionsSwitch('showUserCert')" :span="12">
        <el-form-item :label="$t('ec.user.certNo')" prop="sysrUser.certNo">
          <span v-if="method==='view'">{{ formItem.sysrUser.certNo }}</span>
          <el-input v-else v-model="formItem.sysrUser.certNo" type="text" :placeholder="$t('ec.user.certNo')" maxlength="32" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item :label="$t('ec.user.position')" prop="sysrUser.position" :rules="[]">
          <span v-if="method==='view'">{{ formItem.sysrUser.position }}</span>
          <el-input v-else v-model="formItem.sysrUser.position" type="text" :placeholder="$t('ec.user.position')" maxlength="32" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item :label="getUserPageOptionsSwitch('staffNoAlias')" prop="sysrUser.staffNo" :rules="[]">
          <span v-if="method==='view'">{{ formItem.sysrUser.staffNo }}</span>
          <el-input v-else v-model="formItem.sysrUser.staffNo" type="text" :placeholder="$t('ec.user.staffNo')" maxlength="16" />
        </el-form-item>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="12">
        <el-form-item :label="$t('ec.user.job')" prop="sysrUser.positionIds" :rules="[]">
          <ec-select
            v-model="formItem.sysrUser.positionIds"
            :ec-data="positionList"
            value-field="id"
            attr-name="name"
            multiple
            :str-result="false"
            :readonly="method==='view'"
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item :label="$t('ec.user.address')" prop="sysrUser.address" :rules="[]">
          <span v-if="method==='view'">{{ formItem.sysrUser.address }}</span>
          <el-input v-else v-model="formItem.sysrUser.address" type="text" placeholder="" maxlength="125" />
        </el-form-item>
      </el-col>
    </el-row>

    <el-form-item :label="$t('ec.user.avatar')" prop="sysrUser.avatar" :rules="[]">
      <img
        v-if="method==='view'"
        :src="formItem.sysrUser.avatar ? formItem.sysrUser.avatar : require('@/assets/img/avatar.png')"
        width="40px"
        :alt="$t('ec.user.avatar')"
      >
      <el-input v-else v-model="formItem.sysrUser.avatar" type="text" placeholder="" maxlength="2000" />
    </el-form-item>

    <!--    <el-form-item :label="$t('ec.settings.theme')" prop="sysrUser.utheme" :rules="[]">-->
    <!--      <span v-if="method==='view'">{{ formItem.sysrUser.utheme }}</span>-->
    <!--      <el-input v-else v-model="formItem.sysrUser.utheme" type="text" placeholder="" />-->
    <!--    </el-form-item>-->
    <ec-line :title="'其它设置'" />
    <el-row>
      <el-col :span="12">
        <el-form-item :label="$t('ec.user.verifyEmail')" prop="sysrUser.mailValid" :rules="[{ required: true, message: $t('ec.table.emptyError'), trigger: 'blur'}]">
          <span v-if="method==='view'">{{ formItem.sysrUser.mailValid ? $t('ec.table.yes') : $t('ec.table.no') }}</span>
          <el-switch v-else v-model="formItem.sysrUser.mailValid" active-color="#13ce66" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item :label="$t('ec.user.verifyPhone')" prop="sysrUser.phoneValid" :rules="[{ required: true, message: $t('ec.table.emptyError'), trigger: 'blur'}]">
          <span v-if="method==='view'">{{ formItem.sysrUser.phoneValid ? $t('ec.table.yes') : $t('ec.table.no') }}</span>
          <el-switch v-else v-model="formItem.sysrUser.phoneValid" active-color="#13ce66" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item :label="$t('ec.user.ustatus')" prop="sysrUser.ustatus" :rules="[{ required: true, message: $t('ec.table.emptyError'), trigger: 'blur'}]">
          <ec-radio-group
            v-model="formItem.sysrUser.ustatus"
            :ec-data="[{ value: 0, label: $t('ec.user.ustatusInit') }, { value: 1, label: $t('ec.user.ustatusNormal') }, { value:2, label: $t('ec.user.ustatusFrozen') }]"
            :readonly="method === 'view'"
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item :label="$t('ec.user.insider')" prop="sysrUser.insider" :rules="[{ required: true, message: $t('ec.table.emptyError'), trigger: 'blur'}]">
          <span v-if="method==='view'">{{ formItem.sysrUser.insider ? $t('ec.table.yes') : $t('ec.table.no') }}</span>
          <el-switch v-else v-model="formItem.sysrUser.insider" active-color="#13ce66" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item :label="$t('ec.user.wxBind')" prop="sysrUser.weixinBind" :rules="[]">
          <span v-if="method==='view'">{{ formItem.sysrUser.weixinBind ? $t('ec.table.yes') : $t('ec.table.no') }}</span>
          <el-switch v-else v-model="formItem.sysrUser.weixinBind" active-color="#13ce66" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item :label="$t('ec.user.wxPubOpenId')" prop="sysrUser.weixinMpOpenId" :rules="[]">
          <span v-if="method==='view'">{{ formItem.sysrUser.weixinMpOpenId }}</span>
          <el-input v-else v-model="formItem.sysrUser.weixinMpOpenId" type="text" placeholder="" maxlength="64" />
        </el-form-item>
      </el-col>
      <!-- <el-col :span="12">
        <el-form-item :label="$t('ec.table.version')" prop="sysrUser.rsvn" :rules="[{ validator: validator.number, trigger: 'blur'}]">
          <span v-if="method==='view'">{{ formItem.sysrUser.rsvn }}</span>
          <el-input v-else v-model="formItem.sysrUser.rsvn" type="text" placeholder="" />
        </el-form-item>
      </el-col> -->
      <el-col :span="12">
        <el-form-item :label="$t('ec.user.wxProOpenId')" prop="sysrUser.weixinOpenId" :rules="[]">
          <span v-if="method==='view'">{{ formItem.sysrUser.weixinOpenId }}</span>
          <el-input v-else v-model="formItem.sysrUser.weixinOpenId" type="text" placeholder="" maxlength="1000" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item :label="$t('ec.table.sort')" prop="sysrUser.sortNum">
          <span v-if="method==='view'">{{ formItem.sysrUser.sortNum }}</span>
          <el-input-number v-else v-model="formItem.sysrUser.sortNum" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item :label="$t('ec.user.wxUnionId')" prop="sysrUser.weixinUnionId" :rules="[]">
          <span v-if="method==='view'">{{ formItem.sysrUser.weixinUnionId }}</span>
          <el-input v-else v-model="formItem.sysrUser.weixinUnionId" type="text" placeholder="" maxlength="64" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item
          :label="$t('ec.table.remarks')"
          prop="sysrUser.remark"
        >
          <span v-if="method==='view'">{{ formItem.sysrUser.remark }}</span>
          <el-input v-else v-model="formItem.sysrUser.remark" type="textarea" :autosize="{minRows: 3, maxRows: 5}" maxlength="125" />
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>
<script>
import mixin from 'ecip-web/utils/common-mixin'
import { cloneDeep } from 'ecip-web/utils'
import { getById, save, update, checkAccount } from 'ecip-web/api/vue/user/sysrUserApi'
import { findTenantAccessApps } from 'ecip-web/api/vue/app/sysrRegisterAppApi'
import { findRolesByAppIds } from 'ecip-web/api/vue/role/sysrRoleApi'
import { findPositions } from 'ecip-web/api/vue/position/sysrPositionApi'
import { password } from '@/settings'

const enableTenant = window._CONFIG['enableTenant'] === undefined ? true : window._CONFIG['enableTenant']
const userPageOptions = window._CONFIG['userPageOptions'] === undefined ? {} : window._CONFIG['userPageOptions']
const userPhoneRequired = window._CONFIG['userPhoneRequired'] === undefined ? false : window._CONFIG['userPhoneRequired']
export default {
  name: 'ModulesSystemSysrUserAloneDetailForm',
  mixins: [...mixin],
  data() {
    return {
      enableTenant,
      userPhoneRequired,
      userPageOptions,
      method: '',
      id: '',
      positionList: [],
      accessibleAppList: [],
      roleList: [],
      formItem: {
        orgIdList: '',
        sysrUser: {
          id: '',
          username: '',
          loginPwd: '',
          confirm: '',
          salt: '',
          deptId: '',
          realName: '',
          sex: '0',
          age: null,
          birthday: null,
          email: '',
          superior: null,
          entryDate: null,
          position: '',
          staffNo: '',
          typeCert: '',
          certNo: '',
          phone: '',
          officeTel: '',
          address: '',
          utheme: '',
          ustatus: null,
          createTime: '',
          sortNum: '',
          remark: '',
          rsvn: '',
          appId: '',
          tenantId: '',
          mailValid: true,
          phoneValid: true,
          weixinBind: false,
          insider: false,
          avatar: '',
          weixinOpenId: '',
          weixinMpOpenId: '',
          weixinUnionId: '',
          accessibleAppIds: [],
          roleIds: [],
          positionIds: []
        },
        userAppDeptList: []
      }
    }
  },
  watch: {
    'formItem.sysrUser.tenantId': {
      handler(val) {
        const accessAppIds = this.formItem.sysrUser.accessibleAppIds
        if (accessAppIds && accessAppIds.length > 0) {
          this.findRolesByAppIds(val, accessAppIds)
        }
        this.findTenantAccessApps(val)
        this.findPositionList()
      },
      deep: true,
      immediate: true
    },
    'formItem.sysrUser.accessibleAppIds': {
      handler(val) {
        if (val && val.length > 0) {
          this.findRolesByAppIds(this.formItem.sysrUser.tenantId, this.formItem.sysrUser.accessibleAppIds)
        } else {
          this.roleList = []
        }
      },
      deep: true,
      immediate: true
    }
  },
  methods: {
    async init(method, id) {
      this.method = method
      this.id = id
      this.$refs.form.clearValidate()
      Object.assign(this.$data.formItem, this.$options.data().formItem)
      if (this.method === 'edit' || this.method === 'view') { // 修改或者查看
        await this.getDataById(this.id)
      }
    },
    async findTenantAccessApps(tenantId) {
      const { data } = await findTenantAccessApps(tenantId)
      this.accessibleAppList = data
    },
    async findRolesByAppIds(tenantId, appIds) {
      const { data } = await findRolesByAppIds(tenantId, appIds)
      this.roleList = data
    },
    async findPositionList(tenantId) {
      const { data } = await findPositions({ tenantId })
      this.positionList = data
    },
    async getDataById(id) {
      this.loading = true
      const { data } = await getById(id)
      cloneDeep(this.formItem, data)
      // this.formItem = data
      this.formItem.orgIdList = this.formItem.orgIdList.join()
      this.formItem.sysrUser.deptId = this.formItem.userAppDeptList.map(item => item.deptId).join()
      // 不手动set的话,el-select无法渲染回显
      this.$set(this.formItem.sysrUser, 'accessibleAppIds', data.sysrUser.accessibleAppIds)
      this.$set(this.formItem.sysrUser, 'positionIds', data.sysrUser.positionIds)
      // cloneDeep(this.formItem.sysrUser, data)
      this.loading = false //  关闭遮罩层
    },
    deptChoose(node, Node) {
      if (Node.level && Node.level !== 1) {
        this.formItem.sysrUser.deptId = node.id
      }
    },
    validateDepts(rule, value, callback) {
      const deptSet = new Set()
      const checkedNodes = this.$refs.appDeptSelect.getCheckedNodes()
      for (let i = 0; i < checkedNodes.length; i++) {
        if (deptSet.has(checkedNodes[i].appId)) {
          callback(new Error(this.$t('ec.user.deptError')))
          return
        }
        deptSet.add(checkedNodes[i].appId)
      }
      callback()
    },
    validateOrgs(rule, value, callback) {
      const deptSet = new Set()
      const checkedNodes = this.$refs.orgSelect.getCheckedNodes()
      for (let i = 0; i < checkedNodes.length; i++) {
        if (deptSet.has(checkedNodes[i].tenantId)) {
          callback(new Error(this.$t('ec.user.tenantError')))
          return
        }
        deptSet.add(checkedNodes[i].tenantId)
      }
      callback()
    },
    validateNewPassword(rule, value, callback) {
      if (password && password.reg) {
        if (password.same === false && this.formItem.sysrUser.username === value) {
          callback(new Error(this.$t('ec.login.pwd.sameError')))
          return
        }
        if (!password.reg.test(value)) {
          callback(new Error(this.$t(password.msg) || this.$t('ec.login.pwd.regError') + password.reg))
          return
        }
      } else {
        if (value && value.length > 0 && value.length < 6) {
          callback(new Error(this.$t('ec.login.pwd.lengthError')))
          return
        }
      }
      callback()
    },
    validateEditPassword(rule, value, callback) {
      if (!value) {
        callback()
        return
      }
      if (password && password.reg) {
        if (password.same === false && this.formItem.sysrUser.username === value) {
          callback(new Error(this.$t('ec.login.pwd.sameError')))
          return
        }
        if (!password.reg.test(value)) {
          callback(new Error(this.$t(password.msg) || this.$t('ec.login.pwd.regError') + password.reg))
          return
        }
      } else {
        if (value && value.length > 0 && value.length < 6) {
          callback(new Error(this.$t('ec.login.pwd.lengthError')))
          return
        }
      }
      callback()
    },
    validateConfirm(rule, value, callback) {
      if (value && !this.formItem.sysrUser.loginPwd) {
        callback(new Error(this.$t('ec.login.pwd.empty')))
      }
      if (this.formItem.sysrUser.loginPwd && !value) {
        callback(new Error(this.$t('ec.login.pwd.confirmEmpty')))
      } else if (value !== this.formItem.sysrUser.loginPwd) {
        callback(new Error(this.$t('ec.login.pwd.confirmError')))
      } else {
        callback()
      }
    },
    async validateAccount(rule, value, callback) {
      const { data } = await checkAccount(this.id || '', value)
      if (data.valid) {
        callback()
      } else {
        callback(new Error(this.$t('ec.user.userName') + this.$t('ec.table.exist')))
      }
    },
    async save() {
      if (!this.formItem.sysrUser.tenantId) {
        this.formItem.orgIdList = ''
      }
      this.formItem.userAppDeptList = []
      this.$refs.appDeptSelect.getCheckedNodes().forEach(item => {
        this.formItem.userAppDeptList.push({ appId: item.appId, deptId: item.id })
      })
      const submitResult = Object.assign({}, this.formItem)

      submitResult.orgIdList = submitResult.orgIdList ? submitResult.orgIdList.split(',') : []
      submitResult.sysrUser.deptId = ''
      const valid = await this.$refs.form.validate()
      if (valid) {
        try {
          this.saveLoading = true
          if (this.method === 'edit') {
            await update(this.id, submitResult)
          } else {
            await save(submitResult)
          }
          this.$emit('refreshData')
          this.$notify.success(this.$t('ec.message.saveSuccess'))
          return true
        } catch {
          return false
        }
      }
      return false
    },
    getUserPageOptionsSwitch(option) {
      if (option === 'showUserCert') {
        return userPageOptions.showUserCert === undefined ? true : userPageOptions.showUserCert
      } else if (option === 'phoneRequired') {
        return userPageOptions.phoneRequired === undefined ? false : userPageOptions.phoneRequired
      } else if (option === 'staffNoAlias') {
        return userPageOptions.staffNoAlias === undefined ? this.$t('ec.user.staffNo') : userPageOptions.staffNoAlias
      }
    }
  }
}
</script>

<style scoped>

</style>
