src/views/sales/salesDetails/AddSalesDetailsDialog.vue
@@ -90,10 +90,18 @@
                  </div>
                </el-form-item>
              </el-col>
             111: {{ autoCodeHeadersObj.Ywjh }}
              <el-col :span="12">
                <el-form-item label="销售机会" prop="sale_chance_name"
                :rules="[{ required: autoCodeHeadersObj.Ywjh=='yes'?true:false, message: '请选择销售机会', trigger: 'change' }]">
                <el-form-item
                  label="销售机会"
                  prop="sale_chance_name"
                  :rules="[
                    {
                      required: autoCodeHeadersObj.Ywjh == 'yes' ? true : false,
                      message: '请选择销售机会',
                      trigger: 'change'
                    }
                  ]"
                >
                  <div class="custom-name">
                    <el-autocomplete
                      style="width: 100%"
@@ -107,6 +115,7 @@
                      @select="handleSelectClient('chance', $event)"
                      :disabled="isNameChanceEdit || isView"
                    ></el-autocomplete>
                    <!-- &&editConfig.infomation.client_name -->
                    <div
                      v-if="!isNameChanceEdit && !isView"
                      class="common-select-btn"
@@ -162,8 +171,18 @@
                </el-form-item>
              </el-col> -->
              <el-col :span="12">
                <el-form-item label="销售报价单" prop="quotation_number"
                :rules="[{ required: autoCodeHeadersObj.Bjd=='yes'?true:false, message: '请选择销售报价单', trigger: 'change' }]">
                <el-form-item
                  label="销售报价单"
                  prop="quotation_number"
                  :rules="[
                    {
                      required: autoCodeHeadersObj.Bjd == 'yes' ? true : false,
                      message: '请选择销售报价单',
                      trigger: 'change'
                    }
                  ]"
                >
                  <!-- isAddQuatation || -->
                  <div class="custom-name">
                    <el-autocomplete
                      v-model="editConfig.infomation.quotation_number"
@@ -175,21 +194,18 @@
                      value-key="number"
                      @select="handleSelectClient('quotation', $event)"
                      style="width: 100%"
                      placeholder="请先选择销售机会"
                      :disabled="isAddQuatation || isView"
                      placeholder="请选择销售报价单"
                      :disabled="isView"
                    ></el-autocomplete>
                    <div
                      v-if="!isAddQuatation && !isView"
                      class="common-select-btn"
                      @click="selClientClick('quotation')"
                    >
                    <!-- !isAddQuatation && editConfig.infomation.sale_chance_name &&-->
                    <div v-if="!isView" class="common-select-btn" @click="selClientClick('quotation')">
                      <i class="el-icon-circle-plus-outline" title="选择"></i>
                    </div>
                    <!-- !isAddQuatation && -->
                    <div
                      v-if="
                        editConfig.infomation.quotation_number &&
                        editConfig.infomation.quotation_number.length > 0 &&
                        !isAddQuatation &&
                        !isView
                      "
                      class="common-select-btn"
@@ -209,6 +225,7 @@
                    placeholder="选择日期"
                    style="width: 100%"
                    :disabled="isView"
                    :picker-options="pickerOptionsBefore"
                  >
                  </el-date-picker>
                </el-form-item>
@@ -236,6 +253,7 @@
                    placeholder="选择日期"
                    style="width: 100%"
                    :disabled="isView"
                    :picker-options="pickerOptions"
                  >
                  </el-date-picker>
                </el-form-item>
@@ -300,7 +318,7 @@
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
              <!-- <el-col :span="12">
                <el-form-item label="物流公司" prop="logisticCompany">
                  <el-input v-model="editConfig.infomation.logisticCompany" :disabled="isView"></el-input>
                </el-form-item>
@@ -309,7 +327,7 @@
                <el-form-item label="物流单号" prop="logisticNumber">
                  <el-input v-model="editConfig.infomation.logisticNumber" :disabled="isView"></el-input>
                </el-form-item>
              </el-col>
              </el-col> -->
              <el-col :span="12">
                <el-form-item label="物流费用" prop="logisticCost">
                  <el-input-number
