<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="小程序" prop="appid">
        <el-select 
          v-model="queryParams.appid" 
          placeholder="请选择小程序" 
          clearable 
          filterable
          size="small"
          style="width: 200px"
        >
          <el-option
            v-for="item in appOptions"
            :key="item.appid"
            :label="item.name"
            :value="item.appid"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="上传状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择上传状态" clearable size="small">
          <el-option label="待执行" value="0" />
          <el-option label="执行中" value="1" />
          <el-option label="执行成功" value="2" />
          <el-option label="执行失败" value="3" />
          <el-option label="已取消" value="4" />
        </el-select>
      </el-form-item>
      <el-form-item label="订单号" prop="orderCode">
        <el-input
          v-model="queryParams.orderCode"
          placeholder="请输入订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="wxExpressTaskList">
      <el-table-column label="ID" align="center" prop="id" width="80" />
      <el-table-column label="订单号" align="center" prop="orderCode" width="180" />
      <el-table-column label="用户ID" align="center" prop="userId" width="100" />
      <el-table-column label="数据" align="center" prop="data" width="200" show-overflow-tooltip />
      <el-table-column label="任务状态" align="center" prop="status" width="120">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status === 0" type="info">待执行</el-tag>
          <el-tag v-else-if="scope.row.status === 1" type="warning">执行中</el-tag>
          <el-tag v-else-if="scope.row.status === 2" type="success">执行成功</el-tag>
          <el-tag v-else-if="scope.row.status === 3" type="danger">执行失败</el-tag>
          <el-tag v-else-if="scope.row.status === 4" type="info">已取消</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="重试次数" align="center" prop="retryCount" width="100" />
      <el-table-column label="请求体" align="center" prop="requestBody" width="200" show-overflow-tooltip />
      <el-table-column label="响应体" align="center" prop="responseBody" width="200" show-overflow-tooltip />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="快递公司" align="center" prop="expressCompany" width="120" />
      <el-table-column label="快递单号" align="center" prop="expressNo" width="150" />
      <el-table-column label="订单类型" align="center" prop="type" width="120">
        <template slot-scope="scope">
          <span v-if="scope.row.type === 0">商城订单</span>
          <span v-else-if="scope.row.type === 1">直播订单</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="小程序ID" align="center" prop="appid" width="180" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { list } from "@/api/live/wxExpressTask";
import { list as listAppConfig } from "@/api/course/coursePlaySourceConfig";

export default {
  name: "WxExpressTask",
  data() {
    return {
      loading: true,
      showSearch: true,
      wxExpressTaskList: [],
      total: 0,
      appOptions: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        appid: null,
        status: null,
        orderCode: null
      }
    };
  },
  created() {
    this.getList();
    this.getAppList();
  },
  methods: {
    /** 查询微信快递任务列表 */
    getList() {
      this.loading = true;
      list(this.queryParams).then(response => {
        this.wxExpressTaskList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 获取小程序列表 */
    getAppList() {
      listAppConfig({ pageNum: 1, pageSize: 100 }).then(response => {
        if (response.rows) {
          this.appOptions = response.rows;
        }
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    }
  }
};
</script>

<style scoped>
</style>