src/views/business/productOrder/components/addOrder.vue
@@ -1,48 +1,76 @@
<template>
  <div class="app-container">
    <div v-show="!cableConfigShow&&!auxiliaryShow">
      <div style="display: flex;justify-content: space-between;align-items:center;">
        <div>委托单信息</div>
        <div>
          <el-cascader
            v-model="addObj.quarterItemId"
            :disabled="active>1"
            :options="quarterItemOptions"
            size="small"
            style="width: 380px"
            @focus="getQuarterOnOrderList"></el-cascader>
          <el-select v-show="active==1" v-model="template" placeholder="下单模板" size="small"
                     @change="selectInsOrderTemplateById">
            <el-option v-for="(a, ai) in templates" :key="ai" :label="a.name" :value="a.id">
              <div style="display: flex; align-items: center; justify-content: space-between;">
                <span>{{ a.name }}</span>
                <i class="el-icon-delete"
                   style="color: #66b1ff; font-size: 16px; cursor: pointer;"
                   @click.stop="handleDelete(a)">
                </i>
              </div>
            </el-option>
          </el-select>
          <el-button v-show="active==1" size="small" @click="templateDia=true">
            <span style="color: #3A7BFA;">保存模板</span>
          </el-button>
          <el-button v-if="active==1&&addObj.sampleType!=undefined&&(addObj.sampleType.indexOf('电缆')>-1 ||addObj.sampleType.indexOf('综合')>-1)" size="small" type="primary" @click="openCableConfig">电缆配置</el-button>
          <el-button v-if="active==1&&addObj.sampleType!=undefined&&addObj.sampleType.indexOf('电缆')>-1" size="small" type="primary" @click="openAuxiliaryCore">辅助线芯配置</el-button>
          <el-button v-show="active==1||(tabIndex==4&&active==2)" :loading="saveLoad" size="small" type="primary" @click="save">提交</el-button>
          <!-- 审核 -->
          <el-button v-show="active==3" :disabled="saveLoad" :loading="saveLoad" size="small"
                     @click="upInsOrderOfState(2)">不通过</el-button>
          <el-button v-show="active==3" :loading="saveLoad" size="small" type="primary"
                     @click="upInsOrderOfState(1)">通过</el-button>
          <el-button size="small" @click="goBack">
            <span style="color: #3A7BFA;">返回</span>
          </el-button>
        </div>
    <div v-show="!cableConfigShow&&!auxiliaryShow" class="order-header">
      <span class="order-header__title">委托单信息</span>
      <div class="order-header__actions">
