<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单号">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入订单号"
          clearable
          style="width: 240px;"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="购票人手机号" label-width="100px">
        <el-input
          v-model="queryParams.memberMobile"
          placeholder="请输入购票人手机号"
          clearable
          style="width: 240px;"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="剧目名称">
        <el-input
          v-model="queryParams.performName"
          placeholder="请输入剧目名称"
          clearable
          style="width: 240px;"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单状态">
        <el-select
          v-model="queryParams.status"
          placeholder="订单状态"
          clearable
          style="width: 100%"
        >
          <el-option
            v-for="dict in statusMapList"
            :key="dict.value"
            :label="dict.name"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="购票渠道">
        <el-select
          v-model="queryParams.source"
          placeholder="购票渠道"
          clearable
          style="width: 100%"
        >
          <el-option
            v-for="dict in sourceMapList"
            :key="dict.value"
            :label="dict.name"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="支付时间">
<!--        <el-date-picker-->
<!--          v-model="queryParams.payBeginTime"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="选择日期">-->
<!--        </el-date-picker>-->
        <el-date-picker
          v-model="queryParams.time"
          type="daterange"
          value-format="yyyy-MM-dd"
          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-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table ref="tables" v-loading="loading" :data="dataList" border>
      <el-table-column label="序号" align="center" type="index" width="60"></el-table-column>
      <el-table-column label="订单号" align="center" prop="id" />
      <el-table-column label="购票人手机号" align="center" prop="memberMobile" />
      <el-table-column label="剧目名称" align="center" prop="performName" />
      <el-table-column label="票务名称" align="center" prop="goodsName" />
      <el-table-column label="票务类型" align="center" prop="seatTypeName" />
      <el-table-column label="购票渠道" align="center" prop="type">
        <template slot-scope="scope">
          <span>{{ sourceList[scope.row.source] }}</span>
        </template>
      </el-table-column>
      <el-table-column label="购票数量" align="center" prop="quantity" />
      <el-table-column label="支付总额" align="center" prop="orderPrice">
        <template slot-scope="scope">
          <span>￥{{ scope.row.orderPrice }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="优惠信息" align="center" prop="refundReason" />-->
      <el-table-column label="支付方式" align="center" prop="type">
        <template slot-scope="scope">
          <span>{{ payWayList[scope.row.payWay] }}</span>
        </template>
      </el-table-column>
      <el-table-column label="支付时间" align="center" prop="payTime" width="160" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center" prop="type">
        <template slot-scope="scope">
          <span>{{statusList[scope.row.status]}}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="100" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="openDetails(scope.row)"
            v-hasPermi="['orderMr:orderMr:details']"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

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

    <!-- 详情 -->
    <details-dia ref="detailsDia" @getList="getList"></details-dia>

  </div>
</template>

<script>

import { pageList } from '@/api/order/orderMr'
import detailsDia from "./dialog/details.vue";

export default {
  name: "agreement",
  dicts: ['agreement_type'],
  components: { detailsDia },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      dataList: null,
      // 弹出层标题
      title: "",

      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      statusList: {
        0: '待支付',
        2: '超时取消',
        3: '支付完成，待使用',
        4: '退款中',
        5: '己退款',
        6: '退款失败',
        7: '己使用',
        8: '己超期',
        9: '关闭',
      },
      statusMapList: [
        {id: 1, name: '待支付', value: 0},
        {id: 2, name: '超时取消', value: 2},
        {id: 3, name: '支付完成，待使用', value: 3},
        {id: 4, name: '退款中', value: 4},
        {id: 5, name: '己退款', value: 5},
        {id: 6, name: '退款失败', value: 6},
        {id: 7, name: '己使用', value: 7},
        {id: 8, name: '己超期', value: 8},
        {id: 9, name: '关闭', value: 9},
      ],
      payList: {
        0: '未支付',
        1: '已支付',
        2: '支付中',
        3: '支付失败',
        4: '支付退款',
      },
      payWayList: {
        'cahsh': '现金',
        'wecaht.applet': '微信小程序支付',
        'alipay': '支付宝',
      },
      sourceList: {
        1: '小程序',
        2: '美团',
        3: '携程',
      },
      sourceMapList: [
        {id: 1, name: '小程序', value: 1},
        {id: 2, name: '美团', value: 2},
        {id: 3, name: '携程', value: 3},
      ],
      visibleStatus: false,
      newObj: {},
      visibleType: ''
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      pageList(this.addDateRange(this.queryParams, this.dateRange))
      .then(response => {
          this.dataList = response.data.rows;
          this.total = response.data.total;
          this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.payBeginTime = this.queryParams.time[0];
      this.queryParams.payEndTime = this.queryParams.time[1];
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.$set(this.queryParams, 'orderId', '');
      this.$set(this.queryParams, 'status', '');
      this.$set(this.queryParams, 'memberMobile', '');
      this.$set(this.queryParams, 'source', '');
      this.$set(this.queryParams, 'performName', '');
      this.$set(this.queryParams, 'payBeginTime', '');
      this.$set(this.queryParams, 'payEndTime', '');
      this.$set(this.queryParams, 'time', '');
      this.queryParams.pageNum = 1;
      this.handleQuery();
    },
    /** 详情按钮操作 */
    openDetails(row, type) {
      this.$refs["detailsDia"].openDialog("详情", row, type);
    },
  }
};
</script>
