<template>
  <p-modal
    title="修改"
    width="50%"
    :visible="isvisible"
    @ok="handleOk"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
  >
    <p-grid-form
      :span="8"
      ref="form"
      :label-col="{ span: 8 }"
      class="plg-form"
      :items="items"
      @submit="hanlderSubmit"
    />
  </p-modal>
</template>
<script>
const items = [
  {
    span: 20,
    type: 'input',
    disabled: false,
    name: 'name',
    label: '权限名称',
    disabled: true,
    value: ''
  },
  {
    span: 20,
    type: 'check',
    disabled: false,
    name: 'enabled',
    label: '是否启用',
    value: ''
  },
  {
    span: 20,
    type: 'textarea',
    disabled: false,
    name: 'remark',
    label: '权限描述',
    value: ''
  }
]
import { updateDataAuthHdr } from './../api/addAuth.js'
export default {
  data() {
    return {
      items,
      confirmLoading: false,
      isvisible: false // 详情弹窗
    }
  },
  props: {
    visibleDetial: {
      type: Boolean,
      default: false
    },
    setRecord: {
      type: Object,
      default: {}
    }
  },
  watch: {
    visibleDetial(newVal) {
      this.isvisible = newVal
      this.$nextTick(() => {
        this.$refs.form.form.resetFields()
        this.$refs.form.form.setFieldsValue({
          name: this.setRecord.name,
          enabled: this.setRecord.enabled == 1 ? true : false,
          remark: this.setRecord.remark
        })
      })
    }
  },
  mounted() {},
  methods: {
    hanlderSubmit() {},
    handleCancel() {
      // 取消
      this.isvisible = false
      this.$emit('requestChange', false)
    },
    handleOk() {
      // 确认
      this.confirmLoading = true
      this.$refs.form.form.validateFields((res, values) => {
        this.setUpdateDataAuthHdr(values)
      })
    },
    setUpdateDataAuthHdr(values) {
      // 修改
      let params = {
        id: this.setRecord.id,
        enabled: values.enabled ? 1 : 0,
        name: values.name,
        remark: values.remark
      }
      updateDataAuthHdr(params).then(res => {
        if (res.success) {
          this.confirmLoading = false
          this.$emit('successChange', false)
        } else {
          this.$message.warn(res.message)
        }
      })
    }
  }
}
</script>
<style lang="less" scoped></style>
