<template>
  <div class="requisition_add">

    <el-row type="flex" justify="end" style="margin-bottom: 16px;">
      <el-col :span="1.5">
        <el-button type="primary" :size="size" plain @click="save"
                   v-if="pageStu == 'add' || pageStu == 'edit' || pageStu ==='copy' ">保存
        </el-button>
      </el-col>
      <el-col :span="1.5" style="margin: 0 10px;">
        <el-button type="primary" :size="size" plain @click="submit"
                   v-if="pageStu == 'check' && (row.status == '0' || row.status == '3')">提交
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" :size="size" plain @click="back">返回</el-button>
      </el-col>
    </el-row>
    
    <el-tabs type="border-card" v-model="tabValue" @tab-click="handleClick">
      <el-tab-pane label="基本信息" name="first">
        <div style="width: 100%;height: 580px;overflow-y: auto; overflow-x: hidden;">
          <el-form :model="basicForm" :rules="basicRules" ref="basic" label-width="170px">
            <el-row :gutter="10">
              <el-col :span="6">
                <el-form-item label="单据编码" prop="billCode">
                  <el-input disabled v-model="basicForm.billCode"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="所属组织" prop="orgName">
                  <el-input disabled v-model="basicForm.orgName"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="四级分类" prop="classifyId">
                  <el-select ref="fourTag" v-model="basicForm.classifyId" placeholder="请选择" :disabled="disable"
                             clearable
                             @focus="chooseFourClass">
                    <el-option v-for="item in testOptions" :key="item.id" :label="item.materialType" :value="item.id"/>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="医药物料" prop="isMedicine">
                  <el-select v-model="basicForm.isMedicine" placeholder="医药物料" :disabled="disable"
                             @change="controlMedic">
                    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"/>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row :gutter="10">
              <el-col :span="6">
                <el-form-item label="DI" prop="diCode">
                  <el-input :disabled="disable" v-model.trim="basicForm.diCode"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="物料名称" prop="name">
                  <el-input :disabled="disable" v-model="basicForm.name"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="物料编码" prop="code">
                  <el-input :disabled="disable" v-model="basicForm.code" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="英文名称" prop="enName">
                  <el-input :disabled="disable" v-model="basicForm.enName"></el-input>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row :gutter="10">
              <el-col :span="6">
                <el-form-item label="简称" prop="commonName">
                  <el-input :disabled="disable" v-model="basicForm.commonName"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="规格" prop="specification">
                  <el-input :disabled="disable" v-model="basicForm.specification"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="型号" prop="model">
                  <el-input :disabled="disable" v-model="basicForm.model"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="计量单位" prop="unitId">
                  <el-select ref="units" v-model="basicForm.unitId" placeholder="请选择" clearable :disabled="disable"
                             @focus="chooseUnit">
                    <el-option v-for="item in unitOptions" :key="item.id" :label="item.name" :value="item.id"/>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>


            <el-row :gutter="10">
             
              <el-col :span="6">
                <el-form-item label="生产厂家/代理人" prop="manufacturerId">
                  <el-select ref="factoryOrman" v-model="basicForm.manufacturerId" placeholder="请选择" clearable
                             :disabled="disable" @focus="chooseFactory">
                    <el-option v-for="item in factoryOptions" :key="item.id" :label="item.name" :value="item.id"/>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="注册人/上市许可持有人" prop="registrant">
                  <el-input :disabled="disable" v-model="basicForm.registrant"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="产地" prop="originPlace">
                  <el-select ref="places" v-model="basicForm.originPlace" placeholder="请选择" clearable
                             :disabled="disable"
                             @focus="choosePlace">
                    <el-option v-for="item in placeOptions" :key="item.id" :label="item.name" :value="item.id"/>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="厂家物料名称" prop="manufacturersMaterialName">
                  <el-input :disabled="disable" v-model="basicForm.manufacturersMaterialName"></el-input>
                </el-form-item>
              </el-col>

            </el-row>


            <el-row :gutter="10">
              <el-col :span="6">
                <el-form-item label="厂家物料编码" prop="manufacturersMaterialCode">
                  <el-input type="number" min="0" :disabled="disable"
                            v-model="basicForm.manufacturersMaterialCode"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="ABC分类" prop="classifyAbc">
                  <el-select v-model="basicForm.classifyAbc" placeholder="请选择" clearable :disabled="disable">
                    <el-option v-for="item in dict.type.abc_type" :key="item.value" :label="item.label"
                               :value="item.value"/>
                  </el-select>
                  <!-- <el-input :disabled="disable" v-model="basicForm.classifyAbc"></el-input> -->
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="安全库存" prop="safeStock">
                  <el-input type="number" min="0" :disabled="disable" v-model="basicForm.safeStock"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="B2C物料" prop="isB2c">
                  <el-select v-model="basicForm.isB2c" placeholder="B2C物料" :disabled="disable">
                    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"/>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row :gutter="10">
              
              <el-col :span="6">
                <el-form-item label="成套件" prop="assembly">
                  <el-select v-model="basicForm.assembly" placeholder="成套件" :disabled="disable">
                    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"/>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="批号及库存状态管理" prop="isInventoryStatus">
                  <el-select v-model="basicForm.isInventoryStatus" placeholder="批号及库存状态管理" @change="stockControl"
                             :disabled="disable">
                    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"/>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="序列号管理" prop="serialNoManager">
                  <el-select v-model="basicForm.serialNoManager" placeholder="序列号管理" :disabled="disable || isStock">
                    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"/>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="运输条件" prop="transportationCondition">
                  <el-select v-model="basicForm.transportationCondition" placeholder="请选择" clearable
                             :disabled="disable">
                    <el-option v-for="item in dict.type.sys_conditions_carriage" :key="item.value" :label="item.label"
                               :value="item.value"/>
                  </el-select>
                </el-form-item>
              </el-col>

            </el-row>

            <el-row :gutter="10">
              <el-col :span="6">
                <el-form-item label="中包装单位" prop="mediumPackageUnitId">
                  <el-select ref="midpacks" v-model="basicForm.mediumPackageUnitId" placeholder="请选择" clearable
                             :disabled="disable" @focus="chooseMidpack">
                    <el-option v-for="item in midPackOptions" :key="item.id" :label="item.name" :value="item.id"/>
                  </el-select>
                  <!-- <el-input :disabled="disable" v-model="basicForm.mediumPackageUnitId"></el-input> -->
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="效期管理" prop="expiryDateManagerment">
                  <el-select v-model="basicForm.expiryDateManagerment" placeholder="效期管理" @change="expCt"
                             :disabled="disable || isStock">
                    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"/>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="近效期管理" prop="nearOnsetManagerment">
                  <el-select v-model="basicForm.nearOnsetManagerment" placeholder="近效期管理" :disabled="disable">
                    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"/>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="有效期" prop="usefulLife"
                              :rules="{ required: !isExp, message: '请填写有效期', trigger: 'blur' }">
                  <el-input type="number" min="0" :disabled="disable || isExp"
                            v-model="basicForm.usefulLife"></el-input>
                </el-form-item>
              </el-col>
            </el-row>


            <el-row :gutter="10">
              <el-col :span="6">
                <el-form-item label="效期单位" prop="expiryUnitId"
                              :rules="{ required: !isExp, message: '请选择效期单位', trigger: 'change' }">
                  <el-select v-model="basicForm.expiryUnitId" placeholder="请选择" clearable :disabled="disable || isExp">
                    <el-option v-for="item in dict.type.period_unit" :key="item.value" :label="item.label"
                               :value="item.value"/>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="有效期至单位" prop="usefulLifeUnitId"
                              :rules="{ required: !isExp, message: '请选择有效期至单位', trigger: 'change' }">
                  <el-select v-model="basicForm.usefulLifeUnitId" placeholder="请选择" clearable
                             :disabled="disable || isExp">
                    <el-option v-for="item in dict.type.expiry_date" :key="item.value" :label="item.label"
                               :value="item.value"/>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="近效期预警天数" prop="recentWarningPeriod"
                              :rules="{ required: !isExp, message: '请填写近效期预警天数', trigger: 'blur' }">
                  <el-input type="number" min="0" :disabled="disable || isExp"
                            v-model="basicForm.recentWarningPeriod"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="存储条件" prop="storageCondition">
                  <el-select v-model="basicForm.storageCondition" placeholder="请选择" clearable :disabled="disable">
                    <el-option v-for="item in dict.type.sys_storage_condition" :key="item.value" :label="item.label"
                               :value="item.value"/>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="10">
              
              <el-col :span="6">
                <el-form-item label="物料税类" prop="materialRate">
                  <el-select ref="taxs" v-model="basicForm.materialRate" placeholder="请选择" clearable :disabled="disable"
                             @focus="chooseTax">
                    <el-option v-for="item in taxOptions" :key="item.id" :label="item.name" :value="item.id"/>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="税类编码" prop="rateCode">
                  <el-input disabled v-model="basicForm.rateCode"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="交货周期" prop="deliveryPeriod">
                  <el-input type="number" min="0" :disabled="disable" v-model="basicForm.deliveryPeriod"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="最小起定量" prop="minOrderQty">
                  <el-input type="number" min="0" :disabled="disable" v-model="basicForm.minOrderQty"></el-input>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row :gutter="10">
              <el-col :span="6">
                <el-form-item label="最小包装量" prop="minPackQty">
                  <el-input type="number" min="0" :disabled="disable" v-model="basicForm.minPackQty"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="采购员" prop="puPersonnelId">
                  <el-select ref="staffs" v-model="basicForm.puPersonnelId" placeholder="请选择" clearable
                             :disabled="disable" @focus="chooseStaff">
                    <el-option v-for="item in staffOptions" :key="item.id" :label="item.name" :value="item.code"/>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="最小批量" prop="minBatchQty">
                  <el-input type="number" min="0" :disabled="disable" v-model="basicForm.minBatchQty"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="长度(MM)" prop="length">
                  <el-input type="number" min="0" :disabled="disable" v-model="basicForm.length"></el-input>
                </el-form-item>
              </el-col>
            </el-row>


            <el-row :gutter="10">
              <el-col :span="6">
                <el-form-item label="高度(MM)" prop="height">
                  <el-input type="number" min="0" :disabled="disable" v-model="basicForm.height"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="宽度(MM)" prop="width">
                  <el-input type="number" min="0" :disabled="disable" v-model="basicForm.width"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="箱包装数" prop="boxPackaingQty">
                  <el-input type="number" min="0" :disabled="disable" v-model="basicForm.boxPackaingQty"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="中包装数" prop="mediumPackageQty">
                  <el-input type="number" min="0" :disabled="disable" v-model="basicForm.mediumPackageQty"></el-input>
                </el-form-item>
              </el-col>

            </el-row>

            <el-row :gutter="10">
              
              <el-col :span="6">
                <el-form-item label="包装说明" prop="packExplain">
                  <el-input :disabled="disable" v-model="basicForm.packExplain"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="启用状态" prop="isEnable">
                  <el-input v-show="false" disabled v-model="basicForm.isEnable"></el-input>
                  <el-input disabled value="启用"></el-input>
                </el-form-item>
              </el-col>
              <!-- <el-col :span="6">
                <el-form-item label="业务线" prop="businessLine">
                  <el-select ref="lines" v-model="basicForm.businessLine" placeholder="请选择" clearable
                             :disabled="disable"
                             @focus="chooseLine">
                    <el-option v-for="item in lineOptions" :key="item.id" :label="item.name" :value="item.id"/>
                  </el-select>
                </el-form-item>
              </el-col> -->
              <el-col :span="6">
                <el-form-item label="物料申请人" prop="proposerId">
                  <el-input disabled v-model="basicForm.createName || this.$store.state.user.nickName"></el-input>
                  <el-input v-show="false" v-model="basicForm.proposerId"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="条形码" prop="barCode">
                  <el-input :disabled="disable" v-model="basicForm.barCode"></el-input>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row :gutter="10">
              <el-col :span="6">
                <el-form-item label="使用期限/次数" prop="serviceLife">
                  <el-input :disabled="disable" v-model="basicForm.serviceLife"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="医保代码" prop="healthCode">
                  <el-input :disabled="disable" v-model="basicForm.healthCode"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="原系统物料编码" prop="oriMaterialCode">
                  <el-input :disabled="disable" v-model="basicForm.oriMaterialCode"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="生产许可证" prop="productionPermit"
                              :rules="{ required: !isControl, message: '请填写生产许可证', trigger: 'change' }">
                  <el-input :disabled="disable" v-model="basicForm.productionPermit"></el-input>
                </el-form-item>
              </el-col>
            </el-row>


            <el-row :gutter="10">
              <el-col :span="6">
                <el-form-item label="一级分类" prop="oneClass">
                  <el-input disabled v-model="basicForm.oneClass"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="二级分类" prop="twoClass">
                  <el-input disabled v-model="basicForm.twoClass"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="三级分类" prop="threeClass">
                  <el-input disabled v-model="basicForm.threeClass"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="默认采购组织" prop="purchasingOrganization">
                  <el-select ref="organizations" v-model="basicForm.purchasingOrganization" placeholder="请选择" clearable
                             :disabled="disable" @clear="controlOrg" @focus="chooseOrganizations">
                    <el-option v-for="item in organizationsOptions" :key="item.id" :label="item.label"
                               :value="item.id"/>
                  </el-select>
                </el-form-item>
              </el-col>

            </el-row>

            <el-row :gutter="10">
            
              <el-col :span="6">
                <el-form-item label="内包装单位" prop="innerPackingUnit">
                  <!-- <el-input :disabled="disable" v-model="basicForm.innerPackingUnit"></el-input> -->
                  <el-select ref="innerPackingUnits" v-model="basicForm.innerPackingUnit" placeholder="请选择" clearable
                             :disabled="disable" @focus="chooseInnerPackingUnit">
                    <el-option v-for="item in innerPackingUnitOptions" :key="item.id" :label="item.name"
                               :value="item.id"/>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="内包装数" prop="innerPackingQty">
                  <el-input type="number" min="0" :disabled="disable" v-model="basicForm.innerPackingQty"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="进口产品生产厂家" prop="importsManufacturer">
                  <el-input :disabled="disable" v-model="basicForm.importsManufacturer"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="服务类" prop="serviceClass">
                  <el-select v-model="basicForm.serviceClass" placeholder="" disabled>
                    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"/>
                  </el-select>
                </el-form-item>
              </el-col>
              <!-- <el-col :span="6">
                <el-form-item label="业务部门" prop="businessDepartment">
                  <el-select ref="departs" v-model="basicForm.businessDepartment" placeholder="请选择" clearable
                             :disabled="disable || orgControl" @focus="chooseDepart">
                    <el-option v-for="item in departOptions" :key="item.id" :label="item.label" :value="item.id"/>
                  </el-select>
                </el-form-item>
              </el-col> -->
              
            </el-row>
            <el-row :gutter="10">
              

              <el-col :span="6">
                <el-form-item label="备注" prop="remark">
                  <el-input :disabled="disable" v-model="basicForm.remark"></el-input>
                </el-form-item>
              </el-col>
              
            </el-row>
            
          </el-form>
        </div>
      </el-tab-pane>

      <el-tab-pane label="医药属性" name="second">
        <el-form :model="basicForm2" ref="basic2" label-width="160px">
          <el-row :gutter="10">
            <el-col :span="6">
              <el-form-item label="药品" prop="isDrug"
                            :rules="{ required: !isControl, message: '请选择是否药品', trigger: 'change' }">
                <el-select v-model="basicForm2.isDrug" placeholder="请选择" clearable :disabled="disable || isControl">
                  <el-option v-for="dict in dict.type.sys_medicine" :key="dict.value" :label="dict.label"
                             :value="dict.value"/>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="注册证号/备案凭证编号" prop="registrationNo">
                <el-input :disabled="disable || isControl" v-model="basicForm2.registrationNo"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="医疗器械" prop="medicalInstruments">
                <el-select v-model="basicForm2.medicalInstruments" placeholder="请选择" clearable
                           :disabled="disable || isControl">
                  <el-option v-for="dict in dict.type.medical_instruments" :key="dict.value" :label="dict.label"
                             :value="dict.value"/>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="通用名称" prop="commonName">
                <el-input :disabled="disable || isControl" v-model="basicForm2.commonName"></el-input>
              </el-form-item>
            </el-col>
          </el-row>


          <el-row :gutter="10">
            
            <el-col :span="6">
              <el-form-item label="批准文号" prop="ratifyBatchNo">
                <el-input :disabled="disable || isControl" v-model="basicForm2.ratifyBatchNo"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="剂型" prop="dosageFrom"
                            :rules="{ required: !isControl, message: '请选择剂型', trigger: 'blur' }">
                <el-select ref="doses" v-model="basicForm2.dosageFrom" placeholder="请选择" clearable
                           :disabled="disable || isControl" @focus="chooseDose">
                  <el-option v-for="item in doseOptions" :key="item.id" :label="item.name" :value="item.id"/>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="旧注册证号" prop="oriRegistrationNo">
                <el-input :disabled="disable || isControl" v-model="basicForm2.oriRegistrationNo"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="养护类型" prop="curingType">
                <el-select v-model="basicForm2.curingType" placeholder="请选择" clearable :disabled="disable || isControl">
                  <el-option v-for="dict in dict.type.curing_type" :key="dict.value" :label="dict.label"
                             :value="dict.value"/>
                </el-select>
              </el-form-item>
            </el-col>

          </el-row>
        </el-form>

      </el-tab-pane>

      <el-tab-pane label="维护物料类别" name="third">
        <!-- <el-row style="margin-bottom: 12px;">
        <span>物料类别</span>
        </el-row> -->
        <el-row style="margin-bottom: 12px;">
          <el-button :disabled="disable" type="primary" :size="size" plain @click="addLine">新增</el-button>
          <el-button :disabled="disable" type="primary" :size="size" plain @click="handleDelete">删除</el-button>
          <!-- <el-button :disabled="disable || isControl" type="primary" size="small" plain @click="testsave">暂存</el-button> -->
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-table :data="sysMaterialMedcineItemApply" class="request-table"
                      @selection-change="handleSelectionChange">
              <el-table-column type="selection" width="55"/>
              <el-table-column label="ID" align="center" prop="sort">
                <template slot-scope="scope">
                  <el-input readonly v-model="scope.row.drugId">
                    <!-- <el-button :disabled="disable" slot="append" icon="el-icon-more" @click="chooseDrug"></el-button> -->
                  </el-input>
                </template>
              </el-table-column>
              <el-table-column label="药品类别编码" align="center" prop="medicineCode">
                <template slot-scope="scope">
                  <el-input readonly v-model="scope.row.drugCode"></el-input>
                </template>
              </el-table-column>
              <el-table-column label="药品类别名称" align="center" prop="medicineName">
                <template slot-scope="scope">
                  <el-input readonly v-model="scope.row.drugName"></el-input>
                </template>
              </el-table-column>
            </el-table>
          </el-col>
        </el-row>
      </el-tab-pane>

      <el-tab-pane label="单据信息" name="fourth">
        <el-form :model="basicForm" ref="info" label-width="160px">
          <el-row :gutter="10">
            <el-col :span="6">
              <el-form-item label="申请人" prop="createName">
                <el-input disabled v-model="basicForm.createName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="申请时间" prop="createTime">
                <el-input disabled v-model="basicForm.createTime"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="创建人" prop="createName">
                <el-input disabled v-model="basicForm.createName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="创建时间" prop="createTime">
                <el-input disabled v-model="basicForm.createTime"></el-input>
              </el-form-item>
            </el-col>
            
          </el-row>
          <el-row :gutter="10">
            
            <el-col :span="6">
              <el-form-item label="最后修改人" prop="updateName">
                <el-input disabled v-model="basicForm.updateName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="最后修改时间" prop="updateTime">
                <el-input disabled v-model="basicForm.updateTime"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="单据状态" prop="status">
                <el-select v-model="basicForm.status" size="small" disabled>
                  <el-option v-for="item in statusOptions" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
                <!-- <el-input disabled v-model="basicForm.status"></el-input> -->
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <!-- <el-col :span="6">
              <el-form-item label="最后审核人" prop="reviewedByName">
                <el-input disabled v-model="basicForm.reviewedByName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="最后审核时间" prop="approvalTime">
                <el-input disabled v-model="basicForm.approvalTime"></el-input>
              </el-form-item>
            </el-col> -->
           
          </el-row>
        </el-form>
      </el-tab-pane>
    </el-tabs>

    

    <factory ref="factory" @doSubmit="acceptFactory" :selectData="selectData2" :single="true"/>

    <fourClass ref="fourClass" @doSubmit="acceptFourClass" :selectData="selectData3" :single="true"/>

    <unit ref="unit" @doSubmit="acceptUnit" :selectData="selectData4" :single="true"/>

    <place ref="place" @doSubmit="acceptPlace" :selectData="selectData5" :single="true"/>

    <tax ref="tax" @doSubmit="acceptTax" :selectData="selectData6" :single="true"/>

    <staff ref="staff" @doSubmit="acceptStaff" :selectData="selectData7" :single="true"/>

    <serviceline ref="line" @doSubmit="acceptLine" :selectData="selectData8" :single="true"/>

    <dose ref="dose" @doSubmit="acceptDose" :selectData="selectData9" :single="true"/>

    <orgs ref="orgs" @doSubmit="acceptOrgs" :selectData="selectData10" :single="true"/>

    <depart ref="depart" @doSubmit="acceptDepart" :selectData="selectData11" :single="true"/>

    <drug ref="drug" @doSubmit="acceptDrug" :selectData="selectData12" :single="true"/>

    <midpack ref="midpack" @doSubmit="acceptMidpack" :selectData="selectData13" :single="true"/>

    <inner-packing-unit ref="innerPackingUnit" @doSubmit="acceptInnerPackingUnit" :selectData="selectData14"
                        :single="true"/>
  </div>