<!--        <el-cascader-->
<!--          v-model="addObj.quarterItemId"-->
<!--          :disabled="active>1"-->
<!--          :options="quarterItemOptions"-->
<!--          placeholder="请选择季度"-->
<!--          size="small"-->
<!--          class="order-header__quarter"-->
<!--          @focus="getQuarterOnOrderList"></el-cascader>-->
        <el-select v-show="active==1" v-model="template" placeholder="下单模板" size="small"
                   class="order-header__template"
                   @change="selectInsOrderTemplateById">
          <el-option v-for="(a, ai) in templates" :key="ai" :label="a.name" :value="a.id">
            <div style="display: flex; align-items: center; justify-content: space-between;">
              <span>{{ a.name }}</span>
              <i class="el-icon-delete"
                 style="color: #66b1ff; font-size: 16px; cursor: pointer;"
                 @click.stop="handleDelete(a)">
              </i>
            </div>
          </el-option>
        </el-select>
        <el-button v-show="active==1" size="small" @click="templateDia=true">保存模板</el-button>
        <el-button v-if="active==1&&addObj.sampleType!=undefined&&(addObj.sampleType.indexOf('电缆')>-1 ||addObj.sampleType.indexOf('综合')>-1)" size="small" type="primary" plain @click="openCableConfig">电缆配置</el-button>
        <el-button v-if="active==1&&addObj.sampleType!=undefined&&addObj.sampleType.indexOf('电缆')>-1" size="small" type="primary" plain @click="openAuxiliaryCore">辅助线芯配置</el-button>
        <el-button v-show="active==1||(tabIndex==4&&active==2)" :loading="saveLoad" size="small" type="primary" @click="save">提交</el-button>
        <!-- 审核 -->
        <el-button v-show="active==3" :disabled="saveLoad" :loading="saveLoad" size="small"
                   @click="upInsOrderOfState(2)">不通过</el-button>
        <el-button v-show="active==3" :loading="saveLoad" size="small" type="primary"
                   @click="upInsOrderOfState(1)">通过</el-button>
        <el-button size="small" @click="goBack">返回</el-button>
      </div>
    </div>
    <div v-show="!cableConfigShow&&!auxiliaryShow" style="margin-top: 10px">
      <div class="search">
        <el-form ref="addObj" :inline="true" :model="addObj" :rules="addObjRules" label-width="108px" label-position="right">
    <div v-show="!cableConfigShow&&!auxiliaryShow" class="order-body">
      <el-card shadow="never" class="order-card">
        <el-form ref="newJuOrder" :model="addObj" size="small" label-width="108px" label-position="right">
          <el-row :gutter="16">
            <el-col :span="6"><el-form-item label="检测依据"><el-input v-model="addObj.sample" disabled size="small"><template slot="append"><el-button :disabled="active>1" icon="el-icon-search" @click="selectStandardTree = true" /></template></el-input></el-form-item></el-col>
            <el-col :span="18">
              <el-form-item label="原始记录模板">
                <div v-loading="templateBindingLoading" class="template-tag-list">
                  <el-tag v-for="(item, index) in boundTemplateList" :key="item.templateId" :closable="active==1" size="small" effect="plain" @close="removeBoundTemplate(index)">{{ item.name }}</el-tag>
                  <span v-if="!templateBindingLoading && boundTemplateList.length === 0" class="empty-template-text">暂未绑定原始记录模板</span>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="16">
            <el-col :span="6"><el-form-item label="样品名称"><el-input v-model="addObj.sampleView" :disabled="active>1" size="small" /></el-form-item></el-col>
            <el-col :span="6"><el-form-item label="生产单位"><el-input v-model="addObj.production" :disabled="active>1" size="small" /></el-form-item></el-col>
            <el-col :span="6"><el-form-item label="委托单位"><el-input v-model="addObj.company" disabled size="small"><template slot="append"><el-button :disabled="active>1" icon="el-icon-search" @click="openCompanyList" /></template></el-input></el-form-item></el-col>
            <el-col :span="6"><el-form-item label="检验类别"><el-select v-model="addObj.orderType" :disabled="active>1" size="small"><el-option v-for="item in dict.type.check_type1" :key="item.value" :label="item.label" :value="item.value" /></el-select></el-form-item></el-col>
          </el-row>
          <el-row :gutter="16">
            <el-col :span="6"><el-form-item label="样品数量"><el-input v-model="addObj.testQuantity" :disabled="active>1" placeholder="如:2桶、500mL" size="small" /></el-form-item></el-col>
            <el-col :span="6"><el-form-item label="样品编号"><el-input v-model="sampleCode" :disabled="active>1" size="small" /></el-form-item></el-col>
            <el-col :span="6"><el-form-item label="样品外观"><el-input v-model="addObj.sampleStatus" :disabled="active>1" size="small" /></el-form-item></el-col>
            <el-col :span="6"><el-form-item label="送样人"><el-input v-model="addObj.prepareUser" :disabled="active>1" size="small" /></el-form-item></el-col>
          </el-row>
          <el-row :gutter="16">
            <el-col :span="6"><el-form-item label="生产日期"><el-date-picker v-model="addObj.productionDate" type="date" value-format="yyyy-MM-dd" :disabled="active>1" size="small" /></el-form-item></el-col>
            <el-col :span="6"><el-form-item label="生产批号"><el-input v-model="addObj.productionBatch" :disabled="active>1" size="small" /></el-form-item></el-col>
            <el-col :span="6"><el-form-item label="送样日期"><el-date-picker v-model="addObj.sampleDate" type="date" value-format="yyyy-MM-dd" :disabled="active>1" size="small" /></el-form-item></el-col>
            <el-col :span="6"><el-form-item label="联系方式"><el-input v-model="addObj.phone" :disabled="active>1" size="small" /></el-form-item></el-col>
          </el-row>
          <el-row :gutter="16"><el-col :span="12"><el-form-item label="备注"><el-input v-model="addObj.remark" :disabled="active>1" size="small" /></el-form-item></el-col></el-row>
        </el-form>
        <el-form v-if="false" ref="addObj" :inline="true" :model="addObj" :rules="addObjRules" label-width="108px" label-position="right">
          <el-row>
            <el-col :span="6">
              <el-form-item label="委托编号:" prop="entrustCode">
