<template>
  <div class="order-content">
      <div class="order-status" v-if="profit!=null" >
          <el-steps  :active="profit.profitStatus==4?profit.profitStatus:profit.profitStatus-1" align-center>
            <el-step title="待商务审核"></el-step>
            <el-step title="待财务审核"></el-step>
            <el-step title="待支付"></el-step>
            <el-step title="已完成"></el-step>
          </el-steps>
      </div>
      <div>

      <el-card shadow="never" style="margin-top: 15px">
      <div class="operate-container"  v-if="profit!=null">
        <i class="el-icon-warning color-danger" style="margin-left: 20px"></i>
        <span class="color-danger">当前状态：
           <el-tag prop="status" v-for="(item, index) in statusOptions"    v-if="profit.profitStatus==item.dictValue">{{item.dictLabel}}</el-tag>
        </span>
       
        <div class="operate-button-container" >
          <el-button size="mini" @click="handleAudit(1)" v-if="profit.profitStatus==1"  v-hasPermi="['company:companyProfit:audit1']" >商务审核</el-button>
        </div>
        <div class="operate-button-container" >
          <el-button size="mini" @click="handleAudit(2)" v-if="profit.profitStatus==2"  v-hasPermi="['company:companyProfit:audit2']" >财务审核</el-button>
        </div>
        <div class="operate-button-container" >
          <el-button size="mini" @click="handleAudit(3)" v-if="profit.profitStatus==3"  v-hasPermi="['company:companyProfit:audit3']" >付款</el-button>
        </div>
         
      </div>
      <div style="margin-top: 20px"  v-if="profit!=null">
        <svg-icon icon-class="marker" style="color: #606266"></svg-icon>
        <span class="font-small">基本信息
      
        </span>
      </div>
      <div class="table-layout"  v-if="profit!=null">
        <el-row>
          <el-col :span="6" class="table-cell-title">公司名称</el-col>
          <el-col :span="6" class="table-cell-title">提现金额</el-col>
          <el-col :span="6" class="table-cell-title">余额</el-col>
          <el-col :span="6" class="table-cell-title">银行名称</el-col>
        </el-row>
        <el-row>
          <el-col :span="6" class="table-cell">{{companyName}}</el-col>
          <el-col :span="6" class="table-cell">{{profit.money}}</el-col>
          <el-col :span="6" class="table-cell">{{profit.balances}}</el-col>
          <el-col :span="6" class="table-cell">{{profit.bankName}}</el-col>
        </el-row>
        <el-row>
          <el-col :span="6" class="table-cell-title">支行名称</el-col>
          <el-col :span="6" class="table-cell-title">银行卡号</el-col>
          <el-col :span="6" class="table-cell-title">银行开户名</el-col>
          <el-col :span="6" class="table-cell-title">提交时间</el-col>
        </el-row>
        <el-row>
          <el-col :span="6" class="table-cell">{{profit.bankBranchName}}</el-col>
          <el-col :span="6" class="table-cell">{{profit.bankCardNo}}</el-col>
          <el-col :span="6" class="table-cell">{{profit.bankUserName}}</el-col>
          <el-col :span="6" class="table-cell">{{profit.createTime}}</el-col>
        </el-row>
        <el-row>
          <el-col :span="12" class="table-cell-title">备注</el-col>
          <el-col :span="12" class="table-cell-title">凭证</el-col>
        </el-row>
        <el-row>
          <el-col :span="12" class="table-cell">{{profit.remark}}</el-col>
          <el-col :span="12" class="table-cell"> 
            <el-popover
            placement="right"
            title=""
            trigger="hover"
          >
            <img slot="reference" :src="profit.imgUrl" width="100">
            <img :src="profit.imgUrl" style="max-width: 500px;">
          </el-popover></el-col>
        </el-row>
      </div>
      <div style="margin-top: 20px">
        <svg-icon icon-class="marker" style="color: #606266"></svg-icon>
        <span class="font-small">操作信息</span>
      </div>
      <el-table style="margin-top: 20px;width: 100%"
                ref="orderHistoryTable"
                :data="logs" border>
        <el-table-column label="标题" align="center">
          <template slot-scope="scope">
            {{scope.row.title}}
          </template>
        </el-table-column>
        <el-table-column label="审核记录" align="center">
          <template slot-scope="scope">
            {{scope.row.reason}}
          </template>
        </el-table-column>
        <el-table-column label="操作时间"  width="160" align="center">
          <template slot-scope="scope">
            {{scope.row.createTime}}
          </template>
        </el-table-column>
      </el-table>
      </el-card>
    </div>
      <!-- 添加或修改提现对话框 -->
      <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="status">
          <el-radio-group v-model="form.status">
             <el-radio  :label="1">通过</el-radio>
             <el-radio  :label="0">驳回</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="凭证" prop="profitStatus" v-if="profit.profitStatus==3">
            <el-upload
              v-model="form.imgUrl"
              class="avatar-uploader"
              :action="uploadUrl"
              :show-file-list="false"
              :on-success="handleSuccess"
              :before-upload="beforeUpload">
              <img v-if="form.imgUrl" :src="form.imgUrl" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
      
  </div>
