<!--提现管理-->
<template>
  <div class="app-container" style="background-color: #fff">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="118px"
    >
      <el-form-item label="申请人账号" prop="userPhone">
        <el-input
          v-model="queryParams.userPhone"
          placeholder="请输入申请人账号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请人姓名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入申请人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单编号" prop="withdrawNum">
        <el-input
          v-model="queryParams.withdrawNum"
          placeholder="请输入订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收款银行" prop="bankName">
        <el-input
          v-model="queryParams.bankName"
          placeholder="请输入收款银行"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="银行卡号码" prop="bankNum">
        <el-input
          v-model="queryParams.bankNum"
          placeholder="请输入银行卡号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留手机号" prop="bankPhone">
        <el-input
          v-model="queryParams.bankPhone"
          placeholder="请输入预留手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="持卡人" prop="bankUserName">
        <el-input
          v-model="queryParams.bankUserName"
          placeholder="请输入持卡人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最大提现金额" prop="withdrawAmount">
        <el-input
          v-model="queryParams.withdrawAmount"
          placeholder="请输入最小提现金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="提现类型" prop="withdrawType">
        <el-select
          v-model="queryParams.withdrawType"
          placeholder="请选择提现类型"
          clearable
        >
          <el-option
            v-for="dict in dict.type.sys_wallet_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <!--          <el-form-item prop="createTime" label="选择日期">-->
      <!--            <el-date-picker-->
      <!--              type="date"-->
      <!--              placeholder="选择日期"-->

      <!--              v-model="queryParams.createTime"-->
      <!--              value-format="yyyy-MM-dd"-->
      <!--              style="width: 100%;">-->

      <!--            </el-date-picker>-->
      <!--          </el-form-item>-->
      <el-form-item label="状态">
        <el-select v-model="queryParams.status" placeholder="请选择状态">
          <el-option
            v-for="dict in dict.type.sys_withdrawal_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.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="primary"
          plain
          icon="el-icon-edit"
          size="mini"
          @click="allhand"
          v-hasPermi="['ops:product:add']"
          >审核通过
        </el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-edit"
          size="mini"
          @click="allbohui"
          v-hasPermi="['ops:product:remove']"
          >驳回
        </el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-edit"
          size="mini"
          @click="shoudongxiafa"
          v-hasPermi="['ops:product:remove']"
          >手动下发
        </el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-edit"
          size="mini"
          @click="handleExport"
          v-hasPermi="['ops:product:remove']"
          >手动导出
        </el-button>
      </el-col>

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table :data="productList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="withdrawId" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="申请人账号" align="center" prop="userPhone" />
      <el-table-column label="申请人姓名" align="center" prop="userName" />
      <el-table-column label="直推人数" align="center" prop="ztNum" />
      <el-table-column label="订单编号" align="center" prop="withdrawNum" />
      <el-table-column label="收款银行" align="center" prop="bankName" />
      <el-table-column label="银行卡号码" align="center" prop="bankNum" />
      <el-table-column label="支付宝账号" align="center" prop="notifyData" />

      <el-table-column label="开户行" align="center" prop="bankAddress" />
      <el-table-column label="预留手机号" align="center" prop="bankPhone" />
      <el-table-column label="持卡人" align="center" prop="bankUserName" />
      <el-table-column label="提现类型" align="center" prop="withdrawType">
        <!-- 0账户余额 1推荐奖 2生活补贴金 3信用卡还款金-->
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_wallet_type"
            :value="scope.row.withdrawType"
          ></dict-tag>
        </template>
      </el-table-column>
      <el-table-column label="提现金额" align="center" prop="withdrawAmount" />
<!--      <template slot-scope="scope">-->
<!--      <span v-if="scope.row.withdrawType==0">{{scope.row.withdrawAmount}}</span>-->
<!--        <span v-if="scope.row.withdrawType==1">{{scope.row.withdrawAmount}}</span>-->
<!--      </template>-->
<!--      </el-table-column>-->
      <!--      <el-table-column label="提现结果" align="center" prop="withdrawResult" />-->

      <el-table-column prop="status" label="状态" width="100" align="center">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_withdrawal_status"
            :value="scope.row.status"
          ></dict-tag>
        </template>
      </el-table-column>
      <el-table-column label="成功时间" align="center" prop="successTime" />
      <el-table-column label="失败时间" align="center" prop="passTime" />

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            v-show="scope.row.status == 0"
            size="medium"
            type="primary"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['ops:product:edit']"
            >审核通过
          </el-button>
          <el-button
            v-show="scope.row.status == 0"
            size="medium"
            type="danger"
            @click="handleDelete(scope.row)"
            v-hasPermi="['ops:product: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"
    />

    <!-- 添加或修改产品对话框 -->
  </div>
