<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      
      <el-form-item label="会员昵称" prop="nickname">
        <el-input
          
          v-model="queryParams.nickname"
          placeholder="请输入会员昵称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="phone">
        <el-input
         
          v-model="queryParams.phone"
          placeholder="请输入手机号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提交时间" prop="createTime">
        <el-date-picker clearable size="small" style="width: 205.4px"
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择提交时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select style="width: 200px" v-model="queryParams.status" placeholder="请选择状态" clearable size="small" >
         <el-option
                v-for="item in statusOptions"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.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="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['store:userExtract: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="userExtractList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="会员昵称" align="center" prop="nickname" />
      <el-table-column label="会员手机号" align="center" prop="phone" />
      <el-table-column label="提现类型" align="center" prop="extractType" />
      <!-- <el-table-column label="银行卡" align="center" prop="bankCode" />
      <el-table-column label="开户地址" align="center" prop="bankAddress" />
      <el-table-column label="支付宝账号" align="center" prop="alipayCode" /> -->
      <el-table-column label="提现金额" align="center" prop="extractPrice" />
      <el-table-column label="余额" align="center" prop="balance" />
      <el-table-column label="审核原因" align="center" prop="failMsg" />
      <el-table-column label="状态" align="center" prop="status" >
          <template slot-scope="scope">
              <el-tag prop="status" v-for="(item, index) in statusOptions"    v-if="scope.row.status==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" 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-edit"
            @click="handleAudit(scope.row)"
            v-hasPermi="['store:userExtract:audit']"
          >审核</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="nickname">
          <el-input v-model="form.nickname" disabled   />
        </el-form-item>
        <el-form-item label="会员手机号" prop="phone">
          <el-input v-model="form.phone" disabled />
        </el-form-item>
        
        <el-form-item label="提现金额" prop="extractPrice">
          <el-input v-model="form.extractPrice" disabled placeholder="请输入提现金额" />
        </el-form-item>
       
        <el-form-item label="余额" prop="balance">
          <el-input v-model="form.balance" disabled placeholder="请输入提现金额" />
        </el-form-item>
        <el-form-item label="审核状态">
          <el-radio-group v-model="form.status">
            <el-radio label="1">通过</el-radio>
            <el-radio label="-1">驳回</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审核原因" v-if="form.status==-1" prop="failMsg">
          <el-input type="textarea" :row="5" v-model="form.failMsg" 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 { listUserExtract, getUserExtract, audit,delUserExtract, addUserExtract, updateUserExtract, exportUserExtract } from "@/api/store/userExtract";

export default {
  name: "UserExtract",
  data() {
    return {
      statusOptions:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户提现表格数据
      userExtractList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        realName: null,
        extractType: null,
        bankCode: null,
        bankAddress: null,
        alipayCode: null,
        extractPrice: null,
        mark: null,
        balance: null,
        failMsg: null,
        failTime: null,
        status: null,
        wechat: null,
        isDel: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        status: [
          { required: true, message: "状态不能为空", trigger: "blur" }
        ],
        failMsg: [
          { required: true, message: "原因不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getDicts("user_extract_status").then((response) => {
      this.statusOptions = response.data;
    });
    this.getList();
  },
  methods: {
    /** 查询用户提现列表 */
    getList() {
      this.loading = true;
      listUserExtract(this.queryParams).then(response => {
        this.userExtractList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        realName: null,
        extractType: null,
        bankCode: null,
        bankAddress: null,
        alipayCode: null,
        extractPrice: null,
        mark: null,
        balance: null,
        failMsg: null,
        failTime: null,
        createTime: null,
        updateTime: null,
        status: 0,
        wechat: null,
        isDel: 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.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 修改按钮操作 */
    handleAudit(row) {
      this.reset();
      const id = row.id;
      console.log(id)
      getUserExtract(id).then(response => {
        this.form = response.data;
        this.form.nickname=row.nickname
        this.form.phone=row.phone
        this.form.status="1"
        this.open = true;
        this.title = "审核提现";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          audit(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("操作成功");
                this.open = false;
                this.getList();
              }
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除用户提现编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delUserExtract(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有用户提现数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportUserExtract(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
