<template>
  <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item prop="phonenumber">
          <el-input
            v-model="queryParams.condition"
            placeholder="请输入类别名称"
            clearable
            size="small"
            style="width: 240px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item prop="condition">
          <el-date-picker
            type="daterange"
            v-model="dateRange"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="cyan" 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-table v-loading="loading" :data="list">
        <el-table-column label="序号" type="index" width="50" align="center" />
        <el-table-column label="农户数量" align="center" prop="transferNum" />
        <el-table-column label="打款金额" align="center" prop="transferAmount" :show-overflow-tooltip="true" />
        <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-column label="打款时间" align="center" prop="transferTime" width="160">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.modifiedTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="创建人" align="center" prop="createName" />
        <el-table-column label="打款人" align="center" prop="transferName" />
        <el-table-column label="打款状态" align="center" prop="transferStatus" width="160">
          <template slot-scope="scope">
            <span v-if="scope.row.transferStatus == 0">未清分</span>
            <span v-else-if="scope.row.transferStatus == 1">清分中</span>
            <span v-else="scope.row.transferStatus == 2">清分完成</span>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          width="280"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-view"
              @click="handleView(scope.row)"
              v-hasPermi="['bankCheck:bank:view']"
            >查看</el-button>
            <el-button
              size="mini"
              v-if="scope.row.transferStatus == 0"
              type="warning"
              v-hasPermi="['bankCheck:bank:create']"
              @click="handleSubmit(scope.row)"
            >发送申请</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"
      />
      <add-mobiel
      			v-if="modal.view.visibleModal"
      			:title="modal.view.title"
      			:action="modal.view.action"
      			:visible="modal.view.visibleModal"
      			:selectRow="modal.view.selectRow"
      			@closeviewmodal="closeviewmodal">
      		</add-mobiel>
      <apply-for
          v-if="modal.apply.visibleModal"
          :title="modal.apply.title"
          :action="modal.apply.action"
          :visible="modal.apply.visibleModal"
          :selectRow="modal.apply.selectRow"
          @closeapplymodal="closeapplymodal"
      ></apply-for>
  </div>
</template>

<script>
import { listBank } from "@/api/bankCheck/bank";
import addMobiel from './modal/addMobiel'
import applyFor from './modal/applyFor'
export default {
  name: "bank",
  components: {
    addMobiel,
    applyFor
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: null,
      // 日期范围
      dateRange: "",
      // 表单参数
      form: {},
      //弹出层
      modal:{
        view:{
          action:'',
          title:'',
          visibleModal:false,
          selectRow:null
        },
        apply:{
          action:'',
          title:'',
          visibleModal:false,
          selectRow:null
        }
      },
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /*清分*/
    handleSubmit(row){
      this.modal.apply.visibleModal = true
      this.modal.apply.title = '开始清分'
      this.modal.apply.action = 'add'
      this.modal.apply.selectRow = row
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      listBank(this.addDateRange(this.queryParams, this.dateRange)).then(res => {
          console.log(res)
		  if(res.retHead.errCode == 0){
            this.list = res.retBody
            this.total = res.retHead.total;
          }
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNo:1,
        pageSize:10
      }
      this.handleQuery();
    },
    /** 查看按钮操作 */
    handleView(item){
        this.modal.view.visibleModal = true
        this.modal.view.title = '清分详情'
        this.modal.view.action = 'view'
        this.modal.view.selectRow = item
    },
    //窗口关闭
    closeapplymodal(flag = false){
      this.modal.apply.visibleModal = false
      flag && this.getList()
    },
    closeviewmodal(flag = false){
      this.modal.view.visibleModal = false
      flag && this.getList()
    }
  }
};
</script>
