charles
2024-08-06 5ecb7958c96d3f0b6d47b79aff7eb306c2cf690f
src/views/operate/orderPoint/index.vue
@@ -1,21 +1,7 @@
<template>
  <div class="rightContent">
    <div class="top">
      <SearchCommonView
        :add-title="addTitle"
        :show-discard="showDiscard"
        :show-apply="false"
        :placeholder="'请输入位置/产品'"
        :amount-view="false"
        :search-task-map="searchTaskMap"
        :show-sreen="false"
        :screen-array="screenArray"
        @addCommonClick="addProductClick"
        @searchClick="getList"
        @discardBtnClick="discardBtnClick"
        @delSelectClick="delSelectClick"
        @switchKeywords="switchKeywords"
      />
      <SearchCommonView :add-title="addTitle" :show-discard="showDiscard" :show-apply="false" :placeholder="'请输入位置/产品'" :amount-view="false" :search-task-map="searchTaskMap" :show-sreen="false" :screen-array="screenArray" @addCommonClick="addProductClick" @searchClick="getList" @discardBtnClick="discardBtnClick" @delSelectClick="delSelectClick" @switchKeywords="switchKeywords" />
    </div>
    <div class="content_wrap">
      <div class="con_left">
@@ -32,24 +18,11 @@
      </div>
      <div class="list-view">
        <div class="table">
          <CommonFormTableView
            ref="tablelistRef"
            :isReorder="true"
            :product-table-list="tableList"
            @inputContent="inputContent"
            @selLocationClick="selLocationClick"
            @selProductClick="selProductClick"
            @tableRowClick="tableRowClick"
            @selRouteClick="selRouteClick"
          >
          <CommonFormTableView ref="tablelistRef" :isReorder="true" :product-table-list="tableList" @inputContent="inputContent" @selLocationClick="selLocationClick" @selProductClick="selProductClick" @tableRowClick="tableRowClick" @selRouteClick="selRouteClick">
            <template slot="tableButton">
              <el-table-column label="操作" width="180" align="center">
                <template slot-scope="scope">
                  <span
                    v-if="scope.row.isEdit && scope.row.isView"
                    @click.stop="handleOrderOnceClick(scope.row)"
                    class="yes-cursor"
                  >
                  <span v-if="scope.row.isEdit && scope.row.isView" @click.stop="handleOrderOnceClick(scope.row)" class="yes-cursor">
                    <i class="el-icon-truck"></i>
                    <span>订购一次</span>
                  </span>