@@ -388,7 +406,7 @@
          <!-- 产品管理 -->
          <div class="basic-info-title" style="display: flex">
            产品管理
            <div style="margin-left: 400px">
            <!-- <div style="margin-left: 400px">
              币种
              <el-select
                v-model="editConfig.infomation.currency"
@@ -400,17 +418,30 @@
                <el-option v-for="item in currencyOptions" :key="item.id" :label="item.name" :value="item.id">
                </el-option>
              </el-select>
            </div>
            </div> -->
          </div>
          <div class="product-view">
            <!-- :detail-enter="true" -->
            <CommonFormTableView
              ref="commonFormTableView"
              :detail-enter="true"
              :select-box="selectBox"
              :detail-enter="isView ? true : false"
              :selectBox="false"
              :addTypeIdMultiple="true"
              :show-summary="showSummary"
              pageName="quotation"
              :isOperate="
                (autoCodeHeadersObj.Bjd == 'yes' && editConfig.infomation.quotation_number) ||
                autoCodeHeadersObj.Bjd != 'yes'
                  ? true
                  : false
              "
              :quotationNumber="autoCodeHeadersObj.Bjd == 'yes' ? editConfig.infomation.quotation_number : ''"
              :product-table-list="productTableList"
              @inputContent="inputContent"
              @addProductClick="addProductClick"
              @getSelectArray="getSelectArray"
              @emptyProductClick="emptyProductClick"
              @clearupProduct="clearupProduct"
            ></CommonFormTableView>
          </div>
          <!-- 选择审批流程 -->
@@ -523,7 +554,7 @@
  computed: {
    clientList() {
      return this.$store.state.getClientName.clientList
    }
    },
    // saleChancelist() {
    //   return this.$store.state.getClientName.saleChancelist
    // },
