<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <!-- 主表单区域 -->
      <a-form :form="form" slot="detail">
        <a-row>
          <a-col :span="8" v-show="false">
            <a-form-item label="ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['id']" placeholder="" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" v-show="false">
            <a-form-item label="流程流转条件" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['haveAndNot']" placeholder="" style="width: 100%" disabled/>
            </a-form-item>
          </a-col>
          <a-col :span="8" v-show="false">
            <a-form-item label="ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['id']" placeholder="" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="流程发起人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-select-user-by-dep v-decorator="['createBy']" disabled/>
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="流程发起公司" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-select-company v-decorator="['company']" multi disabled/>
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="流程发起部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-select-depart v-decorator="['sysOrgCode']" multi disabled/>
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="流程发起时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择流程发起时间" v-decorator="['createTime']" :trigger-change="true" :show-time="true"
                      date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" disabled/>
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="物资类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" @change="materialType"
                                 v-decorator="['materialType',validatorRules.materialType]" :trigger-change="true"
                                 dictCode="material_type" placeholder="请选择物资类型"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" v-if="task">
            <a-form-item label="被调拨部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-select-depart v-decorator="['beAllotDepartment',validatorRules.beAllotDepartment]"
                               @change='Department'/>
            </a-form-item>
          </a-col>
          <a-col :span="8
">
            <a-form-item label="文件" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-upload v-decorator="['fileId']" :trigger-change="true"></j-upload>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </j-form-container>
    <!-- 子表单区域 -->
    <a-tabs v-model="activeKey" @change="handleChangeTabs">
      <a-tab-pane tab="物资调拨流程调拨清单" :key="refKeys[0]" :forceRender="true">
        <p-editable-table
          ref="processMaterialsAllotList"
          :loading="processMaterialsAllotListTable.loading"
          :columns="processMaterialsAllotListTable.columns"
          :dataSource="processMaterialsAllotListTable.dataSource"
          :maxHeight="300"
          :disabled="this.heid"
          :isabled="isabled"
          :rowNumber="true"
          :rowSelection="true"
          :actionButton="true"
          @valueChange="onSelect"
          @descriptionFetch="descriptionFetchData"
        />
      </a-tab-pane>
    </a-tabs>
    <j-form-container>
      <a-form :form="form">
        <a-row>
          <a-col :span="24">
            <a-form-item label="流程说明">
              <j-editor v-decorator="[ 'opinion', {} ]" triggerChange></j-editor>
              <!--<a-input type="textarea" v-decorator="[ 'opinion' ]" :rows="4" />-->
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </j-form-container>
    <div class="div_process">
      <a-form-item v-if="!disabled" :wrapperCol="{ span: 24 }" style="text-align: center" v-show="isHava">
        <a-button type="primary" :disabled="disabled||btndisabled" @click="handleSubmit">保存</a-button>
        <a-button style="margin-left: 8px" type="primary" :disabled="disabled||btndisabled" @click="applySubmit">提交申请
        </a-button>
        <a-button style="margin-left: 8px" :disabled="disabled" @click="close">取消</a-button>
      </a-form-item>
      <a-form-item v-if="task" :wrapperCol="{ span: 24 }" style="text-align: center" v-show="isHava">
        <a-button type="primary" @click="passTask">通过</a-button>
        <a-button style="margin-left: 8px" @click="backTask">驳回</a-button>
      </a-form-item>
    </div>
  </a-spin>
</template>