</template>

<script>
// import { listProduct, getProduct, delProduct, addProduct, updateProduct } from "@/api/ops/product";

import {
  gettixianlist,
  shenhesuccess,
  shehepass,
  shoudong,
  tixianexport,
} from "@/api/ops/tixian/tixian.js";

export default {
  dicts: ["sys_wallet_type", "sys_withdrawal_status"],
  name: "Product",
  data() {
    return {
      // 状态
      status: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产品表格数据
      productList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userPhone: "",
        userName: "",
        withdrawNum: "",
        bankName: "",
        bankNum: "",
        bankPhone: "",
        bankUserName: "",
        withdrawType: "",
        status: "",
        withdrawAmount: "",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },

  methods: {
    /** 查询产品列表 */

    getList() {
      this.loading = true;
      gettixianlist(this.queryParams).then((res) => {
        console.log(res, 261);
        this.productList = res.rows;
        this.total = res.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        pageNum: 1,
        pageSize: 10,
        userName: null,
        bankName: null,
        bankNum: null,
        openBank: null,
        phoneNum: null,
        status: null,
        withdrawType: null,
        withdrawAmount: "",
      };

      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      console.log(204);
      this.queryParams.pageNum = 1;
      this.getList();
      // gettixianlist(this.queryParams).then((res) => {
      //   console.log(res, 307);
      //   this.productList = res.rows;
      //   this.total = res.total;
      // });
    },
    /** 重置按钮操作 */
    resetQuery() {
      console.log(210);
      this.resetForm("queryForm");
      this.queryParams.status = null;
      this.queryParams.withdrawType = null;
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      console.log(selection);
      this.ids = selection.map((item) => item.withdrawId);
      // this.single = selection.length!==1
      // this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      console.log(223);
      // this.reset();
      // this.open = true;
      // this.title = "添加产品";
    },
    /** 审核通过按钮操作 */
    handleUpdate(row) {
      this.$confirm("确认进行此操作?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          shenhesuccess(row.withdrawId).then((res) => {
            console.log(res, 335);
            this.getList();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消更改",
          });
        });

      // this.reset();
      // const productId = row.productId || this.ids
      // getProduct(productId).then(response => {
      //   this.form = response.data;
      //   this.open = true;
      //   this.title = "修改产品";
      // })
    },

    //手动下发
    shoudongxiafa() {
      this.$confirm("确认进行此操作?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          shoudong(this.ids).then((res) => {
            console.log(res, 403);
            this.getList();
          });
          // console.log(this.ids);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消更改",
          });
        });
    },
    /** 提交按钮 */
    submitForm() {
      console.log(390);
      // this.$refs["form"].validate(valid => {
      //   if (valid) {
      //     if (this.form.productId != null) {
      //       updateProduct(this.form).then(response => {
      //         this.$modal.msgSuccess("修改成功");
      //         this.open = false;
      //         this.getList();
      //       });
      //     } else {
      //       addProduct(this.form).then(response => {
      //         this.$modal.msgSuccess("新增成功");
      //         this.open = false;
      //         this.getList();
      //       });
      //     }
      //   }
      // });
    },

    // 全部驳回
    allbohui() {
      this.$confirm("确认进行此操作?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          shehepass(this.ids).then((res) => {
            console.log(res, 335);
            this.getList();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消更改",
          });
        });
    },
    // 全部审核
    allhand() {
      this.$confirm("确认进行此操作?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          shenhesuccess(this.ids).then((res) => {
            console.log(res, 335);
            this.getList();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消更改",
          });
        });
    },
    /** 驳回按钮操作 */
    handleDelete(row) {
      this.$confirm("确认进行此操作?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          shehepass(row.withdrawId).then((res) => {
            console.log(res, 375);
            this.getList();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消更改",
          });
        });

      // const productIds = row.productId || this.ids;
      // this.$modal.confirm('是否确认删除产品编号为"' + productIds + '"的数据项?').then(function() {
      //   return delProduct(productIds);
      // }).then(() => {
      //   this.getList();
      //   this.$modal.msgSuccess("删除成功");
      // }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      console.log(422);
      this.download('ops/product/export', {
        ...this.queryParams
      }, `product_${new Date().getTime()}.xlsx`)
      tixianexport().then((res)=>{
        console.log(res);
      })
    },
  },
};
</script>