<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--类型搜索数据-->
      <el-col :span="20" :xs="24">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
         <el-form-item label="流水号" prop="orderId">
            <el-input v-model="queryParams.orderId" placeholder="请输入流水号" clearable style="width: 240px" @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="银行卡" prop="bankNo">
            <el-input v-model="queryParams.bankNo" placeholder="请输入银行卡" clearable style="width: 240px" />
          </el-form-item>
          <el-form-item label="支付宝手机号" prop="phone">
            <el-input v-model="queryParams.phone" placeholder="请输入支付宝手机号" clearable style="width: 260px" />
          </el-form-item>
      <el-form-item label="渠道" prop="channel">
          <el-select v-model="queryParams.channel" placeholder="渠道" clearable>
            <el-option
              v-for="item in channel"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
          <el-select v-model="queryParams.status" placeholder="状态" clearable>
            <el-option
              v-for="item in status"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
        </el-select>
      </el-form-item>
          <el-form-item>
            <el-button type="primary" 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="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['img:withdraw:remove']"
            >删除</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="withdrawList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="编号" align="center" key="id" prop="id" v-if="columns[0].visible" />
          <el-table-column label="流水号" align="center" key="orderId" prop="orderId" v-if="columns[1].visible" width="170"/>
          <el-table-column label="艺术家id" align="center" key="creatorId" prop="creatorId" v-if="columns[2].visible" width="100"/>
          <el-table-column label="提现金额" align="center" key="amt" prop="amt" v-if="columns[3].visible" />
          <el-table-column label="银行卡" align="center" key="bankNo" prop="bankNo" v-if="columns[4].visible" width="170"/>
          <el-table-column label="支付宝手机号" align="center" key="phone" prop="phone" v-if="columns[5].visible" width="140"/>
          <el-table-column label="审核理由" align="center" key="reason" prop="reason" v-if="columns[6].visible" width="120"/>
          <el-table-column label="渠道" align="center" key="channel" prop="channel" v-if="columns[7].visible">
            <template slot-scope="scope">
              {{scope.row.channel == '0' ? "微信" : scope.row.channel == '1' ? "银行卡": scope.row.channel == '2' ? "支付宝" : ''}}
            </template>
          </el-table-column>
          <el-table-column label="状态" align="center" key="status" prop="status" v-if="columns[8].visible">
            <template slot-scope="scope">
              {{scope.row.status == '0' ? "待审核" : scope.row.status == '1' ? "提现中": scope.row.status == '2' ? "提现成功": scope.row.status == '3' ? "提现失败": scope.row.status == '4' ? "审核拒绝": ''}}
            </template>
          </el-table-column>
          <el-table-column label="排序" align="center" key="sort" prop="sort" v-if="columns[9].visible"/>
          <el-table-column label="创建时间" align="center" prop="createTime" v-if="columns[10].visible" width="160">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="更新时间" align="center" prop="updateTime" v-if="columns[11].visible" width="160">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.updateTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="160"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
               v-if="scope.row.status === '0'"
                size="mini"
                type="text"
                icon="el-icon-plus"
                @click="handleVerify(scope.row)"
                v-hasPermi="['img:withdraw:verify']"
              >审核</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['img:withdraw:remove']"
              >删除</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-col>
    </el-row>

    <!-- 审核收益审核单对话框 -->
    <el-dialog :title="title" :visible.sync="verifyOpen" width="600px" append-to-body>
      <el-form ref="verifyForm" :model="verifyForm" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="流水号" prop="orderId">
              <el-input v-model="verifyForm.orderId" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="提现金额" prop="amt">
              <el-input v-model="verifyForm.amt" disabled/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="渠道">
              <el-select v-model="verifyForm.channel" disabled>
                <el-option
                  v-for="item in channel"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
           <el-col :span="12">
            <el-form-item label="银行卡" prop="bankNo">
              <el-input v-model="verifyForm.bankNo" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="支付宝手机号" prop="phone" label-width="120px">
              <el-input v-model="verifyForm.phone" disabled/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="审核状态">
              <el-select v-model="verifyForm.verifyStatus" placeholder="请选择审核状态">
                <el-option
                  v-for="item in verifyStatus"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="审核理由" prop="reason">
              <el-input v-model="verifyForm.reason" placeholder="请输入审核理由" maxlength="30"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="verify">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {  listWithdraw, delWithdraw, getWithdrawDetails, verify } from "@/api/img/withdraw";
import { getUserProfile } from "@/api/system/user";

export default {
  name: "Withdraw",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 审核表单参数
      verifyForm: {},
      // 弹出层标题
      title: "",
      // 是否显示审核弹出层
      verifyOpen: false,
      // 总条数
      total: 0,
      // 提现列表数据
      withdrawList: null,
      //审核状态
      verifyStatus: [
          { value: '0', label: '拒绝'},
          { value: '1', label: '通过'},
        ],
      //渠道
      channel: [
          { value: '0', label: '微信'},
          { value: '1', label: '银行卡'},
          { value: '2', label: '支付宝'}
        ],
      //状态
      status: [
          { value: '0', label: '待审核'},
          { value: '1', label: '提现中'},
          { value: '2', label: '提现成功'},
          { value: '3', label: '提现失败'}
        ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        status: undefined,
        channel: undefined,
        orderId: undefined,
        bankNo: undefined,
        phone: undefined
      },
      // 列信息
      columns: [
        { key: 0, label: `编号`, visible: true },
        { key: 1, label: `流水号`, visible: true },
        { key: 2, label: `艺术家id`, visible: true },
        { key: 3, label: `提现金额`, visible: true },
        { key: 4, label: `银行卡`, visible: true },
        { key: 5, label: `支付宝手机号`, visible: true },
        { key: 6, label: `审核理由`, visible: true },
        { key: 7, label: `渠道`, visible: true },
        { key: 8, label: `状态`, visible: true },
        { key: 9, label: `排序`, visible: true },
        { key: 10, label: `创建时间`, visible: true },
        { key: 11, label: `更新时间`, visible: true }
      ],
      // 表单校验
      rules: {
        verifyStatus: [
          { required: true, message: "审核状态不能为空", trigger: "blur" }
        ],
        reason: [
          { required: true, message: "审核理由不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询类型列表 */
    getList() {
      this.loading = true;
      listWithdraw(this.queryParams).then(response => {
          this.withdrawList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
     // 取消按钮
    cancel() {
      this.verifyOpen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        amt: undefined,
        platform: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除编号为"' + ids + '"的数据项？').then(function() {
        return delWithdraw(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 审核按钮操作 */
    handleVerify(row){
      console.log(row)
      const id = row.id || this.ids;
      getWithdrawDetails(id).then(response => {
        this.verifyForm = response.data;
        //获取管理员id
        getUserProfile().then(response => {
          this.verifyForm.adminId = response.data.userId
        });
        this.verifyOpen = true;
        this.title = "审核提现记录";
      });
    },
    /** 提交审核 */
    verify: function() {
      this.$refs["verifyForm"].validate(valid => {
        if (valid) {
          if (this.verifyForm.id != undefined) {
            let data = {
              id : this.verifyForm.id,
              adminId: this.verifyForm.adminId,
              reason : this.verifyForm.reason,
              verifyStatus : this.verifyForm.verifyStatus
            }
            verify(data).then(response => {
              this.$modal.msgSuccess("审核成功");
              this.verifyOpen = false;
              this.getList();
            });
          }
        }
      });
    }
  }
};
</script>