@@ -67,393 +40,384 @@
</template>
<script>
import CommonFormTableView from "@/components/makepager/CommonFormTableView"
import pageMixin from "@/components/makepager/pager/mixin/pageMixin"
import {
  getReorderRuleList,
  addReorderRule,
  updateReorderRule,
  orderAgain,
  getLocationTreeList
} from "@/api/product/reorderRules"
import { currentTime } from "@/common/config/index"
export default {
  name: "ReorderRules",
  props: {},
  components: { CommonFormTableView },
  mixins: [pageMixin],
  computed: {},
  data() {
    return {
      datas: [],
      defaultProps: {
        children: "children",
        label: "jointName"
      },
      addTitle: "新建",
      showDiscard: false,
      tableList: {},
      tableData: [],
      searchOptions: [],
      countId: 0,
      isNoProduct: true, // 添加明细行时是否有产品未选择
      isRowClick: false,
      locationId: 0,
      productId: 0,
      amount: 0,
      operationId: 0,
      minInventory: 0,
      maxInventory: 1,
      orderNumber: 1,
      unit: "",
      reorderId: 0,
      searchTaskMap: [],
      type: "bh",
      screenArray: [{ id: "0", type: "bh", title: "重新订购" }]
    }
  },
  created() {
    if (this.$route.params.productId) {
      this.getData({
        productId: this.$route.params.productId,
        pageSize: 15,
        page: 1
      })
    }else if(this.$route.params.locationId){
      this.searchTaskMap=[]
      this.getData({
        id: this.$route.params.locationId,
        jointName:this.$route.params.locationName,
        // type:"",
        pageSize: 15,
        page: 1
      })
    }else {
      this.getData()
    }
    this.setTable()
    this.searchTaskMap = [{ id: "0", type: this.type, title: "重新订购" }]
    this.getLocationList()
  },
  methods: {
    setTable() {
      this.tableList = {
        tableData: this.tableData,
        selectBox: false,
        selectIndex: true,
        tableColumn: [
          { label: "产品", prop: "productName", product: true },
          { label: "位置", prop: "locationName", defaultLocation: true },
          { label: "在库数量", prop: "amount" },
          { label: "预测数量", prop: "prediction" },
          { label: "首选路线", prop: "route", route: true },
          { label: "最小数量", prop: "minInventory", inputFloat: true },
          { label: "最大数量", prop: "maxInventory", inputFloat: true },
          { label: "订购数量", prop: "orderNumber", inputFloat: true },
          { label: "计量单位", prop: "unit" }
        ]
      }
    },
    // 请求数据
    async getData(data) {
      await getReorderRuleList({
        locationId: data?.id,
        type: this.type,
        keyWord: data?.jointName,
        page: this.pagerOptions.currPage,
        pageSize: this.pagerOptions.pageSize,
        productId: data?.productId
      }).then((res) => {
        if (res.code === 200) {
          console.log(res)
          const list = res.data?.map((item) => {
            let orderNum = 0
            if (parseFloat(item.minInventory) - parseFloat(item.prediction) > 0) {
              orderNum = this.caculateOrderNumber(
                parseFloat(item.minInventory),
                parseFloat(item.maxInventory),
                parseFloat(item.prediction)
              )
            }
            return {
              ...item,
              productName: item.product.name,
              locationName: item.location.name,
              isSet: false,
              isEdit: true,
              editable: true,
              isOrder: true,
              isView: item?.minInventory - item?.prediction > 0 ? true : false,
              orderNumber: orderNum
            }
          })
          this.tableList.tableData = list || []
          this.tableData = list || []
          this.pagerOptions.totalCount = res.total
        }
      })
    },
    // 技术订购数量
    caculateOrderNumber(minInventory, maxInventory, prediction) {
      return maxInventory > minInventory ? maxInventory - prediction : minInventory - prediction
    },
    // 操作输入
    inputContent(val, prop, row) {
      console.log(row)
      if (prop === "minInventory") {
        this.minInventory = val
        if (parseFloat(this.minInventory) - parseFloat(this.prediction) > 0) {
          this.orderNumber = this.caculateOrderNumber(
            parseFloat(this.minInventory),
            parseFloat(this.maxInventory),
            parseFloat(this.prediction)
          )
        }
      } else if (prop === "maxInventory") {
        this.maxInventory = val
        if (parseFloat(this.minInventory) - parseFloat(this.prediction) > 0) {
          this.orderNumber = this.caculateOrderNumber(
            parseFloat(this.minInventory),
            parseFloat(this.maxInventory),
            parseFloat(this.prediction)
          )
        }
      } else if (prop === "orderNumber") {
        this.orderNumber = val
      }
    },
    // 新增
    addProductClick() {
      console.log(this.addTitle, "qqqqqqqqqqqq")
      this.isSel()
      if (this.isNoProduct && this.addTitle === "新建") {
        this.$refs.tablelistRef.getProductList()
        this.$refs.tablelistRef.getLocationList()
        this.addTitle = "保存"
        this.showDiscard = true
        this.isRowClick = false
        this.operationId = 0
        this.currentRowId = 0
        this.countId++
        this.tableData.unshift({
          countId: this.countId,
          amount: 0,
          minInventory: 0,
          productId: "",
          maxInventory: 0,
          orderNumber: 0,
          prediction: 0,
          locationId: 0,
          createDate: this.currentTime(),
          isSet: true,
          isEdit: false,
          editable: false,
          isOrder: true
        })
        this.tableList.tableData = this.tableData
        this.locationId = 0
        this.productId = 0
      } else {
        this.addTitle = "新建"
        this.showDiscard = false
        let requestUrl = this.currentRowId === 0 ? addReorderRule : updateReorderRule
        let params = this.saveParams()
        if(params.productId===0){
          this.$message.warning("请填写产品信息!")
        }else{
          requestUrl(params)
          .then((res) => {
            console.log(res)
            if (res.code === 200) {
              let tipStr = this.currentRowId === 0 ? "添加成功" : "修改成功"
              this.$message.success(tipStr)
              this.getData()
            }
          })
          .catch((err) => {
            console.log(err)
            this.getData()
          })
        }
        // }
      }
    },
    saveParams() {
  import CommonFormTableView from '@/components/makepager/CommonFormTableView'
  import pageMixin from '@/components/makepager/pager/mixin/pageMixin'
  import { getReorderRuleList, addReorderRule, updateReorderRule, orderAgain, getLocationTreeList } from '@/api/product/reorderRules'
  import { currentTime } from '@/common/config/index'
  export default {
    name: 'ReorderRules',
    props: {},
    components: { CommonFormTableView },
    mixins: [pageMixin],
    computed: {},
    data() {
      return {
        id: this.reorderId,
        amount: this.amount,
        locationId: this.locationId,
        maxInventory: this.maxInventory,
        minInventory: this.minInventory,
        orderNumber: this.orderNumber,
        prediction: this.prediction,
        operationId: this.operationId,
        productId: this.productId,
        route: this.route,
        unit: this.unit
        datas: [],
        defaultProps: {
          children: 'children',
          label: 'name',
        },
        addTitle: '新建',
        showDiscard: false,
        tableList: {},
        tableData: [],
        searchOptions: [],
        countId: 0,
        isNoProduct: true, // 添加明细行时是否有产品未选择
        isRowClick: false,
        locationId: 0,
        productId: 0,
        amount: 0,
        operationId: 0,
        minInventory: 0,
        maxInventory: 1,
        orderNumber: 1,
        unit: '',
        reorderId: 0,
        searchTaskMap: [],
        type: 'bh',
        screenArray: [{ id: '0', type: 'bh', title: '重新订购' }],
      }
    },
    // 是否选择产品
    isSel() {
      for (let i = 0; i < this.tableData.length; i++) {
        if (this.tableData[i].productName?.length === 0) {
          this.isNoProduct = false
          break
        } else {
          this.isNoProduct = true
        }
      }
    },
    // 取消
    discardBtnClick() {
      this.getData()
      this.addTitle = "新建"
      this.showDiscard = false
    },
    // 订购一次
    handleOrderOnceClick(row) {
      let params = {
        ...row
      }
      orderAgain(params).then((res) => {
        if (res.code === 200) {
          this.$message.success("订购成功")
          this.getData()
        }
      })
    },
    // 行点击
    tableRowClick(row, rowIndex) {
      this.locationId = row.locationId
      this.rowIndex = rowIndex
      this.reorderId = row.id
      this.isSel()
      if (!this.isNoProduct && this.currentRowId === 0) {
        this.$message.error("请完成当前新建或取消新建")
    created() {
      if (this.$route.params.productId) {
        this.getData({
          productId: this.$route.params.productId,
          pageSize: 15,
          page: 1,
        })
      } else if (this.$route.params.locationId) {
        this.searchTaskMap = []
        this.getData({
          id: this.$route.params.locationId,
          jointName: this.$route.params.locationName,
          // type:"",
          pageSize: 15,
          page: 1,
        })
      } else {
        this.currentRowId = row.id
        this.addTitle = "保存"
        this.showDiscard = true
        this.isRowClick = true
        if (!this.isNoProduct) {
          this.tableData.splice(this.tableData.length - 1, 1)
        this.getData()
      }
      this.setTable()
      this.searchTaskMap = [{ id: '0', type: this.type, title: '重新订购' }]
      this.getLocationList()
    },
    methods: {
      setTable() {
        this.tableList = {
          tableData: this.tableData,
          selectBox: false,
          selectIndex: true,
          tableColumn: [
            { label: '产品', prop: 'productName', product: true },
            { label: '位置', prop: 'locationName', defaultLocation: true },
            { label: '在库数量', prop: 'amount' },
            { label: '预测数量', prop: 'prediction' },
            { label: '首选路线', prop: 'route', route: true },
            { label: '最小数量', prop: 'minInventory', inputFloat: true },
            { label: '最大数量', prop: 'maxInventory', inputFloat: true },
            { label: '订购数量', prop: 'orderNumber', inputFloat: true },
            { label: '计量单位', prop: 'unit' },
          ],
        }
        this.tableData.map((item, index) => {
          if (index === rowIndex) {
            item.isEdit = false
            item.editable = true
            item.isOrder = true
          } else {
            item.isEdit = true
      },
      // 请求数据
      async getData(data) {
        await getReorderRuleList({
          locationId: data?.id,
          type: this.type,
          keyWord: data?.jointName,
          page: this.pagerOptions.currPage,
          pageSize: this.pagerOptions.pageSize,
          productId: data?.productId,
        }).then((res) => {
          if (res.code === 200) {
            console.log(res)
            const list = res.data?.map((item) => {
              let orderNum = 0
              if (parseFloat(item.minInventory) - parseFloat(item.prediction) > 0) {
                orderNum = this.caculateOrderNumber(parseFloat(item.minInventory), parseFloat(item.maxInventory), parseFloat(item.prediction))
              }
              return {
                ...item,
                productName: item.product.name,
                locationName: item.location.name,
                isSet: false,
                isEdit: true,
                editable: true,
                isOrder: true,
                isView: item?.minInventory - item?.prediction > 0 ? true : false,
                orderNumber: orderNum,
              }
            })
            this.tableList.tableData = list || []
            this.tableData = list || []
            this.pagerOptions.totalCount = res.total
          }
        })
        this.minInventory = row.minInventory
        this.amount = row.amount
        this.productId = row.productId
        this.maxInventory = row.maxInventory
        this.orderNumber = row.orderNumber
        this.prediction = row.prediction
      },
      // 技术订购数量
      caculateOrderNumber(minInventory, maxInventory, prediction) {
        return maxInventory > minInventory ? maxInventory - prediction : minInventory - prediction
      },
      // 操作输入
      inputContent(val, prop, row) {
        console.log(row)
        if (prop === 'minInventory') {
          this.minInventory = val
          if (parseFloat(this.minInventory) - parseFloat(this.prediction) > 0) {
            this.orderNumber = this.caculateOrderNumber(parseFloat(this.minInventory), parseFloat(this.maxInventory), parseFloat(this.prediction))
          }
        } else if (prop === 'maxInventory') {
          this.maxInventory = val
          if (parseFloat(this.minInventory) - parseFloat(this.prediction) > 0) {
            this.orderNumber = this.caculateOrderNumber(parseFloat(this.minInventory), parseFloat(this.maxInventory), parseFloat(this.prediction))
          }
        } else if (prop === 'orderNumber') {
          this.orderNumber = val
        }
      },
      // 新增
      addProductClick() {
        console.log(this.addTitle, 'qqqqqqqqqqqq')
        this.isSel()
        if (this.isNoProduct && this.addTitle === '新建') {
          this.$refs.tablelistRef.getProductList()
          this.$refs.tablelistRef.getLocationList()
          this.addTitle = '保存'
          this.showDiscard = true
          this.isRowClick = false
          this.operationId = 0
          this.currentRowId = 0
          this.countId++
          this.tableData.unshift({
            countId: this.countId,
            amount: 0,
            minInventory: 0,
            productId: '',
            maxInventory: 0,
            orderNumber: 0,
            prediction: 0,
            locationId: 0,
            createDate: this.currentTime(),
            isSet: true,
            isEdit: false,
            editable: false,
            isOrder: true,
          })
          this.tableList.tableData = this.tableData
          this.locationId = 0
          this.productId = 0
        } else {
          this.addTitle = '新建'
          this.showDiscard = false
          let requestUrl = this.currentRowId === 0 ? addReorderRule : updateReorderRule
          let params = this.saveParams()
          if (params.productId === 0) {
            this.$message.warning('请填写产品信息!')
          } else {
            requestUrl(params)
              .then((res) => {
                console.log(res)
                if (res.code === 200) {
                  let tipStr = this.currentRowId === 0 ? '添加成功' : '修改成功'
                  this.$message.success(tipStr)
                  this.getData()
                }
              })
              .catch((err) => {
                console.log(err)
                this.getData()
              })
          }
          // }
        }
      },
      saveParams() {
        return {
          id: this.reorderId,
          amount: this.amount,
          locationId: this.locationId,
          maxInventory: this.maxInventory,
          minInventory: this.minInventory,
          orderNumber: this.orderNumber,
          prediction: this.prediction,
          operationId: this.operationId,
          productId: this.productId,
          route: this.route,
          unit: this.unit,
        }
      },
      // 是否选择产品
      isSel() {
        for (let i = 0; i < this.tableData.length; i++) {
          if (this.tableData[i].productName?.length === 0) {
            this.isNoProduct = false
            break
          } else {
            this.isNoProduct = true
          }
        }
      },
      // 取消
      discardBtnClick() {
        this.getData()
        this.addTitle = '新建'
        this.showDiscard = false
      },
      // 订购一次
      handleOrderOnceClick(row) {
        let params = {
          ...row,
        }
        orderAgain(params).then((res) => {
          if (res.code === 200) {
            this.$message.success('订购成功')
            this.getData()
          }
        })
      },
      // 行点击
      tableRowClick(row, rowIndex) {
        this.locationId = row.locationId
      }
        this.rowIndex = rowIndex
        this.reorderId = row.id
        this.isSel()
        if (!this.isNoProduct && this.currentRowId === 0) {
          this.$message.error('请完成当前新建或取消新建')
        } else {
          this.currentRowId = row.id
          this.addTitle = '保存'
          this.showDiscard = true
          this.isRowClick = true
          if (!this.isNoProduct) {
            this.tableData.splice(this.tableData.length - 1, 1)
          }
          this.tableData.map((item, index) => {
            if (index === rowIndex) {
              item.isEdit = false
              item.editable = true
              item.isOrder = true
            } else {
              item.isEdit = true
            }
          })
          this.minInventory = row.minInventory
          this.amount = row.amount
          this.productId = row.productId
          this.maxInventory = row.maxInventory
          this.orderNumber = row.orderNumber
          this.prediction = row.prediction
          this.locationId = row.locationId
        }
      },
      // 搜索
      getList(val) {
        this.keyword = val
        this.pagerOptions.currPage = 1
        this.getData()
      },
      // 选中位置方法
      selLocationClick(item, prop) {
        console.log(item, prop)
        this.locationId = item?.value ?? item?.id
      },
      // 选中产品方法
      selProductClick(item) {
        this.productId = item.productId
        this.unit = item.unit
        this.amount = item.amount
        this.prediction = item.prediction
      },
      // 选中路线方法
      selRouteClick(item, prop) {
        console.log(item, prop)
        this.route = item.label
      },
      // 获取当前时间
      currentTime() {
        return currentTime()
      },
      //树点击
      handleNodeClick(data) {
        console.log(data, 'sss')
        this.getData(data)
      },
      async getLocationList() {
        await getLocationTreeList().then((res) => {
          this.datas = [
            {
              id: 0,
              jointName: '全部',
              children: [],
            },
            ...res.data,
          ]
        })
      },
      // 删除type
      delSelectClick() {
        this.type = ''
        this.getData()
      },
      switchKeywords(item) {
        console.log(item, 'switchKeywords')
        this.type = item?.length > 0 ? 'bh' : ''
        this.getData()
      },
    },
    // 搜索
    getList(val) {
      this.keyword = val
      this.pagerOptions.currPage = 1
      this.getData()
    },
    // 选中位置方法
    selLocationClick(item, prop) {
      console.log(item, prop)
      this.locationId = item?.value ?? item?.id
    },
    // 选中产品方法
    selProductClick(item) {
      this.productId = item.productId
      this.unit = item.unit
      this.amount = item.amount
      this.prediction = item.prediction
    },
    // 选中路线方法
    selRouteClick(item, prop) {
      console.log(item, prop)
      this.route = item.label
    },
    // 获取当前时间
    currentTime() {
      return currentTime()
    },
    //树点击
    handleNodeClick(data) {
      console.log(data, "sss")
      this.getData(data)
    },
    async getLocationList() {
      await getLocationTreeList().then((res) => {
        this.datas = [
          {
            id: 0,
            jointName: "全部",
            children: []
          },
          ...res.data
        ]
      })
    },
    // 删除type
    delSelectClick() {
      this.type = ""
      this.getData()
    },
    switchKeywords(item) {
      console.log(item, "switchKeywords")
      this.type = item?.length > 0 ? "bh" : ""
      this.getData()
    }
  }
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
::v-deep {
  .el-table {
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    overflow: auto;
  }
  .content_wrap {
    height: calc(100% - 0px);
    display: flex;
    justify-content: space-between;
    .con_left {
      max-height: calc(100% - 40px);
      overflow: hidden;
      width: 190px;
      margin-right: 10px;
      .el-checkbox-group {
        width: 100%;
        display: flex;
        flex-direction: column;
      }
      .stash {
        display: flex;
        flex-direction: column;
        .el-tree {
          background-color: #e6ecf2;
  ::v-deep {
    .el-table {
      border-top-left-radius: 12px;
      border-top-right-radius: 12px;
      overflow: auto;
    }
    .content_wrap {
      height: calc(100% - 0px);
      display: flex;
      justify-content: space-between;
      .con_left {
        max-height: calc(100% - 90px);
        overflow: auto;
        width: 160px;
        margin-right: 10px;
        .el-checkbox-group {
          width: 100%;
          display: flex;
          flex-direction: column;
        }
        .stash {
          display: flex;
          flex-direction: column;
          .el-tree {
            background-color: #e6ecf2;
          }
        }
      }
      .list-view {
        flex: 1;
      }
    }
    .list-view {
      flex: 1;
    .span-ellipsis {
      // overflow: auto;
      // white-space: nowrap;
      // text-overflow: ellipsis;
      font-size: 13px;
      padding: 0px 10px;
    }
  }
  .span-ellipsis {
  ::v-deep {
    .el-tree-node > .el-tree-node__children {
      overflow: visible !important;
    }
    .el-tree-node__content:hover, .el-upload-list__item:hover {
    width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 13px;
  }
}
  }
</style>