<!-- 驳回原因客户姓名输入 -->
<template>
  <a-form ref="form" v-bind="formItemLayout" :form="form">
    <a-form-item label="登录账号">
      <a-input
        :maxLength="11"
        :disabled="true"
        v-decorator="[
          'username',
          {
            rules: [
              { required: true, message: '请输入添加登录账号!', type: 'string' },
            ]
          }
        ]"
        placeholder="请输入添加登录账号!" />
    </a-form-item>
    <a-form-item label="用户姓名">
      <a-input
        :rows="4"
        v-decorator="[
          'name',
          {
            rules: [
              { required: true, message: '请输入添加姓名!', type: 'string' },
            ]
          }
        ]"
        placeholder="请输入添加姓名!" />
    </a-form-item>
    <a-form-item label="初始密码">
      <a-input
        :maxLength="6"
        v-decorator="[
          'password',
          {
            rules: [
              { required: false, message: '默认密码111111 !', type: 'string' },
            ]
          }
        ]"
        placeholder="默认密码111111 !" />
    </a-form-item>
  </a-form>
</template>

<script>
import { editMiddlesManageUser } from '@/api/permissions'
import moment from 'moment'
export default {
  name: 'EditPromissions',
  data: () => ({
    formItemLayout: {
      labelCol: { span: 6 },
      wrapperCol: { span: 14 }
    },
    loading: false
  }),
  props: {
    item: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  mounted () {
    this.$nextTick(() => {
      this.form.setFieldsValue({
        name: this.item.name,
        username: this.item.username
      })
    })
  },
  beforeCreate () {
    this.form = this.$form.createForm(this)
  },
  methods: {
    moment,
    onOk () {
      return new Promise(resolve => {
        this.form.validateFields((errors, values) => {
          const data = {
            name: values.name,
            password: values.password || '111111',
            username: values.username
          }
          if (!errors) {
            editMiddlesManageUser(this.item.middleground_id, data).then((res) => {
              this.$notification.success({
                message: '成功',
                description: '修改成功'
              })
              resolve(true)
            }).catch((err) => {
              this.$notification.error({
                message: '失败',
                description: err.message
              })
              resolve(false)
            })
          }
        })
      })
    }
  }
}
</script>

<style scoped>
.flexrow {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}
</style>