</template>

<script>
import { audit1,audit2,audit3, getCompanyProfit, delCompanyProfit, addCompanyProfit, updateCompanyProfit, exportCompanyProfit } from "@/api/company/companyProfit";

export default {
  name: "profit",
  data() {
    return {
      type:null,
      uploadUrl:process.env.VUE_APP_BASE_API+"/common/uploadOSS",
      baseUrl: process.env.VUE_APP_BASE_API,
       // 弹出层标题
       title: "",
      // 是否显示弹出层
      open: false,
      companyName:null,
      statusOptions:[],
      profitId:null,
      profit:null,
      logs:[],
      rules:{},
      form:{
        status:1,
        imgUrl:null,
      }
    };
  },
  created() {
    this.getDicts("sys_company_profit_status").then((response) => {
      this.statusOptions = response.data;
    });
  },
  methods: {
    handleSuccess(res, file) {
        if(res.code==200){
          this.form.imgUrl=res.url;
        }
        else{
          this.msgError(res.msg);
        }
        
    },
    beforeUpload(file) {
      const isLt1M = file.size / 1024 / 1024 < 1;
      if (!isLt1M) {
        this.$message.error('上传图片大小不能超过 1MB!');
      }
      return   isLt1M;
    },
    handleAudit(auditType) {
      this.type=auditType;
      this.open = true;
      this.title = "审核提现";
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.profitId=this.profitId
          console.log(this.type)
          if(this.type==1){
           
            audit1(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("审核成功");
                this.open = false;
                this.getData(this.companyName,this.profitId);
              }
            });
          }
          if(this.type==2){
            audit2(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("审核成功");
                this.open = false;
                this.getData(this.companyName,this.profitId);
              }
            });
          }
          if(this.type==3){
            audit3(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("审核成功");
                this.open = false;
                this.getData(this.companyName,this.profitId);
              }
            });
          }
          
        }
      });
    },
    getData(companyName,profitId) {
      this.companyName=companyName;
      this.profitId=profitId;
      getCompanyProfit(profitId).then(response => {
        this.profit = response.profit;
        this.logs = response.logs;
       
      });
    },
    
  }
};
</script>
<style scoped>
.order-content{
  margin: 10px;
}
.detail-container {
  width: 80%;
  padding: 20px 20px 20px 20px;
  margin: 20px auto;
}

.operate-container {
  background: #F2F6FC;
  height: 80px;
  margin: -20px -20px 0;
  line-height: 80px;
}

.operate-button-container {
  float: right;
  margin-right: 20px
}

.table-layout {
  margin-top: 20px;
  border-left: 1px solid #DCDFE6;
  border-top: 1px solid #DCDFE6;
}

.table-cell {
  height: 60px;
  line-height: 40px;
  border-right: 1px solid #DCDFE6;
  border-bottom: 1px solid #DCDFE6;
  padding: 10px;
  font-size: 14px;
  color: #606266;
  text-align: center;
  overflow: hidden;
}

.table-cell-title {
  border-right: 1px solid #DCDFE6;
  border-bottom: 1px solid #DCDFE6;
  padding: 10px;
  background: #F2F6FC;
  text-align: center;
  font-size: 14px;
  color: #303133;
}
</style>
