<template>
  <a-drawer
      :title="title"
      :width="800"
      placement="right"
      :closable="false"
      @close="close"
      :visible="visible"
  >

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
      
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="moid">
          <a-input-number v-decorator="[ 'moid', validatorRules.moid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="mocode">
          <a-input placeholder="请输入mocode" v-decorator="['mocode', validatorRules.mocode ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="createdate">
          <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss' v-decorator="[ 'createdate', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="createuser">
          <a-input placeholder="请输入createuser" v-decorator="['createuser', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="modifydate">
          <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss' v-decorator="[ 'modifydate', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="modifyuser">
          <a-input placeholder="请输入modifyuser" v-decorator="['modifyuser', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="updcount">
          <a-input-number v-decorator="[ 'updcount', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="ufts">
          <a-input placeholder="请输入ufts" v-decorator="['ufts', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="define1">
          <a-input placeholder="请输入define1" v-decorator="['define1', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="define2">
          <a-input placeholder="请输入define2" v-decorator="['define2', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="define3">
          <a-input placeholder="请输入define3" v-decorator="['define3', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="define4">
          <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss' v-decorator="[ 'define4', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="define5">
          <a-input-number v-decorator="[ 'define5', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="define6">
          <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss' v-decorator="[ 'define6', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="define7">
          <a-input placeholder="请输入define7" v-decorator="['define7', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="define8">
          <a-input placeholder="请输入define8" v-decorator="['define8', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="define9">
          <a-input placeholder="请输入define9" v-decorator="['define9', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="define10">
          <a-input placeholder="请输入define10" v-decorator="['define10', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="define11">
          <a-input placeholder="请输入define11" v-decorator="['define11', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="define12">
          <a-input placeholder="请输入define12" v-decorator="['define12', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="define13">
          <a-input placeholder="请输入define13" v-decorator="['define13', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="define14">
          <a-input placeholder="请输入define14" v-decorator="['define14', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="define15">
          <a-input-number v-decorator="[ 'define15', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="define16">
          <a-input placeholder="请输入define16" v-decorator="['define16', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="vtid">
          <a-input-number v-decorator="[ 'vtid', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="createtime">
          <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss' v-decorator="[ 'createtime', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="modifytime">
          <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss' v-decorator="[ 'modifytime', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="iprintcount">
          <a-input-number v-decorator="[ 'iprintcount', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="relsvtid">
          <a-input-number v-decorator="[ 'relsvtid', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="csysbarcode">
          <a-input placeholder="请输入csysbarcode" v-decorator="['csysbarcode', {}]" />
        </a-form-item>
		
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "FbsMomOrderModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        moid:{rules: [{ required: true, message: '请输入moid!' }]},
        mocode:{rules: [{ required: true, message: '请输入mocode!' }]},
        },
        url: {
          add: "/fbsMomOrder/fbsMomOrder/add",
          edit: "/fbsMomOrder/fbsMomOrder/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'moid','mocode','createuser','modifyuser','updcount','ufts','define1','define2','define3','define5','define7','define8','define9','define10','define11','define12','define13','define14','define15','define16','vtid','iprintcount','relsvtid','csysbarcode'))
		  //时间格式化
          this.form.setFieldsValue({createdate:this.model.createdate?moment(this.model.createdate):null})
          this.form.setFieldsValue({modifydate:this.model.modifydate?moment(this.model.modifydate):null})
          this.form.setFieldsValue({define4:this.model.define4?moment(this.model.define4):null})
          this.form.setFieldsValue({define6:this.model.define6?moment(this.model.define6):null})
          this.form.setFieldsValue({createtime:this.model.createtime?moment(this.model.createtime):null})
          this.form.setFieldsValue({modifytime:this.model.modifytime?moment(this.model.modifytime):null})
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            formData.createdate = formData.createdate?formData.createdate.format('YYYY-MM-DD HH:mm:ss'):null;
            formData.modifydate = formData.modifydate?formData.modifydate.format('YYYY-MM-DD HH:mm:ss'):null;
            formData.define4 = formData.define4?formData.define4.format('YYYY-MM-DD HH:mm:ss'):null;
            formData.define6 = formData.define6?formData.define6.format('YYYY-MM-DD HH:mm:ss'):null;
            formData.createtime = formData.createtime?formData.createtime.format('YYYY-MM-DD HH:mm:ss'):null;
            formData.modifytime = formData.modifytime?formData.modifytime.format('YYYY-MM-DD HH:mm:ss'):null;
            
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>