index.vue 9.73 KB
<template>
  <div>
    <div class="createANewGroupBtn">
      <GLButton fn="新建群发" @click="addSendGroup" :size="size" type="primary" mode="el-button">
        <i class="el-icon-plus"></i>
        新建群发
      </GLButton>
    </div>
    <div class="container">
      <GLCombiForm :formObj="searchForm" :rowNumber="1" :formData="searchFormData" @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>
      <GLTable ref="activeTable" :noDataImg="url" :getListApi="getListApi" :searchForm="searchFormTable" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn" @setTableFinishFun="setTableFinishFun">
        <div slot="optionBtns" slot-scope="scope">
          <div v-if="scope.scope.sendState == 1">
            <span class="sendRecord" @click="traceRecord(scope.scope)">发送记录</span>
          </div>
          <div v-if="scope.scope.sendState == 3">
            <span class="sendRecord" @click="terminatePopup(scope.scope)">终止</span>
          </div>
        </div>
        <div slot="sendState" slot-scope="scope">
          <div class="loginStatus">
            <span class="cycle" :style="{ background: scope.scope.sendState == '1' ? '#2CCA74' : scope.scope.sendState == '2' ? '#EB4E4E' : scope.scope.sendState == '0' ? '#FDB757' : scope.scope.sendState == '3' ? '#E5E5E5':'' }"></span>
            {{ scope.scope.sendState == '1' ? '已完成' : scope.scope.sendState == '2' ? '发送失败' : scope.scope.sendState == '0' ? '发送中' : scope.scope.sendState == '3' ? '待发送':'' }}
          </div>
        </div>
      </GLTable>
    </div>
    <GLDialog title="提示" @onOk="handleSure" @onCancel="popVisible = false" type="error" content="是否确认终止发送?" :visible.sync="popVisible" mode="small"></GLDialog>
    <el-drawer size="50%" title="发送记录" :visible.sync="sendRecordDrawer.isVisible" :direction="sendRecordDrawer.direction">
      <div class="horizon"></div>
      <div class="sendRecordDrawerbox">
        <div v-for="(item, index) in sendRecordDrawer.traceFailandSuccess" :key="index" class="itemContent">
          <div>
            <p class="title">{{ item.title }}</p>
            <p class="num" :style="{ color: item.color }">{{ item.num }}</p>
          </div>
        </div>
      </div>
      <div class="liststyle">
        <GLTable ref="sendRecordDrawerRef" :noDataImg="url" :getListApi="sendRecordDrawer.getListApi" :searchForm="sendRecordDrawer.searchForm" :tableParams="sendRecordDrawer.tableParams" :pageConf="sendRecordDrawer.pageConf">
          <div slot="sendResult" slot-scope="scope">
            <div class="loginStatus">
              <span class="cycle" :style="{ background: scope.scope.sendResult == true ? '#2CCA74' : scope.scope.sendResult == false ? '#EB4E4E' : '' }"></span>
              {{ scope.scope.sendResult == true ? '成功' : scope.scope.sendResult == false ? '失败' : '' }}
            </div>
          </div>
        </GLTable>
      </div>
    </el-drawer>
  </div>
</template>

