EquityUpgrade.vue 6.6 KB
<template>
  <div>
    <d2-container class="m-t-40">
      <div class="header" slot="header" style="padding: 10px 20px">
        <d2-search ref="showSearch" class="show-search" :search-form="searchForm" :label-width="'100px'"
          :form-data="showFormData">
          <template slot="brand">
            <el-cascader ref="cascader" v-model="searchForm.brandId" filterable :options="options" :value-key="'id'"
              :props="cascaderProps" clearable></el-cascader>
          </template>
        </d2-search>
        <div class="up-btns">
          <el-button @click="handleSearch" size="small" type="primary">
            查询
          </el-button>
          <el-button size="small" @click="handleReset"> 重置 </el-button>
        </div>
      </div>
      <div class="d2-container-content">
        <d2-table-header>
          <el-button size="small" type="primary" @click="handleDialog">
            新增配置
          </el-button>
        </d2-table-header>
        <d2-table ref="table" :get-list-api="getListApi" :search-form="searchFormSearch" :table-params="tableParams"
          :before-search-fn="beforeSearchFn">
          <div slot="brandName" slot-scope="scope">
            <template v-if="scope.scope.brandName">
              {{ scope.scope.brandName.split(",").length > 1 ? scope.scope.brandName.split(",")[0] + '...' :
                scope.scope.brandName.split(",")[0]}}
              <el-popover placement="top-start" width="200" trigger="hover">
                <p v-for="(item, index) in scope.scope.brandName.split(',')" :key="index">
                  {{ item }}
                </p>
                <span class="trick-no" slot="reference" v-show="scope.scope.brandName.split(',').length > 1">({{
                  scope.scope.brandName.split(",").length - 1 }})</span>
                <!-- <el-button slot="reference">hover 激活</el-button> -->
              </el-popover>
            </template>
            <template v-else>-</template>
          </div>
          <div slot="merchantName" slot-scope="scope">
            <template v-if="scope.scope.merchantName">
              {{ scope.scope.merchantName.split(",").length > 1 ? scope.scope.merchantName.split(",")[0] + '...' :
                scope.scope.merchantName.split(",")[0]}}
              <el-popover placement="top-start" width="200" trigger="hover">
                <p v-for="(item, index) in scope.scope.merchantName.split(',')" :key="index">
                  {{ item }}
                </p>
                <span class="trick-no" slot="reference" v-show="scope.scope.merchantName.split(',').length > 1">({{
                  scope.scope.merchantName.split(",").length - 1 }})</span>
                <!-- <el-button slot="reference">hover 激活</el-button> -->
              </el-popover>
            </template>
            <template v-else>-</template>
          </div>
          <div slot="auth-button" slot-scope="scope">
            <el-button type="text" @click="handleEdit(scope.scope)">
              编辑
            </el-button>
            <el-button type="text" @click="handleDelete(scope.scope)">
              删除
            </el-button>
          </div>
        </d2-table>
      </div>
    </d2-container>
  </div>
</template>
<script>
import { deepClone } from "@/common/util"
import { getConfigList, getCarbrandTree, deleteConfig, getMateralDetail } from "@api/contentManager"
export default {
  data() {
    return {
      searchForm: {},
      showFormData: [
        {
          label: "品牌",
          name: "sceneLabelCode",
          addHtml: 'brand'
        },
        // {
        //   label: "门店",
        //   name: "merchantName",
        //   type: "input",
        //   // isClear: true,
        //   // optionList: [],
        //   // optionId: "merchantId",
        //   // optionLabel: "merchantName",
        //   // optionsName: "shopList"
        // },
      ],
      searchFormSearch: {},
      getListApi: getConfigList,
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: "list",
        tableOption: true,
        tableColumns: [
          {
            label: "品牌",
            prop: "brandName",
            addHtml: "brandName"
          },
          {
            label: "关联门店",
            prop: "merchantName",
            addHtml: "merchantName"
          },
          {
            label: "更新时间",
            prop: "updatedDate",
          },
        ]
      },
      baseData: {
        shopList: [],
      },
      options: [],
      cascaderProps: { checkStrictly: true, value: 'id' }
    }
  },
  mounted() {
    this.getCarbrandTree()
  },
  methods: {
    beforeSearchFn() {
      return new Promise((resolve) => {
        this.searchFormSearch = deepClone(this.searchForm)
        const { brandId, merchantName } = this.searchFormSearch
        if (brandId) {
          this.searchFormSearch.brandId = brandId[brandId.length - 1]
        }
        // if (merchantName) {
        //   this.searchFormSearch.scene = 0
        // }
        resolve()
      })
    },
    handleSearch() {
      this.page = this.$options.data.call(this).page
      this.$refs.table.refreshTable(true, true)
    },
    handleReset() {
      this.searchForm = this.$options.data.call(this).searchForm
      console.log("this.searchForm", this.searchForm)
      this.handleSearch()
    },
    // 获取品牌树
    async getCarbrandTree() {
      const res = await getCarbrandTree()
      this.options = res
    },
    handleDialog() {
      this.$router.push({ name: "addEquity" })
    },
    async handleEdit(row) {
      const res = await getMateralDetail({id: row.id})
      console.log(res)
      this.$router.push({ name: "addEquity", query: {
        id: row.id,
        isRelMerchant: res.isRelMerchant,
        materialInfoList: res.materialInfoList,
        brandData: res.relList,
        storeData: res.relMerchantList
      } })
    },
    handleDelete(row) {
      this.$confirm("删除后相关品牌素材将从展业助手中移除", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        closeOnClickModal: false
      })
        .then(async() => {
          const res = await deleteConfig({id: row.id})
          if (res) {
            this.$message.success('删除成功')
            this.$refs.table.refreshTable(true, true)
          }
          else this.$message.error('删除失败')
        })
        .catch((err) => {
          console.log(err)
        })
      
    }
  }
}
</script>
<style scoped>
.m-t-40 {
  margin-top: 40px;
}

.trick-no {
  cursor: pointer;
  font-size: 13px;
  color: #2a58ad;
  line-height: 20px;
}
</style>