<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单号" prop="orderno">
        <el-input
          v-model="queryParams.orderno"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账号类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择账号类型" clearable>
          <el-option
            v-for="dict in dict.type.app_user_cash_account"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="用户ID" prop="uid">
        <el-input
          v-model="queryParams.uid"
          placeholder="请输入用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </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="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:cashrecord:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:cashrecord:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:cashrecord:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="cashrecordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column fixed label="id" align="center" prop="id" />
      <el-table-column fixed label="UID" align="center" prop="uid" />
      <el-table-column fixed label="订单号" align="center" prop="orderno" />
      <el-table-column label="货币单位类型" align="center" prop="unitType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.app_user_cash_unit" :value="scope.row.unitType"/>
        </template>
      </el-table-column>
      <el-table-column label="提现数量" align="center" prop="votes" />
      <el-table-column label="提现金额" align="center" prop="money" />
      <el-table-column label="实际到账金额" align="center" prop="actualMoney" />
      <el-table-column label="提现前金额" align="center" prop="beforeAmount" />
      <el-table-column label="提现后剩余余额" align="center" prop="afterAmount" />
      <el-table-column label="服务费" align="center" prop="service" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.app_user_cash_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="申请时间" align="center" prop="addtime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.addtime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="提现类型" align="center" prop="cashType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.app_cash_type" :value="scope.row.cashType"/>
        </template>
      </el-table-column>
      <el-table-column label="转出备注" align="center" prop="cashOutRemark" />
      <el-table-column label="审核人" align="center" prop="auditby" />
      <el-table-column label="账号类型" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.app_user_cash_account" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="银行名称" align="center" prop="accountBank" />
      <el-table-column label="账号" align="center" prop="account" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="审核备注" align="center" prop="reason" />
      <el-table-column label="备注" align="center" prop="remarks" />
      <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:cashrecord:edit']"
            v-if="scope.row.status == 0"
          >审核</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:cashrecord: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-dialog :title="title" :visible.sync="open" width="70%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="id" prop="cashOutRemark">
          <el-input v-model="form.id" type="textarea" placeholder="请输入内容" disabled/>
        </el-form-item>
        <el-form-item label="用户ID" prop="uid">
          <el-input disabled v-model="form.uid" placeholder="请输入用户ID" />
        </el-form-item>
        <el-form-item label="订单号" prop="orderno">
          <el-input disabled v-model="form.orderno" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="提现数量" prop="votes">
          <el-input disabled v-model="form.votes" placeholder="请输入提现数量(所有类型cash_type都有值)" />
        </el-form-item>
        <el-form-item label="提现金额" prop="money">
          <el-input disabled v-model="form.money" placeholder="请输入提现金额" />
        </el-form-item>
        <el-form-item label="服务费" prop="service">
          <el-input disabled v-model="form.service" placeholder="请输入服务费" />
        </el-form-item>
        <el-form-item label="转出备注" prop="cashOutRemark">
          <el-input disabled v-model="form.cashOutRemark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="账号类型" prop="type">
          <el-select disabled v-model="form.type" placeholder="请选择账号类型">
            <el-option
              v-for="dict in dict.type.app_user_cash_account"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input disabled v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择状态 0:审核中 1:审核通过 2:审核拒绝">
            <el-option
              v-for="dict in dict.type.app_user_cash_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核备注" prop="reason">
          <el-input v-model="form.reason" 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 { listCashrecord, getCashrecord, delCashrecord, addCashrecord, updateCashrecord } from "@/api/business/cashrecord";

export default {
  name: "Cashrecord",
  dicts: ['app_user_cash_unit', 'app_user_cash_status', 'app_cash_type', 'app_user_cash_account'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 提现记录表格数据
      cashrecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cashType: null,
        orderno: null,
        type: null,
        uid: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询提现记录列表 */
    getList() {
      this.loading = true;
      listCashrecord(this.queryParams).then(response => {
        this.cashrecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        account: null,
        accountBank: null,
        actualMoney: null,
        addtime: null,
        afterAmount: null,
        auditby: null,
        beforeAmount: null,
        cashOutBizNo: null,
        cashOutOrderId: null,
        cashOutPayOrderId: null,
        cashOutRemark: null,
        cashOutStatus: null,
        cashType: null,
        guildId: null,
        money: null,
        name: null,
        orderno: null,
        platformService: null,
        reason: null,
        remarks: null,
        service: null,
        status: null,
        statusName: null,
        tradeNo: null,
        type: null,
        uid: null,
        unitType: null,
        uptime: null,
        votes: 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
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加提现记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCashrecord(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "审核";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCashrecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCashrecord(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除提现记录编号为"' + ids + '"的数据项？').then(function() {
        return delCashrecord(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/cashrecord/export', {
        ...this.queryParams
      }, `cashrecord_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
