addDialog.vue 3.78 KB
<!--
 * @Author: 前端 qianduan01@didihu.com.cn
 * @Date: 2024-09-06 09:49:46
 * @LastEditors: 前端 qianduan01@didihu.com.cn
 * @LastEditTime: 2024-12-04 13:42:32
 * @FilePath: \dj-car-life-system\src\views\contentManager\packageConfig\components\addDialog.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!-- 月度库存结算单弹窗 -->
<template>
  <d2-dialog
    :title="cloneId ? '复制全套素材到指定门店' : '新增门店'"
    :is-visible="dialogVisible"
    class="dailog-box"
    width="36%"
    @closeDialog="handleClose"
    @confirmDialog="handleConfirm"
  >
    <div v-loading="loading">
      <div class="dialog-title">
        {{
          cloneId
            ? "将该门店下所有车型的所有素材和套餐推荐数据(不包含客户案例),复制或替换到指定门店"
            : "请选择新增门店,新增门店的套餐配置和素材会复用默认门店的素材,可自定义修改"
        }}
      </div>
      <el-select
        filterable
        class="form-select"
        v-model="formData.merchantId"
        placeholder="请选择"
      >
        <el-option
          v-for="(i, indx) in merchantIdList"
          :key="i.merchantId"
          :label="i.merchantName"
          :value="i.merchantId"
        ></el-option>
      </el-select>
    </div>
  </d2-dialog>
</template>

<script>
import { recepitonUpdate, materialPage } from "@api/contentManager"
import { mapState, mapActions } from "vuex"
export default {
  name: "addDialog",
  data() {
    return {
      formData: { merchantId: "" },
      merchantIdBrandList: [],
      loading: false
    }
  },
  props: {
    dialogVisible: Boolean,
    cloneId: {
      type: Number
    }
  },
  computed: {
    ...mapState("d2admin/merchant", ["merchantIdList"])
  },
  async mounted() {
    this.loading = true
    await this.getMerchantIdList()
    this.loading = false
    console.log(this.cloneId, "cloneId")
    if (this.cloneId) {
      materialPage({ pageSize: 1000, currentPage: 1 }).then((res) => {
        this.merchantIdBrandList = res.list.map((i) => i.merchantId)
      })
    }
  },
  methods: {
    ...mapActions("d2admin/merchant", ["getMerchantIdList"]),
    handleConfirm() {
      const { merchantId } = this.formData
      if (!merchantId) {
        return this.$message.error("请选择门店")
      }

      const merchantName = this.merchantIdList.find(
        (i) => i.merchantId === merchantId
      ).merchantName
      let params = { merchantId, configType: 0, merchantName }
      if (this.cloneId) {
        params = {
          merchantId: merchantId,
          merchantName,
          copyMerchantId: this.cloneId
        }

        if (this.merchantIdBrandList.includes(merchantId)) {
          this.$confirm("该门店下已包含素材,是否复制替换?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
            closeOnClickModal: false
          })
            .then(() => {
              recepitonUpdate(params).then((res) => {
                if (res) {
                  this.handleClose()
                  this.$message.success("操作成功")
                }
              })
            })
            .catch((err) => {
              console.log(err)
            })
          return
        }
      }
      recepitonUpdate(params).then((res) => {
        if (res) {
          this.handleClose()
          this.$message.success("操作成功")
        }
      })
    },
    handleClose() {
      this.$emit("dialogClose")
    }
  }
}
</script>
<style lang="scss">
.dialog-title {
  font-size: 14px;
  line-height: 30px;
  margin-bottom: 15px;
}
.form-select {
  width: 50%;
}
</style>