warningSet.vue 8.13 KB
<template>
  <d2-dialog
    title="预警设置"
    :is-visible="warningVisible"
    class="warningDailog"
    width="1040px"
    btn-ok-label="确定"
    @closeDialog="handleClose"
    @confirmDialog="handleAddConfirm"
  >
    <p class="title">延保</p>
    <glsx-combi-form
      class="yanbao"
      label-width="150px"
      default-width="310px"
      :form-obj="warningForm"
      :form-data="warningFormData"
    ></glsx-combi-form>
    <p class="title">权益</p>
    <glsx-combi-form
      label-width="150px"
      default-width="310px"
      :form-obj="warningForm"
      :form-data="warningFormData2"
    ></glsx-combi-form>
    <div class="explain">
      说明:设置业务兜底指标,按每月进行实时监测,一旦低于设置的目标值,系统自动进行预警
    </div>
  </d2-dialog>
</template>
<script>
import { limitPrice } from "@/common/format"
import {
  saveOrUpdateWarningConfig,
  findWarningConfig
} from "@/api/shopConfig.js"
export default {
  data() {
    return {
      isFlag: true,
      warningForm: {
        id: "",
        merchantNo: "",
        ewConRate: "", //延保转化率
        ewAxbConRate: "", //延保安心包转化率
        ewLtConRate: "", //延保轮胎转化率
        riConRate: "", //权益转化率
        ewPenetrationRate: "", //延保渗透率
        ewAxbPenetrationRate: "", //安心包渗透率
        ewLtPenetrationRate: "", //轮胎渗透率
        batteryPenetrationRate: "", //电池渗透率
        batteryConversionRate: "" //电池转化率
      },
      oldVal: {
        ewConRate: "", //延保转化率
        ewAxbConRate: "", //延保安心包转化率
        ewLtConRate: "", //延保轮胎转化率
        riConRate: "", //权益转化率
        ewPenetrationRate: "", //延保渗透率
        ewAxbPenetrationRate: "", //安心包渗透率
        ewLtPenetrationRate: "", //轮胎渗透率
        batteryPenetrationRate: "", //电池渗透率
        batteryConversionRate: "" //电池转化率
      },
      warningFormData: [
        {
          label: "转化率",
          name: "ewConRate",
          placeholder: "请输入",
          type: "input",
          append: "%",
          listeners: {
            input: () => {
              this.handleInput(this.warningForm.ewConRate, "ewConRate")
            }
          }
        },
        {
          label: "渗透率",
          name: "ewPenetrationRate",
          placeholder: "请输入",
          type: "input",
          append: "%",
          listeners: {
            input: () => {
              this.handleInput(
                this.warningForm.ewPenetrationRate,
                "ewPenetrationRate"
              )
            }
          }
        },
        {
          label: "安心包转化率",
          name: "ewAxbConRate",
          placeholder: "请输入",
          type: "input",
          append: "%",
          listeners: {
            input: () => {
              this.handleInput(this.warningForm.ewAxbConRate, "ewAxbConRate")
            }
          }
        },
        {
          label: "安心包渗透率",
          name: "ewAxbPenetrationRate",
          placeholder: "请输入",
          type: "input",
          append: "%",
          listeners: {
            input: () => {
              this.handleInput(
                this.warningForm.ewAxbPenetrationRate,
                "ewAxbPenetrationRate"
              )
            }
          }
        },
        {
          label: "轮胎转化率",
          name: "ewLtConRate",
          placeholder: "请输入",
          type: "input",
          append: "%",
          listeners: {
            input: (e) => {
              this.handleInput(this.warningForm.ewLtConRate, "ewLtConRate")
            }
          }
        },
        {
          label: "轮胎渗透率",
          name: "ewLtPenetrationRate",
          placeholder: "请输入",
          type: "input",
          append: "%",
          listeners: {
            input: (e) => {
              this.handleInput(
                this.warningForm.ewLtPenetrationRate,
                "ewLtPenetrationRate"
              )
            }
          }
        },
        {
          label: "电池转化率",
          name: "batteryConversionRate",
          placeholder: "请输入",
          type: "input",
          append: "%",
          listeners: {
            input: (e) => {
              this.handleInput(
                this.warningForm.batteryConversionRate,
                "batteryConversionRate"
              )
            }
          }
        },
        {
          label: "电池渗透率",
          name: "batteryPenetrationRate",
          placeholder: "请输入",
          type: "input",
          append: "%",
          listeners: {
            input: (e) => {
              this.handleInput(
                this.warningForm.batteryPenetrationRate,
                "batteryPenetrationRate"
              )
            }
          }
        }
      ],
      warningFormData2: [
        {
          label: "转化率",
          name: "riConRate",
          placeholder: "请输入",
          type: "input",
          append: "%",
          listeners: {
            input: (e) => {
              this.handleInput(this.warningForm.riConRate, "riConRate")
            }
          }
        }
      ]
    }
  },
  props: {
    warningVisible: {
      type: Boolean,
      default: false
    },
    info: {
      type: Object,
      default: () => {}
    }
  },
  watch: {
    warningVisible(val) {
      if (val) {
        this.getData()
      }
    }
  },
  mounted() {
    // console.log(this.info)
    // this.warningForm.merchantNo = this.info.merchantId
    // this.getData()
  },
  methods: {
    async getData() {
      const details = await findWarningConfig({
        merchantNo: this.info.merchantId
      })
      if (details) {
        this.warningForm = details
      } else {
        this.warningForm = {
          id: "",
          merchantNo: "",
          ewConRate: "", //延保转化率
          ewAxbConRate: "", //延保安心包转化率
          ewLtConRate: "", //延保轮胎转化率
          riConRate: "",
          ewPenetrationRate: "", //延保渗透率
          ewAxbPenetrationRate: "",
          ewLtPenetrationRate: "",
          batteryPenetrationRate: "",
          batteryConversionRate: ""
        }
      }
    },
    handleInput(newVal, name) {
      newVal = newVal.replace(/[^\d.]/g, "") // 清除“数字”和“.”以外的字符
      this.warningForm[name] = limitPrice(
        newVal,
        this.oldVal[name],
        3,
        2,
        0,
        100
      )
      this.oldVal[name] = this.warningForm[name]
    },
    async handleAddConfirm() {
      if (this.isFlag) {
        this.isFlag = false
        try {
          let params = {
            id: this.warningForm.id,
            merchantNo: this.warningForm.merchantNo || this.info.merchantId,
            ewConRate: this.warningForm.ewConRate,
            ewAxbConRate: this.warningForm.ewAxbConRate,
            ewLtConRate: this.warningForm.ewLtConRate,
            riConRate: this.warningForm.riConRate,
            batteryConversionRate: this.warningForm.batteryConversionRate,
            batteryPenetrationRate: this.warningForm.batteryPenetrationRate,
            ewPenetrationRate: this.warningForm.ewPenetrationRate,
            ewAxbPenetrationRate: this.warningForm.ewAxbPenetrationRate,
            ewLtPenetrationRate: this.warningForm.ewLtPenetrationRate
          }
          const res = await saveOrUpdateWarningConfig(params)
          if (res) {
            this.$message.success("保存成功")
            this.warningVisible = false
            this.$emit("confirmWarnDialog")
          }
        } catch (error) {
          this.$message.error(error)
        } finally {
          this.isFlag = true
        }
      }
    },
    handleClose() {
      this.$emit("closeWarnDialog")
    }
  }
}
</script>
<style scoped lang="scss">
.warningDailog {
  .title {
    color: #292d33;
    font-size: 15px;
    font-weight: bold;
  }
  .explain {
    color: #999ea8;
    font-size: 14px;
  }
  .yanbao {
    ::v-deep .glsx-combi-form-block {
      display: flex;
      align-items: center;
      flex-wrap: wrap;
    }
  }
}
</style>