index.vue 9.87 KB
<template>
  <div>

    <el-container>
      <el-header>
        <div class="app-container">
          <el-button type="primary" @click="handleCreate()">创建</el-button>
          <el-button type="primary" @click="exportTO()">导出</el-button>
        </div>
      </el-header>
      <el-main>
        <div class="app-container">
          <el-table
            v-loading="loading"
            :data="qrcodelist"
            style="width: 100%">
            <el-table-column prop="sceneStr" label="场景">
            </el-table-column>
            <el-table-column prop="ticket" label="二维码">
              <template slot-scope="scope">
                <a :href="ticket+scope.row.ticket" target="_blank"><el-image style="width:60px;" :src="ticket+scope.row.ticket"></el-image></a>
              </template>
            </el-table-column>
            <el-table-column prop="subCount" label="订阅数量">
            </el-table-column>
            <el-table-column prop="unsubCount" label="取消订阅数量">
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-link type="primary" icon="el-icon-edit" @click="handleEdit(scope.$index, scope.row)">修改</el-link>
                <el-link type="primary" @click="handleDetail(scope.$index, scope.row)">详情<i
                  class="el-icon-view el-icon--right"></i></el-link>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-main>

      <el-footer>

      </el-footer>

      <el-dialog title="场景二维码新建/保存"
                 :visible.sync="dialogFormVisible"
      >
        <el-form :model="editForm" label-width="80px">
          <el-form-item label="场景名:">
            <el-input v-model="editForm.sceneStr"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="qrCodeSave()">确 定</el-button>
        </div>
      </el-dialog>

      <el-dialog title="详情"
                 :visible.sync="dialogDetailVisible"
      >
        <el-header>
          <el-date-picker
            clearable
            v-model="value"
            type="daterange"
            align="right"
            unlink-panels
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="timestamp"
            @change="chooseTime"
            :picker-options="pickerOptions">
          </el-date-picker>
          <el-link @click="oneWeek" type="primary">最近一周</el-link>
          <el-link @click="oneMonth" type="primary">最近一个月</el-link>
          <el-link @click="threeMonth" type="primary">最近三个月</el-link>
          <el-button type="primary" @click="exportExcel">导出</el-button>
        </el-header>
        <el-main>
          <div>
            <el-table
              v-loading="subloading"
              :data="sublist">
              <el-table-column prop="openid" label="openid">
              </el-table-column>
              <el-table-column prop="subscribe" label="事件操作">
                <template slot-scope="scope">
                  <el-tag type="info" v-show="scope.row.subscribe===0">取消订阅</el-tag>
                  <el-tag type="success" v-show="scope.row.subscribe===1">订阅</el-tag>
                </template>
              </el-table-column>
              <el-table-column prop="createTime" label="时间">
                <template slot-scope="scope">
                  {{timestampToTime(scope.row)}}
                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-main>
        <el-footer>
          <div class="block" style="text-align:right;">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page.sync="tableForm.page"
              :page-size="tableForm.size"
              layout="total,prev, pager, next, jumper"
              :total="total">
            </el-pagination>
          </div>
        </el-footer>
      </el-dialog>

    </el-container>
  </div>
</template>

<script>
  import {request} from '@/api/fetch-api';
  import api from '@/api/api.js'

  let urls = {
    qrlist: "/aiwanpaiapi/tianbao/qr/code/list",
    sublist: "/aiwanpaiapi/tianbao/subscribe/list",
    export2: "/aiwanpaiapi/tianbao/subscribe/export2",
    export3: "/aiwanpaiapi/tianbao/subscribe/export3",
    save: "/aiwanpaiapi/tianbao/qr/code/save"
  };
  export default {
    data() {
      return {
        ticket: 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=',
        qrcodelist: [],
        sublist: [],
        qrcode: {},
        editForm: {},
        loading: true,
        subloading: true,
        total: 0,
        tableForm: {
          qrCodeCode: '',
          start: '',
          end: '',
          page: 1,
          size: 10
        },
        value: [],
        dialogFormVisible: false,
        dialogDetailVisible: false,
        pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
      }
    },
    methods: {
      initQrCodeList() {
        request.get(urls.qrlist, {}).then(response => {
          this.qrcodelist = response.content;
          this.loading = false
        });
      },
      subscribeByQrCodeCode() {
        console.log("tableForm===", this.tableForm)
        request.get(urls.sublist, this.tableForm).then(response => {
          this.sublist = response.content.list;
          this.total = response.content.total;
          this.subloading = false;
        });
      },
      /*导出部分*/
      exportExcel() {
        console.log("start", this.tableForm.start);
        console.log("end", this.tableForm.end);
        let url = request.build(urls.export3, this.tableForm);
        window.open(url);
      },
      /*创建场景二维码*/
      handleCreate() {
        this.dialogFormVisible = true;
        this.editForm = {}
      },
      /*导出场景*/
      exportTO() {
        let url = request.build(urls.export2);
        window.open(url);
      },
      qrCodeSave() {
        request.post(urls.save, this.editForm).then(response => {
          this.dialogFormVisible = false;
          this.initQrCodeList();

          if (response.content === "error") {
            this.$message.error("身份错误")
          } else {
            this.$message.success("保存成功");
          }
        }).catch(() => {
          this.$message.error("保存失败")
        });
      },

      /*弹出修改窗口*/
      handleEdit(index, row) {
        this.dialogFormVisible = true;
        this.editForm = row;
      },
      /*详情窗口*/
      handleDetail(index, row) {
        this.dialogDetailVisible = true;
        this.tableForm.qrCodeCode = row.qrCodeCode;
        console.log("tableForm.qeCodecode", this.tableForm.qrCodeCode);
        this.oneWeek();
        //this.subscribeByQrCodeCode();
      },
      /*分页*/
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
        this.tableForm.size = val;
        this.subscribeByQrCodeCode()
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        this.tableForm.page = val;
        this.subscribeByQrCodeCode()
      },
      /*时间戳转时间*/
      timestampToTime(row) {
        var date = new Date(row.createTime * 1000); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
        var Y = date.getFullYear() + '-';
        var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
        var D = date.getDate() + ' ';
        var h = date.getHours() + ':';
        var m = date.getMinutes() + ':';
        var s = date.getSeconds();
        return Y + M + D + h + m + s
      },
      /*改变时间*/
      chooseTime(time) {
        console.log("time", time)
        if (time != null) {
          this.tableForm.start = Math.round(time[0] / 1000).toString();
          this.tableForm.end = Math.round(time[1] / 1000).toString();
        } else {
          this.tableForm.start = '';
          this.tableForm.end = '';
        }
        this.subscribeByQrCodeCode();
      },
      /*一周*/
      period(lastDay) {
        let now = new Date();
        this.tableForm.end = Math.round((now.getTime()) / 1000).toString();
        let seventDay = Math.round((now.getTime() - lastDay * 24 * 60 * 60 * 1000) / 1000).toString();
        this.tableForm.start = seventDay;
        this.value=[];
        this.value.push(new Date(now.getTime() - lastDay * 24 * 60 * 60 * 1000));
        this.value.push(now);
      },
      /*最近一周*/
      oneWeek() {
        this.period(7);
        this.subscribeByQrCodeCode();
      },
      oneMonth() {
        this.period(30);
        this.subscribeByQrCodeCode();
      },
      threeMonth() {
        this.period(90);
        this.subscribeByQrCodeCode();
      },

    },
    created() {
      this.initQrCodeList()
    }
  }
</script>

<style scoped>

</style>