index.vue 8.21 KB
<template>
  <div class="scrm-sub-client-container" v-loading="loading">
    <el-tabs v-model="activeName" @tab-click="handleClick()">
      <el-tab-pane label="推荐人群" name="first"></el-tab-pane>
      <el-tab-pane label="自定义人群" name="second">
        <GLButton class="addBtn" fn="新建人群" v-if="userType == 1" @click="addClick">
          <i class="el-icon-plus"></i>
          新建人群
        </GLButton>
      </el-tab-pane>
    </el-tabs>
    <div class="pageContent">
      <search-form class="searchTop border-shadow" :formModel="searchForm" :formList="tagsPartFormList">
        <span class="inline-b" slot="form-slot">
          <!-- <el-button @click="resetTable" plain>重置</el-button> -->
          <el-button class="searchBtn" type="primary" @click="searchTable">查询</el-button>
        </span>
      </search-form>
      <GLTable class="crowdTable" @setTableHeightEvent="setTableHeightEvent" @setTableFinishFun="setTableFinishFun" v-if="isReload" ref="crowdManage" :hasNum="false" :getListApi="getListApi" :beforeSearchFn="beforeSearchFn" :searchForm="searchForm" :pageConf="pageConf" :noDataImg="url" :tableParams="tableParams">
        <span slot="crowdName" slot-scope="scope">
          <span class="line-ellipsis">{{ scope.scope.crowdName.slice(0, 24) }}</span>
        </span>
        <span slot="crowdDesc" slot-scope="scope">
          <span class="line-ellipsis">{{ scope.scope.crowdDesc.slice(0, 24) }}</span>
        </span>
        <template slot="xxx" slot-scope="scope">
          <!-- <span @click="btnClick('detail', scope.scope)" class="blue-text">查看详情</span> -->
          <GLButton type="text" @click="btnClick('detail', scope.scope)" class="blue-text" fn="查看详情">查看详情</GLButton>
          <!-- <span style="margin-left: 20px" @click="btnClick('view', scope.scope)" class="blue-text">查看客户</span> -->
          <GLButton class="blue-text leftDistance" type="text" fn="客户列表" v-if="userType !== 2" @click="btnClick('view', scope.scope)">查看客户</GLButton>
          <el-button type="text" class="blue-text" @click="createMarketSOP(scope.scope)">营销SOP</el-button>
        </template>
      </GLTable>
    </div>
  </div>
</template>

