<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <!-- 主表单区域 -->
      <a-form :form="form" slot="detail">
        <a-row>
          <a-col :span="12" >
            <a-form-item label="送货单" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-image-upload isMultiple v-decorator="['deliveryRecordPics']"></j-image-upload>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </j-form-container>
  </a-spin>
</template>

<script>

  import pick from 'lodash.pick'
  import { getAction, postAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import JFormContainer from '@/components/jeecg/JFormContainer'
  import JDate from '@/components/jeecg/JDate'  
  import JImageUpload from '@/components/jeecg/JImageUpload'

  export default {
    name: 'IostDeliveryNoteForm4Pic',
    components: {
      JFormContainer,
      JDate,
      JImageUpload,
    },
    data() {
      return {
        form: this.$form.createForm(this),
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 6 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        labelCol2: {
          xs: { span: 24 },
          sm: { span: 3 },
        },
        wrapperCol2: {
          xs: { span: 24 },
          sm: { span: 20 },
        },
        confirmLoading: false,
        // 新增时子表默认添加几行空数据
        validatorRules: {
        },
        url: {
          edit: "/basedata/iostDeliveryNote/edit4Pic",
        }
      }
    },
    props: {
      //流程表单data
      formData: {
        type: Object,
        default: ()=>{},
        required: false
      },
      //表单模式：false流程表单 true普通表单
      formBpm: {
        type: Boolean,
        default: false,
        required: false
      },
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    computed: {
      formDisabled(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return false
          }
          return true
        }
        return this.disabled
      },
      showFlowSubmitButton(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return true
          }
        }
        return false
      }
    },
    created () {
    },
    methods: {
      handleOk(record)
      {
        let that = this;
        let url = `${window._CONFIG['domianURL']}/basedata/iostDeliveryNote/edit4Pic`;
        
        postAction(url, {iostDeliveryNotePage:this.model}).then((res) => {
          if (res.success) {
            this.$emit('ok');
          }
          that.loading = false;
        });
      },
      edit(record){
        editPic(record)
      },
      editPic (record) {
        let that = this;
        let url = `${window._CONFIG['domianURL']}/basedata/iostDeliveryNote/queryById4Pic`;
        getAction(url, {id:record.deliveryRecordId}).then((res) => {
          console.log("res");
          console.log(res);
          if (res.success) {
            console.log("res.result");
            console.log(res.result);
            that.form.resetFields();
            res.result.deliveryRecordPics = res.result.deliveryRecordPicsString;
            that.model = Object.assign({}, res.result);
            that.visible = true;
            that.$nextTick(() => {
              that.form.setFieldsValue(pick(that.model,'deliveryRecordPicsString'))
            })
          }
          that.loading = false;
        });

      },
     popupCallback(row){
       this.form.setFieldsValue(pick(row, 'deliveryRecordPicsString'))
     },
    }
  }
</script>

<style scoped>
</style>