<template>
  <div class="examination">
    <el-dialog
      @close="closeDialog"
      :visible.sync="dialogTableVisible"
      width="80%"
    >
      <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="80px"
        :rules="ruleValidate"
        :model="baseData"
      >
        <el-row>
          <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 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 label="采样单位" prop="smpCompanyNo">
              <el-select
                v-model="baseData.smpCompanyNo"
                clearable
                filterable
                style="width: 100%"
                collapse-tags
                @change="selectsmpDept"
                size="small"
              >
                <el-option
                  v-for="item in smpCompanyType"
                  :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="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 prop="deptNo" label="检验车间">
              <el-select
                v-model="baseData.deptNo"
                filterable
                clearable
                style="width: 100%"
                @change="selectClass3"
                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="smpDeptNo" label="采样车间">
              <el-select
                v-model="baseData.smpDeptNo"
                filterable
                clearable
                style="width: 100%"
                @change="selectClass2"
                collapse-tags
                size="small"
              >
                <el-option
                  v-for="item in smpDeptNoType"
                  :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="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="sectionNo" label="检验班组">
              <el-select
                v-model="baseData.sectionNo"
                filterable
                clearable
                style="width: 100%"
                collapse-tags
                size="small"
              >
                <el-option
                  v-for="item in sectionClass3"
                  :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="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.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="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="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 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 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="suppNo" label="供应单位">
              <el-select
                v-model="baseData.suppNo"
                clearable
                filterable
                collapse-tags
                size="small"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in suppNameType"
                  :key="index"
                  :label="item.merchName"
                  :value="item.merchNo"
                >
                </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="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 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="transportTypeCode" label="运输类型">
              <el-select
                v-model="baseData.transportTypeCode"
                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="matShapeCode" label="试样形状">
              <el-select
                v-model="baseData.matShapeCode"
                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="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 label="是否计量">
              <el-select
                v-model="baseData.isMater"
                clearable
                filterable
                style="width: 100%"
                collapse-tags
                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="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.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="entTime" label="进厂时间">
              <el-date-picker
                v-model="baseData.entTime"
                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="sampleNum" label="样品数量(个)">
              <el-input
                v-model="baseData.sampleNum"
                oninput="value=value.replace(/[^0-9.]/g,'')"
                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"
                oninput="value=value.replace(/[^0-9.]/g,'')"
                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="carNo" label="委托样号">
              <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 prop="pointNo" label="取样地点">
              <el-select
                v-model="baseData.pointNo"
                clearable
                filterable
                collapse-tags
                size="small"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in pointNameType"
                  :key="index"
                  :label="item.pointName"
                  :value="item.pointNo"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="sampleWgt" label="样品重量(g)">
              <el-input
                v-model="baseData.sampleWgt"
                oninput="value=value.replace(/[^0-9.]/g,'')"
                clearable
                style="width: 100%"
                size="small"
              ></el-input>
            </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-row>
        <el-row>
          <el-col :span="6">
            <el-form-item prop="contractNo" label="合同号">
              <el-input
                v-model="baseData.contractNo"
                clearable
                style="width: 100%"
                size="small"
              ></el-input>
            </el-form-item>
          </el-col>
          <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 label="到货批次">
              <el-input
                v-model="baseData.lotsNo"
                clearable
                style="width: 100%"
                size="small"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="netWgt" label="计划重量(t)">
              <el-input
                v-model="baseData.netWgt"
                oninput="value=value.replace(/[^0-9.]/g,'')"
                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="备注">
              <el-input
                v-model="baseData.memo"
                clearable
                style="width: 100%"
                size="small"
              ></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);
