index.vue 5.19 KB
<template>
  <view class="customer-box">
    <view class="tips flex">
      <view class="today flex">
        <view class="sprite-icon icon-customer-sop-1"></view>
        今日活动({{ toDay }})
      </view>
      <view class="text">根据SOP策略生成营销活动,请及时推送客户</view>
    </view>
    <view class="tabs-box flex">
      <template v-for="(tab, index) in tabs">
        <view :class="['tab flex', { active: index === tabIndex }]" :key="index" @click="changeTab(index)">
          <view
            :class="['sprite-icon', index === tabIndex ? `icon-customer-sop-${index + 2}-a` : `icon-customer-sop-${index + 2}`]">
          </view>
          {{ tab }}
        </view>
      </template>
    </view>
    <view class="customer-content">
      <Table :type="tabIndex" @openPopup="openPopup" @loadMore="loadMore" :list="tableData" ref="table" />
    </view>
    <CustomerPopup ref="customerPopup" />
  </view>
</template>
<script type='text/ecmascript-6'>
import dayjs from 'dayjs';
import Table from './components/Table'
import CustomerPopup from './components/CustomerPopup'
export default {
  name: 'CustomerOpportunities',
  components: { Table, CustomerPopup },
  inject: ['userInfo'],
  props: {
    show: Boolean
  },
  data() {
    return {
      tabIndex: 0,
      tabs: ['待执行推送客户(0)', '近7日已推送客户(0)'],
      toDay: dayjs().format('MM-DD'),
      total: 0,
      pageNum: 1,
      pageSize: 10,
      tableData: []
    }
  },
  watch: {
    show: {
      handler(val) {
        if (val) {
          this.getTodaySopTaskCustomerPage()
          this.getLastWeekSopTaskCustomerPage(false)
        } else {
          this.tabs = this.$options.data.call(this).tabs
          this.tabIndex = 0
          this.initRequestParams()
        }
      },
      immediate: true,
      deep: true
    }
  },
  computed: {

  },
  mounted() {
  },
  methods: {
    tableRef() {
      return this.$refs.table || null
    },
    initRequestParams() {
      this.pageNum = 1
      this.pageSize = 10
      this.tableData = []
      if (this.tableRef()) {
        this.tableRef().loadComplete = false
        this.tableRef().noMore = false
      }
      uni.hideLoading()
    },
    /**
     * 切换标签
     * @param {number} index
     */
    changeTab(index) {
      if (index == this.tabIndex) return
      this.tabIndex = index
      this.initRequestParams()
      if (index == 0) this.getTodaySopTaskCustomerPage()
      else this.getLastWeekSopTaskCustomerPage()
    },
    openPopup(data) {
      this.$refs.customerPopup.open(data)
    },
    loadMore() {
      let { total, pageSize, pageNum, tabIndex } = this
      if (Math.ceil(total / pageSize) > pageNum) {
        this.pageNum += 1
        if (tabIndex == 0) this.getTodaySopTaskCustomerPage()
        else this.getLastWeekSopTaskCustomerPage()
      } else this.tableRef().noMore = true
    },
    async getTodaySopTaskCustomerPage() {
      try {
        uni.showLoading({ title: '加载中...', mask: true })
        let { shopMerchantId: merchantId } = this.userInfo,
          { pageNum, pageSize, tableData } = this,
          { list, total } = await uni.$api.customerApi.getTodaySopTaskCustomerPage({ merchantId, pageNum, pageSize })
        uni.hideLoading()
        this.tableData = [...tableData, ...list]
        this.tableRef().loadComplete = true
        this.total = total
        this.$set(this.tabs, 0, `待执行推送客户(${total})`)
      } catch (error) {
        this.tableRef() && (this.tableRef().loadComplete = true)
      }
    },
    async getLastWeekSopTaskCustomerPage(assignment = true) {
      try {
        if (assignment) uni.showLoading({ title: '加载中...', mask: true })
        let { shopMerchantId: merchantId } = this.userInfo,
          { pageNum, pageSize, tableData } = this,
          { list, total } = await uni.$api.customerApi.getLastWeekSopTaskCustomerPage({ merchantId, pageNum, pageSize })
        if (assignment) {
          this.tableData = [...tableData, ...list]
          this.tableRef().loadComplete = true
          this.total = total
          uni.hideLoading()
        }
        this.$set(this.tabs, 1, `近7日已推送客户(${total})`)
      } catch (error) {
        this.tableRef() && (this.tableRef().loadComplete = true)
      }
    }
  }
}
</script>
<style scoped lang='scss'>
.customer-box {
  width: 100%;
  height: 100%;
  padding: toRpx(32) toRpx(40) 0;
  box-sizing: border-box;

  .sprite-icon {
    margin-right: toRpx(8);
  }

  .tips {
    height: toRpx(64);
    background: #2C66F70D;
    padding: 0 toRpx(24);
    font-size: toRpx(26);
    color: #6C6F75;
    border-radius: toRpx(20);
    .today{
      line-height: toRpx(38);
    }
    .text {
      margin-left: auto;
    }
  }

  .tabs-box {
    display: flex;
    margin: toRpx(28) 0;
    gap: toRpx(28);

    .tab {
      line-height: toRpx(64);
      height: toRpx(64);
      padding: 0 toRpx(32);
      border-radius: toRpx(16);
      background: #F2F2F2;
      font-size: toRpx(28);
      color: #292D33;
      justify-content: center;
      transition: all 0.2s ease-in-out;
    }

    .tab.active {
      background: #2C66F71A;
      color: #2C66F7;
    }
  }

  .customer-content {
    height: calc(100% - #{toRpx(184)});
  }
}
</style>