<script>
import url from '@/assets/clientDataOverview/nodata.png'
export default {
  name: 'crowdManage',
  data() {
    return {
      loading: false,
      activeName: 'first',
      isReload: true,
      url: url,
      searchForm: {},
      merchantId: '', //商户号
      // crowdType:1,//人群类型
      // totalCount: 0,
      tagsPartFormList: [
        {
          type: 'input',
          inputType: 'text',
          prop: 'req.keyword',
          label: '人群名称:',
          placeholder: '请输入人群名称',
          clearable: true
        }
      ],
      pageConf: { pageSize: 'req.pageSize', pageNum: 'req.pageNum', totalCount: 'data.total' },
      tableParams: {
        listName: 'data.crowdUnitList',
        tableColumns: [
          {
            label: '人群名称',
            prop: 'crowdName',
            addHtml: 'crowdName'
            // width: 160
            // width: 431
          },
          {
            label: '人群描述',
            prop: 'crowdDesc',
            addHtml: 'crowdDesc'
            // width: 160
          },
          {
            label: '人数',
            prop: 'total'
          },
          {
            label: '操作',
            prop: 'xxx',
            fixed: 'right',
            addHtml: 'xxx',
            width: 250
          }
        ]
      },
      getListApi: this.$apis.crowdManage.getCrowdList,
      expande: true,
      needShowExpande: false
    }
  },
  computed: {},
  created() {
    if (window.__POWERED_BY_QIANKUN__) {
      //运行在qiankun容器中
      this.merchantId = this.$globalState.session.merchantId
      this.admin = this.$globalState.session.admin
      this.userType = this.$globalState.session.userType
    }
    this.searchForm = { 'req.merchantId': this.merchantId, 'req.crowdType': this.crowdType }
    //标签管理保存初始化保存自定义人群状态
    // if (this.$route.query.selectTab == 1) {
    //   this.activeName = 'second'
    //   // window.history.pushState(null, null, location.origin + location.pathname)
    // }
    // 
    if (this.$route.query.selectTab) {
      this.$route.query.selectTab == 1 || this.$route.query.selectTab == 'first' ? (this.activeName = 'first') : (this.activeName = 'second')
    }
  },
  mounted() {},
  methods: {
    createMarketSOP(crowd) {
      var params = {
        addOrEdit: 'add',
        fromPage: `/custom/crowdManage/index?selectTab=${this.activeName}`,
        $title: encodeURI('新建SOP'),
        info: {
          // 人群
          customerOptType: 2,
          crowdList: []
        }
      }
      params.info.crowdList.push(crowd)
      this.$common.utils.storage.set('sopInfo', params)
      this.$history.push({
        path: 'marketing/sop/editSop'
      })
    },
    btnClick(type, data) {
      const crowdType = this.activeName == 'first' ? 1 : 2
      const transData = JSON.stringify(data)
      if (type == 'detail') {
        this.$router.push(`/crowdManage/crowdDetail/${data.crowdId}?crowdType=${crowdType}`)
      }
      if (type == 'view') {
        this.$router.push(`/clientDataOverview/group/${data.crowdId}/${crowdType}?crowdInfo=${transData}`)
      }
    },
    addClick() {
      this.$router.push('/crowdManage/crowdAdd')
    },
    setTableFinishFun() {
      if (!this.$refs.crowdManage.data.length) {
        this.$nextTick(() => this.$refs.crowdManage.setTableHeightFun())
      } else {
        this.$refs.crowdManage.tableHeightValues = ''
      }
    },
    setTableHeightEvent() {
      this.$refs.crowdManage.setTableHeightFun()
    },
    handleClick() {
      this.searchForm = { 'req.keyword': '' }
      this.searchTable()
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        const crowdType = this.activeName == 'first' ? 1 : 2
        this.searchForm = Object.assign(this.searchForm, { 'req.merchantId': this.merchantId, 'req.crowdType': crowdType })
        resolve()
      })
    },
    //搜索表格
    searchTable() {
      this.$refs.crowdManage.refreshTable()
    }
    //重置表格
    // resetTable() {
    //   this.searchForm = { 'labelTreeReq.shopId': this.merchantId, 'labelTreeReq.edition': this.merchantModel }
    //   this.$refs.crowdManage.refreshTable()

    // }
  },
  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (from.params.crowdType) {
        vm.activeName = from.params.crowdType == 2 ? 'second' : 'first'
        vm.crowdType = from.params.crowdType
        vm.beforeSearchFn()
      }
    })
  }
}
</script>

<style lang="scss" scoped>
@import '@/styles/variables.scss';
@import '@/styles/resetelement.scss';
.addBtn {
  height: 32px;
  background: $btnBlue;
  border-radius: 3px;
  padding: 5px 16px;
  color: #fff;
  font-size: 16px;
  margin-bottom: 10px;
  &:hover {
    background-color: $lightBtnBlue;
  }
}
/deep/ .el-tabs__header {
  margin: 0 0 10px;
}
/deep/ .el-tabs__nav-wrap::after {
  content: none;
}
/deep/ .el-tabs__item {
  font-size: 16px;

  color: #717171;
  letter-spacing: 0.8px;
}
/deep/ .is-active {
  color: #5850ff;
  font-weight: 600;
}
.leftDistance {
  margin-left: 10px;
}
.scrm-sub-client-container {
  .pageContent {
    /deep/.search-form {
      .itemWidth {
        display: flex;
        .el-form-item {
          display: flex;
        }
      }

      .el-form-item__content {
        width: auto;
        display: inline-block;
        margin-left: 0px !important;
        .el-input {
          width: 415px;
          .el-input__inner {
            width: 415px;
          }
        }
      }
    }
  }

  .pageContent {
    padding: 6px 20px 30px;
    
    background-color: #fff;
    .el-button + .el-button {
      margin-left: 10px;
    }
    .searchTop {
      /deep/ .el-form-item:nth-child(2) {
        position: static !important;
        .el-form-item__content {
          margin-left: 15px !important;
        }
      }
    }
    .allTagsWrap {
      position: relative;
    }
  }
  .crowdTable {
    // padding: 0 20px;

    /deep/ .line-ellipsis {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      width: 20vw;
      display: block;
    }
  }
}
</style>