<script>
import url from '@/assets/empty.png'
export default {
  name: 'collocation',
  data() {
    return {
      url,
      selectItem:{},
      popVisible:false,
      sendRecordDrawer: {
        isVisible: false,
        direction: 'rtl',
        traceFailandSuccess: [
          {
            title: '发送成功',
            id: '1',
            num: '',
            color: '#2CCA74'
          },
          {
            title: '发送失败',
            id: '2',
            num: '',
            color: '#EB4E4E '
          }
        ],
        searchForm: {
          msgId: ''
        },
        tableParams: {
          listName: 'data',
          tableColumns: [
            {
              label: '客户',
              prop: 'customerName'
            },
            {
              label: '发送时间',
              prop: 'sendTime'
            },
            {
              label: '发送结果',
              prop: 'sendResult',
              addHtml: 'sendResult'
            }
          ]
        },
        getListApi: this.$apis.wechatGroup.recordSend,
        pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'count' }
      },
      searchForm: {},
      searchFormData: [
        {
          label: '群发名称',
          name: 'msgName',
          type: 'input',
          isClear: true
        },
        {
          label: '群发时间',
          name: 'daterange',
          type: 'datePicker',
          isClear: true,
          valueFormat: 'yyyy-MM-dd',
          pickerOptions: {
            disabledDate(time) {
              return time.getTime() > Date.now() || time.getTime() < new Date('2017-12-31').getTime()
            }
          }
        },
        {
          label: '群发门店',
          name: 'msgMerchantName',
          type: 'input',
          isClear: true
        }
      ],
      searchFormTable: {},
      tableParams: {
        listName: 'data',
        tableColumns: [
          {
            label: '群发名称',
            prop: 'msgName',
            width: 170,
            line: 1
          },
          {
            label: '群发门店',
            prop: 'msgMerchant',
            width: 170,
            line: 1
          },
          {
            label: '客户数',
            prop: 'customerCount',
            // width: 80
          },
          {
            label: '标签/人群',
            prop: 'labelCrowdName',
            width: 220,
            line: 1
          },
          {
            label: '创建时间',
            prop: 'createTime',
            width: 250,
            line: 1
          },
          {
            label: '发送时间',
            prop: 'sendTime',
            width: 180,
            line: 1
          },
          {
            label: '发送状态',
            prop: 'sendState',
            addHtml: 'sendState',
            width: 150,
          },
          {
            label: '发送成功',
            prop: 'successCompletion',
            width: 150,
          },
          {
            label: '发送失败',
            prop: 'failCompletion',
            width: 150,
          },
          {
            label: '操作',
            prop: 'optionBtns',
            width: '100px',
            addHtml: 'optionBtns',
            fixed: 'right'
          }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'count' },
      getListApi: this.$apis.wechatGroup.batchmessagingRecord
    }
  },
  methods: {
    async handleSure(){
      const {msgId}  = this.selectItem
      await this.$apis.wechatGroup.sendStop({msgId}).then(res =>{
        this.$message({
          message: res.code == '0' ? '终止成功' : res.message,
          type: res.code == '0' ? 'success' : 'error'
        })
      })
      this.popVisible = false
      this.handleReset()
    },
    terminatePopup(scope){
      this.selectItem = scope
      this.popVisible = true
    },
    handleSearch() {
      this.$refs.activeTable.refreshTable()
    },
    // 重置搜索框搜索
    handleReset() {
      this.searchForm = {}
      this.handleSearch()
    },
    getParams() {
      let params = JSON.parse(JSON.stringify(this.searchForm))
      if (params.daterange) {
        params.startTime = this.searchForm.daterange[0]
        params.endTime = this.searchForm.daterange[1]
      } else {
        if (params.startTime) delete params.startTime && delete params.endTime
      }
      delete params.daterange
      return params
    },
    beforeSearchFn() {
      return new Promise(async resolve => {
        this.searchFormTable = this.getParams()
        resolve()
      })
    },
    setTableFinishFun() {
      //接收到的数据为空
      this.$refs.activeTable.data.length ? (this.$refs.activeTable.tableHeightValues = '') : this.$refs.activeTable.setTableHeightFun()
    },
    // 跳转新建群发
    addSendGroup() {
      this.$router.push('/wechatGroup/addWechatGroup')
    },
    async traceRecord(scope) {
      const { msgId, successCompletion, failCompletion } = scope
      this.sendRecordDrawer.traceFailandSuccess[0].num = successCompletion
      this.sendRecordDrawer.traceFailandSuccess[1].num = failCompletion
      this.sendRecordDrawer.searchForm.msgId = msgId
      this.sendRecordDrawer.isVisible = true
      this.$nextTick(() => {
        this.$refs.sendRecordDrawerRef.refreshTable()
      })
    }
  }
}
</script>

<style lang="scss" scoped>
/deep/.el-drawer.rtl{
  overflow: scroll;
}
/deep/ {
  .el-table th > .cell {
    padding: 0 16px;
  }
}
.el-table--border .el-table__cell:first-child .cell, .el-table .cell{
  padding-right: 10px;
}
.loginStatus {
  display: flex;
  align-items: center;
  .cycle {
    margin-right: 8px;
    width: 6px;
    height: 6px;
    display: inline-block;
    border-radius: 50%;
  }
}
.createANewGroupBtn {
  margin-bottom: 16px;
}
.container {
  padding: 20px;
  background-color: #fff;
  .table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    .header-text {
      font-size: 16px;
      color: #333333;
      font-weight: 600;
    }
  }
  .table-btn {
    color: #5850ff;
    border: 1px solid #5850ff;
  }
  .sendRecord {
    color: #5850ff;
    cursor: pointer;
  }
  /deep/.loginStatus {
    display: flex;
    align-items: center;
    .cycle {
      margin-right: 8px;
      width: 6px;
      height: 6px;
      display: inline-block;
      border-radius: 50%;
    }
  }
}
.horizon {
  width: 100%;
  height: 1px;
  background: #e8e8ea;
}
.sendRecordDrawerbox {
  padding: 20px;
  display: flex;
  justify-content: space-between;
  .itemContent {
    width: 46%;
    padding: 8px 0 8px 20px;
    border: 1px solid #e8e8ea;
  }
  .title {
    color: #666666;
    font-size: 14px;
    margin-bottom: 8px;
  }
  .num {
    font-size: 20px;
    font-width: 600;
  }
}
.liststyle{
  padding: 0 20px;
}
</style>