<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="订单名称" prop="OrderName">
       <el-select clearable v-model="queryParams.status" placeholder="请选择订单状态" multiple>
        <el-option :value="1" label="待支付" >待支付</el-option>
        <el-option :value="2" label="支付失败" >支付失败</el-option>
        <el-option :value="3"  label="支付超时">支付超时</el-option>
        <el-option :value="4" label="待取餐" >待取餐</el-option>
        <el-option :value="5" label="已完成" >已完成</el-option>
        <el-option :value="6"  label="已退款">已退款</el-option>
      </el-select>
      <!-- {{ queryParams.status }} -->
        <!-- <el-input v-model="queryParams.OrderName" placeholder="请输入订单名称" clearable @keyup.enter.native="handleQuery"/> -->
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)"
                   v-hasPermi="['restaurant:order:create']">新增</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"
                   v-hasPermi="['restaurant:order:export']">导出</el-button>
      </el-col> -->
              <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

      <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
            <!-- <el-table-column label="订单编号" align="center" prop="id" /> -->
      <el-table-column label="订单名称" align="center" prop="name" />
      <el-table-column label="取餐人手机尾号" align="center" prop="phone" />
      <el-table-column label="订单价格" align="center" prop="priceVisable" >
        <template v-slot="scope">
          <span>{{ scope.row.priceVisable}}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单类型" align="center" prop="type" >
        <template v-slot="scope">
          <span v-show="scope.row.type==1">到店</span>
          <span v-show="scope.row.type==2">配送</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="订单图标" align="center" prop="OrderIcon" /> -->
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center" prop="state" >
        <template v-slot="scope">
          <span v-show="scope.row.state==1">待支付</span>
          <span v-show="scope.row.state==2">支付失败</span>
          <span v-show="scope.row.state==3">支付超时</span>
          <span v-show="scope.row.state==4">待取餐</span>
          <span v-show="scope.row.state==5">已完成</span>
          <span v-show="scope.row.state==6">已退款</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template v-slot="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)"
                    v-show="scope.row.state==4"
                     v-hasPermi="['restaurant:order:update']">修改</el-button>
          <el-button style="color: #666;" size="mini" type="text" icon="el-icon-search" @click="handleInspect(scope.row.id)"
                     v-hasPermi="['restaurant:order:update']">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>
    <!-- 对话框(添加 / 修改) -->
    <OrderForm ref="formRef" @success="getList" />
    </div>
</template>

<script>
import * as OrderApi from '@/api/restaurant/order';
import * as TypeApi from '@/api/restaurant/type';
import OrderForm from './OrderForm.vue';
export default {
  name: "Order",
  components: {
   OrderForm,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
              // 总条数
        total: 0,
      // 订单列表
      list: [],
      // 是否展开，默认全部展开
      isExpandAll: true,
      // 重新渲染表格状态
      refreshTable: true,
      // 选中行
      currentRow: {},
      // 查询参数
      queryParams: {
                    pageNo: 1,
            pageSize: 10,
            desc:'true',
        OrderName: null,
        OrderPrice: null,
        OrderIcon: null,
        createTime: [],
        OrderTypeId: null,
        // status:[],
      },
      typeArray:[],
            };
  },
  created() {
    this.getList();
    // this.getType()
  },
  methods: {
    /** 查询列表 */
    async getList() {
      try {
      this.loading = true;
      // if(this.queryParams.status !=''){
      //   this.queryParams.status=  this.queryParams.status;
      // }

              const res = await OrderApi.pageOrder(this.queryParams);
              console.log('res',res)
        this.list = res.list;
        this.total = res.total;
      } finally {
        this.loading = false;
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.status=[]
      console.log('resetQuery',this.queryParams.status)
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleInspect(id) {
      this.$refs["formRef"].inspect(id);
    },
    /** 添加/修改操作 */
    openForm(id) {
      this.$refs["formRef"].open(id);
    },
    /** 导出按钮操作 */
    async handleExport() {
      await this.$modal.confirm('是否确认导出所有订单数据项?');
      try {
        this.exportLoading = true;
        const data = await OrderApi.exportOrderExcel(this.queryParams);
        this.$download.excel(data, '订单.xls');
      } catch {
      } finally {
        this.exportLoading = false;
      }
    },
              }
};
</script>
