<!-- 新增、修改临时计划 -->
<template>
    <div class="examination">
      <el-dialog @close="closeDialog" :visible.sync="dialogTableVisible" width='70%'>
        <div slot="title" class="titleBox">
        <i :class="tableType === 0? 'el-icon-document':'el-icon-edit-outline'" style="font-size: 20px"></i>
        <!-- <img style="width: 25px; height: 25px" src='../../../../assets/img/imgScreen/more.png' /> -->
        <span style="margin-left:10px;font-size:18px">{{tableTypeDsc}}</span>
        </div>
        <el-form ref="baseData" label-width="90px" :rules="rules" :model="baseData">
          <el-row>
          <el-col :span="6">
            <el-form-item prop='matClassNo' label="物料分类">
              <el-select v-model="baseData.matClassNo" @change="selctMatName" clearable style="width:100%" filterable collapse-tags size="small" >
                <el-option v-for="(item,index) in matClassNameType" :key="index" :label="item.matClassName"
                  :value="item.matClassNo">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="planCompanyNo" label="委托单位">
              <el-select v-model="baseData.planCompanyNo" clearable filterable style="width:100%" collapse-tags  size="small">
                <el-option v-for="item in entrOrgNameType" :key="item.orgCode" :label="item.orgName" :value="item.orgCode">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
           <el-col :span="6">
             <el-form-item label="检验单位" prop="companyNo">
              <el-select v-model="baseData.companyNo" clearable filterable style="width:100%" collapse-tags @change="selectDepartment(baseData.companyNo,1)" size="small">
                <el-option v-for="item in companyNameType" :key="item.orgCode" :label="item.orgName" :value="item.orgCode">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="cnsnContactMan" label="是否检验">
              <el-select v-model="baseData.cnsnContactMan" clearable filterable style="width:100%" collapse-tags  size="small" @change="valChange">
                <el-option v-for="item in cnsnContactManType" :key="item.id" :label="item.cnsnContactManName" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

         </el-row>
         <el-row>
          <el-col :span="6">
            <el-form-item prop="matNo" label="物料名称">
              <el-select v-model="baseData.matNo" clearable  style="width:100%" filterable collapse-tags size="small" >
                <el-option v-for="(item,index) in matNameType" :key="index" :label="item.matName"
                  :value="item.matNo">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="entrTypeCode" label="委托类型">
              <el-select v-model="baseData.entrTypeCode"  clearable filterable style="width:100%" collapse-tags size="small">
                <el-option v-for="(item,index) in entrTypeNameType" :key="index" :label="item.baseName" :value="item.baseCode">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
           <el-col :span="6">
           <el-form-item prop="deptNo" label="检验车间">
              <el-select v-model="baseData.deptNo" filterable clearable style="width:100%" @change="selectClass" collapse-tags size="small" >
                <el-option v-for="item in sectionNameType" :key="item.orgCode" :label="item.orgName" :value="item.orgCode">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
           <el-col :span="6">
            <el-form-item label="是否商检">
              <el-select v-model="baseData.isCiq" clearable filterable style="width:100%" collapse-tags  size="small">
                <el-option v-for="item in CiqType" :key="item.id" :label="item.CiqName" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
         </el-row>
          <el-row>
          <el-col :span="6">
             <el-form-item prop="gradeNo" label="牌号/等级">
              <el-select v-model="baseData.gradeNo" filterable collapse-tags size="small">
                 <el-option v-for="(item,index) in gradeType" :key="index" :label="item.gradeName" :value="item.gradeNo">
                 </el-option>
               </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
          <el-form-item prop='sampleTypeCode' label="样品类型">
              <el-select v-model="baseData.sampleTypeCode" clearable style="width:100%" filterable collapse-tags size="small" >
                <el-option v-for="(item,index) in sampleTypeNameType" :key="index" :label="item.baseName"
                  :value="item.baseCode">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="sectionNo" label="检验班组">
              <el-select
                v-model="baseData.sectionNo"
                filterable
                clearable
                style="width: 100%"
                collapse-tags
                size="small"
              >
                <el-option
                  v-for="item in sectionClass"
                  :key="item.orgCode"
                  :label="item.orgName"
                  :value="item.orgCode"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
            <el-col :span="6">
            <el-form-item label="是否配批">
              <el-select v-model="baseData.isBatch" clearable filterable style="width:100%" collapse-tags  size="small">
                <el-option v-for="item in BatchType" :key="item.id" :label="item.BatchName" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          </el-row>
          <el-row>
          <el-col :span="6">
            <el-form-item prop='suppName' label='供应单位'>
                <el-select v-model="baseData.suppName" clearable filterable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="(item,index) in suppNameType" :key="index" :label="item.customerSupplierName"
                    :value="item.customerSupplierName">
                  </el-option>
                </el-select>
              </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item prop='testTypeCode' label="检验类型">
              <el-select v-model="baseData.testTypeCode" clearable style="width:100%" filterable collapse-tags size="small">
                <el-option v-for="(item,index) in testTypeNameType" :key="index" :label="item.baseName" :value="item.baseCode">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
           <el-col :span="6">
             <el-form-item prop="smpCompanyNo" label="取样单位">
                <el-select v-model="baseData.smpCompanyNo"  filterable style="width:100%" collapse-tags @change="selectDepartment2" size="small">
                  <el-option v-for="item in companyNameType2" :key="item.orgCode" :label="item.orgName" :value="item.orgCode">
                  </el-option>
                </el-select>
              </el-form-item>
          </el-col>
           <el-col :span="6">
            <el-form-item label="是否取样">
              <el-select v-model="baseData.isSmp" clearable filterable style="width:100%" collapse-tags  size="small">
                <el-option v-for="item in isSmpType" :key="item.id" :label="item.isSmp" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
         </el-row>
          <el-row>
           <el-col :span="6">
            <el-form-item prop='acceptName' label='收货单位'>
               <!-- <el-select v-model="baseData.acceptName" clearable filterable style="width:100%" collapse-tags  size="small">
                <el-option v-for="item in entrOrgNameType" :key="item.orgCode" :label="item.orgName" :value="item.orgName">
                </el-option>
              </el-select> -->
                <el-select v-model="baseData.acceptName" filterable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="(item,index) in acceptNameType" :key="index" :label="item.customerSupplierName"
                    :value="item.customerSupplierName">
                  </el-option>
                </el-select>
              </el-form-item>
          </el-col>
           <el-col :span="6">
            <el-form-item prop='matShapeName' label='试样形状'>
                <el-select v-model="baseData.matShapeName" clearable filterable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="(item,index) in matShapeNameType" :key="index" :label="item.baseName"
                    :value="item.baseCode">
                  </el-option>
                </el-select>
              </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="smpDeptNo" label="取样车间">
                <el-select v-model="baseData.smpDeptNo" clearable filterable style="width:100%" @change="selectClass2" collapse-tags size="small" >
                  <el-option v-for="item in sectionNameType2" :key="item.orgCode" :label="item.orgName" :value="item.orgCode">
                  </el-option>
                </el-select>
              </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="isCheck" label="是否加权">
              <el-select v-model="baseData.isCheck" clearable filterable style="width:100%" collapse-tags  size="small">
                <el-option v-for="item in isCheckType" :key="item.id" :label="item.isCheck" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
         </el-row>
         <el-row>
           <el-col :span="6">
            <el-form-item prop="cnsnOrgName" label="业务类型">
              <el-select
                v-model="baseData.cnsnOrgName" clearable filterable collapse-tags size="small" style="width: 100%">
                <el-option v-for="(item, index) in meterTypeNameItem" :key="index" :label="item.baseName"
                  :value="item.baseName"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
           <el-col :span="6">
            <el-form-item prop='transportTypeName' label='运输类型'>
                <el-select v-model="baseData.transportTypeName" clearable filterable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="(item,index) in transportTypeNameType" :key="index" :label="item.baseName"
                    :value="item.baseCode">
                  </el-option>
                </el-select>
              </el-form-item>
          </el-col>
           <el-col :span="6">
             <el-form-item  prop="smpSectionNo" label="取样班组">
                <el-select v-model="baseData.smpSectionNo" clearable style="width:100%" collapse-tags size="small">
                  <el-option v-for="item in sectionClass2" :key="item.orgCode" :label="item.orgName" :value="item.orgCode">
                  </el-option>
                </el-select>
              </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="是否计量" >
              <el-select v-model="baseData.isMater" clearable filterable style="width:100%" collapse-tags @change="addrules($event)"  size="small">
                <el-option v-for="item in isMaterType" :key="item.id" :label="item.isMater" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
         </el-row>
         <el-row>
          <el-col :span="6">
            <el-form-item prop='smpDeliCode' label='取样频次'>
                <el-select v-model="baseData.smpDeliCode" clearable filterable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="(item,index) in smpDeliNameType" :key="index" :label="item.baseName"
                    :value="item.baseCode">
                  </el-option>
                </el-select>
              </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item prop='packTypeCode' label='包装类型'>
               <el-select v-model="baseData.packTypeCode" clearable filterable style="width:100%" collapse-tags  size="small">
                <el-option v-for="item in packType" :key="item.baseCode" :label="item.baseName" :value="item.baseCode">
                </el-option>
              </el-select>
                <!-- <el-select v-model="baseData.acceptNo" filterable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="(item,index) in acceptNameType" :key="index" :label="item.acceptName"
                    :value="item.acceptNo">
                  </el-option>
                </el-select> -->
              </el-form-item>
          </el-col>
          <el-col :span='6'>
            <el-form-item prop='pointName' label='取样地点'>
                <el-select v-model="baseData.pointName" clearable filterable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="(item,index) in pointNameType" :key="index" :label="item.pointName"
                    :value="item.pointName">
                  </el-option>
                </el-select>
              </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item prop='isPrep' label='是否组合'>
              <el-select v-model="baseData.isPrep" clearable filterable style="width:100%" collapse-tags  size="small">
                <el-option v-for="item in isPrepType" :key="item.id" :label="item.isPrep" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

         </el-row>
         <el-row>
           <el-col :span='6'>
              <el-form-item prop="planCompanyNo" label="计划单位">
                <el-select v-model="baseData.planCompanyNo" filterable style="width:100%" collapse-tags @change="selectDepartment" size="small">
                  <el-option v-for="item in companyNameType" :key="item.orgCode" :label="item.orgName" :value="item.orgCode">
                  </el-option>
                </el-select>
              </el-form-item>
          </el-col>
           <el-col :span="6">
            <el-form-item prop="planDate" label="计划时间">
              <el-date-picker v-model="baseData.planDate" clearable type="datetime" style="width:100%" placeholder="选择时间" size="small" ></el-date-picker>
            </el-form-item>
          </el-col>
            <!-- <el-col :span="6">
            <el-form-item prop="carNo" label="分析时限(h)">
              <el-input v-model="baseData.carNo" clearable style="width:100%" size="small"></el-input>
            </el-form-item>
          </el-col> -->
          <el-col :span='6'>
            <el-form-item label="发货地点">
                <el-input v-model="baseData.sendPlace" clearable style="width:100%" size="small"></el-input>
              </el-form-item>
          </el-col>
          <el-col :span="6">
             <el-form-item prop="sampleWgt" label="样品重量">
              <el-input v-model="baseData.sampleWgt" clearable style="width:100%" size="small"></el-input>
            </el-form-item>
           </el-col>
          <!-- <el-col :span="6">
            <el-form-item prop="testCost" label="检测费用">
              <el-input v-model="baseData.testCost" clearable style="width:100%" size="small"></el-input>
            </el-form-item>
          </el-col> -->

        </el-row>
        <el-row>
         <el-col :span='6'>
             <el-form-item prop="planDeptNo" label="计划车间">
               <el-select v-model="baseData.planDeptNo" filterable style="width:100%" collapse-tags size="small" >
                <el-option v-for="item in sectionNameType" :key="item.orgCode" :label="item.orgName" :value="item.orgCode">
                </el-option>
               </el-select>
             </el-form-item>
            </el-col>
         <el-col :span="6">
            <el-form-item prop="spec" label="规格">
              <el-input v-model="baseData.spec" clearable style="width:100%" size="small"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item prop='unloadPlace' label="卸货地点">
              <el-input v-model="baseData.unloadPlace" clearable style="width:100%" size="small"></el-input>
            </el-form-item>
           </el-col>
           <el-col :span='6'>
            <el-form-item prop="sampleNum" label="客户样量">
              <el-input v-model="baseData.sampleNum" clearable style="width:100%" size="small"></el-input>
            </el-form-item>
          </el-col>
          </el-row>
          <el-row>
            <el-col :span='6'>
              <el-form-item prop='planName' label='计划名称'>
                <el-input v-model="baseData.planName" size="small" style="width: 100%;"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span='6'>
            <el-form-item prop="matOrigin" label="产地">
              <el-input v-model="baseData.matOrigin" clearable style="width:100%" size="small"></el-input>
            </el-form-item>
          </el-col>
            <el-col :span='6'>
              <el-form-item prop="cnsnOrgAddr" label-width="90px" label="超差比例(%)">
                <!-- <el-input v-model="baseData.cnsnOrgAddr" clearable style="width:100%" size="small"></el-input> -->
                <el-input v-model="baseData.cnsnOrgAddr" clearable size="small" type="number" style="width: 100%;"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item prop="netWgt" label="计划重量(t)">
                <el-input v-model="baseData.netWgt" clearable style="width:100%" size="small"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span='24'>
              <el-form-item label='计划说明'>
                <span slot="label">计划说明<el-tooltip
                  class="tooltip"
                  effect="dark"
                  content="多样录入规则,样品名称1-数量1-分析项目2/样品名称2-数量2-分析项目2"
                  placement="top"
                >
                  <i class="el-icon-question infoPrompt"></i>
                </el-tooltip></span>
                <el-input v-model="baseData.planDesc"  rows="2" type="textarea" size="small" style="width: 100%;"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
       <span slot="footer" class="dialog-footer">
        <el-button type="goon" size="mini" icon="el-icon-check" @click="tableType === 0 ? addData():modifyData()">确定</el-button>
        <el-button size="mini" type="goon" icon="el-icon-remove-outline" @click="cancel">取消</el-button>
      </span>
    </el-dialog>
    </div>
