src/views/sales/salesDetails/index.vue
@@ -50,6 +50,9 @@
                  <template v-if="scope.row.status === 3||scope.row.status === 4">
                    <el-button @click.stop="shipmentsClick(scope.row)" type="text" size="small">发货</el-button>
                  </template>
                  <template v-if="scope.row.status === 3||scope.row.status === 4">
                    <el-button @click.stop="confirmClick(scope.row)" type="text" size="small">确认完成</el-button>
                  </template>
                </template>
              </el-table-column>
            </template>
@@ -176,7 +179,8 @@
  getProductOrderInfo,
  updateStatus,
  getProjectList,
  sendSalesDetailsToOtherSystem
  sendSalesDetailsToOtherSystem,
  confirmOutputOver
} from "@/api/sales/salesDetails"
import pageMixin from "@/components/makepager/pager/mixin/pageMixin"
import DetailSpecification from "@/views/sales/salesDetails/DetailSpecification"
@@ -217,11 +221,26 @@
      { label: "产品规格", prop: "specs" },
      { label: "单位", prop: "unit" },
      { label: "订单数量", prop: "amount" },
      { label: "已完成数量", prop: "finishAmount" },
      { label: "已发货数量", prop: "deliveryAmount" },
      { label: "采购数量", prop: "purchaseAmount" },
      { label: "生产数量", prop: "makeAmount" },
      { label: "委外数量", prop: "outsourcingAmount" },
      {
        label: "已完成数量",
        prop: "finishAmount",
        isClass: true,
        getClassName: this.getAmountClassName,
      },
      { label: "已发货数量", prop: "deliveryAmount",
        isClass: true,
        getClassName: this.getAmountClassName,  },
      { label: "采购数量",
        isClass: true,
        getClassName: this.getFinishAmountClassName,
        prop: "purchaseAmount",
      },
      { label: "生产数量", prop: "makeAmount" ,
        isClass: true,
        getClassName: this.getFinishAmountClassName, },
      { label: "委外数量", prop: "outsourcingAmount",
        isClass: true,
        getClassName: this.getFinishAmountClassName,  },
      { label: "销售单价", prop: "price", price: true },
      { label: "成本单价", prop: "cost" },
      { label: "毛利", prop: "profit" },
