<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :maskClosable="false"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
    :footer="null">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form" style="padding-bottom: 30px;padding-top: 30px">

        <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['remark',validatorRules.remark]" rows="4" :maxlength="100" placeholder="请输入备注"/>
        </a-form-item>


      </a-form>
    </a-spin>
    <div class="drawer-bootom-button">
      <a-button class="ant-btn"  @click="handleCancelOut">关闭</a-button>
      <a-button class="ant-btn ant-btn-primary" style="margin-left: 8px"  @click="handleOkIn">确定</a-button>
    </div>
  </a-modal>

</template>

<script>
  import { httpAction } from '@/api/manage'
  import JDate from '@/components/jeecg/JDate'
  import JUpload from '@/components/jeecg/JUpload'
  import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
  import JDictSelectTag from '@/components/dict/JDictSelectTag'
  import Vue from 'vue'
  import { ACCESS_TOKEN } from '@/store/mutation-types'
  import { getAction, deleteAction, putAction, postAction,downFile } from '@/api/manage'
  import pick from 'lodash.pick'
  const remark = (params) => putAction('/requiremanager/hwRequirement/remark', params)


  export default {
    name: 'HwRequireRemarkModal',
    components: {
      JDate,
      JUpload,
      JSelectDepart,
      JDictSelectTag,
    },
    data() {
      return {
        uploadAction: window._CONFIG['domianURL'] + '/hpSys/common/ossUpload',
        urlDownload: window._CONFIG['domianURL'] + '/hpSys/common/ossDownload',
        headers: {},
        fileList: [],
        form: this.$form.createForm(this),
        title: '操作',
        width: 600,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        defaultFileList:[],
        accept:'.pdf',
        id:0,
        platType:1,
        confirmLoading: false,
        validatorRules: {
          remark: { rules: [{ required: true, message: '请输入备注' }] },
        },
        url: {
          fileUpload: window._CONFIG['domianURL'] + '/hpSys/common/ossUpload',
          edit: '/requiremanager/hwRequirement/edit',
          importExcelUrl: "requiremanager/hwRequirement/importExcel?id=",
          exportXlsUrl:"/requiremanager/hwRequirement/tyemplateGeneration"
        },
      }
    },
    watch: {

    },
    created() {
      const token = Vue.ls.get(ACCESS_TOKEN)
      this.headers = { 'X-Access-Token': token }

    },
    methods: {
      add() {
        this.edit({})
      },
      edit(record) {
        this.model={}
        this.form.resetFields()
        this.model = record
        this.visible = true
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model, 'id','remark'))
        })
      },
      close() {
        this.visible = false
      },
      handleOk(){
        this.$emit('ok')
        this.close()
      },
      handleOkIn() {
        this.form.validateFields((err, values) => {
          if(!err){
            let formData = Object.assign(this.model, values);
            remark({ id: this.model.id, remark: this.model.remark }).then((res) => {
              if (res.success) {
                this.$message.success(res.message)
                this.handleOk()
              } else {
                this.$message.warning(res.message)
              }
            })
          }
        })
      },
      handleCancel(){
        this.visible = false
      },
      handleCancelOut() {
          this.visible = false
      },
      popupCallback(row) {
        this.form.setFieldsValue(pick(row,'remark'))
      },

    }
  }
</script>
<style>
  .drawer-bootom-button {
    position: absolute;
    bottom: -8px;
    width: 100%;
    border-top: 1px solid #e8e8e8;
    padding: 10px 16px;
    text-align: right;
    left: 0;
    background: #fff;
    border-radius: 0 0 2px 2px;
  }

  .ant-upload{
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
  }
</style>