<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="profitStatus">
         <el-select style="width: 220px" v-model="queryParams.profitStatus" placeholder="请选择状态" clearable size="small">
              <el-option
                v-for="dict in statusOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              />
        </el-select>
      </el-form-item>
      <el-form-item label="提交时间">
            <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="['company:companyProfit: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="companyProfitList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="profitId" />
      <el-table-column label="公司" align="center" prop="companyName" />
      <el-table-column label="提现金额" align="center" prop="money" />
      <el-table-column label="余额" align="center" prop="balances" />
      <el-table-column label="银行名称" align="center" prop="bankName" />
      <el-table-column label="支行名称" align="center" prop="bankBranchName" />
      <el-table-column label="银行卡号" align="center" prop="bankCardNo" />
      <el-table-column label="开户名" align="center" prop="bankUserName" />
      <el-table-column label="状态" align="center" prop="profitStatus" width="160px" >
        <template slot-scope="scope">
              <el-tag prop="status" v-for="(item, index) in statusOptions"  :type="scope.row.profitStatus==0?'danger':'success'"  v-if="scope.row.profitStatus==item.dictValue">{{item.dictLabel}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="提交时间" align="center" prop="createTime" />
      <el-table-column label="审核时间" align="center" prop="updateTime" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="凭证" align="center" width="120">
        <template slot-scope="scope">
          <el-popover
            placement="right"
            title=""
            trigger="hover"
          >
            <img slot="reference" :src="scope.row.imgUrl" width="100">
            <img :src="scope.row.imgUrl" style="max-width: 500px;">
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right" width="120px" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleShow(scope.row)"
            v-hasPermi="['company:companyProfit:query']"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog :title="show.title" :visible.sync="show.open" width="1000px" append-to-body>
      <company-profit  ref="profit" />
    </el-dialog>

  
  </div>
</template>

<script>
import { audit,listCompanyProfit, getCompanyProfit, delCompanyProfit, addCompanyProfit, updateCompanyProfit, exportCompanyProfit } from "@/api/company/companyProfit";
import { getCompanyList } from "@/api/company/company";
import companyProfit from "../components/companyProfit";
export default {
  components: {companyProfit },
  name: "CompanyProfit",
  data() {
    return {
      show:{
        title:'查看',
        open:false,
      },

      companys:[],
      statusOptions:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      dateRange: [],
      // 提现表格数据
      companyProfitList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        companyId: null,
        bankName: null,
        bankBranchName: null,
        bankCardNo: null,
        bankUserName: null,
        money: null,
        balances: null,
        profitStatus: null,
        profitType: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        companyId: [
          { required: true, message: "公司ID不能为空", trigger: "blur" }
        ],
        profitStatus: [
          { required: true, message: "提现状态不能为空", trigger: "blur" }
        ],
        
      }
    };
  },
  created() {
    this.getDicts("company_profit_status").then((response) => {
      this.statusOptions = response.data;
    });
    getCompanyList().then(response => {
      this.companys = response.data;
    });
    this.getList();
  },
  methods: {
    handleShow(row){
        this.show.open=true;
        this.show.open=true;
        const profitId = row.profitId ;
        setTimeout(() => {
          this.$refs.profit.getData(row.companyName,profitId);
        }, 500);
    },
   
    /** 查询提现列表 */
    getList() {
      this.loading = true;
      listCompanyProfit(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.companyProfitList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        profitId: null,
        companyId: null,
        bankName: null,
        bankBranchName: null,
        bankCardNo: null,
        bankUserName: null,
        money: null,
        balances: null,
        profitStatus:1,
        profitType: null,
        remark: null,
        createTime: null,
        updateTime: 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.profitId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
   
    
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有提现数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportCompanyProfit(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
