<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" >
      <el-form-item label="姓名" prop="nameOrPhone" label-width="40px">
        <el-input
          v-model.trim="queryParams.nameOrPhone"
          placeholder="请输入姓名"
          clearable
          size="small"
          style="width: 160px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="消费时间">
         <el-date-picker
         style="margin-top:5px;"
          v-model="dateRange"
          size="small"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary"  size="mini" @click="handleQuery">搜索</el-button>
        <el-button plain  size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="adminList" >
      <el-table-column label="序号" align="center" prop="" show-overflow-tooltip >
        <template slot-scope="scope">
         {{scope.$index + 1}}
        </template>
      </el-table-column>
      <el-table-column label="姓名" align="center" prop="name"  show-overflow-tooltip />
      <el-table-column label="卡编号" align="center" prop="cardNo" show-overflow-tooltip />
      <el-table-column label="消费金额（元）" align="center" prop="amt" show-overflow-tooltip >
        <template slot-scope="scope">
          <span>{{Number(scope.row.amt).toFixed(2) || "0.00"}}</span>
        </template>
      </el-table-column>
      <el-table-column label="消费终端名称" align="center" prop="termName" show-overflow-tooltip />
      <el-table-column label="消费类型" align="center" prop="shopName" show-overflow-tooltip />
      <el-table-column label="交易类型" align="center" prop="type" show-overflow-tooltip >
         <template slot-scope="scope">
          <span v-if="scope.row.type == 1" style="color:#67C23A">消费</span>
          <span v-if="scope.row.type == 1001" style="color:#F56C6C">消费撤单</span>
        </template>
      </el-table-column>
      <el-table-column label="餐饮时段" align="center" prop="part" show-overflow-tooltip >
        <template slot-scope="scope">
          <span v-if="scope.row.part == 1" style="color:#909399">早餐</span>
          <span v-if="scope.row.part == 2" style="color:#E6A23C">午餐</span>
          <span v-if="scope.row.part == 3" style="color:#409EFF">晚餐</span>
          <span v-if="scope.row.part == 4" style="color:#F56C6C">夜宵</span>
        </template>
      </el-table-column>

      <el-table-column label="余额（元）" align="center" prop="balance" show-overflow-tooltip >
       <template slot-scope="scope">
          <span>{{Number(scope.row.balance).toFixed(2) || "0.00"}}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime"  show-overflow-tooltip >
        <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.current"
      :limit.sync="queryParams.size"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listDetal, exportDetail, updataChannel } from "@/api/recharge/consumption";

export default {
  name: "admin",
  data() {
    return {
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 参数表格数据
      adminList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        nameOrPhone: undefined,

      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //强制el-input刷新
    onInput(){
        this.$forceUpdate();
    },
    /** 查询参数列表 */
    getList() {
      this.loading = true;
      this.queryParams.params =undefined
      listDetal(this.addDateRange(this.queryParams,this.dateRange,'section')).then(response => {
          this.adminList = response.data.records;
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        ids: undefined,
        name: undefined,
        topChannelName: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.current = 1;
      this.getList();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      Object.assign(this.form, row.id ? this.adminList.find(val=>val.id === row.id) : this.adminList.find(val=>val.id === this.ids[0]))
      updataChannel(this.form).then(response => {
        this.msgSuccess("修改成功");
        this.getList();
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.queryParams.startMoney = undefined;
      this.queryParams.endMoney = undefined;
      this.queryParams.startTime = undefined;
      this.queryParams.endTime = undefined;
      this.queryParams.payType = undefined;
      this.queryParams.userName = undefined;
      this.queryParams.userPhone = undefined;
      this.queryParams.orderFlag = undefined;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      let queryParams = {...this.queryParams};
      delete queryParams.current
      delete queryParams.size
      this.exportLoading = true;
      exportDetail(queryParams).then(response =>{
        this.exportLoading = false;
        localStorage.setItem('fileExportId', response.data)
        this.$router.push({path:'/recharge/fileExport'})
      })
      // this.$confirm('是否确认导出数据?', "警告", {
      //   confirmButtonText: "确定",
      //   cancelButtonText: "取消",
      //   type: "warning"
      // }).then(() => {
      //   this.exportLoading = true;
      //   return exportDetail(queryParams);
      // }).then(res => {
      //   this.downloadBlob(res)
      //   this.exportLoading = false;
      // }).catch(() => {
      //   this.exportLoading = false;
      // });
    }

    //   exportDetail(queryParams).then(res => {
    //       this.$router.push({path:'/recharge/detailed'})
    //       localStorage.setItem('fileExportId', msg)
    //       // // this.downloadBlob(res)
    //       // this.exportLoading = false;
    //     }).catch(() => {
    //       // this.exportLoading = false;
    //     });
    //     // exportDetail(queryParams).then(response =>{
    //     //   this.$router.push({path:'/recharge/detailed'})
    //     //   localStorage.setItem('fileExportId', msg)
    //     // }).catch(err =>{

    //     // })
    //     // localStorage.setItem("timeout","大于10s")
    //   //  this.$confirm('是否确认导出数据?', "警告", {
    //   //     confirmButtonText: "确定",
    //   //     cancelButtonText: "取消",
    //   //     type: "warning"
    //   //   }).then(() => {
    //   //     this.exportLoading = true;
    //   //     return exportDetail(queryParams);
    //   //   }).then(res => {
    //   //     // this.downloadBlob(res)
    //   //     this.exportLoading = false;
    //   //   }).catch(() => {
    //   //     this.exportLoading = false;
    //   //   });
    // },
  }
};
</script>
