<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="订单号" label-width="60px">
        <el-input
          v-model="queryParams.id"
          placeholder="请输入订单号"
          clearable
          style="width: 240px;"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收支类型">
        <el-select
          v-model="queryParams.incomeExpenses"
          placeholder="收支类型"
          clearable
          style="width: 100%"
        >
          <el-option
            v-for="dict in incomeExpensesList"
            :key="dict.id"
            :label="dict.name"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="业务类型">
        <el-select
          v-model="queryParams.businessType"
          placeholder="业务类型"
          clearable
          style="width: 100%"
        >
          <el-option
            v-for="dict in businessTypeList"
            :key="dict.id"
            :label="dict.name"
            :value="dict.value"
          />
        </el-select>
      </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"  style="margin-left: 0; margin-top: 10px">
      <el-button
        type="primary"
        size="mini"
        icon="el-icon-download"
        :disabled="tableData.length === 0"
        v-hasPermi="['flowingWaterMr:flowingWaterMr:downloadExcel']"
        @click="handleExport"
        v-loading.fullscreen.lock="handleExportLoading"
        element-loading-text="正在拼命生成数据中..."
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.5)"
      >导出excel</el-button>
      <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="type">
        <template slot-scope="scope">
          <span>￥{{ scope.row.orderPrice }}</span>
        </template>
      </el-table-column>
      <el-table-column label="收支类型" align="center" prop="incomeExpenses" />
      <el-table-column label="业务类型" align="center" prop="businessType" />
      <el-table-column label="产生渠道" align="center" prop="refundTime" width="160" >
        <template slot-scope="scope">
          <!-- <span>{{ sourceMap[scope.row.source] }}</span> -->
          <dict-tag :options="dict.type.order_form_type" :value="scope.row.source"/>
        </template>
      </el-table-column>
      <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"
    />

  </div>
</template>

<script>

import { pageList, downOrderListXls } from '@/api/financeMr/flowingWaterMr'
import { exportExcel } from '@/utils/exportexcel'
export default {
  name: "agreement",
  dicts: ['agreement_type','order_form_type'],
  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: [
        {id: 1, name: '申请中', value: 0},
        {id: 2, name: '退款成功', value: 1},
        {id: 3, name: '退款失败', value: 2},
        {id: 4, name: '退款中', value: 3},
      ],
      sourceMap: {
        1: '小程序',
        2: '美团',
        3: '携程',
        4: '公众号',
        5: '支付宝',
      },
      incomeExpensesList: [
        {id: 1, name: '收入', value: '收入'},
        {id: 2, name: '支出', value: '支出'},
      ],
      businessTypeList: [
        {id: 1, name: '购买演出票', value: '购买演出票'},
        {id: 2, name: '票务退款', value: '票务退款'},
      ],
      visibleStatus: false,
      newObj: {},
      visibleType: '',
      handleExportLoading: false,
      tableData: {}
    };
  },
  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.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.$set(this.queryParams, 'id', '');
      this.$set(this.queryParams, 'businessType', '');
      this.$set(this.queryParams, 'incomeExpenses', '');
      this.queryParams.pageNum = 1;
      this.handleQuery();
    },
    /** 详情按钮操作 */
    openDetails(row, type) {
      this.$refs["detailsDia"].openDialog("详情", row, type);
    },
    /**
     * 导出报表
     * @date 2022-10-24
     * @returns {any}
     */
    handleExport() {
      this.$confirm('您确定要导出当前查询的数据吗？', '提示', {
        confirmButtonText: '确定 ',
        cancelButtonText: '取消 ',
        type: 'warning'
      })
        .then(() => {
          this.handleExportLoading = true;
          // const { pageNum, pageSize} = this.params;
          let postMap = {}
          for (let key in this.queryParams) {
            if(key != 'pageNum' && key != 'pageSize'){
              postMap[key] = this.queryParams[key]
            }
          }
          downOrderListXls(postMap)
            .then((res) => {
              exportExcel(res, '流水管理', '.xlsx');
              this.handleExportLoading = false;
            })
            .catch(() => {
              this.handleExportLoading = false;
            });
        })
        .catch(() => {
          this.$message.info('您已取消导出！');
        });
    },
  }
};
</script>
