index.vue 6.4 KB
<template>
  <section class="checkcode-container">
    <!--工具条-->
    <div class="toolbar">
      <el-input width="200" v-model="filters.openid" placeholder="请输入用户openid"></el-input>
      <el-switch
        style="display: block"
        v-model="switchValue"
        active-color="#13ce66"
        inactive-color="#ff4949"
        active-text="只看发送失败"
        inactive-text="全部结果"
      ></el-switch>
      <el-button type="primary" :disabled="loading" v-on:click="reqGetDrawsnQuery">查询</el-button>
    </div>

    <template>
      <div class="app-container" v-for="(application,index) in applications" :key="index">
        <h3>{{application.appName}} {{application.appDir}}</h3>
        <el-table
          class="table"
          highlight-current-row
          v-loading="application.loading || loading"
          :data="application.list"
        >
          <el-table-column label="openid" prop="openid"></el-table-column>
          <el-table-column label="头像">
            <template slot-scope="scope">
              <div class="avatar">
                <img v-show="scope.row.avatar" :src="scope.row.avatar" />
              </div>
            </template>
          </el-table-column>
          <el-table-column label="昵称" prop="nickname"></el-table-column>
          <el-table-column label="串码" prop="drawSn"></el-table-column>
          <el-table-column label="奖品名称" prop="prizeName"></el-table-column>
          <el-table-column label="派发结果">
            <template slot-scope="scope">
              <el-tag type="success" v-if="scope.row.sendSuccess == 1">成功</el-tag>
              <el-tooltip
                v-if="scope.row.sendSuccess == 0"
                class="item"
                effect="dark"
                :content="scope.row.failureReason"
                placement="top-start"
              >
                <el-tag type="danger">失败</el-tag>
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column label="中奖时间" :formatter="formatDate"></el-table-column>
          <el-table-column label="派发结果">
            <template slot-scope="scope">
              <el-button
                type="primary"
                plain
                v-if="scope.row.sendSuccess == 0"
                @click="markSuccess(application,index,scope.row)"
                :disabled="loading"
              >标记成功</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="tips">*标记成功的数据将于当日发送到portal平台</div>
      </div>
    </template>
    <!--列表-->
    <!-- <template>
      <el-table
        class="table"
        highlight-current-row
        v-loading="loading"
        style="width: 100%;"
      >
        <el-table-column label="头像">
          <template slot-scope="scope">
            <div class="avatar">
              <img v-show="scope.row.avatar" :src="scope.row.avatar" />
            </div>
          </template>
        </el-table-column>
      </el-table>
    </template>-->
  </section>
</template>

<script>
Date.prototype.format = function(fmt) {
  var o = {
    "M+": this.getMonth() + 1, //月份
    "d+": this.getDate(), //日
    "h+": this.getHours(), //小时
    "m+": this.getMinutes(), //分
    "s+": this.getSeconds(), //秒
    "q+": Math.floor((this.getMonth() + 3) / 3), //季度
    S: this.getMilliseconds() //毫秒
  };
  if (/(y+)/.test(fmt))
    fmt = fmt.replace(
      RegExp.$1,
      (this.getFullYear() + "").substr(4 - RegExp.$1.length)
    );
  for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt))
      fmt = fmt.replace(
        RegExp.$1,
        RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)
      );
  return fmt;
};

let urls = {
  applications: "/admin/kd/application/available",
  query: "/admin/kd/record/query",
  change: "/admin/kd/record/success"
};

import { request } from "./../../api/api.js";
import { formatDate } from "./../../common/utils.js";

export default {
  data() {
    return {
      loading: false,
      filters: {
        openid: "oUzSMtz0_YXWTTfi5WJfm2yqZa1I"
      },
      switchValue: true,
      applications: [],
      total: 0,
      page: 1,
      pageSize: 20,
      searchNeedMinLength: 3
    };
  },
  methods: {
    init() {
      request.get(urls.applications).then(res => {
        this.applications = res.data.content;
        console.log("this.applications==", this.applications);
        this.applications.forEach(element => {
          element.loading = false;
          element.list = [];
        });
      });
    },
    markSuccess(application, index, row) {
      let params = {
        appCode: application.appCode,
        recordCodes: [row.recordCode]
      };
      this.$confirm("请确保红包下发给用户后再标记成功哦!", "提示", {
        confirmButtonText: "已经下发成功",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.loading = true;
          request.post(urls.change, params).then(res => {
            this.loading = false;
            this._requestResult(index, application);
          });
        })
        .catch(() => {});
    },
    formatDate: function(row, column) {
      return row.createAt
        ? new Date(row.createAt).format("yyyy-MM-dd hh:mm:ss")
        : "-";
    },
    reqGetDrawsnQuery() {
      for (let index in this.applications) {
        let application = this.applications[index];
        this._requestResult(index, application);
      }
    },
    _requestResult(index, application) {
      let params = {
        appCode: application.appCode,
        onlyFailure: this.switchValue ? 1 : 0,
        openid: this.filters.openid
      };
      application.loading = true;
      this.$set(this.applications, index, application);
      request.get(urls.query, params).then(res => {
        application.list = res.data.content;
        application.loading = false;
        this.$set(this.applications, index, application);
        console.log(this.applications);
      });
    }
  },
  mounted() {
    this.init();
  }
};
</script>

<style scoped lang="less">
.toolbar {
  display: flex;
  align-items: center;
}

.el-input {
  width: 200px;
}

.el-switch {
  margin: 0 20px;
}

.app-container {
  width: 100%;
  margin-top: 20px;
  padding: 20px;

  img {
    max-width: 50px;
    max-height: 50px;
  }
}
.tips {
  text-align: right;
  color: #ff0000;
}
</style>