@@ -204,8 +232,8 @@
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div>
      </el-card>
      <div v-if="false">
        <div style="display: flex;justify-content: space-between;background-color: #F5F7FB;margin-bottom: 6px">
          <div v-if="active==1">
            <el-form :inline="true" :model="addObj1" label-width="90px">
@@ -427,7 +455,7 @@
              <el-col :span="24">
                <span><i
                    :class="`node_i ${data.children != undefined ? (data.code==='[1]'?'el-icon-folder-opened':'el-icon-folder') : 'el-icon-tickets'}`"></i>
                  {{ data.code }} {{ data.label }}</span>
                  {{ data.label }}</span>
              </el-col>
            </el-row>
          </div>
@@ -606,12 +634,17 @@
  upInsOrderOfState
} from "@/api/business/add";
import {selectUserCondition} from "@/api/performance/class";
import {selectsStandardMethodByFLSSM} from "@/api/standard/standardLibrary";
import {selectTemplateBindings, selectsStandardMethodByFLSSM} from "@/api/standard/standardLibrary";
import limsTable from "@/components/Table/lims-table.vue";
import {selectCustomPageList} from "@/api/system/customer";
import {mapGetters} from "vuex";
import { bigEval } from "@/utils/bigEval";
import {addQuarter, updateQuarterOnOrder} from "@/api/business/finishedProductSampling";
import {
  isLeafPath,
  buildSelectTree,
  dropLastLabel,
} from "@/utils/standardTree";
export default {
  name: 'AddOrder',
@@ -638,6 +671,9 @@
      active: '',
      tabIndex: '',
      currentId: '',
      sampleCode: '',
      boundTemplateList: [],
      templateBindingLoading: false,
      sampleSelectionList: [],//样品表格选中数据
      editTable:[],
      template: null,
@@ -666,7 +702,7 @@
        orderType: null,
        send: 1,
        formType: '送检', //  来样方式
        sampleStatus: 'In good condition', // 样品状态
        sampleStatus: '', // 样品状态
        testQuantity: '', // 样品状态
        production: null,
        productionEn: null,
@@ -692,7 +728,7 @@
          { required: true, message: '请选择紧急程度', trigger: 'change' }
        ],
        sample: [
          { required: true, message: '请选择样品名称', trigger: 'change' }
          { required: true, message: '请选择检测依据', trigger: 'change' }
        ],
        sampleNum: [
          { required: true, message: '请填写样品数量', trigger: 'blur' }
@@ -744,6 +780,8 @@
      list: [],
      selectStandardTreeLoading: false,
      selectTree: null,
      // 当前选中的树节点(用于按层级推导字段)
      selectTreeNode: null,
      sampleViewEn: null,
      expandedKeys: [],
      sampleList: [],
@@ -919,6 +957,8 @@
          };
          this.addObj.type = String(this.addObj.type)
          const samples = this.HaveJson(res.data.sampleProduct)
          this.sampleCode = samples.length ? samples[0].sampleCode || '' : ''
          this.boundTemplateList = this.sortTemplateList(res.data.templateList)
          const loadSamples = this.canSelectProduct
            ? Promise.all(samples.map(sample => this.loadSelectableProducts(sample)))
            : Promise.resolve(samples)