export default {
  props: ["showFlag", "Params"],
  data() {
    return {
      dialogTableVisible: false,
      tableTypeDsc: "新增检验委托信息",
      tableType: 0,
      sectionClass3: [],
      sectionClass2: [],
      entrTypeNameType: [], //委托类型
      matClassNameType: [], //物料类型
      matNameType: [], //物料名称
      entrOrgNameType: [], //委托单位
      pointNameType: [], //取样地点
      testTypeNameType: [], //检验类型
      companyNameType: [], //公司名称
      sectionNameType: [], //部门名称
      sampleTypeNameType: [], //样品类型
      suppNameType: [], //供应单位
      matShapeNameType: [], //试样形状
      carrNameType: [], //承运商
      transportTypeNameType: [], //运输类型
      acceptNameType: [], //收货单位
      smpDeliNameType: [], //送样方式
      smpDeptNoType: [],
      BatchType: [
        { id: "0", BatchName: "否" },
        { id: "1", BatchName: "是" },
      ],
      CiqType: [
        { id: "0", CiqName: "否" },
        { id: "1", CiqName: "是" },
      ],
      isSmpType: [
        { id: "0", isSmp: "否" },
        { id: "1", isSmp: "是" },
      ],
      isPrepType: [
        { id: "0", isPrep: "否" },
        { id: "1", isPrep: "是" },
      ],
      isCheckType: [
        { id: "0", isCheck: "否" },
        { id: "1", isCheck: "是" },
      ],
      isMaterType: [
        { id: "0", isMater: "否" },
        { id: "1", isMater: "是" },
      ],
      smpCompanyType: [],
      baseData: {
        isCiq: "0",
        isBatch: "1",
        isSmp: "1",
        isPrep: "1",
        isCheck: "0",
        isMater: "1",
        matNo: "",
        contractNo: "",
        companyNo: "",
        smpCompanyNo: "",
        entrTypeCode: "",
        planCompanyNo: "",
        deptNo: "",
        smpDeptNo: "",
        sectionNo: "",
        smpSectionNo: "",
        lotsNo: "",
        matClassNo: "",
        sampleTypeCode: "",
        sendPlace: "",
        matNo: "",
        testTypeCode: "",
        unloadPlace: "",
        suppNo: "",
        matShapeCode: "",
        matOrigin: "",
        carrNo: "",
        transportTypeCode: "",
        sampleNum: "4",
        acceptName: "",
        pointNo: "",
        sampleWgt: "100",
        testCost: "0",
        carNo: "",
        smpDeliCode: "",
        netWgt: "",
        spec: "",
        trainNo: "",
        entTime: "",
        memo: "",
      },
      ruleValidate: {
        entrTypeCode: [
          { required: true, message: "该项不能为空", trigger: "change" },
        ],
        // pointNo: [{ required: true, message: '该项不能为空', trigger: 'change' }],
        matClassNo: [
          { required: true, message: "该项不能为空", trigger: "change" },
        ],
        matNo: [{ required: true, message: "该项不能为空", trigger: "change" }],
        testTypeCode: [
          { required: true, message: "该项不能为空", trigger: "change" },
        ],
        planCompanyNo: [
          { required: true, message: "该项不能为空", trigger: "change" },
        ],
        companyNo: [
          { required: true, message: "该项不能为空", trigger: "change" },
        ],
        // smpCompanyNo: [{ required: true, message: '该项不能为空', trigger: 'change' }],
        deptNo: [
          { required: true, message: "该项不能为空", trigger: "change" },
        ],
        // smpDeptNo: [{ required: true, message: '该项不能为空', trigger: 'change' }],
        sampleTypeCode: [
          { required: true, message: "该项不能为空", trigger: "change" },
        ],
        smpDeliCode: [
          { required: true, message: "该项不能为空", trigger: "change" },
        ],
        entTime: [
          { required: true, message: "该项不能为空", trigger: "change" },
        ],
      },
    };
  },
  created() {
    this.baseData.entTime = new Date();
  },
  mounted() {
    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.baseData.pointNo = this.getCode(
          "化验室",
          this.pointNameType,
          "pointName",
          "pointNo"
        );
      });
    this.axios
      .post(
        "pass/baseManagement/v1/sysorgs/querySysOrgCompanyAll",
        {},
        { individualType: "json" }
      )
      .then((response) => {
        this.acceptNameType = this.entrOrgNameType = response.data;
        this.baseData.planCompanyNo = this.getCode(
          "检测中心",
          this.entrOrgNameType,
          "orgName",
          "orgCode"
        );
      });
    //委托类型
    this.axios
      .post(
        "pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",
        { validFlag: 1, baseCode: 4802 },
        { individualType: "json" }
      )
      .then((res) => {
        this.entrTypeNameType = res.data;
        this.baseData.entrTypeCode = this.getCode(
          "内部",
          this.entrTypeNameType,
          "baseName",
          "baseCode"
        );
      });
    //检验类型
    this.axios
      .post(
        "pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",
        { validFlag: 1, baseCode: 4803 },
        { individualType: "json" }
      )
      .then((res) => {
        this.testTypeNameType = res.data;
        this.baseData.testTypeCode = this.getCode(
          "初检",
          this.testTypeNameType,
          "baseName",
          "baseCode"
        );
      });
    this.getMatClassNameType();
    //获取公司
    this.getCompanyNameType();
    //样品类型
    this.axios
      .post(
        "pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",
        { validFlag: 1, baseCode: 4801 },
        { individualType: "json" }
      )
      .then((res) => {
        this.sampleTypeNameType = res.data;
        this.baseData.sampleTypeCode = this.getCode(
          "原料样",
          this.sampleTypeNameType,
          "baseName",
          "baseCode"
        );
      });
    this.axios
      .post(
        "pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",
        { validFlag: 1, baseCode: 4819 },
        { individualType: "json" }
      )
      .then((res) => {
        this.matShapeNameType = res.data;
        this.baseData.matShapeCode = this.getCode(
          "固体",
          this.matShapeNameType,
          "baseName",
          "baseCode"
        );
      });
    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: 4841 },
        { individualType: "json" }
      )
      .then((res) => {
        this.transportTypeNameType = res.data;
        this.baseData.transportTypeCode = this.getCode(
          "汽运",
          this.transportTypeNameType,
          "baseName",
          "baseCode"
        );
      });
    this.axios
      .post(
        "pass/baseManagement/v1/limsmerchantsinfos/querysupcu",
        { merchTypeCode: 483201, merchTypeName: "供应商" },
        { individualType: "json" }
      )
      .then((res) => {
        this.suppNameType = res.data;
      });
    // this.axios.post("pass/baseManagement/v1/limsmerchantsinfos/querysupcu",{merchTypeCode:483203,merchTypeName:'承运单位'}, {individualType: 'json'}).then(res => {
    //   this.carrNameType = res.data;
    // });
  },
  methods: {
    getCode(code, arr, codeKey, nameKey) {
      if (!code || !arr) {
        return "";
      }
      let targetRow = arr.find((item) => {
        return item[codeKey] === code;
      });
      // console.log(targetRow, 'targetRow');
      return targetRow ? targetRow[nameKey] : "";
    },
    getCompanyNameType() {
      this.axios
        .post(
          "pass/baseManagement/v1/sysorgs/querySysOrgCompanyAll",
          {},
          { individualType: "json" }
        )
        .then((response) => {
          this.companyNameType = response.data;
          this.smpCompanyType = response.data;
          this.baseData.companyNo = this.getCode(
            "检测中心",
            this.companyNameType,
            "orgName",
            "orgCode"
          );
          this.selectDepartment(this.baseData.companyNo, 1);
          this.selectClass3("O31301700");
          this.baseData.deptNo = this.getCode(
            "生产装备室",
            this.sectionNameType,
            "orgName",
            "orgCode"
          );
        });
    },
    getMatClassNameType() {
      this.axios
        .get("pass/baseManagement/v1/limsbasematerialsclasss/" + "?validFlag=1")
        .then((res) => {
          this.matClassNameType = res.data.list;
          this.baseData.matClassNo = this.getCode(
            "原辅料",
            this.matClassNameType,
            "matClassName",
            "matClassNo"
          );
          this.selctMatName(this.baseData.matClassNo);
        });
    },
    selectDepartment(val, index) {
      console.log(val, "val");
      this.sectionNameType = [];
      this.companyNameType.find((item) => {
        if (val === item.orgCode) {
          this.sectionNameType = item.sysOrgList;
          if (index === 1) {
            this.baseData.deptNo =
              item.sysOrgList.length > 0 ? item.sysOrgList[0].orgCode : "";
          }
        }
      });
    },
    selectsmpDept(val) {
      this.smpDeptNoType = [];
      this.smpCompanyType.find((item) => {
        if (val === item.orgCode) {
          this.smpDeptNoType = item.sysOrgList;
          this.baseData.clearFlag ? "" : (this.baseData.smpDeptNo = "");
        }
      });
    },
    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;
        });
    },
    selectClass2(val) {
      this.sectionClass2 = [];
      this.smpDeptNoType.find((item) => {
        if (val === item.orgCode) {
          this.sectionClass2 = item.sysOrgList;
          this.baseData.clearFlag ? "" : (this.baseData.smpSectionNo = "");
        }
      });
    },
    selectClass3(val) {
      this.sectionClass3 = [];
      this.sectionNameType.find((item) => {
        if (val === item.orgCode) {
          this.sectionClass3 = item.sysOrgList;
          this.baseData.clearFlag ? "" : (this.baseData.sectionNo = "");
        }
      });
    },
    cancel() {
      this.baseData = {
        isCiq: "0",
        isBatch: "1",
        isSmp: "1",
        isPrep: "1",
        isCheck: "0",
        isMater: "1",
        matNo: "",
        contractNo: "",
        companyNo: "",
        smpCompanyNo: "",
        entrTypeCode: "",
        planCompanyNo: "",
        deptNo: "",
        smpDeptNo: "",
        sectionNo: "",
        smpSectionNo: "",
        lotsNo: "",
        matClassNo: "",
        sampleTypeCode: "",
        sendPlace: "",
        matNo: "",
        testTypeCode: "",
        unloadPlace: "",
        suppNo: "",
        matShapeCode: "",
        matOrigin: "",
        carrNo: "",
        transportTypeCode: "",
        sampleNum: "4",
        acceptName: "",
        pointNo: "",
        sampleWgt: "100",
        testCost: "0",
        carNo: "",
        smpDeliCode: "",
        netWgt: "",
        spec: "",
        trainNo: "",
        entTime: "",
        memo: "",
      };
      this.dialogTableVisible = false;
      this.baseData.pointNo = this.getCode(
        "化验室",
        this.pointNameType,
        "pointName",
        "pointNo"
      );
      this.baseData.planCompanyNo = this.getCode(
        "检测中心",
        this.entrOrgNameType,
        "orgName",
        "orgCode"
      );
      this.baseData.entrTypeCode = this.getCode(
        "内部",
        this.entrTypeNameType,
        "baseName",
        "baseCode"
      );
      this.baseData.testTypeCode = this.getCode(
        "初检",
        this.testTypeNameType,
        "baseName",
        "baseCode"
      );
      this.baseData.sampleTypeCode = this.getCode(
        "原料样",
        this.sampleTypeNameType,
        "baseName",
        "baseCode"
      );
      this.baseData.matShapeCode = this.getCode(
        "固体",
        this.matShapeNameType,
        "baseName",
        "baseCode"
      );
      this.baseData.smpDeliCode = this.getCode(
        "每车",
        this.smpDeliNameType,
        "baseName",
        "baseCode"
      );
      this.baseData.transportTypeCode = this.getCode(
        "汽运",
        this.transportTypeNameType,
        "baseName",
        "baseCode"
      );
      this.baseData.entTime = new Date();
    },
    addData() {
      let _this = this;
      _this.$refs["baseData"].validate((valid) => {
        if (valid) {
          this.baseData.createMan = userName;
          this.baseData.createNo = userId;
          // this.baseData.sampleTypeCode = '480101',
          // this.baseData.sampleTypeName = '原料样',
          this.baseData.entrTime = formatDate(new Date(), "yyyy-MM-dd");
          this.baseData.sectionName = this.getCode(
            this.baseData.sectionNo,
            this.sectionClass3,
            "orgCode",
            "orgName"
          );
          this.baseData.smpSectionName = this.getCode(
            this.baseData.smpSectionNo,
            this.sectionClass2,
            "orgCode",
            "orgName"
          );
          this.baseData.matName = this.getCode(
            this.baseData.matNo,
            this.matNameType,
            "matNo",
            "matName"
          );
          this.baseData.planCompanyName = this.getCode(
            this.baseData.planCompanyNo,
            this.entrOrgNameType,
            "orgCode",
            "orgName"
          );
          this.baseData.pointName = this.getCode(
            this.baseData.pointNo,
            this.pointNameType,
            "pointNo",
            "pointName"
          );
          this.baseData.matClassName = this.getCode(
            this.baseData.matClassNo,
            this.matClassNameType,
            "matClassNo",
            "matClassName"
          );
          this.baseData.entrTypeName = this.getCode(
            this.baseData.entrTypeCode,
            this.entrTypeNameType,
            "baseCode",
            "baseName"
          );
          this.baseData.testTypeName = this.getCode(
            this.baseData.testTypeCode,
            this.testTypeNameType,
            "baseCode",
            "baseName"
          );
          this.baseData.companyName = this.getCode(
            this.baseData.companyNo,
            this.companyNameType,
            "orgCode",
            "orgName"
          );
          this.baseData.deptName = this.getCode(
            this.baseData.deptNo,
            this.sectionNameType,
            "orgCode",
            "orgName"
          );
          this.baseData.smpDeptName = this.getCode(
            this.baseData.smpDeptNo,
            this.smpDeptNoType,
            "orgCode",
            "orgName"
          );
          this.baseData.smpCompanyName = this.getCode(
            this.baseData.smpCompanyNo,
            this.smpCompanyType,
            "orgCode",
            "orgName"
          );
          this.baseData.sampleTypeName = this.getCode(
            this.baseData.sampleTypeCode,
            this.sampleTypeNameType,
            "baseCode",
            "baseName"
          );
          this.baseData.matShapeName = this.getCode(
            this.baseData.matShapeCode,
            this.matShapeNameType,
            "baseCode",
            "baseName"
          );
          this.baseData.transportTypeName = this.getCode(
            this.baseData.transportTypeCode,
            this.transportTypeNameType,
            "baseCode",
            "baseName"
          );
          this.baseData.smpDeliName = this.getCode(
            this.baseData.smpDeliCode,
            this.smpDeliNameType,
            "baseCode",
            "baseName"
          );
          // this.baseData.acceptName = this.getCode(this.baseData.acceptNo,this.entrOrgNameType,'orgCode','orgName')
          this.baseData.suppName = this.getCode(
            this.baseData.suppNo,
            this.suppNameType,
            "merchNo",
            "merchName"
          );
          this.axios
            .post(
              "pass/testManagement/v1/limstestentrusts/saveLimsTestEntrust",
              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() {
      let _this = this;
      this.$refs["baseData"].validate((valid) => {
        if (valid) {
          this.baseData.sectionName = this.getCode(
            this.baseData.sectionNo,
            this.sectionClass3,
            "orgCode",
            "orgName"
          );
          this.baseData.smpSectionName = this.getCode(
            this.baseData.smpSectionNo,
            this.sectionClass2,
            "orgCode",
            "orgName"
          );
          this.baseData.matName = this.getCode(
            this.baseData.matNo,
            this.matNameType,
            "matNo",
            "matName"
          );
          this.baseData.planCompanyName = this.getCode(
            this.baseData.planCompanyNo,
            this.entrOrgNameType,
            "orgCode",
            "orgName"
          );
          this.baseData.pointName = this.getCode(
            this.baseData.pointNo,
            this.pointNameType,
            "pointNo",
            "pointName"
          );
          this.baseData.matClassName = this.getCode(
            this.baseData.matClassNo,
            this.matClassNameType,
            "matClassNo",
            "matClassName"
          );
          this.baseData.entrTypeName = this.getCode(
            this.baseData.entrTypeCode,
            this.entrTypeNameType,
            "baseCode",
            "baseName"
          );
          this.baseData.testTypeName = this.getCode(
            this.baseData.testTypeCode,
            this.testTypeNameType,
            "baseCode",
            "baseName"
          );
          this.baseData.companyName = this.getCode(
            this.baseData.companyNo,
            this.companyNameType,
            "orgCode",
            "orgName"
          );
          this.baseData.deptName = this.getCode(
            this.baseData.deptNo,
            this.sectionNameType,
            "orgCode",
            "orgName"
          );
          this.baseData.smpDeptName = this.getCode(
            this.baseData.smpDeptNo,
            this.smpDeptNoType,
            "orgCode",
            "orgName"
          );
          this.baseData.sampleTypeName = this.getCode(
            this.baseData.sampleTypeCode,
            this.sampleTypeNameType,
            "baseCode",
            "baseName"
          );
          this.baseData.smpCompanyName = this.getCode(
            this.baseData.smpCompanyNo,
            this.smpCompanyType,
            "orgCode",
            "orgName"
          );
          this.baseData.matShapeName = this.getCode(
            this.baseData.matShapeCode,
            this.matShapeNameType,
            "baseCode",
            "baseName"
          );
          this.baseData.transportTypeName = this.getCode(
            this.baseData.transportTypeCode,
            this.transportTypeNameType,
            "baseCode",
            "baseName"
          );
          this.baseData.smpDeliName = this.getCode(
            this.baseData.smpDeliCode,
            this.smpDeliNameType,
            "baseCode",
            "baseName"
          );
          // this.baseData.acceptName = this.getCode(this.baseData.acceptNo,this.entrOrgNameType,'orgCode','orgName')
          this.baseData.suppName = this.getCode(
            this.baseData.suppNo,
            this.suppNameType,
            "merchNo",
            "merchName"
          );
          this.axios
            .post(
              "pass/testManagement/v1/limstestentrusts/saveLimsTestEntrust",
              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 = {
        isCiq: "0",
        isBatch: "1",
        isSmp: "1",
        isPrep: "1",
        isCheck: "0",
        isMater: "1",
        matNo: "",
        contractNo: "",
        companyNo: "",
        smpCompanyNo: "",
        entrTypeCode: "",
        planCompanyNo: "",
        deptNo: "",
        smpDeptNo: "",
        sectionNo: "",
        smpSectionNo: "",
        lotsNo: "",
        matClassNo: "",
        sampleTypeCode: "",
        sendPlace: "",
        matNo: "",
        testTypeCode: "",
        unloadPlace: "",
        suppNo: "",
        matShapeCode: "",
        matOrigin: "",
        carrNo: "",
        transportTypeCode: "",
        sampleNum: "4",
        acceptName: "",
        pointNo: "",
        sampleWgt: "100",
        testCost: "0",
        carNo: "",
        smpDeliCode: "",
        netWgt: "",
        spec: "",
        trainNo: "",
        entTime: "",
        memo: "",
      };
      this.dialogTableVisible = false;
      this.baseData.pointNo = this.getCode(
        "化验室",
        this.pointNameType,
        "pointName",
        "pointNo"
      );
      this.baseData.planCompanyNo = this.getCode(
        "检测中心",
        this.entrOrgNameType,
        "orgName",
        "orgCode"
      );
      this.baseData.entrTypeCode = this.getCode(
        "内部",
        this.entrTypeNameType,
        "baseName",
        "baseCode"
      );
      this.baseData.testTypeCode = this.getCode(
        "初检",
        this.testTypeNameType,
        "baseName",
        "baseCode"
      );
      this.baseData.sampleTypeCode = this.getCode(
        "原料样",
        this.sampleTypeNameType,
        "baseName",
        "baseCode"
      );
      this.baseData.matShapeCode = this.getCode(
        "固体",
        this.matShapeNameType,
        "baseName",
        "baseCode"
      );
      this.baseData.smpDeliCode = this.getCode(
        "每车",
        this.smpDeliNameType,
        "baseName",
        "baseCode"
      );
      this.baseData.transportTypeCode = this.getCode(
        "汽运",
        this.transportTypeNameType,
        "baseName",
        "baseCode"
      );
      this.baseData.entTime = new Date();
    },
  },
  watch: {
    showFlag(arg) {
      let _this = this;
      if (arg) {
        _this.dialogTableVisible = true;
        if (_this.Params !== null) {
          this.baseData = Object.assign({ clearFlag: true }, this.Params);
          this.selctMatName(this.baseData.matClassNo);
          this.selectDepartment(this.baseData.companyNo);
          this.selectsmpDept(this.baseData.smpCompanyNo);
          this.selectClass2(this.baseData.smpDeptNo);
          this.selectClass3(this.baseData.deptNo);
          this.baseData.clearFlag = false;
          _this.tableType = 1;
          _this.tableTypeDsc = "修改检验委托信息";
        } else {
          _this.tableType = 0;
          this.getMatClassNameType();
          this.getCompanyNameType();
          _this.tableTypeDsc = "新增检验委托信息";
        }
      }
    },
  },
};
</script>
<style lang="less">
.customWidth_syst {
  width: 600px !important;
}
</style>
