src/views/business/productOrder/components/addOrder.vue
@@ -612,6 +612,12 @@
import {mapGetters} from "vuex";
import { bigEval } from "@/utils/bigEval";
import {addQuarter, updateQuarterOnOrder} from "@/api/business/finishedProductSampling";
import {
  isLeafPath,
  buildSelectTree,
  deriveTreeFields,
  dropLastLabel,
} from "@/utils/standardTree";
export default {
  name: 'AddOrder',
@@ -744,6 +750,8 @@
      list: [],
      selectStandardTreeLoading: false,
      selectTree: null,
      // 当前选中的树节点(用于按层级推导字段)
      selectTreeNode: null,
      sampleViewEn: null,
      expandedKeys: [],
      sampleList: [],
@@ -1470,9 +1478,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 +1488,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,22 +1512,18 @@
        return data.label.indexOf(value) !== -1;
      },
      activeStandardTree() {
        let trees = this.selectTree.split(" - ")
        if (trees.length < 3) {
        const fields = deriveTreeFields(this.selectTreeNode)
        if (fields.labels.length < 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.factory = fields.factory
        this.addObj.laboratory = fields.laboratory
        this.addObj.sampleType = fields.sampleType
        this.addObj.sample = fields.sample || fields.sampleType
        this.addObj.sampleView = this.addObj.sample
        this.addObj.sampleViewEn = this.sampleViewEn
        this.addObj.model = (trees[4] == undefined ? null : trees[4])
        this.addObj.model = fields.model
        this.selectStandardTree = false
        this.sampleList = []
        for (var i = 0; i < this.addObj.sampleNum; i++) {
@@ -1575,26 +1545,35 @@
        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
        selectsStandardMethodByFLSSM({
          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 +1812,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 +1877,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 +1924,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 +2066,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,