@@ -533,7 +564,7 @@
  },
  data() {
    return {
      dialogWidth: "50%",
      dialogWidth: "60%",
      editConfig: this.editCommonConfig,
      rules: {
        client_name: [{ required: true, message: "请选择客户名称", trigger: "change" }],
@@ -556,7 +587,7 @@
        show: true,
        total: true,
        sumProp: ["Amount", "total"],
        mergeNumber: 2
        mergeNumber: 7
      },
      editSelectClientConfig: {
        editVisible: false,
@@ -593,20 +624,49 @@
      quotationList: [],
      quotationId: this.editCommonConfig.infomation.quotationId,
      tableData: [],
      selProductData: [],
      isView: this.editCommonConfig.title === "查看",
      selectBox: this.editCommonConfig.title !== "查看",
      thatMember: {}
      thatMember: {},
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7
        }
      },
      pickerOptionsBefore: {
        disabledDate(time) {
          return time.getTime() > Date.now()
        }
      }
    }
  },
  mounted(){
    this.getSaleChanceList()
    this.getQuotation()
  },
  created() {
    if (this.editConfig.title !== "新建") {
      this.productTableList.tableData = [
        {
          productId: this.productId,
          id: 0,
          amount: 0,
          desc: "",
          name: "",
          number: "",
          price: 0,
          cost: "",
          profit: "",
          margin: "",
          total: 0,
          unit: ""
        }
      ]
      this.isAddQuatation = false
    }
    this.$store.dispatch("geClient")
    this.setTableForm()
    this.getCommonData()
    this.formInfo()
    this.getUseSystemSet({ modeType: "xsmx" })
    if (this.editConfig.title === "编辑") {
      this.productTableList.tableData = this.editConfig.infomation.products
    }
@@ -661,53 +721,67 @@
    saveClick(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          for (let i = 0; i < this.selProductData.length; i++) {
            if (this.selProductData[i].name.length === 0) {
              this.isNoProduct = true
              break
            } else {
              this.isNoProduct = false
          // for (let i = 0; i < this.tableData.length; i++) {
          //   if (this.tableData[i].name.length === 0) {
          //     this.isNoProduct = true
          //     break
          //   } else {
          //     this.isNoProduct = false
          //   }
          // }
          // if (this.isNoProduct) {
          //   this.$message.error("请选择产品")
          // } else {
          for (let i = 0; i < this.tableData.length; i++) {
            if (this.tableData[i].cost) {
              let reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/
              if (!reg.test(this.tableData[i].cost)) {
                this.$message.error("成本单价需要填写大于0的2位小数!")
                return true
              }
            }
          }
          if (this.isNoProduct) {
            this.$message.error("请选择产品")
          const params = this.saveParams()
          if (this.editConfig.title === "新建") {
            getAddSalesDetails(params).then((res) => {
              console.log(res)
              this.editConfig.visible = false
              if (res.code === 200) {
                this.tableData.map((item) => {
                  this.amountTotal += parseFloat(item.total)
                })
                let config = {
                  amountTotal: this.amountTotal,
                  id: res.data.id
                }
                this.$emit("addCollectionPlanClick", config)
              }
            })
          } else {
            const params = this.saveParams()
            if (this.editConfig.title === "新建") {
              getAddSalesDetails(params).then((res) => {
                console.log(res)
                this.editConfig.visible = false
                if (res.code === 200) {
                  this.selProductData.map((item) => {
                    this.amountTotal += parseFloat(item.total)
                  })
                  let config = {
                    amountTotal: this.amountTotal,
                    id: res.data.id
                  }
                  this.$emit("addCollectionPlanClick", config)
                }
              })
            } else {
              console.log(this.selProductData)
              getUpdateSalesDetails(params).then((res) => {
                console.log(res)
                this.editConfig.visible = false
                if (res.code === 200) {
                  this.$message.success("编辑成功")
                  this.$parent.getData()
                }
              })
            }
            getUpdateSalesDetails(params).then((res) => {
              console.log(res)
              this.editConfig.visible = false
              if (res.code === 200) {
                this.$message.success("编辑成功")
                this.$parent.getData()
              }
            })
          }
        } else {
          console.log("error submit")
          return false
        }
        // } else {
        //   console.log("error submit")
        //   return false
        // }
      })
    },
    saveParams() {
      let data = this.editConfig.infomation
      let products = []
      this.tableData.map((item) => {
        if (item.number.length > 0) {
          products.push(item)
        }
      })
      let commonParam = {
        address: data.address || "",
        addressee: data.addressee || "",
@@ -717,7 +791,7 @@
        memberId: data.memberId || 0,
        number: data.number || "",
        phone: data.phone || "",
        products: this.selProductData,
        products: products,
        remark: data.remark || "",
        saleChanceId: this.saleChanceId || 0,
        saleType: data.saleType || 0,
@@ -750,39 +824,34 @@
    },
    // 获取报价单
    getQuotation(id, value) {
      getQuotationList({
        page: 0,
     let params={
         page: 0,
        pageSize: 0,
        search_map: {
          sale_chance_id: id
        }
      }).then((res) => {
     }
     if(id){
      params.search_map={
        sale_chance_id: id
      }
     }
      getQuotationList(params).then((res) => {
        if (res.code == 200) {
          console.log(res)
          this.quotationList = res.data.list
          this.count = res.data.count
          if (value === "全部产品") {
            this.quotationList.map((item) => {
              if (item.id === this.editConfig.infomation.quotationId) {
                this.tableData = item.products
                this.tableData.map((item, index) => {
                  item.productId = index + 1
                  this.selProductData.forEach((key) => {
                    if (item.number === key.number) {
                      item.amount = key.amount
                      item.id = key.id
                    }
                  })
                })
                this.productTableList.tableData = this.tableData
                this.selProductData.forEach((key) => {
                  this.tableData.forEach((row) => {
                    if (key.number === row.number) {
                      this.$refs.commonFormTableView.$refs.fromTable.toggleRowSelection(row, true)
                    }
                  })
                })
              }
            })
            // this.quotationList.map((item) => {
            // if (item.id === this.editConfig.infomation.quotationId) {
            //   this.tableData.map((item, index) => {
            //     item.productId = index + 1
            //     this.tableData.forEach((key) => {
            //       if (item.number === key.number) {
            //         item.amount = key.amount
            //         item.id = key.id
            //       }
            //     })
            //   })
            // }
            // })
          }
        }
      })
@@ -794,11 +863,12 @@
        restaurants = this.clientList
        console.log(restaurants, "客户单")
      } else if (value === "chance") {
        restaurants = this.saleChancelist
          restaurants = this.saleChancelist
      } else if (value === "subbill") {
        restaurants = this.subOrderList
      } else if (value === "quotation") {
        restaurants = this.quotationList
          restaurants = this.quotationList
        console.log(this.quotationList,'quotationList')
      }
      var results = queryString ? restaurants.filter(this.createStateFilter(queryString, value)) : restaurants
      cb(results)
@@ -814,13 +884,22 @@
    },
    // 销售机会列表
    async getSaleChanceList(item) {
      await getSaleChanceList({
        page: 1,
        pageSize: 15,
        search_map: {
      let params={}
      if(item){
        params={
          page: 1,
          pageSize: 15,
        }
        params.search_map={
          client_id: item.id
        }
      }).then((res) => {
      }else{
        params={
          page: 0,
          pageSize: 0,
        }
      }
      await getSaleChanceList(params).then((res) => {
        console.log(res)
        this.saleChancelist = res.data.list
      })
@@ -857,7 +936,7 @@
        this.editConfig.infomation.subbill_name = item.number
      } else if (value === "quotation") {
        this.productTableList.tableData = item.products
        // this.tableData = item.products
        this.tableData = item.products
        this.editConfig.infomation.quotation_number = item.number
        this.quotationId = item.id
      }
@@ -866,7 +945,9 @@
      if (value === "client") {
        this.editSelectClientConfig.editVisible = true
      } else if (value === "chance") {
        this.editSelectChanceConfig.clientId = this.clientId
        if (this.clientId) {
          this.editSelectChanceConfig.clientId = this.clientId
        }
        this.editSelectChanceConfig.editVisible = true
      } else if (value === "subbill") {
        this.editSelCommonConfig.title = "销售子单"
@@ -874,22 +955,37 @@
        this.editSelCommonConfig.clientId = this.clientId
      } else if (value === "quotation") {
        this.editSelCommonConfig.title = "报价单"
        if (this.saleChanceId && this.clientId) {
          this.editSelCommonConfig.clientId = this.clientId
          // 正向选择客户 销售机会  报价单
          this.editSelCommonConfig.isRequest = false
          this.editSelCommonConfig.count = this.count
          this.editSelCommonConfig.tableInfomation = [...this.quotationList]
        } else {
          // 反向选择
          this.editSelCommonConfig.isRequest = true
        }
        this.editSelCommonConfig.editVisible = true
        this.editSelCommonConfig.clientId = this.clientId
        this.editSelCommonConfig.tableInfomation = [...this.quotationList]
      }
    },
    selClient(row, value) {
      if (value === "client") {
        this.editConfig.infomation.sale_chance_name = ""
        this.saleChanceId = ""
        this.editConfig.infomation.subbill_name = ""
        // 清空报价单
        this.editConfig.infomation.quotation_number = ""
        this.editConfig.infomation.client_name = row.name
        this.clientId = row.id
        this.getSaleChanceList(row)
        this.getSubOrderList(row)
      } else if (value === "chance") {
        this.editConfig.infomation.sale_chance_name = row.name
        this.editConfig.infomation.client_name = row.client.name
        this.clientId = row.client.id
        this.saleChanceId = row.id
        // 清空报价单
        this.editConfig.infomation.quotation_number = ""
        this.isAddQuatation = false
        this.getQuotation(row.id)
      } else if (value === "subbill") {
@@ -897,8 +993,14 @@
        this.subbillId = row.id
      } else if (value === "quotation") {
        this.productTableList.tableData = row.products
        // this.tableData = row.products
        this.tableData = row.products
        this.editConfig.infomation.quotation_number = row.number
        //反向 客户名称
        this.editConfig.infomation.client_name = row.client.name
        this.clientId = row.client.id
        //反向 销售机会
        this.editConfig.infomation.sale_chance_name = row.sale_chance.name
        this.saleChanceId = row.sale_chance.id
        this.quotationId = row.id
      }
    },
@@ -927,6 +1029,7 @@
        this.quotationId = 0
      }
      this.productTableList.tableData = []
      this.tableData = []
    },
    // 添加附件
    addAnnexClick() {},
@@ -934,37 +1037,121 @@
    setFormatClick() {},
    setTableForm() {
      if (this.editConfig.title === "新建" || this.editConfig.infomation.products.length === 0) {
        this.tableData = []
        this.tableData = [
          {
            productId: this.productId,
            id: 0,
            amount: 0,
            desc: "",
            name: "",
            number: "",
            price: 0,
            cost: "",
            profit: "",
            margin: "",
            total: 0,
            unit: ""
          }
        ]
      } else {
        this.selProductData = this.editConfig.infomation.products
        this.tableData = this.editConfig.infomation.products
        this.tableData.map((item, index) => {
          item.productId = index + 1
        })
        this.getQuotation(this.editConfig.infomation.saleChanceId, "全部产品")
      }
      // let productData = this.quotationList.products
      let isBjdRequird = false
      if (this.autoCodeHeadersObj.Bjd == "yes") {
        isBjdRequird = true
      }
      this.productTableList = {
        tableData: this.tableData,
        isReturn: true,
        tableColumn: [
          { label: "#", prop: "productId", width: 40 },
          { label: "产品名称", prop: "name", isRequird: true },
          // { label: "#", prop: "productId", width: 40 },
          { label: "产品名称", prop: "name", productName: true, isRequird: true, min: 110 },
          { label: "规格", prop: "specs" },
          { label: "型号", prop: "type" },
          { label: "产品编号", prop: "number" },
          { label: "数量", prop: "amount", inputNumber: true, isRequird: true },
          { label: "单位", prop: "unit" },
          { label: "销售单价", prop: "price", isRequird: true },
          { label: "销售单价", prop: "price", inputFloat: !isBjdRequird, isRequird: true },
          { label: "成本单价", prop: "cost", input: !isBjdRequird },
          { label: "毛利", prop: "profit" },
          { label: "毛利率(%)", prop: "margin", min: 90 },
          { label: "数量", prop: "amount", inputNumber: true, isRequird: true },
          { label: "价税合计", prop: "total" }
        ]
      }
    },
    // 产品列表输入
    inputContent(val, prop, row) {
      this.productId = row.productId
      // this.productId = row.productId
      this.tableData.map((item) => {
        if (item.productId === row.productId) {
        if (item.number === row.number) {
          item[prop] = val
        }
      })
    },
    // 选择产品
    getSelectArray(val) {
      this.selProductData = val
    // 产品新增
    addProductClick() {
      // this.productId++
      // this.tableData.push({
      //   productId: this.productId,
      //   id: 0,
      //   amount: 0,
      //   desc: "",
      //   name: "",
      //   number: "",
      //   price: 0,
      //   cost:'',
      //   profit:'',
      //   margin:'',
      //   total: 0,
      //   unit: ""
      // })
      // this.showSummary.show = true
    },
    // 新增方式修改
    getSelectArray(val, index) {
      if (this.tableData.length == 1 && this.tableData[0].number.length == 0) {
        this.tableData = []
      }
      if (index < this.tableData.length) {
        this.tableData.splice(index, 1)
        val.map((item, ind) => {
          this.tableData.splice(index + ind, 0, item)
        })
      } else {
        this.tableData = this.tableData.concat(val)
      }
      this.productTableList.tableData = this.tableData
      this.showSummary.show = true
    },
    //  产品清空
    emptyProductClick() {
      this.productId = 1
      this.tableData = [
        {
          productId: this.productId,
          id: 0,
          amount: 0,
          desc: "",
          name: "",
          number: "",
          price: 0,
          cost: "",
          profit: "",
          margin: "",
          total: 0,
          unit: ""
        }
      ]
      this.productTableList.tableData = this.tableData
    },
    clearupProduct(data) {
      this.tableData = data
      this.productTableList.tableData = this.tableData
    },
    // 获取项目列表
    async getProjectList() {