</template>
<script>
import {
  getCookie,
  formatDate
} from '@/utils/util.js';
import {
  cookieUserId,
  cookieUserName
} from '@/config/config.js';
let userName = getCookie(cookieUserName);
let userId = getCookie(cookieUserId);
import { momentImmutableMethods } from 'moment-immutable-methods'
import moment from 'moment'
momentImmutableMethods(moment)
export default {
  props: ['showFlag', 'Params'],
    data () {
        return {
          dialogTableVisible: false,
          tableTypeDsc: '新增临时计划信息表',
          tableType: 0,
          seen: true,
          seenNo: true,
          beInvalid: false,
          planYear: '',
          planDate: '',
          testTime: '',
          durTime: '',
          testLimit: '',
          memo: '',
          baseData:{
            cnsnOrgNo: '',  // 业务类型
            cnsnOrgName: '',  // 业务类型
            cnsnOrgAddr: '10',  // 超差比例
            sampleNum: '0',
            isSmp:'0',
            isBatch:'0',
            isPrep: '0',
            cnsnContactMan: '1',
            isCheck: '0',
            sampleWgt: '100',
            isCiq: '0',
            contractNo: '',
            companyNo: '',
            planCompanyNo: '',
            gradeName:'',
            lotsNo: '',
            matClassNo: '',
            planDate:new Date(),
            smpDeliCode:'481820',
            entrTypeCode:'480201', // 内部
            sampleTypeCode:'480102', // 中控样
            testTypeCode:'480305', // 抽检
            sendPlace: '',
            matNo: '',
            unloadPlace: '',
            suppNo: '',
            planDeptNo:'',
            smpDeptNo:'',
            smpSectionNo:'',
            deptNo:'P31301100',
            sectionNo:'',
            isMater: '1',//是否计量
            matShapeCode: '',
            matOrigin: '',
            carrNo: '',
            spec: '',
            gradeNo:''
          },
          deliver:[],
          testTypeNameType:[],
          smpDeliNameType: [],//送样方式
          gradeType: [], // 牌号等级下拉框
          pointNameTypeIndex: 0,//取样单位
          transportTypeNameType: [],//运输类型
          sampleTypeNameTypeIndex: 0,//样品类型
          companyNameTypeIndex: 0,//计划单位
          entrOrgNameType:[],//委托单位
          suppNameType: [],//供应单位
          meterTypeNameItem: [], // 业务类型
          matShapeNameType: [],//试样形状
          matNameTypeIndex: 0,//物料名称
          deptNameTypeIndex: 0,//计划车间
          smpDeptNameTypeIndex: 0,//采样单位
          isSmpTypeIndex: 1,//是否取样
          pointNameType: [],
          acceptNameType: [],//收货单位
          entrTypeNameType:[],
          matNameType: [], //物料名称
          sampleTypeNameType: [],
          companyNameType:[],
          packType:[],
          sectionClass:[],
          companyNameType2:[],
          sectionNameType2:[],
          sectionClass2:[],
          companyNameType3:[],
          sectionNameType3:[],//中心分析室
          sectionClass3:[],
          matClassNameType:[],
          rules: {
            planDate: [{ required: true, message: '不能为空', trigger: 'change' },],
            entrTypeCode: [{ required: true, message: '不能为空', trigger: 'change' },],
            planCompanyNo: [{ required: true, message: '不能为空', trigger: 'change' },],
            smpCompanyNo: [{ required: true, message: '不能为空', trigger: 'change' },],
            matClassNo: [{ required: true, message: '不能为空', trigger: 'change' },],
            planDeptNo: [{ required: true, message: '不能为空', trigger: 'change' },],
            matNo: [{ required: true, message: '不能为空', trigger: 'change' },],
            pointNo: [{ required: true, message: '不能为空', trigger: 'change' },],
            smpDeptNo: [{ required: true, message: '不能为空', trigger: 'change' },],
            sampleTypeCode: [{ required: true, message: '不能为空', trigger: 'change' },],
            durTime: [{ required: true, message: '不能为空', trigger: 'blur' },],
            testLimit: [],
            smpDeliCode: [{ required: true, message: '不能为空', trigger: 'change' },],
            testTypeCode: [{ required: true, message: '不能为空', trigger: 'change' },],
            companyNo: [{ required: true, message: '不能为空', trigger: 'change' },],
            deptNo: [{ required: true, message: '不能为空', trigger: 'change' },]
          },
          cnsnContactManType:[{id:"0",cnsnContactManName:'否'},{id:"1",cnsnContactManName:'是'}],
          CiqType:[{id:"0",CiqName:'否'},{id:"1",CiqName:'是'}],
          BatchType:[{id:"0",BatchName:'否'},{id:"1",BatchName:'是'}],
          isCheckType:[{id:"0",isCheck:'否'},{id:"1",isCheck:'是'}],
          isPrepType:[{id:"0",isPrep:'否'},{id:"1",isPrep:'是'}],
          isMaterType:[
            {id:"0",isMater:'否'},
            {id:"1",isMater:'是'}
            ],

          isBatchType: [
              {id: '0', isBatch: '否'},
              {id: '1', isBatch: '是'}
            ],
            sectionNameType: [],
            smpDeptNameType: [
              // {smpDeptNo:'0', smpDeptName: '分厂'},
              // {smpDeptNo:'1', smpDeptName: '外检内检'}
            ],

            isSmpType: [
              {id: '0', isSmp: '否'},
              {id: '1', isSmp: '是'},
            ],
            monitorForm: {
            tableData: []}
        }
    },
    mounted () {
      this.getGradeType();
      this.axios.post("pass/baseManagement/v1/sysorgs/querySysOrgCompanyAll",{}, {individualType: 'json'}).then(response => {
        this.entrOrgNameType = response.data
        this.planCompanyNameType = response.data
        this.companyNameType2 = response.data
        this.baseData.planCompanyNo = this.getCode('营销公司',this.entrOrgNameType,'orgName','orgCode')
      });
      //获取公司
      this.axios.post("pass/baseManagement/v1/sysorgs/querySysOrgCompanyAll",{}, {individualType: 'json'}).then(response => {
        this.companyNameType = response.data
        this.companyNameType2 = response.data
        this.companyNameType3 = response.data
      });
      //获取公司
      this.getCompanyNameType();
        //物料类型
      this.axios.get('pass/baseManagement/v1/limsbasematerialsclasss/'+ '?validFlag=1').then(res => {
        this.matClassNameType = res.data.list;
      })
      this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",{validFlag:1,baseCode:4818}, {individualType: 'json'}).then(res => {
        this.smpDeliNameType = res.data;
        this.baseData.smpDeliCode = this.getCode('每车',this.smpDeliNameType,'baseName','baseCode')
      });
      //样品类型
      this.axios.post('pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode',{validFlag:1,baseCode:4801}, {individualType: 'json'}).then(res => {
        this.sampleTypeNameType = res.data
      })
      this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",{validFlag:1,baseCode:4841}, {individualType: 'json'}).then(res => {
        this.transportTypeNameType = res.data;
        this.baseData.transportTypeName = this.getCode('汽车检斤',this.transportTypeNameType,'baseName','baseCode')
      });
      //检验类型
      this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",{validFlag:1,baseCode:4803}, {individualType: 'json'}).then(res => {
        this.testTypeNameType = res.data;
      });
      //包装类型
      this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",{validFlag:1,baseCode:4845}, {individualType: 'json'}).then(res => {
        this.packType = res.data
      });
      this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",{validFlag:1,baseCode:4819}, {individualType: 'json'}).then(res => {
        this.matShapeNameType = res.data;
        this.baseData.matShapeName = this.getCode('粉状',this.matShapeNameType,'baseName','baseCode')
      });
      //送样频次
      this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",{validFlag:1,baseCode:4818}, {individualType: 'json'}).then(res => {
        this.deliver = res.data;
      });
      this.axios.get('pass/systemBase/v1/meterbasecustomersuppliers/like/?pageNum=1&pageSize=100000&checkFlag=1' ,{individualType: 'json'}).then(res => {
        this.suppNameType = res.data.list;
        this.acceptNameType = res.data.list;
      });
      // this.axios.post("pass/baseManagement/v1/limsbasepoints/queryLimsBasePointPage",{object:{companyNo:'',pointTypeCode:'480401',validFlag:1},pageIndex:1,pageSize:9999}, {individualType: 'json'}).then(response => {
      //   this.pointNameType = response.data.list
      // });
      this.axios.post('pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode',{validFlag:1,baseCode:4802}, {individualType: 'json'}).then(res => {
              this.entrTypeNameType = res.data;
            });
      // this.getsampleTypeNameType ()
      // this.getmatNameType ()
       // 业务类型数据
    this.axios.get('pass/systemBase/v1/combaseinfos/noPage' + '?pBaseCode=001006' + '&validFlag=1')
      .then(res => {
        // console.log('业务类型数据', res.data)
        this.meterTypeNameItem = res.data;
        // this.baseData.meterTypeName = res.data[0].baseName;
      })
    },
    methods: {
      getCode (code, arr, codeKey, nameKey) {
        if (!code) {
          return '';
        }
        let targetRow = arr.find(item => {
          return item[codeKey] === code;
        });
        // console.log(targetRow, 'targetRow');
        return targetRow ? targetRow[nameKey] : '';
      },
      cancel () {
        this.baseData = {isSmp:'0',isMater: '1',spec: '',isBatch:'0',matNo: '',sampleNum: '0',cnsnOrgAddr: '10',sampleWgt: '100',isCheck: '0',smpDeliCode:'481820',planDeptNo:'',planDate:new Date(),smpDeptNo:'',smpSectionNo:'',deptNo:'',sectionNo:'',isCiq: '0',cnsnContactMan: '1'}
        this.dialogTableVisible = false;
        this.baseData.matShapeName = this.getCode('粉状',this.matShapeNameType,'baseName','baseCode')
        this.baseData.transportTypeName = this.getCode('汽车检斤',this.transportTypeNameType,'baseName','baseCode')
        this.baseData.smpDeliCode = this.getCode('每车',this.smpDeliNameType,'baseName','baseCode')
        this.baseData.planCompanyNo = this.getCode('营销公司',this.entrOrgNameType,'orgName','orgCode')
      },
         //根据选中的公司，查询部门名称数据
    selectDepartment(val){
      this.sectionNameType = []
      // this.pointNameType = []
      this.companyNameType.find(item =>{
        if(val === item.orgCode){
          this.sectionNameType = item.sysOrgList

          this.baseData.clearFlag ? '' : this.baseData.planDeptNo = ''
        }
      })
    },
      selectClass(val) {
      this.sectionClass = [];
      this.sectionNameType.find((item) => {
        if (val === item.orgCode) {
          this.sectionClass = item.sysOrgList;
          this.baseData.clearFlag ? "" : this.baseData.sectionNo = "";
        }
      });
    },valChange(val){
      if (val === '1') {
        this.ruleValidate.cnsnOrgAddr[0].required = false
        this.ruleValidate.gradeNo[0].required = false

        this.ruleValidate.planCompanyNo[0].required = true
        this.ruleValidate.companyNo[0].required = true
        this.ruleValidate.entrTypeCode[0].required = true
        this.ruleValidate.deptNo[0].required = true
        this.ruleValidate.sampleTypeCode[0].required = true
        this.ruleValidate.testTypeCode[0].required = true
        this.ruleValidate.smpCompanyNo[0].required = true
        this.ruleValidate.matShapeName[0].required = true
        this.ruleValidate.smpDeptNo[0].required = true
        this.ruleValidate.transportTypeName[0].required = true
        this.ruleValidate.planDate[0].required = true
        this.ruleValidate.smpDeliCode[0].required = true
        this.ruleValidate.packTypeCode[0].required = true
      } else {
        this.ruleValidate.cnsnOrgAddr[0].required = true
        this.ruleValidate.gradeNo[0].required = true

        this.ruleValidate.planCompanyNo[0].required = false
        this.ruleValidate.companyNo[0].required = false
        this.ruleValidate.entrTypeCode[0].required = false
        this.ruleValidate.deptNo[0].required = false
        this.ruleValidate.sampleTypeCode[0].required = false
        this.ruleValidate.testTypeCode[0].required = false
        this.ruleValidate.smpCompanyNo[0].required = false
        this.ruleValidate.matShapeName[0].required = false
        this.ruleValidate.smpDeptNo[0].required = false
        this.ruleValidate.transportTypeName[0].required = false
        this.ruleValidate.planDate[0].required = false
        this.ruleValidate.smpDeliCode[0].required = false
        this.ruleValidate.packTypeCode[0].required = false
      }
    },//根据选中的部门名称，查询班组名称
      getCompanyNameType () {
      this.axios.post("pass/baseManagement/v1/sysorgs/querySysOrgCompanyAll",{}, {individualType: 'json'}).then(response => {
        this.companyNameType = response.data
        this.baseData.companyNo = this.getCode('检测中心',this.companyNameType,'orgName','orgCode')
        this.selectDepartment(this.baseData.companyNo, 1)
        this.baseData.deptNo = this.getCode('中心分析室',this.sectionNameType,'orgName','orgCode')
     });
    },
    selectDepartment2(val){
      this.sectionNameType2 = []
      this.pointNameType = []
      this.companyNameType2.find(item =>{
        if(val === item.orgCode){
          this.sectionNameType2 = item.sysOrgList
          this.baseData.clearFlag ? '' : this.baseData.smpDeptNo = ''
          this.baseData.clearFlag ? '' :this.baseData.pointNo= ''
        }
      })
      let obj = {
        object:{companyNo:val,pointTypeCode:'480401',validFlag:1},
        pageIndex:1,
        pageSize:9999
      }
      this.axios.post("pass/baseManagement/v1/limsbasepoints/queryLimsBasePointPage",obj, {individualType: 'json'}).then(response => {
      this.pointNameType = response.data.list
    });
    },
    //根据选中的部门名称，查询班组名称
    selectClass2(val){
      this.sectionClass2 = []
      this.sectionNameType2.find(item =>{
        if(val === item.orgCode){
          this.sectionClass2 = item.sysOrgList
          this.baseData.clearFlag ? '' : this.baseData.smpSectionNo = ''
        }
      })
    },
    selectDepartment3(val){
      this.sectionNameType3 = []
      this.companyNameType3.find(item =>{
        if(val === item.orgCode){
          this.sectionNameType3 = item.sysOrgList
          console.log(this.sectionNameType3, 'list')
          console.log(this.getCode('中心分析室',this.sectionNameType3,'orgName','orgCode'), '中心分析室编码')
          this.baseData.deptNo = 'P31301100'
        }
      })
    },
    //根据选中的部门名称，查询班组名称
    selectClass3(val){
      this.sectionClass3 = []
      this.sectionNameType3.find(item =>{
        if(val === item.orgCode){
          this.sectionClass3 = item.sysOrgList
          this.baseData.clearFlag ? '' : this.baseData.sectionNo = ''
        }
      })
    },
    smpSection () {
      this.$forceUpdate()
    },
    getGradeType () {
        let that = this;
        let obj = {
          object: {
            validFlag: '1'
          },
          pageIndex: 1,
          pageSize: 99999
        }
        that.axios.post('pass/baseManagement/v1/limsbasegrades/queryLimsBaseGradePage', obj, {
          individualType: 'json'
        }).then(res => {
          if (res.succeed) {
            this.gradeType = res.data.list
          }
        }).catch(e => {
        })
      },
      selctMatName(val){
        this.matNameType = []
        this.baseData.clearFlag ? '' : this.baseData.matNo = ''
        if (!val) {
          return
      }
        //物料名称
        this.axios.post('pass/baseManagement/v1/limsbasematerialss/queryLimsBaseMaterialsPage/',{object:{validFlag:1,matClassNo:val},pageIndex:1,pageSize:99999},{individualType: 'json'}).then(res => {
          this.matNameType = res.data.list;
        })
      },
      addData () {
        this.$refs['baseData'].validate((valid) => {
          if (valid) {
            this.baseData.planYear = moment(this.baseData.planYear).get('year');
            this.baseData.planTypeCode = '481702';
            this.baseData.planTypeName = '临时计划';
            this.baseData.pointName = this.getCode(this.baseData.pointNo,this.pointNameType,'pointNo','pointName')
            this.baseData.sampleTypeName = this.getCode(this.baseData.sampleTypeCode,this.sampleTypeNameType,'baseCode','baseName')
            this.baseData.entrTypeName = this.getCode(this.baseData.entrTypeCode,this.entrTypeNameType,'baseCode','baseName')
            this.baseData.planCompanyName = this.getCode(this.baseData.planCompanyNo,this.companyNameType,'orgCode','orgName')
            this.baseData.planDeptName = this.getCode(this.baseData.planDeptNo,this.sectionNameType,'orgCode','orgName')
            // this.baseData.sectionName = this.getCode(this.baseData.sectionNo,this.sectionClass,'orgCode','orgName')
            this.baseData.smpCompanyName = this.getCode(this.baseData.smpCompanyNo,this.companyNameType2,'orgCode','orgName')
            this.baseData.planCompanyName = this.getCode(this.baseData.planCompanyNo,this.entrOrgNameType,'orgCode','orgName')
            this.baseData.smpDeptName = this.getCode(this.baseData.smpDeptNo,this.sectionNameType2,'orgCode','orgName')
            this.baseData.smpSectionName = this.getCode(this.baseData.smpSectionNo,this.sectionClass2,'orgCode','orgName')
            this.baseData.companyName = this.getCode(this.baseData.companyNo,this.companyNameType3,'orgCode','orgName')
            this.baseData.deptName = this.getCode(this.baseData.deptNo,this.sectionNameType3,'orgCode','orgName')
            this.baseData.sectionName = this.getCode(this.baseData.sectionNo,this.sectionClass3,'orgCode','orgName')
            this.baseData.acceptNo = this.getCode(this.baseData.acceptName,this.acceptNameType,'customerSupplierName','customerSupplierNo')
            this.baseData.matName = this.getCode(this.baseData.matNo,this.matNameType,'matNo','matName')
            this.baseData.matShapeCode = this.getCode(this.baseData.matShapeName,this.matShapeNameType,'baseName','baseCode')
            this.baseData.smpDeliName = this.getCode(this.baseData.smpDeliCode,this.smpDeliNameType,'baseCode','baseName')
            this.baseData.suppNo = this.getCode(this.baseData.suppName,this.suppNameType,'customerSupplierName','customerSupplierNo')
            this.baseData.matClassName = this.getCode(this.baseData.matClassNo,this.matClassNameType,'matClassNo','matClassName')
            this.baseData.smpDeliName = this.getCode(this.baseData.smpDeliCode,this.deliver,'baseCode','baseName')
            this.baseData.transportTypeCode = this.getCode(this.baseData.transportTypeName,this.transportTypeNameType,'baseName','baseCode')
            this.baseData.testTypeName = this.getCode(this.baseData.testTypeCode,this.testTypeNameType,'baseCode','baseName')
            this.baseData.cnsnOrgNo = this.getCode(this.baseData.cnsnOrgName, this.meterTypeNameItem, 'baseName', 'baseCode')
            this.baseData.packTypeName = this.getCode(this.baseData.packTypeCode,this.packType,'baseCode','baseName')
            let obj = this.gradeType.find((item) => {
              return item.gradeNo === this.baseData.gradeNo;
            });
            this.baseData.gradeName = this.getCode(this.baseData.gradeName, this.baseData.gradeNo, 'baseName', 'baseCode')
            this.axios.post('pass/testManagement/v1/limstestplans/saveLimsTestPlan', this.baseData, {individualType: 'json'}).then(res => {
              if (res.succeed) {
                this.dialogTableVisible = false;
                this.$message.success('添加成功')
                this.$emit('refresh')
              } else {
                this.$message.error(res.message)
              }
            }).catch(e => {
              this.$message.error(e.message)
            })
          }
       })
      },
      modifyData () {
        this.$refs['baseData'].validate((valid) => {
          if (valid) {
            this.baseData.planYear = moment(this.baseData.planYear).get('year');
            this.baseData.pointName = this.getCode(this.baseData.pointNo,this.pointNameType,'pointNo','pointName')
            this.baseData.sampleTypeName = this.getCode(this.baseData.sampleTypeCode,this.sampleTypeNameType,'baseCode','baseName')
            this.baseData.entrTypeName = this.getCode(this.baseData.entrTypeCode,this.entrTypeNameType,'baseCode','baseName')
            this.baseData.planCompanyName = this.getCode(this.baseData.planCompanyNo,this.companyNameType,'orgCode','orgName')
            this.baseData.planDeptName = this.getCode(this.baseData.planDeptNo,this.sectionNameType,'orgCode','orgName')
            // this.baseData.sectionName = this.getCode(this.baseData.sectionNo,this.sectionClass,'orgCode','orgName')
            this.baseData.smpCompanyName = this.getCode(this.baseData.smpCompanyNo,this.companyNameType2,'orgCode','orgName')
            this.baseData.planCompanyName = this.getCode(this.baseData.planCompanyNo,this.entrOrgNameType,'orgCode','orgName')
            this.baseData.smpDeptName = this.getCode(this.baseData.smpDeptNo,this.sectionNameType2,'orgCode','orgName')
            this.baseData.smpSectionName = this.getCode(this.baseData.smpSectionNo,this.sectionClass2,'orgCode','orgName')
            this.baseData.companyName = this.getCode(this.baseData.companyNo,this.companyNameType3,'orgCode','orgName')
            this.baseData.deptName = this.getCode(this.baseData.deptNo,this.sectionNameType3,'orgCode','orgName')
            this.baseData.sectionName = this.getCode(this.baseData.sectionNo,this.sectionClass3,'orgCode','orgName')
            this.baseData.acceptNo = this.getCode(this.baseData.acceptName,this.acceptNameType,'customerSupplierName','customerSupplierNo')
            this.baseData.matName = this.getCode(this.baseData.matNo,this.matNameType,'matNo','matName')
            this.baseData.matShapeCode = this.getCode(this.baseData.matShapeName,this.matShapeNameType,'baseName','baseCode')
            this.baseData.smpDeliName = this.getCode(this.baseData.smpDeliCode,this.smpDeliNameType,'baseCode','baseName')
            this.baseData.suppNo = this.getCode(this.baseData.suppName,this.suppNameType,'customerSupplierName','customerSupplierNo')
            this.baseData.matClassName = this.getCode(this.baseData.matClassNo,this.matClassNameType,'matClassNo','matClassName')
            this.baseData.smpDeliName = this.getCode(this.baseData.smpDeliCode,this.deliver,'baseCode','baseName')
            this.baseData.transportTypeCode = this.getCode(this.baseData.transportTypeName,this.transportTypeNameType,'baseName','baseCode')
            this.baseData.cnsnOrgNo = this.getCode(this.baseData.cnsnOrgName, this.meterTypeNameItem, 'baseName', 'baseCode')
            this.baseData.testTypeName = this.getCode(this.baseData.testTypeCode,this.testTypeNameType,'baseCode','baseName')
            this.baseData.packTypeName = this.getCode(this.baseData.packTypeCode,this.packType,'baseCode','baseName')
            let obj = this.gradeType.find((item) => {
              return item.gradeNo === this.baseData.gradeNo;
            });
            this.baseData.gradeName = this.getCode(this.baseData.gradeName, this.baseData.gradeNo, 'baseName', 'baseCode')
            this.axios.post('pass/testManagement/v1/limstestplans/saveLimsTestPlan', this.baseData, {individualType: 'json'}).then(res => {
              if (res.succeed) {
                this.dialogTableVisible = false;
                this.$message.success('修改成功')
                this.$emit('refresh')
              } else {
               this.$message.error(res.message)
              }
            }).catch(e => {
              this.$message.error(e.message)
            })
          }
       })
      },
    closeDialog () {
      this.baseData = {isSmp:'0',isMater: '1',spec: '',isBatch:'0',matNo: '',isCheck: '0',cnsnOrgAddr: '10',sampleNum: '0',sampleWgt: '100', smpDeliCode:'481820',isCiq: '0',planDeptNo:'',packTypeCode:'',planDate:new Date(),smpDeptNo:'',smpSectionNo:'',cnsnContactMan: '1',deptNo:'',sectionNo:''}
      this.baseData.deptNo = this.getCode('中心分析室',this.sectionNameType3,'orgName','orgCode')
      this.baseData.matShapeName = this.getCode('粉状',this.matShapeNameType,'baseName','baseCode')
      this.baseData.transportTypeName = this.getCode('汽车检斤',this.transportTypeNameType,'baseName','baseCode')
      this.baseData.smpDeliCode = this.getCode('每车',this.smpDeliNameType,'baseName','baseCode')
      this.baseData.planCompanyNo = this.getCode('营销公司',this.entrOrgNameType,'orgName','orgCode')
    }
    },
    watch: {
      showFlag (arg) {
        console.log('监听到事件1')
        let _this = this;
        this.dialogTableVisible = true;
        if (_this.Params !== null) {
          // if(this.Params.isMater == 0){
          //   this.ruleValidate.cnsnOrgName[0].required = false
          // }else{
          //   this.ruleValidate.cnsnOrgName[0].required = true
          // }
          this.baseData = Object.assign({clearFlag:true},this.Params)
          this.selctMatName(this.baseData.matClassNo); // 物料名称选择
          this.selectDepartment(this.baseData.planCompanyNo)
          this.selectDepartment2(this.baseData.smpCompanyNo)
          this.selectClass2(this.baseData.smpDeptNo)
          this.selectClass(this.baseData.deptNo);
          this.selectDepartment3(this.baseData.companyNo)
          this.selectClass3(this.baseData.deptNo)
          this.baseData.cnsnContactMan = this.baseData.cnsnContactMan =='是' ? '1' : '0'
          this.baseData.clearFlag = false
          _this.tableType = 1;
          _this.tableTypeDsc = '修改临时计划信息表';
        } else {
          _this.tableType = 0;
          _this.tableTypeDsc = '新增临时计划信息表';
          _this.baseData = { // 初始化数据
            companyNo:'F31300000',
            isSmp:'0',
            isBatch:'0',
            planDate:new Date(),
            smpDeliCode:'481820',
            entrTypeCode:'480201', // 内部
            sampleTypeCode:'480102', // 中控样
            testTypeCode:'480305', // 抽检
            matNo: '',
            planDeptNo:'',
            isCheck: '0',
            isMater: '1',
            isPrep: '0',
            sampleWgt: '100',
            sampleNum: '0',
            cnsnOrgAddr: '10',
            smpDeptNo:'',
            smpSectionNo:'',
            deptNo:'P31301100',
            sectionNo:'',
            cnsnContactMan: '1'
          }
          this.baseData.smpCompanyNo = 'F31300000'
          this.baseData.planCompanyNo = 'G31500000'
          this.baseData.packTypeCode = '484501'
          this.selectDepartment2(this.baseData.smpCompanyNo)
          this.selctMatName(this.baseData.matClassNo);
          // alert(this.baseData.matClassNo)
          this.selectClass(this.baseData.deptNo);
          this.baseData.matShapeName = this.getCode('粉状',this.matShapeNameType,'baseName','baseCode')
          this.baseData.isCiq = this.baseData.isCiq =='是' ? '1' : '0'
          this.selectDepartment2(this.baseData.smpCompanyNo)
          _this.selectDepartment3(_this.baseData.companyNo)
          _this.$nextTick(() => {
            _this.$refs.baseData.clearValidate();
          });
        }
        // this.baseData.isSmp = '1'
        // this.baseData.isBatch = '1'
      }
    }
}
</script>
<style lang="less">
.customWidth_certifi3{
  width: 600px !important
}
.infoPrompt{
  color:#409eff;
  font-size: 14px;
}
</style>
