<template>
  <div class="container"  style="padding: 30px!important; ">
    <el-form :model="queryParam" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="工具类型" prop="toolType">
        <el-select v-model="queryParam.toolType">
          <el-option label="" value="">请选择</el-option>
          <el-option v-for="item in this.toolTypes" :key="item.dictValue" :label="item.dictLabel"
                     :value="item.dictValue * 1"/>
        </el-select>
      </el-form-item>
      <el-form-item label="交付方式" prop="deliverType">
        <el-select v-model="queryParam.deliverType">
          <el-option label="" value="">请选择</el-option>
          <el-option label="License" value="License">License</el-option>
          <el-option label="SaaS" value="SaaS">SaaS</el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="订单时间">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </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="orders" ref="multipleTable">
      <el-table-column label="订单编号" align="center" key="orderNumber" width="200" prop="orderNumber" :show-overflow-tooltip="true"/>
      <el-table-column label="用户姓名" align="center" key="userName" prop="userName"  :show-overflow-tooltip="true">
        <template slot-scope="scope">
           {{scope.row.userName}}
        </template>
      </el-table-column>
      <el-table-column label="商品名称" align="center" key="name" prop="name"  :show-overflow-tooltip="true">
        <template slot-scope="scope">
       <router-link :to="'/test/tool/detail/'+ scope.row.toolId" class="link-type">  {{scope.row.name}}</router-link>
        </template>
      </el-table-column>
      <el-table-column label="商品类型" align="center" key="type" prop="type"  width="150" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <tool-type :type="scope.row.type"></tool-type>
        </template>
      </el-table-column>
      <el-table-column label="交付方式" align="center" key="deliverType" prop="deliverType" width="100"
                       :show-overflow-tooltip="true">
      </el-table-column>
      <el-table-column label="商品数量" align="center" key="amount" prop="amount" width="100"
                       :show-overflow-tooltip="true"/>
      <el-table-column label="订单金额" align="center" key="fee" prop="fee" width="100" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{scope.row.fee}}元</span>
        </template>
      </el-table-column>
      <el-table-column label="付款方式" align="center" key="payType" prop="payType" width="100" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{scope.row.payType=='wx'?'微信支付':'支付宝支付' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center" key="status" prop="status" width="100" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{scope.row.status==0?'未支付':scope.row.status==1?'支付成功':'支付失败' }}</span>
        </template>
      </el-table-column>
      <!--      <el-table-column label="创建时间" align="center" key="createTime" prop="createTime" width="200">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span>{{ parseTime(scope.row.createTime) }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column label="支付时间" align="center" key="payTime" prop="payTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payTime) }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParam.pageNum"
      :limit.sync="queryParam.pageSize"
      @pagination="handleQuery"
    />
  </div>
</template>

<script>
  import {listOrder} from "@/api/order/order";
  import ToolType from "@/views/components/enum/ToolType";

  export default {
    name: "OrderList",
    components: {ToolType},
    data() {
      return {
        loading: false,
        orders: [],
        // 总条数
        total: 0,
        // 日期范围
        dateRange: [],
        toolTypes: [],
        // 查询参数
        queryParam: {
          pageNum: 1,
          pageSize: 10,
          deliverType: undefined,
          toolType: undefined
        }
      }
    },
    created() {
     this.handleQuery();
      this.getDicts("sys_tool_type").then(response => {
        this.toolTypes = response.data;
      })
    },
    methods: {
      handleQuery() {
        listOrder(this.addDateRange(this.queryParam, this.dateRange)).then(response => {
          this.orders = response.rows;
          this.total = response.total;
        })
      },
      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.handleQuery();
      }
    }
  }
</script>

<style scoped>
</style>