@@ -1149,6 +1189,14 @@
        return str.replaceAll(find, value);
      },
      save() {
        if (this.addObj.standardTreeId) {
          if (!this.addObj.sample || !this.addObj.company || !this.addObj.orderType || !this.addObj.testQuantity) {
            this.$message.error('请填写检测依据、委托单位、检验类别和样品数量');
            return;
          }
          this.saveData([]);
          return;
        }
        this.$refs['addObj'].validate((valid) => {
          if (valid) {
            this.sampleList.forEach(item => {
@@ -1329,6 +1377,10 @@
        }
      },
      saveMethod(sampleList){
        if (this.addObj.standardTreeId) {
          this.saveData([]);
          return;
        }
        if (this.addObj.quarterItemId) {
          this.addObj.quarterItemId = this.addObj.quarterItemId[1]
        }
@@ -1375,7 +1427,18 @@
        })
      }else{
        // 常规提交
        addInsOrder({insOrder: {...this.addObj,typeSource:-1}, sampleList: sampleList}).then(res => {
        const newJuOrder = {...this.addObj,typeSource:-1}
        delete newJuOrder.temperature
        delete newJuOrder.humidity
        const payload = this.addObj.standardTreeId
          ? {
              insOrder: newJuOrder,
              standardTreeId: this.addObj.standardTreeId,
              sampleCode: this.sampleCode,
              templateList: this.boundTemplateList.map((item, index) => ({ templateId: item.templateId, sort: index }))
            }
          : { insOrder: {...this.addObj,typeSource:-1}, sampleList: sampleList }
        addInsOrder(payload).then(res => {
          this.saveLoad = false
          this.$message.success('已提交')
          this.bsm3Dia = false;
@@ -1470,9 +1533,9 @@
      },
      nodeOpen(data, node, el) {
        $($(el.$el).find('.node_i')[0]).attr('class', 'node_i el-icon-folder-opened')
        if (node.data.code === '[3]') {
        if (data.sampleTypeEn !== undefined && data.sampleTypeEn !== null) {
          this.sampleViewEn = data.sampleTypeEn
        } else if (node.data.code === '[4]') {
        } else if (data.sampleEn !== undefined && data.sampleEn !== null) {
          this.sampleViewEn = data.sampleEn
        }
      },
@@ -1480,47 +1543,13 @@
        $($(el.$el).find('.node_i')[0]).attr('class', 'node_i el-icon-folder')
      },
      handleNodeClick(val, node, el) {
        this.selectTree = ''
        this.models = val.children
        this.getNodeParent(node)
        let flag = false
        if (node.level == 3) {
          if(node.data.children.length>0){
            node.data.children.forEach(a => {
              let key = Object.keys(a)
              if(!key.includes('level')) {
                flag = true
              }
            })
          }
        }
        if (node.data.code === '[3]') {
        this.selectTreeNode = node
        this.models = val.children || []
        this.selectTree = buildSelectTree(node, '')
        if (val.sampleTypeEn !== undefined && val.sampleTypeEn !== null) {
          this.sampleViewEn = val.sampleTypeEn
        } else if (node.data.code === '[4]') {
          if (node.data.children!==null && node.data.children.length>0) {
            this.sampleViewEn = val.sampleEn
          }
        }
        this.selectTree = this.selectTree.replace(' - ', '')
        if(flag) {
          this.selectTree =  ' -  - ' + this.selectTree
        }
        let data = this.selectTree.split(' - ')
        let data2 = ''
        for (let index = data.length - 1; index >= 0; index--) {
          data2 += " - " + data[index]
        }
        this.selectTree = data2.replace(' - ', '')
      },
      getNodeParent(val) {
        if (val.parent != null) {
          if (val.data.children === null) {
            this.selectTree += ' - ' + val.label + ' - ' + ''
          } else {
            this.selectTree += ' - ' + val.label
          }
          this.getNodeParent(val.parent)
        } else if (val.sampleEn !== undefined && val.sampleEn !== null) {
          this.sampleViewEn = val.sampleEn
        }
      },
      selectStandardTreeList() {
@@ -1538,42 +1567,42 @@
        return data.label.indexOf(value) !== -1;
      },
      activeStandardTree() {
        let trees = this.selectTree.split(" - ")
        if (trees.length < 3) {
          this.$message.error('未选择对象')
        if (!this.selectTreeNode || this.selectTreeNode.data.code !== '[2]') {
          this.$message.error('请选择二级产品')
          return
        }
        this.addObj.factory = trees[0]
        this.addObj.laboratory = trees[1]
        this.addObj.sampleType = trees[2]
        if (trees[3] === undefined || trees[3] === '' || trees[3] === '- ') {
          this.addObj.sample = trees[2]
        } else {
          this.addObj.sample = trees[3]
        }
        this.addObj.sampleView = this.addObj.sample
        this.addObj.sampleViewEn = this.sampleViewEn
        this.addObj.model = (trees[4] == undefined ? null : trees[4])
        const productName = this.selectTreeNode.data.label
        this.addObj.sample = productName
        this.addObj.standardTreeId = this.selectTreeNode.data.id
        this.loadTemplateBindings(this.addObj.standardTreeId)
        this.selectStandardTree = false
        this.sampleList = []
        for (var i = 0; i < this.addObj.sampleNum; i++) {
          this.sample.joinName = null
          this.sample.joinModel = null
          this.sample.joinNum = 1
          this.sample.sample = this.addObj.sample
          this.sample.model = this.addObj.model
          this.sample.unit = this.addObj.unit
          this.sample.standardMethodListId = null
          this.sample.insProduct = []
          this.sample.id = this.count
          this.sample.childSampleList = []
          this.sample.insulating = null
          this.sample.sheath = null
          this.sampleList.push(this.HaveJson(this.sample))
          this.count++
      },
      sortTemplateList(list) {
        return (list || []).slice().sort((a, b) => (a.sort || 0) - (b.sort || 0))
      },
      // 下单时从标准库绑定的模板里删减,提交时随 templateList 一起下发
      removeBoundTemplate(index) {
        this.boundTemplateList.splice(index, 1)
      },
      async loadTemplateBindings(standardTreeId) {
        this.boundTemplateList = []
        if (!standardTreeId) return
        this.templateBindingLoading = true
        try {
          const res = await selectTemplateBindings({standardTreeId})
          this.boundTemplateList = this.sortTemplateList(res.data)
        } finally {
          this.templateBindingLoading = false
        }
        this.$refs.sampleTable.doLayout()
        // this.selectsStandardMethodByFLSSM()
      },
      // 用指定型号替换树路径末段(末段即标准/型号)
      buildFactoryPath(model) {
        const tree = this.selectTree || ''
        if (!tree || !model) return tree
        const tokens = tree.split(' - ')
        tokens[tokens.length - 1] = model
        return tokens.join(' - ')
      },
      selectsStandardMethodByFLSSMList() {
        this.methodLoad = true
@@ -1581,20 +1610,21 @@
          tree: this.selectTree
        }).then(res => {
          this.methodLoad = false
          try {
            if (res.data.standardMethodList.length == 0 && this.selectTree.split('-').length == 5) {
              let arr = this.selectTree.split('-')
              let arr0 = arr.slice(0, arr.length - 1)
              let selectTree = arr0.join('-').substring(0, arr0.join('-').length - 1)
          const list = (res.data && res.data.standardMethodList) || []
          // 当前是叶子(标准)却查不到标准时,回退到父级再查一次
          // 用路径判定叶子:模板回填时 selectTreeNode 为空,节点对象判定会失效
          if (list.length === 0 && isLeafPath(this.selectTree)) {
            const parentTree = dropLastLabel(this.selectTree)
            if (parentTree) {
              selectsStandardMethodByFLSSM({
                tree: selectTree
                tree: parentTree
              }).then(ress => {
                this.methods = ress.data.standardMethodList
                this.methods = (ress.data && ress.data.standardMethodList) || []
              })
            } else {
              this.methods = res.data.standardMethodList
              return
            }
          } catch (e) {}
          }
          this.methods = list
        })
      },
      addStandardTree() {
@@ -1833,13 +1863,11 @@
          }
        }
        this.getProductLoad = true
        let selectTreeList = this.selectTree.split(" - ")
        this.addObj.model&&(selectTreeList[selectTreeList.length - 1] = this.addObj.model)
        selectStandardProductList({
          model: this.addObj.model?this.addObj.model:row.model,
          modelNum: row.modelNum,
          standardMethodListId: val,
          factory: selectTreeList.join(" - "),
          factory: this.buildFactoryPath(this.addObj.model),
          cores: row.cores,
          conductorMaterial: row.conductorMaterial,
          conductorType: row.conductorType,
@@ -1900,14 +1928,12 @@
          this.isAskOnlyRead = false
        }
        this.getProductLoad = true
        let selectTreeList = this.selectTree.split(" - ")
        this.addObj.model&&(selectTreeList[selectTreeList.length - 1] = this.addObj.model)
        selectStandardProductList({
          model: this.addObj.model?this.addObj.model:row.model,
          modelNum: row.modelNum,
          standardMethodListId: val,
          cores: row.cores,
          factory: selectTreeList.join(" - "),
          factory: this.buildFactoryPath(this.addObj.model),
        }).then(res => {
          res.data.forEach(a => {
            a.state = this.inspectionScope === 'all' ? 1 : 0
@@ -1949,13 +1975,13 @@
      },
      handleChangeModel(e) {
        this.productList = []
        let num = this.selectTree.split('-').length;
        if (num != 5) {
          this.selectTree = this.selectTree + ' - ' + e
        const tree = this.selectTree || ''
        // 路径末段已是标准(叶子):替换末段;否则追加
        // 用路径判定:模板回填(obj.selectTree)时没有可用的树节点对象
        if (isLeafPath(tree)) {
          this.selectTree = this.buildFactoryPath(e)
        } else {
          let arr = this.selectTree.split('-')
          let arr0 = arr.slice(0, arr.length - 1)
          this.selectTree = arr0.join('-') + '- ' + e
          this.selectTree = tree ? tree + ' - ' + e : e
        }
      },
      // 要求值变化时
@@ -2091,13 +2117,7 @@
        const selectedProducts = sample.insProduct || []
        if (!sample.standardMethodListId) return Promise.resolve(sample)
        const product = selectedProducts[0] || {}
        const factory = [
          product.factory || this.addObj.factory,
          product.laboratory || this.addObj.laboratory,
          product.sampleType || this.addObj.sampleType,
          product.sample || sample.sample,
          product.model || sample.model
        ].join(' - ')
        const factory = this.buildFactoryPath(product.model || sample.model)
        return selectStandardProductList({
          model: sample.model,
          modelNum: sample.modelNum,
@@ -2365,4 +2385,71 @@
  color: orange;
  font-size: 18px;
}
.template-tag-list {
  min-height: 32px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.empty-template-text {
  color: #909399;
}
/* 委托单信息:顶部操作栏 */
.order-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid #ebeef5;
}
.order-header__title {
  font-size: 16px;
  font-weight: bold;
  color: #303133;
}
.order-header__actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
/* 间距统一交给 gap,去掉相邻按钮自带的 margin-left */
.order-header__actions>>>.el-button+.el-button {
  margin-left: 0;
}
.order-header__quarter {
  width: 220px;
}
.order-header__template {
  width: 160px;
}
/* 委托单信息:表单卡片 */
.order-body {
  margin-top: 12px;
}
.order-card>>>.el-card__body {
  padding: 20px 20px 6px;
}
.order-card>>>.el-form-item {
  margin-bottom: 16px;
}
/* 控件统一占满标签之外的整列宽度:el-date-editor 默认写死 220px、
   el-select 宽度收缩成固有宽度,不指定就会和其他输入框左右边缘对不齐 */
.order-card>>>.el-input,
.order-card>>>.el-select {
  width: 100%;
}
/* append 单元格的 20px 内边距 + 按钮 -10px 负边距是按默认 40px 按钮标定的,
   small 输入下按钮会比输入框高、上下溢出;改成按钮直接撑满单元格 */
.order-card>>>.el-input-group__append {
  padding: 0;
}
.order-card>>>.el-input-group__append .el-button {
  margin: 0;
  padding: 9px 15px;
  font-size: 12px;
}
</style>