index.vue 11 KB
<template>
  <div class="send-assistant">
    <div class="menu-sub">
      <div
        class="menu-sub-item"
        :class="[activeIndex == '1' ? 'active' : '']"
        @click="switchMenu(1)"
      >客户群发</div>
      <div
        class="menu-sub-item"
        :class="[activeIndex == '2' ? 'active' : '']"
        @click="switchMenu(2)"
      >客户群群发</div>
    </div>
    <div v-if="activeIndex == 1" class="container">
      <div class="container-header">
        <!-- <el-button
          type="primary"
          :size="size"
          icon="el-icon-plus"
          @click="btnClick('create', 1)"
        >新建群发</el-button>-->
        <GLButton
          type="primary"
          :size="size"
          icon="el-icon-plus"
          fn="新建客户群发"
          @click="btnClick('create', 1)"
        >新建群发</GLButton>
        <div class="text">企业统一选择要发送的客户,由添加客户的成员确认后发送给客户,消息内容仅管理员和负责人可创建。</div>
      </div>
      <!-- 表格区域 开始 -->
      <GLTable
        :key="key"
        ref="customer"
        :getListApi="customerList"
        :tableParams="gueastTableParams"
        :pageConf="gueastPageConf"
      >
        <div slot="entmicro-name" class="entmicro" slot-scope="scope">
          <span v-for="(i, index) in scope.scope.attachmentList" :key="index">
            [共{{scope.scope.attachmentList.length}}条]
            <span v-show="i.attType == 1">{{i.attContent}}</span>
            <span v-show="i.attType == 2 || i.attType == 3">[{{ATT_TYPE[i.attType]}}]</span>
            <span v-show="i.attType == 4 || i.attType == 5">[{{ATT_TYPE[i.attType]}}]</span>
          </span>
        </div>
        <div class="table-btns" slot="optionBtns" slot-scope="scope">
          <span v-if="scope.scope.status == -1" style="color: #EB4E4E;">创建失败</span>
          <span v-else>
            <el-button
              type="text"
              :disabled="scope.scope.unsendUserNum == 0 || (scope.scope.unsendUserNum != 0 && scope.scope.isRemind == 1) || new Date(scope.scope.sendTime) > new Date()"
              @click="btnClick('remind', 1, scope.scope)"
            >提醒发送</el-button>
            <GLButton type="text" fn="客户群发详情" @click="btnClick('detail', 1, scope.scope)">详情</GLButton>
            <!-- <el-button type="text" @click="btnClick('detail', 1, scope.scope)">详情</el-button> -->
          </span>
        </div>
      </GLTable>
      <!-- 表格区域 end -->
    </div>
    <div v-if="activeIndex == 2" class="container">
      <div class="container-header">
        <!-- <el-button
          type="primary"
          :size="size"
          icon="el-icon-plus"
          @click="btnClick('create', 2)"
        >新建群发</el-button>-->
        <GLButton
          type="primary"
          :size="size"
          fn="新建客户群群发"
          icon="el-icon-plus"
          @click="btnClick('create', 2)"
        >新建群发</GLButton>
        <div class="text">管理员或负责人统一创建内容,群主收到通知后,可选择他管理的客户群并群发。</div>
      </div>
      <!-- 表格区域 开始 -->
      <GLTable
        :key="groupKey"
        ref="customerGroup"
        :getListApi="customerGroupList"
        :tableParams="gueastGroupTableParams"
        :pageConf="gueastPageConf"
      >
        <div slot="entmicro-name" class="entmicro" slot-scope="scope">
          <span v-for="(i, index) in scope.scope.attachmentList" :key="index">
            [共{{scope.scope.attachmentList.length}}条]
            <span v-show="i.attType == 1">{{i.attContent}}</span>
            <span v-show="i.attType == 2 || i.attType == 3">[{{ATT_TYPE[i.attType]}}]</span>
            <span v-show="i.attType == 4 || i.attType == 5">[{{ATT_TYPE[i.attType]}}]</span>
          </span>
        </div>
        <div class="table-btns" slot="optionBtns" slot-scope="scope">
          <span v-if="scope.scope.status == -1" style="color: #EB4E4E;">创建失败</span>
          <span v-else>
            <el-button
              type="text"
              :disabled="scope.scope.unsendUserNum == 0 || (scope.scope.unsendUserNum != 0 && scope.scope.isRemind == 1)"
              @click="btnClick('remind', 2, scope.scope)"
            >提醒发送</el-button>
            <GLButton type="text" fn="客户群群发详情" @click="btnClick('detail', 2, scope.scope)">详情</GLButton>
            <!-- <el-button type="text" @click="btnClick('detail', 2, scope.scope)">详情</el-button> -->
          </span>
        </div>
      </GLTable>
      <!-- 表格区域 end -->
    </div>
  </div>
