<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
       <el-form-item label="公司名" prop="companyId">
          <el-select filterable style="width: 220px" v-model="queryParams.companyId" placeholder="请选择公司名" clearable size="small">
              <el-option
                v-for="item in companys"
                :key="item.companyId"
                :label="item.companyName"
                :value="item.companyId"
              />
        </el-select>
       
      </el-form-item>
      <el-form-item label="开始时间" prop="startTime">
         <el-date-picker v-model="dateRange" size="small" style="width: 220px" 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="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-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['platform:companyMoneyLogs:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table height="500" border v-loading="loading" :data="companyMoneyLogsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="logsId" />
      <el-table-column label="企业" align="center" prop="companyName" />
      <el-table-column label="金额" align="center" prop="money" />
      <el-table-column label="余额" align="center" prop="balance" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
       <el-table-column label="类型" align="center" prop="logsType" >
        <template slot-scope="scope">
              <el-tag prop="logsType" v-for="(item, index) in typesOptions"   v-if="scope.row.logsType==item.dictValue">{{item.dictLabel}}</el-tag>
        </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 {  listCompanyMoneyLogs2, getCompanyMoneyLogs, delCompanyMoneyLogs, addCompanyMoneyLogs, updateCompanyMoneyLogs, exportCompanyMoneyLogs } from "@/api/company/companyMoneyLogs";
import { getCompanyList } from "@/api/company/company";

export default {
  name: "CompanyMoneyLogs",
  data() {
    return {
      typesOptions:[],
      companys:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 企业账户记录表格数据
      companyMoneyLogsList: [],
      // 弹出层标题
      title: "",
      dateRange:[],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        companyId: null,
        money: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getDicts("sys_company_money_logs_type").then((response) => {
      this.typesOptions = response.data;
    });
     getCompanyList().then(response => {
      this.companys = response.data;
       
    });
    this.getList();
  },
  methods: {
    
    /** 查询企业账户记录列表 */
    getList() {
      this.loading = true;
      listCompanyMoneyLogs2(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.companyMoneyLogsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        logsId: null,
        companyId: null,
        money: null,
        remark: null,
        createTime: 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.logsId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      queryParams.logsType=2;
      queryParams.type=0;
      this.$confirm('是否确认导出所有企业账户记录数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportCompanyMoneyLogs(queryParams);
        }).then(response => {
          
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