</template>

<script>
  import factory from '@/components/PopDialog/productFactory.vue'
  import fourClass from '@/components/PopDialog/fourClass.vue'
  import unit from '@/components/PopDialog/unit.vue'
  import innerPackingUnit from '@/components/PopDialog/innerPackingUnit.vue'
  // import innerPackingUnit from '@/components/PopDialog/InnerPackingUnit.vue'
  import place from '@/components/PopDialog/place.vue'
  import tax from '@/components/PopDialog/tax.vue'
  import staff from '@/components/PopDialog/staff.vue'
  import serviceline from '@/components/PopDialog/serviceline.vue'
  import dose from '@/components/PopDialog/dose.vue'
  // 公用一个树形(组织部门传值不同)
  import orgs from '@/components/PopDialog/organization.vue'
  import depart from '@/components/PopDialog/organization.vue'
  // 药品类别子别
  import drug from '@/components/PopDialog/drug.vue'

  import midpack from '@/components/PopDialog/midPack.vue'

  import {addReq, getReqDetail, editReq} from '@/api/requisition/basic'
  // 调用物料分类详情接口用于数据回显
  import {getDetail} from '@/api/classify/basic';
  // 生产厂商/代理人调用用于回显
  import {getProductFactory} from '@/api/changeApply/basic'
  // 计量单位,产地调用用于回显
  import {getUnit, getPlace, getTax, getStaff, getLine, getDose, getOrgs, getMidPack} from '@/api/requisition/basic'

  export default {
    name: 'requisition_add',
    dicts: ['sys_storage_condition', 'sys_conditions_carriage', 'sys_medicine', 'medical_instruments', 'curing_type', 'period_unit', 'expiry_date', 'abc_type'],
    components: {
      factory,
      fourClass,
      unit,
      place,
      tax,
      staff,
      serviceline,
      dose,
      orgs,
      depart,
      drug,
      midpack,
      innerPackingUnit
    },
    props: ['pageStu', 'row', 'disable'],
    model: {
      prop: 'isList',
      event: 'jugislist'
    },
    data() {
      return {
        size:'mini',
        testOptions: [],
        factoryOptions: [],
        unitOptions: [],
        innerPackingUnitOptions: [],
        placeOptions: [],
        taxOptions: [],
        staffOptions: [],
        lineOptions: [],
        doseOptions: [],
        organizationsOptions: [],
        departOptions: [],
        midPackOptions: [],
        tabValue: 'first',
        isControl: true,
        orgControl: true,
        isStock: false,
        isExp: false,
        isOneClass: false,
        basicForm: {
          billCode: '',
          orgName: '德荣集团',
          orgId: '',
          // 四级分类/物料分类
          classifyId: '',
          // 是否医药物料
          isMedicine: '2',
          // DI
          diCode: '',
          // 物料名称
          name: '',
          // 英文名称
          enName: '',
          commonName: '',
          specification: '',
          model: '',
          unitId: '',
          manufacturerId: '',
          registrant: '',
          originPlace: '',
          manufacturersMaterialName: '',
          manufacturersMaterialCode: '',
          classifyAbc: '',
          rateCode: '',
          isB2c: '2',
          assembly: '2',
          isInventoryStatus: '0',
          serialNoManager: '2',
          expiryDateManagerment: '0',
          nearOnsetManagerment: '0',
          usefulLife: '',
          expiryUnitId: '',
          usefulLifeUnitId: '',
          recentWarningPeriod: '',
          storageCondition: '',
          transportationCondition: '',
          materialRate: '',
          deliveryPeriod: '',
          minOrderQty: '',
          minPackQty: '',
          puPersonnelId: '',
          minBatchQty: '',
          length: '',
          height: '',
          width: '',
          boxPackaingQty: '',
          mediumPackageQty: '',
          packExplain: '',
          businessLine: '',
          proposerId: '',
          barCode: '',
          serviceLife: '',
          healthCode: '',
          oriMaterialCode: '',
          productionPermit: '',
          oneClass: '',
          twoClass: '',
          threeClass: '',
          // 新增默认采购组织
          purchasingOrganization: '',
          // 新增业务部门
          businessDepartment: '',
          isEnable: '0',
          importsManufacturer: '',
          serviceClass: '',
          innerPackingUnit: '',
          innerPackingQty: '',
          safeStock: '',
          mediumPackageUnitId: '',
          remark: '',
          // 物料申请单-单据信息
          applyBillInfo: {
            createByName: '',
            createTime: '',
            updateByName: '',
            updateTime: '',
            reviewedByName: '',
            auditTime: ''
          },
          // 单据信息字段
          status: ''
        },
        options: [{
          value: '0',
          label: '是'
        }, {
          value: '2',
          label: '否'
        }],
        statusOptions: [{
          value: '0', label: '未提交'
        }, {
          value: '1', label: '审批中'
        }, {
          value: '2', label: '已完成'
        }, {
          value: '3', label: '已驳回'
        },],
        basicRules: {
          classifyId: [{required: true, message: '请选择四级分类', trigger: 'change'}],
          name: [{required: true, message: '请输入物料名称', trigger: 'blur'}],
          specification: [{required: true, message: '请输入规格', trigger: 'blur'}],
          unitId: [{required: true, message: '请选择计量单位', trigger: 'change'}],
          manufacturerId: [{required: true, message: '请选择生产厂家/代理人', trigger: 'change'}],
          registrant: [{required: true, message: '请输入注册人/上市许可持有人', trigger: 'blur'}],
          originPlace: [{required: true, message: '请选择产地', trigger: 'change'}],
          storageCondition: [{required: true, message: '请选择存储条件', trigger: 'change'}],
          materialRate: [{required: true, message: '请选择物料税类', trigger: 'change'}],
          deliveryPeriod: [{required: true, message: '请输入交货周期', trigger: 'blur'}],
          minOrderQty: [{required: true, message: '请输入最小起定量', trigger: 'blur'}],
          minPackQty: [{required: true, message: '请输入最小包装量', trigger: 'blur'}],
          puPersonnelId: [{required: true, message: '请选择采购员', trigger: 'change'}],
          minBatchQty: [{required: true, message: '请输入最小批量', trigger: 'blur'}],
          packExplain: [{required: true, message: '请输入包装说明', trigger: 'blur'}],
          purchasingOrganization: [{required: true, message: '请选择默认采购组织', trigger: 'change'}],
          // businessDepartment: [{required: true, message: '请选择业务部门', trigger: 'change'}],
        },
        basicForm2: {
          // 是否药品
          isDrug: '',
          registrationNo: '',
          medicalInstruments: '',
          commonName: '',
          ratifyBatchNo: '',
          dosageFrom: '',
          oriRegistrationNo: '',
          curingType: '',
          // 医药属性子表
          // medicineTypeChanges:[
          // ],
        },
        // 医药属性子表
        sysMaterialMedcineItemApply: [],

        // tableList: [],
        // 子表选中
        ids: [],
        // 弹窗
        name: '',
        selectData: [],
        selectData2: [],
        selectData3: [],
        selectData4: [],
        selectData5: [],
        selectData6: [],
        selectData7: [],
        selectData8: [],
        selectData9: [],
        selectData10: [],
        selectData11: [],
        selectData12: [],
        selectData13: [],
        selectData14: []
      }
    },
    // watch: {
    //   value: {
    //     handler (newVal) {
    //       this.selectData = []
    //       if (newVal) {
    //         newVal.split(',').forEach((id) => { // 回显拿数据
    //           this.contractService.queryById(id).then(({data}) => {
    //             if (data && data.id !== '') {
    //               this.selectData.push(data)
    //             }
    //           })
    //         })
    //       }
    //     },
    //     immediate: true,
    //     deep: false
    //   },
    //   selectData: {
    //     handler (newVal) {
    //       this.name = newVal.map(contract => contract.contractName).join(',')
    //     },
    //     immediate: false,
    //     deep: false
    //   }
    // },
    mounted() {
      console.log('页面状态', this.pageStu)
      if (this.pageStu == 'check') {
        // alert('详情页面:')
        console.log('页面状态', this.pageStu)
        console.log('数据', this.row)
        console.log('取VUEX里面的数据：', this.$store.state.user.name)
        this.getDetails(this.row)
        // 控制效期单位后面的是否可填写
        if (this.row.expiryDateManagerment == '0') {
          this.isExp = false
        } else {
          this.isExp = true
        }
        // 生产厂家代理人用于回显
        if (this.row.manufacturerId) {
          this.getFactoryDetails(this.row.manufacturerId)
        }
        // 计量单位回显
        if (this.row.unitId) {
          this.getUnitDetails(this.row.unitId)
        }
        // 产地回显
        if (this.row.originPlace) {
          this.getPlaceDetails(this.row.originPlace)
        }
        // 物料税类回显
        if (this.row.materialRate) {
          this.getTaxDetails(this.row.materialRate)
        }
        // 物料税类回显
        if (this.row.puPersonnelId) {
          this.getStaffDetails(this.row.puPersonnelId)
        }
        // 业务线回显
        if (this.row.businessLine) {
          this.getLineDetails(this.row.businessLine)
        }
        // 中包装单位回显
        if (this.row.mediumPackageUnitId) {
          this.getMidPackDetails(this.row.mediumPackageUnitId)
        }
        // 内包装单位回显
        if (this.row.innerPackingUnit) {
          this.getInnerPackingUnitDetails(this.row.innerPackingUnit)
        }
      } else if (this.pageStu == 'edit') {
        // alert('修改页面')
        console.log('页面状态', this.pageStu)
        console.log('数据', this.row)
        this.getDetails(this.row)
        console.log('修改页面-批号库存管理状态', this.row.isInventoryStatus)
        this.stockControl(this.row.isInventoryStatus)
        // 控制效期单位后面的是否可填写
        if (this.row.expiryDateManagerment == '0') {
          this.isExp = false
        } else {
          this.isExp = true
        }
        // 控制业务部门是否能够填写
        if (this.row.purchasingOrganization) {
          this.orgControl = false
        } else {
          this.orgControl = true
        }
        // 控制医药属性是否能够填写
        if (this.row.isMedicine == '0') {
          this.isControl = false
        } else {
          this.isControl = true
        }
        // 生产厂家代理人用于回显
        if (this.row.manufacturerId) {
          this.getFactoryDetails(this.row.manufacturerId)
        }
        // 计量单位回显
        if (this.row.unitId) {
          this.getUnitDetails(this.row.unitId)
        }
        // 产地回显
        if (this.row.originPlace) {
          this.getPlaceDetails(this.row.originPlace)
        }
        // 物料税类回显
        if (this.row.materialRate) {
          this.getTaxDetails(this.row.materialRate)
        }
        // 物料税类回显
        if (this.row.puPersonnelId) {
          this.getStaffDetails(this.row.puPersonnelId)
        }
        // 业务线回显
        if (this.row.businessLine) {
          this.getLineDetails(this.row.businessLine)
        }
        // 中包装单位回显
        if (this.row.mediumPackageUnitId) {
          this.getMidPackDetails(this.row.mediumPackageUnitId)
        }
        // 内包装单位回显
        if (this.row.innerPackingUnit) {
          this.getInnerPackingUnitDetails(this.row.innerPackingUnit)
        }
      } else if (this.pageStu == 'add') {
        // alert('新增页面')
        console.log('页面状态', this.pageStu)
      } else if (this.pageStu === 'copy') {
        this.getDetails(this.row)
        // 控制效期单位后面的是否可填写
        if (this.row.expiryDateManagerment == '0') {
          this.isExp = false
        } else {
          this.isExp = true
        }
        // 控制业务部门是否能够填写
        if (this.row.purchasingOrganization) {
          this.orgControl = false
        } else {
          this.orgControl = true
        }
        // 控制医药属性是否能够填写
        if (this.row.isMedicine == '0') {
          this.isControl = false
        } else {
          this.isControl = true
        }
        // 生产厂家代理人用于回显
        if (this.row.manufacturerId) {
          this.getFactoryDetails(this.row.manufacturerId)
        }
        // 计量单位回显
        if (this.row.unitId) {
          this.getUnitDetails(this.row.unitId)
        }
        // 产地回显
        if (this.row.originPlace) {
          this.getPlaceDetails(this.row.originPlace)
        }
        // 物料税类回显
        if (this.row.materialRate) {
          this.getTaxDetails(this.row.materialRate)
        }
        // 物料税类回显
        if (this.row.puPersonnelId) {
          this.getStaffDetails(this.row.puPersonnelId)
        }
        // 业务线回显
        if (this.row.businessLine) {
          this.getLineDetails(this.row.businessLine)
        }
        // 中包装单位回显
        if (this.row.mediumPackageUnitId) {
          this.getMidPackDetails(this.row.mediumPackageUnitId)
        }
        // 内包装单位回显
        if (this.row.innerPackingUnit) {
          this.getInnerPackingUnitDetails(this.row.innerPackingUnit)
        }
      }
    },
    methods: {
      handleClick(tab, event) {
        console.log(tab, event);
        console.log('页面状态', this.pageStu)
      },
      // 批号及库存状态管理控制效期管理
      stockControl(val) {
        if (val == 0) {
          this.isStock = false
        } else {
          // 联动效期管理
          this.basicForm.expiryDateManagerment = '2';
          this.basicForm.serialNoManager = '2';
          this.expCt(val)
          this.isStock = true
        }
      },
      // 选择效期管理控制后面字段是否可填写
      expCt(val) {
        console.log('效期管理值:', val)
        if (val == 0) {
          this.isExp = false
        } else {
          this.basicForm.usefulLife = ''
          this.basicForm.expiryUnitId = ''
          this.basicForm.usefulLifeUnitId = ''
          this.basicForm.recentWarningPeriod = ''
          this.isExp = true
        }
      },
      // 选择采购组织时控制业务部门
      controlOrg(val) {
        this.basicForm.businessDepartment = ''
        this.orgControl = true
      },
      // 选择是否医药物料时控制医药属性
      controlMedic(val) {
        console.log('val1111111', val)
        if (val == '0') {
          this.isControl = false
          this.basicForm2.dosageFrom = '0001A11000000000BX7Z'
          this.getDoseDetails(this.basicForm2.dosageFrom)
        } else {
          this.basicForm2.isDrug = ''
          this.basicForm2.registrationNo = ''
          this.basicForm2.medicalInstruments = ''
          this.basicForm2.commonName = ''
          this.basicForm2.ratifyBatchNo = ''
          this.basicForm2.dosageFrom = ''
          this.basicForm2.oriRegistrationNo = ''
          this.basicForm2.curingType = ''
          this.isControl = true
        }
      },
      // 用于回显四级分类树形选择
      getTreeDetails(id) {
        getDetail(id).then(res => {
          if (res.code === 200) {
            this.testOptions.push(res.data)
            this.basicForm.oneClass = res.data.oneClass
            this.basicForm.twoClass = res.data.twoClass
            this.basicForm.threeClass = res.data.threeClass
            const classjudge = res.data.oneClass
            if (classjudge.includes('介入耗材&5') || classjudge.includes('骨科耗材&2') || classjudge.includes('普通耗材&3') || classjudge.includes('医用设备&1') || classjudge.includes('体外诊断&4')) {
              this.isOneClass = true
            } else {
              this.isOneClass = false
            }
          }
        })
      },
      // 生产厂家/代理人用于回显
      getFactoryDetails(id) {
        getProductFactory({id: id}).then(res => {
          if (res.code === 200) {
            this.factoryOptions = res.data.tableBody
          }
        })
      },
      // 计量单位回显
      getUnitDetails(id) {
        getUnit({id: id}).then(res => {
          console.log('计量单位回显', res)
          if (res.code === 200) {
            this.unitOptions = res.data.tableBody
            console.log('1111', this.unitOptions)
          }
        })
      },
      // 产地回显
      getPlaceDetails(id) {
        getPlace({id: id}).then(res => {
          console.log('产地', res)
          if (res.code === 200) {
            this.placeOptions = res.data.tableBody
          }
        })
      },
      // 物料税类回显
      getTaxDetails(id) {
        getTax({id: id}).then(res => {
          console.log('物料税类', res)
          if (res.code === 200) {
            this.taxOptions = res.data.tableBody
          }
        })
      },
      // 采购员回显
      getStaffDetails(id) {
        getStaff({id: id}).then(res => {
          console.log('采购员', res)
          if (res.code === 200) {
            this.staffOptions = res.data.tableBody
          }
        })
      },
      // 业务线回显
      getLineDetails(id) {
        getLine({id: id}).then(res => {
          console.log('业务线', res)
          if (res.code === 200) {
            this.lineOptions = res.data.tableBody
          }
        })
      },
      // 剂型回显
      getDoseDetails(id) {
        getDose({id: id}).then(res => {
          console.log('剂型', res)
          if (res.code === 200) {
            this.doseOptions = res.data.tableBody
          }
        })
      },
      // 采购组织回显
      getOrgDetails(id) {
        getOrgs({deptId: id}).then(res => {
          if (res.code === 200) {
            this.organizationsOptions = res.data
          }
        })
      },
      // 业务部门回显
      getDepartDetails(id) {
        getOrgs({deptId: id}).then(res => {
          if (res.code === 200) {
            this.departOptions = res.data
          }
        })
      },
      // 中包装单位回显
      getMidPackDetails(id) {
        getMidPack({id: id}).then(res => {
          if (res.code === 200) {
            this.midPackOptions = res.data.tableBody
          }
        })
      },
      // 如果是详情进入，则调用详情接口
      getDetails(row) {
        getReqDetail(row.id).then(res => {
          console.log('res', res)
          if (res.code === 200) {

            this.basicForm = res.data;

            if (this.pageStu === 'copy') {

              this.basicForm.id = '';

              this.basicForm.billCode = '';

              this.basicForm.diCode = '';

              this.basicForm.healthCode = '';

              this.basicForm.status = '0';

              this.basicForm.sysMaterialMedcineApply.id = '';

              this.basicForm.sysMaterialMedcineItemApply.length &&

              this.basicForm.sysMaterialMedcineItemApply.forEach(item => (item.id = ''));

              this.basicForm.createName = '';

              this.basicForm.createTime = '';

              this.basicForm.updateName = '';

              this.basicForm.updateTime = '';


            }

            // 获取树形详情
            if (res.data.classifyId) {
              this.getTreeDetails(res.data.classifyId)
            }
            if (res.data.purchasingOrganization) {
              this.basicForm.purchasingOrganization = res.data.purchasingOrganization
              this.getOrgDetails(res.data.purchasingOrganization)
            }
            if (res.data.businessDepartment) {
              this.basicForm.businessDepartment = res.data.businessDepartment
              this.getDepartDetails(res.data.businessDepartment)
            }
            if (res.data.unitId) {
              this.basicForm.unitId = res.data.unitId
            }
            if (res.data.manufacturerId) {
              this.basicForm.manufacturerId = res.data.manufacturerId.toString()
            }
            if (res.data.usefulLifeUnitId) {
              this.basicForm.usefulLifeUnitId = res.data.usefulLifeUnitId.toString()
            }
            if (res.data.expiryUnitId) {
              this.basicForm.expiryUnitId = res.data.expiryUnitId.toString()
            }
            if (res.data.sysMaterialMedcineApply) {
              this.basicForm2 = res.data.sysMaterialMedcineApply
            }
            // 剂型回显
            if (res.data.sysMaterialMedcineApply && res.data.sysMaterialMedcineApply.dosageFrom) {
              this.getDoseDetails(res.data.sysMaterialMedcineApply.dosageFrom)
            }
            // 物料类别回显
            if (res.data.sysMaterialMedcineItemApply) {
              this.sysMaterialMedcineItemApply = res.data.sysMaterialMedcineItemApply
            }
          }
        })
      },
      save() {
        // let sparams = { ...this.basicForm, ...{ status: 0 } }
        // console.log(sparams, 'sparams');
        if (this.pageStu == 'edit') {
          if (!this.basicForm.proposerId) {
            this.basicForm.proposerId = this.$store.state.user.name
          }
          let sparams = {...this.basicForm, ...{status: 0}}
          sparams.sysMaterialMedcineApply = this.basicForm2
          sparams.sysMaterialMedcineItemApply = this.sysMaterialMedcineItemApply
          console.log('提交参数', sparams)

          const form1 = new Promise((resolve, reject) => {
            this.$refs['basic'].validate(valid => {
              if (valid) resolve()
            })
          })
          const form2 = new Promise((resolve, reject) => {
            this.$refs['basic2'].validate(valid => {
              if (valid) resolve()
            })
          })

          Promise.all([form1, form2]).then(() => {
            if (this.basicForm.isMedicine == '0' && this.sysMaterialMedcineItemApply.length == 0) {
              this.$modal.notifyWarning("医药物料需要维护物料类别!");

            } else {
              this.$modal.loading("保存中...");
              editReq(sparams).then(res => {
                if (res.code === 200) {
                  this.$message({
                    message: res.msg,
                    type: 'success'
                  });
                  this.$modal.closeLoading();
                  this.back()
                }
              }).catch(err => {
                this.$modal.closeLoading();
              })
            }
          })
        } else {

          // alert('保存传status：0')
          if (!this.basicForm.proposerId) {
            this.basicForm.proposerId = this.$store.state.user.name
          }
          let sparams = {...this.basicForm, ...{status: 0}};

          sparams.sysMaterialMedcineApply = this.basicForm2;

          sparams.sysMaterialMedcineItemApply = this.sysMaterialMedcineItemApply;

          console.log('保存参数', sparams)
          const form1 = new Promise((resolve, reject) => {
            this.$refs['basic'].validate(valid => {
              if (valid) resolve()
            })
          })
          const form2 = new Promise((resolve, reject) => {
            this.$refs['basic2'].validate(valid => {
              if (valid) resolve()
            })
          })
          Promise.all([form1, form2]).then(() => {
            if (this.basicForm.isMedicine == '0' && this.sysMaterialMedcineItemApply.length == 0) {
              this.$modal.notifyWarning("医药物料需要维护物料类别!");
            } else {
              this.$modal.loading("保存中...");
              addReq(sparams).then(res => {
                if (res.code === 200) {
                  this.$message({
                    message: res.msg,
                    type: 'success'
                  });
                  this.$modal.closeLoading();
                  this.back()
                }
              }).catch(err => {
                this.$modal.closeLoading();
              })
            }
          })
        }
      },
      submit() {
        // alert('提交传status：1')
        if (!this.basicForm.proposerId) {
          this.basicForm.proposerId = this.$store.state.user.name
        }
        let sparams = {...this.basicForm, ...{status: 1}}
        sparams.sysMaterialMedcineApply = this.basicForm2
        sparams.sysMaterialMedcineItemApply = this.sysMaterialMedcineItemApply
        console.log('提交参数', sparams)
        const form1 = new Promise((resolve, reject) => {
          this.$refs['basic'].validate(valid => {
            if (valid) resolve()
          })
        })
        const form2 = new Promise((resolve, reject) => {
          this.$refs['basic2'].validate(valid => {
            if (valid) resolve()
          })
        })
        Promise.all([form1, form2]).then(() => {
          // 提交时候要维护物料类别
          if (this.sysMaterialMedcineItemApply.length !== 0) {
            this.$modal.loading("提交中...");
            editReq(sparams).then(res => {
              if (res.code === 200) {
                this.$message({
                  message: res.msg,
                  type: 'success'
                });
                this.$modal.closeLoading();
                this.back()
              }
            }).catch(err => {
              this.$modal.closeLoading();
            })
          } else {
            this.$message({
              message: '请维护物料类别后再提交',
              type: 'warning'
            });
          }
        })
      },
      back() {
        this.$emit('jugislist', true)
        // let queryParams = {
        //   pageNum: 1,
        //   pageSize: 10
        // }
        this.$emit('refresh')
      },
      // 子表增删行
      handleSelectionChange(val) {
        this.ids = val
        console.log('this.ids', this.ids)
      },
      addLine() {
        //添加行数
        // let newValue = {
        //   drugId:'',
        //   drugCode: '',
        //   drugName: '',
        // };
        // this.sysMaterialMedcineItemApply.push(newValue);
        this.chooseDrug()
      },
      handleDelete(index) {
        if (this.ids.length == 0) {
          this.$message({
            message: '请选择删除条目',
            type: 'warning'
          });
        } else {
          // console.log('index',index)
          // this.basicForm2.medicineTypeChanges.splice(index, 1);
          this.sysMaterialMedcineItemApply = this.sysMaterialMedcineItemApply.filter(item =>
            !this.ids.some(ele =>
              ele.drugId == item.drugId))
        }
      },
      testsave() {
        console.log('暂存表格：', this.sysMaterialMedcineItemApply)
        console.log('暂存表单1', this.basicForm)
        let params = {...this.basicForm}
        params.sysMaterialMedcineApply = this.basicForm2
        params.sysMaterialMedcineItemApply = this.sysMaterialMedcineItemApply
        console.log('暂存总表单', params)
      },

      // 选择生产厂家/代理人
      acceptFactory(selections) {
        console.log('选择的数据', selections)
        this.factoryOptions = selections
        this.basicForm.manufacturerId = selections[0].id
        this.getFactoryDetails(selections[0].id)
      },
      // 生产厂家/代理人显示列表
      chooseFactory() {
        this.$refs.factoryOrman.blur()
        this.$refs.factory.init()
      },
      // 选择四级分类
      acceptFourClass(selections) {
        console.log('父组件收到的数据', selections)
        this.testOptions.push(selections)
        console.log('收到的数据转成数组', this.testOptions)
        this.basicForm.classifyId = selections.id
        this.getTreeDetails(selections.id)
      },
      // 四级分类显示列表
      chooseFourClass() {
        this.$refs.fourTag.blur()
        this.$refs.fourClass.init(this.basicForm.classifyId)
      },
      // 选择计量单位
      acceptUnit(selections) {
        console.log('父组件收到的数据', selections)
        this.unitOptions = selections
        console.log('绑定的数组', this.unitOptions)
        this.basicForm.unitId = selections[0].id
        this.getUnitDetails(selections[0].id)
      },
      // 计量单位显示列表
      chooseUnit() {
        this.$refs.units.blur()
        this.$refs.unit.init()
      },
      // 选择产地
      acceptPlace(selections) {
        this.placeOptions = selections
        this.basicForm.originPlace = selections[0].id
        this.getPlaceDetails(selections[0].id)
      },
      // 产地显示列表
      choosePlace() {
        this.$refs.places.blur()
        this.$refs.place.init()
      },
      // 选择物料税类
      acceptTax(selections) {
        this.taxOptions = selections
        this.basicForm.materialRate = selections[0].id
        this.basicForm.rateCode = selections[0].code
        this.getTaxDetails(selections[0].id)
      },
      // 物料税类显示列表
      chooseTax() {
        this.$refs.taxs.blur()
        this.$refs.tax.init()
      },
      // 选择采购员
      acceptStaff(selections) {
        this.staffOptions = selections
        this.basicForm.puPersonnelId = selections[0].code
        this.getStaffDetails(selections[0].id)
      },
      // 采购员显示列表
      chooseStaff() {
        this.$refs.staffs.blur()
        this.$refs.staff.init()
      },
      // 选择业务线
      acceptLine(selections) {
        this.lineOptions = selections
        this.basicForm.businessLine = selections[0].id
        this.getLineDetails(selections[0].id)
      },
      // 业务线显示列表
      chooseLine() {
        this.$refs.lines.blur()
        this.$refs.line.init()
      },
      // 选择剂型-树形
      acceptDose(selections) {
        this.doseOptions.push(selections)
        this.basicForm2.dosageFrom = selections.id
        this.getDoseDetails(selections.id)
      },
      // 剂型显示列表
      chooseDose() {
        this.$refs.doses.blur()
        this.$refs.dose.init()
      },
      // 选择默认采购组织
      acceptOrgs(selections) {
        console.log('接收的采购组织', selections)
        this.basicForm.purchasingOrganization = selections.id;
        // 控制业务部门是否可以选择
        this.orgControl = false
        this.getOrgDetails(selections.id)
        this.basicForm.businessDepartment = '';
        this.departOptions = [];
      },
      // 默认采购组织显示列表
      chooseOrganizations() {
        this.$refs.organizations.blur()
        this.$refs.orgs.init('1')
      },
      // 选择业务部门
      acceptDepart(selections) {
        console.log('接收的业务部门', selections)
        this.basicForm.businessDepartment = selections.id
        this.getDepartDetails(selections.id)
      },
      // 业务部门显示列表
      chooseDepart() {
        this.$refs.departs.blur()
        this.$refs.depart.init('0', this.basicForm.purchasingOrganization)
      },
      // 选择医药类别
      acceptDrug(selections) {
        console.log('接收的物料类别', selections)
        const sleObj = {}
        sleObj.drugId = selections.id
        sleObj.drugCode = selections.code
        sleObj.drugName = selections.name
        // 便利表格内数据
        if (this.sysMaterialMedcineItemApply.some(item => item.drugId == sleObj.drugId)) {
          this.$modal.msgWarning("请勿选择重复物料")
        } else {
          this.sysMaterialMedcineItemApply.push(sleObj)
        }
      },
      // 医药类别子表的显示列表
      chooseDrug() {
        this.$refs.drug.init()
      },
      // 选择中包装单位
      acceptMidpack(selections) {
        console.log('接收到的中包装单位', selections)
        this.midPackOptions = selections
        console.log('绑定的数组', this.midPackOptions)
        this.basicForm.mediumPackageUnitId = selections[0].id
        this.getMidPackDetails(selections[0].id)
      },
      // 中包装单位显示列表
      chooseMidpack() {
        this.$refs.midpacks.blur()
        this.$refs.midpack.init()
      },

      // 内包装单位显示列表
      chooseInnerPackingUnit() {
        this.$refs.innerPackingUnits.blur()
        this.$refs.innerPackingUnit.init()
      },

      // 选择内包装单位
      acceptInnerPackingUnit(selections) {
        this.innerPackingUnitOptions = selections
        this.basicForm.innerPackingUnit = selections[0].id
        this.getInnerPackingUnitDetails(selections[0].id)
      },

      //内包装单位回显
      getInnerPackingUnitDetails(id) {
        getUnit({id: id}).then(res => {
          console.log('内包装单位回显', res)
          if (res.code === 200) {
            this.innerPackingUnitOptions = res.data.tableBody
            console.log('1111', this.innerPackingUnitOptions)
          }
        })
      },

    }
  }
</script>

<style lang="scss" scoped>
  .requisition_add {
    // height: calc(100vh - 84px);
    padding: 12px;
    box-sizing: border-box;
    overflow-y: auto;
  }

  .btn_group {
    width: 100%;
    margin: 20px 0;
    display: flex;
    justify-content: center;
  }
</style>
