<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="订单号" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入订单号查找"
          clearable
          style="width: 200px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="选择套餐" prop="packageType">
        <el-select v-model="queryParams.packageType" placeholder="选择套餐" clearable style="width: 150px">
          <el-option
            v-for="item in packageOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="选择状态" prop="payStatus">
        <el-select v-model="queryParams.payStatus" placeholder="选择状态" clearable style="width: 150px">
          <el-option
            v-for="item in statusOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </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-row :gutter="10" class="mb8">
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
     </el-row>

         <el-table v-loading="loading" :data="orderList">
      <el-table-column label="订单号" align="center" prop="orderId" :show-overflow-tooltip="true" />
      <el-table-column label="用户昵称" align="center" prop="userNickname" :show-overflow-tooltip="true" />
      <el-table-column label="套餐名称" align="center" prop="packageName" :show-overflow-tooltip="true" />
      <el-table-column label="金额" align="center" prop="amountYuan" width="100">
        <template slot-scope="scope">
          <span>¥{{ scope.row.amountYuan }}</span>
        </template>
      </el-table-column>
      <el-table-column label="支付方式" align="center" prop="payTypeName" width="120" />
      <el-table-column label="开通时间" align="center" prop="startTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="到期时间" align="center" prop="endTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="statusName" width="100">
        <template slot-scope="scope">
          <el-tag :type="getStatusType(scope.row.statusName)" size="mini">
            {{ scope.row.statusName }}
          </el-tag>
        </template>
      </el-table-column>
             <el-table-column label="创建时间" align="center" prop="createTime" width="160">
         <template slot-scope="scope">
           <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
         </template>
       </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    
  </div>
</template>

<script>
import { listOrderInfo } from "@/api/system/orderInfo";

export default {
  name: "Member",
  data() {
    return {
             loading: true,
       showSearch: true,
       total: 0,
       orderList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderId: null,
        packageType: null,
        payStatus: null
      },
      
      packageOptions: [
        { label: '包月', value: '1' },
        { label: '包季度', value: '3' },
        { label: '半年', value: '6' },
        { label: '一年', value: '12' }
      ],
      statusOptions: [
        { label: '待支付', value: 1 },
        { label: '待出货', value: 2 },
        { label: '待退款', value: 3 },
        { label: '已退款', value: 4 },
        { label: '已完成', value: 5 }
      ]
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单列表 */
    getList() {
      this.loading = true;
      listOrderInfo(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
         },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
         /** 重置按钮操作 */
     resetQuery() {
       this.resetForm("queryForm");
       this.handleQuery();
     },
    /** 获取状态标签类型 */
    getStatusType(statusName) {
      switch (statusName) {
        case '待支付':
          return 'warning';
        case '待出货':
          return 'primary';
        case '待退款':
          return 'info';
        case '已退款':
          return 'danger';
        case '已完成':
          return 'success';
        default:
          return 'info';
      }
    }
  }
};
</script>

<style scoped>
.el-tag {
  border-radius: 12px;
}
</style>