<script>

  import pick from 'lodash.pick'
  import { getAction, getCurrentTime, httpAction, getStringArry, getRecord } from '@/api/manage'
  import { FormTypes, getRefPromise, validateFormAndTables } from '@/utils/JEditableTableUtil'
  import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
  import JSelectCompany from '../../../components/jeecgbiz/JSelectCompany'
  import JFormContainer from '@/components/jeecg/JFormContainer'
  import JDate from '@/components/jeecg/JDate'
  import JUpload from '@/components/jeecg/JUpload'
  import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
  import JSelectUserByDep from '@/components/jeecgbiz/JSelectUserByDep'
  import JDictSelectTag from '@/components/dict/JDictSelectTag'

  export default {
    name: 'ProcessMaterialsAllotForm',
    mixins: [JEditableTableMixin],
    components: {
      JFormContainer,
      JDate,
      JUpload,
      JSelectDepart,
      JSelectUserByDep,
      JDictSelectTag,
      JSelectCompany
    },
    data() {
      return {
        heid: true,
        isabled: true,
        libraryAssociationIdInvisible: 'ZK',
        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 }
        },
        // 新增时子表默认添加几行空数据
        addDefaultRowNum: 1,
        refKeys: ['processMaterialsAllotList'],
        tableKeys: ['processMaterialsAllotList'],
        activeKey: 'processMaterialsAllotList',
        // 物资调拨流程调拨清单
        processMaterialsAllotListTable: {
          loading: false,
          dataSource: [],
          columns: [
            {
              title: '物料组',
              key: 'materialGroup',
              // type: FormTypes.slot, //  <-------------改为 slot 格式
              // slotName: 'actions',   //  <-------------slot 的名称，对应 v-slot 冒号后面和等号前面的内容
              type: FormTypes.sel_search,
              dictCode: '',
              width: '200px',
              placeholder: '请输入${title}',
              options: []
              // props:{title: 'show title'}
              // scopedSlots: { customRender: 'edit' },//引入的插槽
              // customRender:function (t,r,index) {
              //     console.log(t,r);
              //
              // }
            },
            {
              title: '物料编号',
              key: 'equipment',
              type: FormTypes.sel_search,
              dictCode: '',
              width: '200px',
              placeholder: '请输入${title}',
              options: []
            },
            {
              title: 'WBS',
              key: 'wbs',
              type: FormTypes.input,
              dictCode: '',
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: ''
            },
            {
              title: '物料名称及规格型号',
              key: 'materialName',
              type: FormTypes.input,
              dictCode: '',
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: ''
            },
            {
              title: '单位',
              key: 'materialUnit',
              type: FormTypes.input,
              dictCode: '',
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: ''
            },
            {
              title: '调拨数量',
              key: 'allotNumber',
              type: FormTypes.inputNumber,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: ''
            },
            // {
            //   title: '库存数量',
            //   key: 'number',
            //   type: FormTypes.inputNumber,
            //   width: '200px',
            //   placeholder: '请输入${title}',
            //   defaultValue: ''
            // },
            {
              title: '调拨目标',
              key: 'allotTarget',
              type: FormTypes.sel_search,
              dictCode: '',
              width: '200px',
              placeholder: '请输入${title}',
              options: []
            },
            {
              title: '单价（元）',
              key: 'materialPrice',
              type: FormTypes.inputNumber,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: ''
            },
            {
              title: '金额（元）',
              key: 'materialAmount',
              type: FormTypes.inputNumber,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: ''
            },
            {
              title: '需求时间',
              key: 'requiredTime',
              type: FormTypes.date,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: ''
            },
            {
              title: '供货商',
              key: 'supplierId',
              type: FormTypes.input,
              dictCode: '',
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: ''
            },
            {
              title: '用途',
              key: 'purpose',
              type: FormTypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: ''
            }
          ]
        },
        url: {
          getForm: '/actBusiness/getForm',
          add: '/hy/processMaterialsAllot/add',
          edit: '/hy/processMaterialsAllot/edit',
          addAlloApply: '/hy/processMaterialsAllot/addAlloApply',
          editAlloApply: '/hy/processMaterialsAllot/editAlloApply',
          queryById: '/hy/processMaterialsAllot/queryById',
          descriptionRake: '/wastematerials/processWasteMaterials/wasteMaterialsName', //查询物料组
          descriptionRakeUrl: '/hy/processMaterialWarehousingList/queryByIdWarehousingList', //查询物料组
          merchandiseNewsList: '/wastematerials/processWasteMaterials/merchandiseNewsName',
          unitWasteNameUrl: '/unitwaste/processUnitWasteWarehouseCode/unitWasteName',
          puwwlistByuntil: '/unitwaste/processUnitWasteWarehouseCode/list',
          getFirstNode: '/actProcessIns/getFirstNode',
          processMaterialsAllotList: {
            list: '/hy/processMaterialsAllot/queryProcessMaterialsAllotListByMainId'
          }
        },
        btndisabled: false,
        isHava:false,
        describes: '',
        assignees: '',
        validatorRules: {
          // 'blur'是鼠标失去焦点的时候会触发验证
          materialType: { rules: [{ required: true, message: '请选择物资类型!' }] },
          beAllotDepartment: { rules: [{ required: true, message: '被调拨部门不能为空!' }] },
          processPlan: { rules: [{ required: true, message: '请选择流程计划!' }] }
        },
        bigIdMerchandiseNewsList: [],
        materialGroupId: undefined
      }
    },
    props: {
      /*流程数据*/
      processData: {
        type: Object,
        default: () => {
          return {}
        },
        required: false
      },
      /*是否新增*/
      isNew: { type: Boolean, default: false, required: false },
      /*是否处理流程*/
      task: { type: Boolean, default: false, required: false },
      //流程表单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() {
      //如果是流程中表单，则需要加载流程表单data
      this.showFlowData()
      if (!this.isNew) {
        this.init()
      }
      let company = sessionStorage.getItem('PARENT_ID')
      let userInfo = sessionStorage.getItem('USER_INFORMATION')
      // console.log("userInfouserInfo",JSON.parse(userInfo));

      // userInfo.company=company;
      this.popupCallback(company, userInfo)

    },
    methods: {
      async onSelect(record) {
        // console.log(record)
        let isDB = true
        if (record.row.materialGroup !== '' && record.row.materialGroup !== undefined) {

          if (record.row.id !== '' && record.row.id !== undefined && this.materialGroupId !== record.row.materialGroup) {
            // console.log("执行materialGroup")
            this.fetchMerchandiseNews(record.row.materialGroup, 1)
            let value = [
              {
                rowKey: record.row.id,
                values: {
                  'equipment': '',
                  'materialGroup': record.row.materialGroup,
                  'materialName': '',
                  'materialUnit': '',
                  'supplierId': '',
                  'materialPrice': '',
                  // 'number': '',
                  'allotNumber': '',
                  'materialAmount': ''
                }
              }
            ]
            this.$nextTick(() => {
              this.$refs.processMaterialsAllotList.setValues(value)
            })
            this.materialGroupId = record.row.materialGroup
            isDB = false
          }

        }
        if (record.row.materialGroup !== '' && record.row.materialGroup !== undefined && record.row.equipment !== '' && record.row.allotNumber === '' && isDB) {
          // console.log("执行materialNumber")
          let materialName = {}
          this.bigIdMerchandiseNewsList.forEach(item => {
            if (item.merchandiseNewsId === record.row.equipment) {
              materialName = {
                name: item.merchandiseName,
                unit: item.materialsUnit,
                supplierName: item.supplierId,
                price: item.materialPrice
                // number : item.residueNumber === undefined ? 0 : item.residueNumber,
              }
            }
          })
          let values = [
            {
              rowKey: record.row.id,
              values: {
                'equipment': record.row.equipment,
                'materialGroup': record.row.materialGroup,
                'materialName': materialName.name,
                'materialUnit': materialName.unit,
                'supplierId': materialName.supplierName,
                'materialPrice': materialName.price,
                // 'number': materialName.number,
                'materialAmount': 0
              }
            }
          ]
          // console.log("",values);
          this.$refs.processMaterialsAllotList.setValues(values)
        }

        // 根据请发数量计算
        if (record.row.allotNumber !== '' && record.row.allotNumber !== undefined && isDB) {
          let res = record.row
          let materialName = {}
          this.bigIdMerchandiseNewsList.forEach(item => {
            if (item.merchandiseNewsId === record.row.equipment) {
              materialName = {
                number: item.residueNumber === undefined ? 0 : item.residueNumber
              }
            }
          })
          // console.log("materialName.residueNumber",materialName.residueNumber)
          // if(parseInt( res.allotNumber) > parseInt( materialName.number )){
          //   // console.log("大于")
          //   this.$message.warn("输入调拨数量不能大于库存数量")
          //   res.allotNumber = materialName.number;
          // }
          if (res.id != undefined) {
            let value = [
              {
                rowKey: res.id,
                values: {
                  'equipment': res.equipment,
                  // 'materialGroup': res.materialGroup,
                  // 'materialName': res.name,
                  // 'materialUnit': res.unit,
                  // 'supplier': res.supplierName,
                  // 'materialPrice': res.price,
                  // 'number': res.number,
                  'allotNumber': res.allotNumber,
                  'materialAmount': res.materialPrice * parseInt(res.allotNumber)
                }
              }
            ]
            this.$nextTick(() => {
              this.$refs.processMaterialsAllotList.setValues(value)
            })
          }


          // console.log('****>',value)

        }

      },
      fetchMerchandiseNews(value) { //查询物料清单信息
        //查询大品类数据
        return new Promise((resolve, reject) => {
          //你的逻辑代码
          let par = {
            delFlag: 0,
            descriptionId: value

          }
          this.bigIdMerchandiseNewsList = []
          let qc = []
          let numberList = []
          if (this.processMaterialsAllotListTable.columns[1].options.length > 0) {
            this.processMaterialsAllotListTable.columns[1].options = []
          }
          this.$refs.processMaterialsAllotList.getValues((a, b, c) => {
            console.log(a, b, c)
            b.forEach(item => {
              if (item.equipment !== '' && item.equipment !== undefined && item.equipment !== null) {
                numberList.push(item.equipment)
              }
            })
          })
          getAction(this.url.merchandiseNewsList, par).then((res) => {
            if (res.success) {
              console.log(res.result)
              let newList = res.result
              // console.log("12312312:"+numberList.length);
              if (numberList.length > 0) {
                newList.forEach(item => {
                  qc.push({
                    title: item.materialsNumber,
                    value: item.merchandiseNewsId,
                    disabled: false
                  })
                })
                numberList.forEach(num => {
                  qc.forEach(i => {
                    if (num === i.value) {
                      // console.log(num,i.value);
                      i.disabled = true
                    }
                  })
                })
                this.processMaterialsAllotListTable.columns[1].options = qc
              } else {
                newList.forEach(item => {
                  this.processMaterialsAllotListTable.columns[1].options.push({
                    title: item.materialsNumber,
                    value: item.merchandiseNewsId,
                    disabled: false
                  })
                })
              }
              // console.log(this.processUdgetPlanMaterialTable.columns[1].options);
              resolve(this.bigIdMerchandiseNewsList = res.result)
              // return
            }
          })

        })

      },
      descriptionFetchData(value) { //查询物料组
        //查询数据
        let par = {
          delFlag: 0,
          accountingAttributes: value
          // sysOrgCode: this.data.sysOrgCode
        }
        getAction(this.url.descriptionRake, par).then((res) => {
          if (res.success) {

            if (this.processMaterialsAllotListTable.columns[0].options.length > 0) {
              this.processMaterialsAllotListTable.columns[0].options = []
            }
            res.result.forEach(item => {
              this.processMaterialsAllotListTable.columns[0].options.push({
                title: item.descriptionName,
                value: item.descriptionId
              })
            })
          }
        })

        getAction(this.url.unitWasteNameUrl, null).then((res) => {
          if (res.success) {
            if (this.processMaterialsAllotListTable.columns[6].options.length > 0) {
              this.processMaterialsAllotListTable.columns[6].options = []
            }
            res.result.forEach(item => {
              this.processMaterialsAllotListTable.columns[6].options.push({
                title: item.departName,
                value: item.libraryAssociationIdInvisible
              })
            })
          }
        })

        this.materialGroupId = undefined

      },

      materialType(val) {
        if (val !== undefined) {
          this.heid = false
          this.descriptionFetchData(val)
        }
      },
      /*回显数据*/
      init() {
        this.btndisabled = true
        var r = this.processData
        this.getAssignees(r)
        // console.log("2323232323232323232323232323232323232323",r)
        this.getAction(this.url.queryById, {
          id: r.tableId,
          tableName: r.tableName
        }).then((res) => {
          if (res.success) {
            let formData = res.result
            formData.tableName = r.tableName
            this.data = formData
            console.log('表单回显数据', this.data)
            this.editAfter()
            this.btndisabled = false
          } else {
            this.$message.error(res.message)
          }
        })
      },
      close() {
        //todo 关闭后的回调
        this.$emit('close')
      },
      /*通过审批*/
      passTask() {
        this.$emit('passTask')
      },
      /*驳回审批*/
      backTask() {
        this.$emit('backTask')
      },
      /*提交申请*/
      applySubmit(e) {
        this.getAllTable().then(tables => {
          return validateFormAndTables(this.form, tables)
        }).then(allValues => {
          console.log('所有数据', allValues)
          if (typeof this.classifyIntoFormData !== 'function') {
            throw this.throwNotFunction('classifyIntoFormData')
          }
          let formData = this.classifyIntoFormData(allValues)
          formData.fileId = getStringArry(formData.fileId)
          // if (formData.materialType === null || formData.materialType ==='' || formData.materialType === undefined){
          //   this.$message.error("物资类型不能为空")
          //   return;
          // }
          // if (formData.beAllotDepartment === null || formData.beAllotDepartment ==='' || formData.beAllotDepartment === undefined){
          //   this.$message.error("被调拨部门不能为空")
          //   return;
          // }
          for (let i = 0; i < formData.processMaterialsAllotListList.length; i++) {
            if (i == 0) {
              this.describes = formData.processMaterialsAllotListList[i].materialName
            } else {
              this.describes = this.describes + '---' + formData.processMaterialsAllotListList[i].materialName
            }
          }
          formData.describes = this.describes
          this.form.validateFields((err, values) => {
            if (!err) {
              formData.procDefId = this.processData.id
              formData.procDeTitle = this.processData.name
              formData.title = this.processData.description
              formData.targetLibrary = this.libraryAssociationIdInvisible
              if (!formData.tableName) formData.tableName = this.processData.businessTable
              console.log('格式化后的数据', formData)
              var url = this.url.addAlloApply
              let method = 'post'
              if (!this.isNew) {
                url = this.url.editAlloApply
                method = 'put'
                formData.assignees = this.assignees
                formData.tableName = this.processData.tableName
                formData.procDefId = this.processData.procDefId
                formData.procDeTitle = this.processData.processName
                formData.title = this.processData.title
                formData.processInstanceId = this.processData.id
                if (!this.assignees) {
                  this.$message.error('审批节点未分配候选审批人员，请联系管理员！')
                  return
                }
              }
              console.log('提交方法', method)
              this.btndisabled = true
              httpAction(url, formData, method).then((res) => {
                if (res.success) {
                  this.$message.success('提交申请成功！')
                  //todo 将表单的数据传给父组件
                  this.$emit('loadData')
                  this.close()
                } else {
                  this.$message.error(res.message)
                }
              }).finally(() => {
                this.btndisabled = false
              })
            }
          })
        })

      },
      handleSubmit(e) {
        this.getAllTable().then(tables => {
          return validateFormAndTables(this.form, tables)
        }).then(allValues => {
          console.log('所有数据', allValues)
          if (typeof this.classifyIntoFormData !== 'function') {
            throw this.throwNotFunction('classifyIntoFormData')
          }
          let formData = this.classifyIntoFormData(allValues)
          formData.fileId = getStringArry(formData.fileId)
          // if (formData.materialType === null || formData.materialType ==='' || formData.materialType === undefined){
          //   this.$message.error("物资类型不能为空")
          //   return;
          // }
          // if (formData.beAllotDepartment === null || formData.beAllotDepartment ==='' || formData.beAllotDepartment === undefined){
          //   this.$message.error("被调拨部门不能为空")
          //   return;
          // }
          for (let i = 0; i < formData.processMaterialsAllotListList.length; i++) {
            if (i == 0) {
              this.describes = formData.processMaterialsAllotListList[i].materialName
            } else {
              this.describes = this.describes + '---' + formData.processMaterialsAllotListList[i].materialName
            }
          }
          formData.describes = this.describes
          this.form.validateFields((err, values) => {
            if (!err) {
              formData.procDefId = this.processData.id
              formData.procDeTitle = this.processData.name
              formData.title = this.processData.description
              formData.targetLibrary = this.libraryAssociationIdInvisible
              if (!formData.tableName) formData.tableName = this.processData.businessTable
              console.log('格式化后的数据', formData)
              var url = this.url.add
              let method = 'post'
              if (!this.isNew) {
                url = this.url.edit
                method = 'put'
              }
              console.log('提交方法', method)
              this.btndisabled = true
              httpAction(url, formData, method).then((res) => {
                if (res.success) {
                  this.$message.success('保存成功！')
                  //todo 将表单的数据传给父组件
                  this.$emit('afterSubmit', formData)
                } else {
                  this.$message.error(res.message)
                }
              }).finally(() => {
                this.btndisabled = false
              })
            }
          })
        })

      },
      addBefore() {
        this.form.resetFields()
        this.processMaterialsAllotListTable.dataSource = []
      },
      getAllTable() {
        let values = this.tableKeys.map(key => getRefPromise(this, key))
        return Promise.all(values)
      },
      /** 调用完edit()方法之后会自动调用此方法 */
      editAfter() {
        if (this.data.id != null && this.data.id != '' && this.data.id != undefined && this.data.fileId != null && this.data.fileId != '') {
          //1、文件回显
          this.data = getRecord(this.data)
        }
        console.log(this.data.haveAndNot,"------------666666666666665555555555555555")

        if (this.data.haveAndNot==0){
          this.isHava=true;
          this.disabled=true
          console.log(this.disabled,"55555555555555555555555")
        }
        let fieldval = pick(this.data, 'id', 'company', 'createTime', 'sysOrgCode', 'createBy', 'materialType', 'beAllotDepartment', 'fileId', 'haveAndNot')
        this.$nextTick(() => {
          this.form.setFieldsValue(fieldval)
        })
        // 加载子表数据
        if (this.data.id) {
          let params = { id: this.data.id }
          this.requestSubTableData(this.url.processMaterialsAllotList.list, params, this.processMaterialsAllotListTable)
        }
      },
      /** 整理成formData */
      classifyIntoFormData(allValues) {
        let main = Object.assign(this.model, allValues.formValue)
        return {
          ...main, // 展开
          processMaterialsAllotListList: allValues.tablesValue[0].values
        }
      },
      //渲染流程表单数据
      showFlowData() {
        if (this.formBpm === true) {
          let params = { id: this.formData.dataId }
          getAction(this.url.queryById, params).then((res) => {
            if (res.success) {
              this.edit(res.result)
            }
          })
        }
      },
      validateError(msg) {
        this.$message.error(msg)
      },
      Department(value) {
        if (value !== null || value !== '' || value !== undefined) {
          let params = {}
          params.unit = value
          getAction(this.url.puwwlistByuntil, params).then((rest) => {
            console.log('rest>>>>>>>>>>>>>>>>>>>>>>>>>>>>', rest)
            if (rest.success && rest.result.total > 0) {
              this.libraryAssociationIdInvisible = value
            } else {
              this.libraryAssociationIdInvisible = 'ZK'
            }
            console.log('value>>>>>>>>>>>>>>>>>>>>>>>>>>>>', this.libraryAssociationIdInvisible)
          })

        }

      },
      popupCallback(company, row) {
        let res = JSON.parse(row)
        console.log('获取我的数据', res.id)
        let param = {}

        param.createBy = res.username
        param.company = company
        param.sysOrgCode = res.departIds
        param.createTime = getCurrentTime()
        this.data = param
        let fieldval = pick(this.data, 'createBy', 'company', 'sysOrgCode', 'createTime')
        this.$nextTick(() => {
          this.form.setFieldsValue(fieldval)
        })
      },
      getAssignees(v) {
        getAction(this.url.getFirstNode, {
          procDefId: v.procDefId,
          tableId: v.tableId,
          tableName: v.tableName
        }).then(res => {
          if (res.success) {
            if (res.result.users && res.result.users.length > 0) {
              // 默认勾选
              let ids = []
              res.result.users.forEach(e => {
                ids.push(e.username)
              })
              this.assignees = ids.join(',')
            }

          }
        })
      }

    }
  }
</script>

<style scoped>
  .div_process {
    margin-top: 30px;
  }
</style>