<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="90px"
    >
      <el-form-item label="盲票组名称" prop="boxTitle">
        <el-input
          v-model="queryParams.boxTitle"
          placeholder="请输入盲票组名称"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="盲票类型" prop="boxType">
        <el-select
          v-model="queryParams.boxType"
          placeholder="请选择盲票类型"
          style="width: 100%"
          size="small"
          filterable
          clearable
          @change="handleQuery"
        >
          <el-option label="线上盲票" value="online"></el-option>
          <el-option label="线下盲票" value="offline"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="用户手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入用户手机号"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="下单时间">
        <el-date-picker
          v-model="tradeTimeArr"
          type="datetimerange"
          size="small"
          value-format="timestamp"
          range-separator="至"
          start-placeholder="时间选择"
          end-placeholder="时间选择"
          @change="tardeTime"
        >
        </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">
      <el-col :span="1.5">
        <el-button
          type="infor"
          plain
          icon="el-icon-download"
          size="small"
          @click="handleExportDraw"
          v-hasPermi="['order:deliver:export']"
          >导出订单</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <!-- 订单状态 -->
    <el-tabs type="card" v-model="state">
      <el-tab-pane label="全部" name="null"></el-tab-pane>
    </el-tabs>

    <!-- 列表 -->
    <el-table ref="table" v-loading="loading" :data="list">
      <el-table-column
        label="订单号"
        fixed="left"
        align="center"
        prop="orderId"
        min-width="110"
      />
      <el-table-column label="下单时间" min-width="100">
        <template slot-scope="{ row }">
          <div>{{ parseTime(row.createdTime) }}</div>
        </template>
      </el-table-column>
      <el-table-column label="盲票组名称" prop="title" min-width="95" />
      <el-table-column label="盲票类型" prop="boxType" min-width="95" />
      <el-table-column label="盲票售价(元)" prop="parentName" min-width="95">
        <template slot-scope="{ row }">
          <div>{{ $numberFormat(row.salePrice) }}</div>
        </template>
      </el-table-column>
      <el-table-column label="支付金额(元)" min-width="95">
        <template slot-scope="{ row }">
          <div>{{ $numberFormat(row.payAmt) }}</div>
        </template>
      </el-table-column>
      <el-table-column label="用户昵称/手机号" min-width="120">
        <template slot-scope="{ row }">
          <div>{{ row.nickName }}/{{ row.phone }}</div>
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" align="center" width="80">
        <template slot-scope="{ row }">
          <div>
            <el-button
              v-hasPermi="['order:channel:query']"
              type="text"
              @click="$router.push({ name: 'UserTicketDetail', query: { id: row.orderId } })"
              >查看</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="pageParams.pageNum"
      :limit.sync="pageParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script>
import { ticketOrderList, ticketOrderExport } from "@/api/business/order";
export default {
  name: "UserTicket",
  data() {
    return {
      loading: false,
      showSearch: true,
      // 筛选
      queryParams: {
        boxTitle: "",
        boxType: "",
        startTime: "",
        endTime: "",
        phone: "",
      },
      // 分页
      pageParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 总条数
      total: 0,
      list: [
        {
          orderId: 1,
        },
      ],
      // 下单时间
      tradeTimeArr: [],
      // 订单列表状态
      state: "null",
    };
  },
  created() {
    this.getList()
  },
  methods: {
    // 订单列表
    getList() {
      this.loading = true;
      ticketOrderList(
        "pageNum=" +
          this.pageParams.pageNum +
          "&pageSize=" +
          this.pageParams.pageSize +
          "&",
        this.queryParams
      )
        .then((res) => {
          this.loading = false;
          if (res.code == 0) {
            this.total = res.total;
            this.list = res.rows;
            this.list.forEach((item) => {
              item.boxType = JSON.parse(item.boxType).desc;
            });
          }
        })
        .catch(() => {
          this.loading = false;
        });
    },

    //搜索
    handleQuery() {
      this.siteList = this.siteCopyList;
      this.pageParams.pageNum = 1;
      this.getList();
    },

    // 重置
    resetQuery() {
      this.resetForm("queryForm");
      this.tradeTimeArr = [];
      this.pageParams.pageNum = 1;
      this.queryParams.startTime = "";
      this.queryParams.endTime = "";
      this.getList();
    },

    // 选择下单时间
    tardeTime(e) {
      if (e) {
        this.queryParams.startTime = e[0];
        this.queryParams.endTime = e[1];
        this.handleQuery();
      } else {
        this.queryParams.startTime = "";
        this.queryParams.endTime = "";
        this.handleQuery();
      }
    },

    // 查看详情
    getDetail(row) {
      this.$router.push({ name: "ChannelDetail", query: { id: row.orderId } });
    },

    // 点击发货
    toGoods(row) {
      this.goodsShow = true;
      this.goodsInfo = row;
      this.getBoxList(row);
    },

    // 关闭发货弹框
    close() {
      this.getList();
    },

    // 导出订单
    handleExportDraw() {
      this.$confirm("是否确认导出订单?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.vloading = this.$loading({
            lock: true,
            text: "正在导出订单.....",
            background: "rgba(0, 0, 0, 0.7)",
          });
          return ticketOrderExport(this.queryParams);
        })
        .then((response) => {
          this.vloading.close();
          this.download(response.msg);
        })
        .catch(() => {
          this.vloading.close();
        });
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-tabs--border-card > .el-tabs__content {
  padding: 0;
}
</style>