</template>
<script>
import * as dayjs from 'dayjs'
export default {
  name: 'SendAssistant',
  data() {
    const ATT_TYPE = {
      2: '图文消息',
      3: '图文消息',
      4: '链接',
      5: '链接'
    }
    return {
      ATT_TYPE,
      activeIndex: 1,
      gueastTableParams: {
        listName: 'data',
        tableOption: false,
        tableColumns: [
          {
            label: '群发类型',
            prop: 'sendType',
            formatter: cellValue => {
              return {
                1: '立即发送',
                2: '定时发送'
              }[cellValue.sendType]
            }
          },
          {
            label: '群发内容',
            prop: 'massName',
            line: 2,
            minWidth: '100px',
            addHtml: 'entmicro-name'
          },
          {
            label: '发送时间',
            prop: 'sendTime',
            width: 170,
            line: 2
            // formatter: cellValue => {
            //   if (cellValue.sendTime) {
            //     return dayjs(cellValue.sendTime).format('YYYY-MM-DD HH:mm:ss')
            //   } else {
            //     return ''
            //   }
            // }
          },
          {
            label: '已发送员工',
            prop: 'sendUserNum',
            line: 2
          },
          {
            label: '已送达客户',
            prop: 'sendCustomerNum',
            line: 2
          },
          {
            label: '未发送员工',
            prop: 'unsendUserNum',
            line: 2
          },
          {
            label: '未送达客户',
            prop: 'unsendCustomerNum',
            line: 2
          },
          {
            label: '操作',
            prop: 'optionBtns',
            width: '140px',
            addHtml: 'optionBtns'
          }
        ]
      },
      gueastPageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'count' },
      customerList: this.$apis.customerTransform.customerList,
      customerGroupList: this.$apis.customerTransform.customerGroupList,
      gueastGroupTableParams: {
        listName: 'data',
        tableOption: false,
        tableColumns: [
          {
            label: '群发名称',
            prop: 'massName'
          },
          {
            label: '群发内容',
            prop: 'massName',
            line: 2,
            minWidth: '100px',
            addHtml: 'entmicro-name'
          },
          {
            label: '发送时间',
            prop: 'sendTime',
            width: 150,
            line: 2
            // formatter: cellValue => {
            //   if (cellValue.sendTime) {
            //     return dayjs(cellValue.sendTime).format('YYYY-MM-DD HH:mm:ss')
            //   } else {
            //     return ''
            //   }
            // }
          },
          {
            label: '已发送群主',
            prop: 'sendUserNum',
            line: 2
          },
          {
            label: '送达群聊',
            prop: 'sendCustomerNum',
            line: 2
          },
          {
            label: '未发送群主',
            prop: 'unsendUserNum',
            line: 2
          },
          {
            label: '未送达群聊',
            prop: 'unsendCustomerNum',
            line: 2
          },
          {
            label: '操作',
            prop: 'optionBtns',
            width: '140px',
            addHtml: 'optionBtns'
          }
        ]
      },
      key: new Date(),
      groupKey: new Date()
    }
  },
  beforeRouteEnter(to, from, next) {
    next(vm => {
      const path = from.path
      const pathArr = path.split('/')
      if (pathArr[2] == 'addCustomerGroup' || pathArr[2] == 'detaiCustomeGroup') vm.activeIndex = 2
    })
  },
  methods: {
    switchMenu(val) {
      this.$nextTick(() => {
        this.activeIndex = val
        if (val == 1) {
          this.key = new Date()
          if (this.$refs.customer) this.$refs.customer.refreshTable()
        } else {
          this.groupKey = new Date()
          if (this.$refs.customerGroup) this.$refs.customerGroup.refreshTable()
        }
      })
    },
    /**
     * name: 按钮名称
     * type: 1 客户 2 客户群
     * rowData: 行数据
     */
    btnClick(name, type, rowData) {
      switch (name) {
        case 'create':
          if (type == 1) {
            this.$router.push('/customerTransform/addCustomer')
          } else {
            this.$router.push('/customerTransform/addCustomerGroup')
          }
          break
        case 'detail':
          if (type == 1) {
            this.$router.push('/customerTransform/detailCustomer/' + rowData.id)
          } else {
            this.$router.push('/customerTransform/detaiCustomeGroup/' + rowData.id)
          }
          break
        case 'remind':
          var params = {
            id: rowData.id,
            type
          }
          // if (type == 1) {
          this.$apis.customerTransform.listRemindOperate(params).then(res => {
            this.$message({
              type: 'success',
              message: '操作成功!'
            })
            if (type == 1) {
              this.$refs.customer.refreshTable()
            } else {
              this.$refs.customerGroup.refreshTable()
            }
          })
          // } else {
          // }
          break
        default:
          console.log(11)
      }
    }
  }
}
</script>

<style lang="scss" scope>
.send-assistant {
  // margin-top: 26px;
  .menu-sub {
    margin-bottom: 15px;
    .menu-sub-item {
      display: inline-block;
      text-align: center;
      color: #303133;
      font-size: 14px;
      // width: 180px;
      // padding: 0 20px;
      margin-right: 40px;
      height: 32px;
      line-height: 32px;
      cursor: pointer;
      // &:first-child {
      //   padding-left: 0;
      // }
      &.active {
        // background-color: #fff;
        color: #5850ff;
        border-bottom: 2px solid #5850ff;
      }
    }
  }
  .container {
    margin-bottom: 20px;
    background: #ffffff;
    box-shadow: 0 10px 20px 0 rgba(88, 80, 255, 0.1);
    padding: 20px;
    margin-top: 2px;
    &-header {
      display: flex;
      // justify-content: space-between;
      align-items: center;
      padding-bottom: 20px;
      .text {
        font-size: 14px;
        color: #999;
        margin-left: 20px;
      }
    }
  }
}
.entmicro {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
</style>