<!--
 * @Date: 2021-01-05 13:40:58
 * @LastEditors: zwq
 * @LastEditTime: 2022-10-20 13:56:44
 * @FilePath: \basic-admin\src\views\RoleManager\EditForm.vue
 * @Description:
-->
<template>
  <div>
    <el-dialog v-bind="$attrs" :title="'formItem.role.edit' | i18nFilter" v-on="$listeners" @open="onOpen" @close="onClose">
      <el-form ref="编辑角色" :model="formData" :rules="rules" size="medium" label-width="100px">
        <el-form-item :label="$t('roleManage.roleCode')" prop="code">
          <el-input v-model="formData.code" :placeholder="['placeholder.input', $t('roleManage.roleCode')] | i18nFilterForm" clearable :style="{width: '100%'}" />
        </el-form-item>
        <el-form-item :label="$t('roleManage.roleName')" prop="name">
          <el-input v-model="formData.name" :placeholder="['placeholder.input', $t('roleManage.roleName')] | i18nFilterForm" clearable :style="{width: '100%'}" />
        </el-form-item>
        <el-form-item :label="$t('roleManage.roleType')" prop="category">
          <el-select v-model="formData.category">
            <el-option
              v-for="item in categoryOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('roleManage.remark')" prop="remark">
          <el-input v-model="formData.remark" :placeholder="['placeholder.input', $t('roleManage.remark')] | i18nFilterForm" clearable :style="{width: '100%'}" />
        </el-form-item>
        <el-form-item :label="$t('roleManage.rolestartstop')" prop="enabled">
          <el-switch v-model="formData.enabled" :active-value="1" :inactive-value="0" @change="enableStateChange" />
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="close">{{ 'btn.cancel' | i18nFilter }}</el-button>
        <el-button type="primary" @click="handelConfirm">{{ 'btn.confirm' | i18nFilter }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  components: {},
  inheritAttrs: false,
  props: {
    targetInfo: {
      type: Object,
      default: () => {
        return {
        }
      }
    }
  },
  data() {
    return {
      formData: {
        code: undefined,
        name: undefined,
        remark: undefined,
        category: 1,
        enabled: true
      },
      categoryOptions: [{
        value: 1,
        label: 'pc'
      }, {
        value: 5,
        label: 'pda'
      }],
      rules: {
        code: [{
          required: true,
          message: this.$i18nForm(['placeholder.input', this.$t('roleManage.roleCode')]),
          trigger: 'blur'
        }],
        name: [{
          required: true,
          message: this.$i18nForm(['placeholder.input', this.$t('roleManage.roleName')]),
          trigger: 'blur'
        }],
        remark: []
      }
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    onOpen() {
      this.getInfo()
    },
    onClose() {
      this.$emit('done')
      this.$refs['编辑角色'].resetFields()
    },
    close() {
      this.$emit('update:visible', false)
    },
    async enableStateChange(val) {
      console.log(val)
    },
    handelConfirm() {
      this.$refs['编辑角色'].validate(async valid => {
        if (!valid) return
        this.$message({
          type: 'success',
          message: '修改成功！'
        })
        this.close()
      })
    },
    async getInfo() {
      console.log(this.targetInfo)
      this.formData = this.targetInfo
    }
  }
}

</script>
<style>
</style>
