<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="areaId" >
        <el-select v-model="queryParams.areaId" placeholder="请选择运营区">
          <el-option
            v-for="item in areaOptions"
            :key="item.areaId"
            :label="item.areaName"
            :value="item.areaId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          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">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:reconciliation:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="refundList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="时间" align="center" prop="day" />
      <el-table-column label="运营商" align="center" prop="deptName" />
      <el-table-column label="运营区" align="center" prop="areaName" />
      <el-table-column label="累计营收" align="center" prop="income" />
      <el-table-column label="运营商分账" align="center" prop="deptFee" />
      <el-table-column label="合伙人分账" align="center" prop="partnerFee" />
      <el-table-column label="平台服务费" align="center" prop="platformServiceFee" />
      <el-table-column label="骑行订单" align="center" prop="ridingFee" />
      <el-table-column label="调度费用" align="center" prop="dispatchFee" />
    </el-table>

  </div>
</template>

<script>
import { listReconciliation,getAreaList } from "@/api/system/reconciliation";

export default {
  name: "Reconciliation",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 日期范围
      dateRange: [],
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 退款订单表格数据
      refundList: [],
      // 区域列表
      areaOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        refundNo: null,
        orderNo: null,
        userId: null,
        amount: null,
        itemDesc: null,
        areaId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        orderNo: [
          { required: true, message: "关联订单不能为空", trigger: "blur" }
        ],
        userId: [
          { required: true, message: "用户ID不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    getAreaList().then(response => {
      this.areaOptions = response.data;
      if (this.areaOptions.length >= 1) {
        this.queryParams.areaId = this.areaOptions[0].areaId;
      }
      this.getList();
    });
  },
  methods: {
    /** 查询退款订单列表 */
    getList() {
      this.loading = true;
      // console.log("================="+JSON.stringify(this.dateRange))
      this.queryParams.timeStart = this.dateRange[0];
      this.queryParams.timeEnd = this.dateRange[1];
      listReconciliation(this.queryParams).then(response => {
        this.refundList = response.data.reconciliationList;
        // this.total = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        refundNo: null,
        orderNo: null,
        userId: null,
        amount: null,
        dispatchFee: null,
        manageFee: null,
        ridingFee: null,
        appointmentFee: null,
        reason: null,
        createTime: null,
        itemDesc: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    // /** 新增按钮操作 */
    // handleAdd() {
    //   this.reset();
    //   this.open = true;
    //   this.title = "添加退款订单";
    // },
    // /** 修改按钮操作 */
    // handleUpdate(row) {
    //   this.reset();
    //   const id = row.id || this.ids
    //   getRefund(id).then(response => {
    //     this.form = response.data;
    //     this.open = true;
    //     this.title = "修改退款订单";
    //   });
    // },
    // /** 提交按钮 */
    // submitForm() {
    //   this.$refs["form"].validate(valid => {
    //     if (valid) {
    //       if (this.form.id != null) {
    //         updateRefund(this.form).then(response => {
    //           this.$modal.msgSuccess("修改成功");
    //           this.open = false;
    //           this.getList();
    //         });
    //       } else {
    //         addRefund(this.form).then(response => {
    //           this.$modal.msgSuccess("新增成功");
    //           this.open = false;
    //           this.getList();
    //         });
    //       }
    //     }
    //   });
    // },
    // /** 删除按钮操作 */
    // handleDelete(row) {
    //   const ids = row.id || this.ids;
    //   this.$modal.confirm('是否确认删除退款订单编号为"' + ids + '"的数据项？').then(function() {
    //     return delRefund(ids);
    //   }).then(() => {
    //     this.getList();
    //     this.$modal.msgSuccess("删除成功");
    //   }).catch(() => {});
    // },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/refund/export', {
        ...this.queryParams
      }, `refund_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
