elementui选中数据,加入另一个数据表格

  // 点击药品或检查项目抽屉页面的添加并关闭按钮
    hanldeAddCareItem() {
      const coType = this.submitCareOrder.careOrder.coType
      if (this.selectItemList.length === 0) {
        this.msgError('请选择【' + (coType === '0' ? '药品' : '检查项目') + '】')
        return
      }
      if (coType === '0') { // 药品
        this.selectItemList.filter(item => { // filter() 不会改变原始数组。抽屉选中的数组
          const obj = { //构造obj
            itemRefId: item.medicinesId,
            itemName: item.medicinesName,
            itemType: coType,
            num: 1,
            price: item.prescriptionPrice,
            amount: 1 * item.prescriptionPrice,
            remark: '请按说明服用'
          }
          let flag = false// 默认里面没有加
          this.submitCareOrder.careOrderItems.filter(i => {//需要往里加的药品数组
            if (i.itemRefId === obj.itemRefId) {
              i.num = i.num + 1 //如果有相同的数量加1
              flag = true// 说明之前加过
            }
          })
          if (!flag) {
            this.submitCareOrder.careOrderItems.push(obj)//如果符合条件追加obj
          }
          this.openDrawerMedicines = false
        })
      } else { // 检查项目
        this.selectItemList.filter(item => {
          const obj = {
            itemRefId: item.checkItemId,
            itemName: item.checkItemName,
            itemType: coType,
            num: 1,
            price: item.unitPrice,
            amount: 1 * item.unitPrice,
            remark: '按要求检查'
          }
          let flag = false// 默认里面没有加
          this.submitCareOrder.careOrderItems.filter(i => {
            if (i.itemRefId === obj.itemRefId) {
              i.num = i.num + 1
              flag = true// 说明之前加过
            }
          })
          if (!flag) {
            this.submitCareOrder.careOrderItems.push(obj)
          }
          this.openDrawerCheckItem = false
        })
      }
      // 计算总价
      this.computeOrderItemAllAmount()
    },

 

posted @ 2020-11-18 23:37  java_静止  阅读(1015)  评论(0编辑  收藏  举报