customCouse.vue 6.71 KB
<!-- 自定义配课 -->
<template>
  <div class="coustom-dialog">
    <baseDialog
      :dialog-config="dialogConfig"
      :is-show.sync="visible"
      class="accountDailog"
      :config="config"
      @handleClick="handleConfirm"
      @closeDialog="handleClose"
    >
      <el-form class="edit-sub-block" label-width="160px">
        <el-form-item label="归属业务:">
          {{
            coustomForm.scene == 1
              ? "延保"
              : coustomForm.scene == 2
              ? "轻改"
              : "权益"
          }}
        </el-form-item>
        <el-form-item label="品牌:">
          {{ longItemData.brand || "-" }}
        </el-form-item>
      </el-form>
      <glsx-combi-form
        ref="editFormRef"
        :form-ref="handleFormRef"
        label-width="150px"
        default-width="400px"
        :form-obj="coustomForm"
        :form-data="coustomFormData"
        :form-rules="infoRules"
      >
        <template slot="condition" slot-scope="scope">
          <div class="condition-tabs">
            <div
              :class="['condition-tab', item.active ? 'active' : '']"
              v-for="(item, index) in conditionData.metricRuleList"
              :key="index"
              @click="handleChange(index)"
            >
              {{ item.metricName }}{{ item.itemBrand }}
            </div>
          </div>
        </template>
      </glsx-combi-form>
      <div class="footer">
        <el-button type="primary" @click="handleConfirm">
          {{ config.confirm_name }}
        </el-button>
        <el-button @click="handleClose">
          {{ config.cancel_name }}
        </el-button>
      </div>
    </baseDialog>
  </div>
</template>
<script>
import { customizeList } from "@/api/serviceCentre"
export default {
  props: {
    customVisible: {
      type: Boolean,
      default: false
    },
    longItemData: {
      type: Object,
      default: () => {}
    },
    longForm: {
      type: Object,
      default: () => {}
    }
  },
  watch: {
    longItemData: {
      handler(val) {
        this.handleData(val)
      },
      immediate: true,
      deep: true
    },
    longForm: {
      handler(val) {
        this.coustomForm.scene = val.scene
      },
      immediate: true,
      deep: true
    }
  },

  computed: {
    visible: {
      get() {
        return this.customVisible
      },
      set(newVal) {
        this.$emit("dialogClose", {
          flag: newVal,
          attrName: "customVisible"
        })
      }
    }
  },
  data() {
    return {
      dialogConfig: {
        title: "自定义配课",
        width: "720px"
      },
      config: {
        showClose: true,
        appendToBody: false, // 是否将自身插入至 body 元素,有嵌套的弹窗时一定要设置
        isShowFooter: false,
        cancel_name: "重置规则",
        confirm_name: "配置课程"
      },
      handleFormRef: "handleFormRef",
      infoRules: {
        unionOrAndType: [
          {
            required: true,
            message: "请选择组合筛选条件",
            trigger: "change"
          }
        ],
        merchantNos: [
          {
            required: true,
            message: "请选择筛选条件",
            trigger: "click"
          }
        ]
      },
      coustomForm: {
        merchantNos: "",
        unionOrAndType: "",
        scene: "",
        brandId: ""
      },
      coustomFormData: [
        {
          label: "选择筛选条件",
          name: "merchantNos",
          addHtml: "condition"
        },
        {
          label: "组合筛选条件",
          name: "unionOrAndType",
          type: "radio",
          optionId: "confId",
          optionLabel: "confLabel",
          optionList: [
            {
              confLabel: "符合其中一项规则(或)",
              confId: 1
            },
            {
              confLabel: "符合已选规则(且)",
              confId: 2
            }
          ],
          handleRadioChange: () => {}
        }
      ],
      conditionData: {}
    }
  },
  methods: {
    handleChange(index) {
      this.conditionData.metricRuleList[index].active =
        !this.conditionData.metricRuleList[index].active
      let merchantNos = []
      this.conditionData.metricRuleList.forEach((item) => {
        if (item.active) {
          console.log(item)
          if (!item.merchantNos || item.merchantNos.length == 0) {
            item.merchantNos = [-1]
          }
          merchantNos.push(item.merchantNos.join(","))
        }
      })
      console.log(merchantNos)
      if (merchantNos.length > 0) {
        this.$refs.editFormRef.$refs[this.handleFormRef].clearValidate(
          `merchantNos`
        )
      }
      this.coustomForm.merchantNos = merchantNos
    },
    handleData(val) {
      this.coustomForm.brandId = val.id
      let data = JSON.parse(JSON.stringify(val))
      data.metricRuleList.forEach((item) => {
        item.active = false
      })
      this.conditionData = data
    },
    handleClose() {
      //将已选项进行重置
      // this.visible = false
      this.coustomForm.merchantNos = ""
      this.coustomForm.unionOrAndType = ""
      this.coustomForm.brandId = ""
      this.conditionData.metricRuleList.forEach((item) => {
        item.active = false
      })
    },
    handleConfirm() {
      this.$refs.editFormRef.$refs[this.handleFormRef].validate(
        async (valid) => {
          if (valid) {
            let data = await this.getStaffInfoData()
            if (data && data.length > 0) {
              this.$router.push({
                name: "configureCourse",
                query: this.coustomForm
              })
              this.visible = false
            } else {
              this.$message({
                message: "选中指标无匹配驻店人员",
                type: "warning"
              })
            }
          }
        }
      )
    },
    getStaffInfoData() {
      return new Promise((resolve, reject) => {
        customizeList({ ...this.coustomForm }).then((res) => {
          console.log(res)
          resolve(res)
        })
      })
    }
  }
}
</script>
<style scoped lang="scss">
.coustom-dialog {
  .glsx-combi-form .el-form-item--small.el-form-item {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
  }
  .footer {
    display: flex;
    justify-content: flex-end;
  }
}
.condition-tabs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  width: 500px;
  .condition-tab {
    padding: 6px 12px;
    border-radius: 2px;
    color: #333333;
    font-size: 14px;
    font-weight: 400;
    background: #f2f3f5;
    margin-right: 8px;
    margin-bottom: 8px;
    box-sizing: border-box;
    line-height: 20px;
  }
  .active {
    color: #2a58ad;
    font-weight: 500;
    background: #2a58ad26;
  }
}
</style>