<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="" v-if="company!=null" >
          <span style="font-weight:bold;" >{{company.companyName}}</span>
      </el-form-item>
      <el-form-item label="推广佣金" v-if="company!=null" >
          <span style="font-size:20px;color:red;">{{company.tuiMoney.toFixed(2)}}</span>元
      </el-form-item>
      <el-form-item label="可提现金额" v-if="company!=null" >
          <span style="font-size:20px;color:red;">{{company.money.toFixed(2)}}</span>元
      </el-form-item>
      <el-form-item label="提现状态" prop="profitStatus">
         <el-select 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>
        <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="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['company:companyProfit:profit']"
        >提现</el-button>
      </el-col>
     
      <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="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" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.profitStatus==1"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['company:companyProfit:cancel']"
          >取消提现</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="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="提现金额" prop="money">
          <el-input-number v-model="form.money" :min="0" placeholder="请输入提现金额" />
        </el-form-item>
        <el-form-item label="银行名称" prop="bankName">
          <el-input v-model="form.bankName" placeholder="请输入银行名称" />
        </el-form-item>
        <el-form-item label="支行名称" prop="bankBranchName">
          <el-input v-model="form.bankBranchName" placeholder="请输入银行支行名称" />
        </el-form-item>
        <el-form-item label="银行卡号" prop="bankCardNo">
          <el-input v-model="form.bankCardNo" placeholder="请输入银行卡号" />
        </el-form-item>
        <el-form-item label="银行开户名" prop="bankUserName">
          <el-input v-model="form.bankUserName" placeholder="请输入银行开户名" />
        </el-form-item>
      
       </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { profit,cancel,listCompanyProfit, getCompanyProfit, delCompanyProfit, addCompanyProfit, updateCompanyProfit, exportCompanyProfit } from "@/api/company/companyProfit";
import { getCompanyInfo } from "@/api/company/company";
export default {
  name: "CompanyProfit",
  data() {
    return {
      company:null,
      statusOptions:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 提现表格数据
      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: {
        money: [
          { required: true, message: "公司ID不能为空", trigger: "blur" }
        ],
        bankName: [
          { required: true, message: "银行名称不能为空", trigger: "blur" }
        ],
        bankBranchName: [
          { required: true, message: "支行名称不能为空", trigger: "blur" }
        ],
        bankCardNo: [
          { required: true, message: "银行卡号不能为空", trigger: "blur" }
        ],
        bankUserName: [
          { required: true, message: "银行开户名不能为空", trigger: "blur" }
        ],
       
        
      }
    };
  },
  created() {
    this.getDicts("sys_company_profit_status").then((response) => {
      this.statusOptions = response.data;
    });
    this.getCompanyInfo();
    this.getList();
    
  },
  methods: {
    getCompanyInfo(){
      getCompanyInfo().then(response => {
        this.company = response.data;
      });
    },
    /** 查询提现列表 */
    getList() {
      this.loading = true;
      listCompanyProfit(this.queryParams).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: "0",
        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
    },
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "提现";
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          profit(this.form).then(response => {
            if (response.code === 200) {
              this.msgSuccess(response.msg);
              this.open = false;
              this.getList();
              this.getCompanyInfo()
            }
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$confirm('是否确认取消提现?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          var data={profitId:row.profitId}
          return cancel(data);
        }).then(() => {
          this.getList();
          this.msgSuccess("操作成功");
          this.getCompanyInfo()
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    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>
