<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="订单号" label-width="60px">
        <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.idCard"
          placeholder="用户身份信息"
          clearable
          style="width: 240px;"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="核销设备类型">
        <el-select
          v-model="queryParams.deviceType"
          placeholder="核销设备类型"
          clearable
          style="width: 100%;"
        >
          <el-option
            v-for="dict in dict.type.device_sys_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="设备名称" label-width="70px">
        <el-input
          v-model="queryParams.deviceName"
          placeholder="设备名称"
          clearable
          style="width: 240px;"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="核销日期" label-width="70px">
        <el-date-picker
          style="width: 250px;"
          v-model="queryParams.writeoffTime"
          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="orderId" />
      <el-table-column label="用户身份证信息" align="center" prop="idCard" />
      <el-table-column label="观影人姓名" align="center" prop="name" />
      <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="deviceType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.device_sys_type" :value="scope.row.deviceType"/>
        </template>
      </el-table-column>
      <el-table-column label="设备名称" align="center" prop="deviceName" />
      <el-table-column label="核销时间" align="center" prop="createTime" width="160" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </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/writeOffMr'
import detailsDia from "./dialog/details.vue";
import moment from "moment"
export default {
  name: "WriteOffMr",
  dicts: ['device_sys_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,
      },
    };
  },
  created() {
    this.$set(this.queryParams,'writeoffTime',[moment().format("yyyy-MM-DD"),moment().format("yyyy-MM-DD")])
    this.getList();
  },
  activated(){
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      if(this.queryParams.writeoffTime){
        this.queryParams.createTimeBegin = this.queryParams.writeoffTime[0];
        this.queryParams.createTimeEnd = this.queryParams.writeoffTime[1];
      }else{
        this.queryParams.createTimeBegin = null
        this.queryParams.createTimeEnd = null
      }
      pageList(this.addDateRange(this.queryParams))
      .then(response => {
          this.dataList = response.data.rows;
          this.total = response.data.total;
          this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if(this.queryParams.writeoffTime){
        this.queryParams.createTimeBegin = this.queryParams.writeoffTime[0];
        this.queryParams.createTimeEnd = this.queryParams.writeoffTime[1];
      }else{
        this.queryParams.createTimeBegin = null
        this.queryParams.createTimeEnd = null
      }
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.$set(this.queryParams, 'orderId', '');
      this.$set(this.queryParams, 'idCard', '');
      this.$set(this.queryParams, 'deviceType', '');
      this.$set(this.queryParams, 'deviceName', '');
      this.$set(this.queryParams, 'writeoffTime', []);
      this.queryParams.pageNum = 1;
      this.handleQuery();
    },
    /** 详情按钮操作 */
    openDetails(row, type) {
      this.$refs["detailsDia"].openDialog("详情", row, type);
    },
  }
};
</script>