@@ -241,7 +260,7 @@
      { label: "承运商", prop: "carrier" },
      { label: "运单号", prop: "waybill" },
      { label: "创建时间", prop: "warehouse" },
      { label: "状态", prop: "status" },
      { label: "状态", prop: "status",isCallMethod: true,getCallMethod: this.getStatusFive },
    ]
    // 制造信息
    const makeColumn = [
@@ -318,57 +337,47 @@
      {
        label: "委外订单",
        prop: "outsourcingId",
        default: true
      },
      {
        label: "产品编号",
        prop: "productId",
        default: true
      },
      {
        label: "产品名称",
        prop: "productName",
        default: true
      },
      {
        label: "产品规格",
        prop: "specs",
        default: true
      },
      {
        label: "产品单位",
        prop: "unit",
        default: true
      },
      {
        label: "委外数量",
        prop: "amount",
        default: true
      },
      {
        label: "完成数量",
        prop: "finishAmount",
        default: true
      },
      {
        label: "订单状态",
        prop: "status",
        default: true
        default: true, isCallMethod: true, getCallMethod: this.getStatus
      },
      {
        label: "委外供应商",
        prop: "supplierName",
        default: true
      },
      {
        label: "签约日期",
        prop: "startTime",
        default: true
      },
      {
        label: "交付日期",
        prop: "endTime",
        default: true
      },
    ]
    return {
@@ -439,7 +448,7 @@
      TabsIndex: "0",
      productTableList: {},
      productColumn: productColumn,
      showProductCol: ["产品编号", "产品名称","产品规格", "单位", "订单数量", "已完成数量", "已发货数量", "采购数量", "生产数量", "委外数量","销售单价","成本单价","毛利","毛利率","价税合计"],
      showProductCol: ["产品编号", "产品名称","产品规格", "单位", "订单数量", "已完成数量", "已发货数量", "采购数量", "生产数量", "委外数量","销售单价","成本单价","毛利","毛利率(%)","价税合计"],
      inventoryColumn: inventoryColumn,
      showInventoryCol: [
        "出库单",
@@ -456,7 +465,7 @@
        "状态"
      ],
      makeColumn: makeColumn,
      showMakeCol: ["生产订单", "产品名称", "订单状态", "工单编号", "工单状态", "计划开始时间", "计划结束时间"],
      showMakeCol: ["生产订单", "产品编号", "产品名称", "产品规格", "产品单位", "订单数量", "完成数量","工单编号","工单状态","计划开始时间","计划结束时间"],
      // 采购
      purchaseColumn: purchaseColumn,
      outsourceColumn:outsourceColumn,
@@ -473,7 +482,9 @@
        projectId: [{ required: true, message: "请选择项目", trigger: "change" }]
      },
      purchaseStatusList: getDataByType("purchaseStatus"),
      loading: false
      loading: false,
      isRequest: true, //请求
      productDataBottom:{},
    }
  },
  created() {
@@ -489,6 +500,29 @@
    this.getProjectList()
  },
  methods: {
    getFinishAmountClassName(val, row) {
      let parts = val.split("/");
      let numerator = parseInt(parts[0], 10); // 分子
      let denominator = parseInt(parts[1], 10); // 分母
      let classname = "";
      if (numerator / denominator === 0||numerator===0) {
        classname = "error";
      }else if(numerator / denominator === 1){
        classname = "success";
      }else if((numerator / denominator) > 0&&(numerator / denominator) <1){
        classname = "warning-radio";
      }
      console.log(classname, numerator,denominator,"看下")
      return classname;
    },
    getAmountClassName(val){
      console.log(val,"val11")
      let classname = "";
      if(val===0){
        classname = "error";
      }
      return classname;
    },
    getpurchaseStatus(val) {
      if (val) {
        for (let i in this.purchaseStatusList) {
@@ -618,21 +652,12 @@
        })
    },
    // 获取产品/库存信息
    async getProductInventoryInfo(row) {
      if (this.TabsIndex == 0 || row.status == 1) {
        this.getProductOrderInfo(row)
        // row.products.map((item)=>{
        //   item.purchaseAmount=item.purchaseFinishAmount+"/"+item.purchaseAmount
        //   item.makeAmount=item.makeFinishAmount+"/"+item.makeAmount
        //   item.outsourcingAmount=item.outsourcingFinishAmount+"/"+item.outsourcingAmount
        // })
        // this.productTableList.tableInfomation = row.products || []
      } else {
        if (row.number) {
    async getProductInventoryInfo(number) {
        if (number) {
          this.loading = true
          await getProductInventoryInfo(row.number)
          await getProductInventoryInfo(number)
            .then((res) => {
              console.log(res,"resss")
              this.productTableList.tableInfomation = res.data?.length > 0 ? res.data : []
              this.loading = false
            })
@@ -641,15 +666,65 @@
              this.loading = false
            })
        }
      }
    },
    // 获取制造信息
    async getProductOrderInfo(number) {
      if (number) {
        this.loading = true
        await getProductOrderInfo(number)
          .then((res) => {
            if (this.TabsIndex == 0) {
        if (this.TabsIndex == 0) {
          // 产品信息列表
          this.tableBottomColumn = this.productColumn // 表头
          this.showBottomCol = this.showProductCol  // 动态表头
          this.setBottomList()
        }else if(this.TabsIndex == 1){
          // 发货信息列表
          this.tableBottomColumn = this.inventoryColumn
          this.showBottomCol = this.showInventoryCol
          this.setBottomList()
        }else if (this.TabsIndex == 2) {
          // 制造信息列表
          this.tableBottomColumn = this.makeColumn
          this.showBottomCol = this.showMakeCol
          this.setBottomList()
        } else if (this.TabsIndex == 3) {
          // 采购信息列表
          this.tableBottomColumn = this.purchaseColumn
          this.showBottomCol = this.showPurchaseCol
          this.setBottomList()
        }else if (this.TabsIndex == 4) {
          // 委外信息列表
          this.tableBottomColumn = this.outsourceColumn
          this.showBottomCol = this.showOutsourceCol
          this.setBottomList()
        }
        console.log(this.isRequest,'===isRequest')
        if (this.TabsIndex != 1&&this.isRequest == false) {
          this.isRequest = true;
          this.getListValue(this.productDataBottom)
          return true;
        }
          if (this.TabsIndex == 1&&this.selectRow.status == 1) {
            this.productTableList.tableInfomation = []
          }
          console.log(this.selectRow,"看看")
          this.getProductInventoryInfo(number)
          this.loading = true
          await getProductOrderInfo(number)
            .then((res) => {
              this.productDataBottom=res;
              this.getListValue(this.productDataBottom)
              this.loading = false
            })
            .catch(() => {
              this.productTableList.tableInfomation = []
              this.loading = false
            })
      }
    },
    getListValue(res){
      if (this.TabsIndex == 0) {
              if(res&&res.data){
                res.data.productInfo.map((item=>{
                  item.purchaseAmount=item.purchaseFinishAmount+"/"+item.purchaseAmount
@@ -658,22 +733,13 @@
                }))
              }
              this.productTableList.tableInfomation = res.data && res.data.productInfo ? res.data.productInfo : []
            } else if (this.TabsIndex == 1) {
              this.productTableList.tableInfomation = res.data ? res.data : []
            } else if (this.TabsIndex == 2) {
            }  else if (this.TabsIndex == 2) {
              this.productTableList.tableInfomation = res.data && res.data.makeInfo ? res.data.makeInfo : []
            } else if (this.TabsIndex == 3) {
              this.productTableList.tableInfomation = res.data && res.data.purchaseInfo ? res.data.purchaseInfo : []
            } else if(this.TabsIndex == 4) {
              this.productTableList.tableInfomation = res.data && res.data.outsourcingInfo ? res.data.outsourcingInfo : []
            }
            this.loading = false
          })
          .catch(() => {
            this.productTableList.tableInfomation = []
            this.loading = false
          })
      }
    },
    // 搜索
    onFilterSearch(searchText) {
@@ -733,8 +799,78 @@
    shipmentsClick(row){
      this.editShipmentsConfig.visible=true
      this.editShipmentsConfig.infomation.saleDetailID=row.id
      this.editShipmentsConfig.infomation.deliverType=row.deliverType?row.deliverType:1
      this.editShipmentsConfig.infomation.saleDetailNumber=row.number
      this.editShipmentsConfig.infomation.projectId=row.projectId
    },
    // 确认发货完成
    async confirmClick(row){
      this.selectRow = row
      await getProductInventoryInfo(this.selectRow.number)
        .then((res) => {
          console.log(res,"resss")
          if(res.data){
          this.productTableList.tableInfomation = res.data?.length > 0 ? res.data : []
            // let accumulator=res.data
            // const reducedArray = array.reduce((accumulator, currentItem) => {
            //   // 查找当前number是否已存在于accumulator中
            //   const existingItem = accumulator.find(item => item.number === currentItem.number);
            //   if (existingItem) {
            //     // 如果存在,累加num
            //     existingItem.amount += currentItem.amount;
            //   } else {
            //     // 如果不存在,将当前项添加到accumulator中
            //     accumulator.push(currentItem);
            //   }
            //   return accumulator;
            // }, []); // 初始化accumulator为一个空数组
            // console.log(reducedArray,"新数组");
          }
          this.loading = false
        })
        // let obj=[
        //   {
        //     name:"小明",
        //     id:1,
        //     num:10
        //   },
        //   {
        //     name:"小明",
        //     id:1,
        //     num:20
        //   },
        //   {
        //     name:"小明",
        //     id:1,
        //     num:5
        //   },
        //   {
        //     name:"小红",
        //     id:1,
        //     num:5
        //   },
        //   {
        //     name:"小红",
        //     id:1,
        //     num:10
        //   },
        //   {
        //     name:"小房",
        //     id:5,
        //     num:3
        //   },
        // ]
        .catch(() => {
          this.productTableList.tableInfomation = []
          this.loading = false
        })
      // await confirmOutputOver({saleDetailNumber:row.number}).then((res)=>{
      //   if(res&&res.code===200){
      //     this.$message.success("确认发货完成")
      //     this.getData()
      //   }
      // })
    },
    // 关闭
    closeClick(row) {
@@ -812,63 +948,21 @@
    //获取当前选中资源的id
    getTab(tab) {
      this.TabsIndex = tab
      if (this.TabsIndex == 0) {
        // 产品信息列表
        this.tableBottomColumn = this.productColumn // 表头
        this.showBottomCol = this.showProductCol  // 动态表头
        this.setBottomList()
        this.getProductInventoryInfo(this.selectRow.number)
      } else if (this.TabsIndex == 1) {
        // 发货信息列表
        this.tableBottomColumn = this.inventoryColumn
        this.showBottomCol = this.showInventoryCol
        this.setBottomList()
        if (this.selectRow.status == 1) {
          this.productTableList.tableInfomation = []
        } else {
          this.getProductInventoryInfo(this.selectRow)
        }
      } else if (this.TabsIndex == 2) {
        // 制造信息列表
        this.tableBottomColumn = this.makeColumn
        this.showBottomCol = this.showMakeCol
        this.setBottomList()
        this.getProductOrderInfo(this.selectRow.number)
      } else if (this.TabsIndex == 3) {
        // 采购信息列表
        this.tableBottomColumn = this.purchaseColumn
        this.showBottomCol = this.showPurchaseCol
        this.setBottomList()
        this.getProductOrderInfo(this.selectRow.number)
      }if (this.TabsIndex == 4) {
        // 委外信息列表
        this.tableBottomColumn = this.outsourceColumn
        this.showBottomCol = this.showOutsourceCol
        this.setBottomList()
        this.getProductOrderInfo(this.selectRow.number)
      if (this.TabsIndex == 1) {
        this.isRequest =true;
      } else{
        this.isRequest = false;
      }
      this.getProductOrderInfo(this.selectRow.number)
    },
    // 状态
    getStatus(val) {
      return val === 1 ? "待确认" : val === 2 ? "待出库" : val === 3 ? "备货中" : val === 4 ? "待出库" : val === 5 ? "出库完成" : val=== 6 ? "已关闭": "--"
      return val === 1 ? "待确认" : val === 2 ? "待分解" : val === 3 ? "备货中" : val === 4 ? "待出库" : val === 5 ? "出库完成" : val=== 6 ? "已关闭": "--"
    },
    // top 行点击
    tableRowClick(row) {
      this.selectRow = row
      if (this.TabsIndex == 0) {
        this.getProductInventoryInfo(this.selectRow.number)
      } else if (this.TabsIndex == 1) {
        if (this.selectRow.status == 1) {
          this.productTableList.tableInfomation = []
        } else {
          this.getProductInventoryInfo(this.selectRow)
        }
      } else if (this.TabsIndex == 2) {
        this.getProductOrderInfo(this.selectRow.number)
      } else if (this.TabsIndex == 3) {
        // 采购信息
        this.getProductOrderInfo(this.selectRow.number)
      }
      this.getProductOrderInfo(this.selectRow.number)
    },
    // 获取项目列表
    async getProjectList() {
@@ -927,7 +1021,14 @@
          })
        }
      })
    }
    },
    getStatusFive(val) {
      if (val) {
        return val==0?'就绪':'完成'
      } else {
        return "--";
      }
    },
  }
}
</script>