<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="提现类型" prop="extractType">
        <el-select v-model="queryParams.extractType" placeholder="请选择提现类型" clearable size="small">
          <el-option
            v-for="dict in extractTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>


      <el-form-item label="提现时间" prop="createTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择提现时间">
        </el-date-picker>
      </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"

        >申请提现</el-button>
 </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
  <el-tabs type="card" v-model="queryParams.status" @tab-click="handleClickX">
      <el-tab-pane v-for="(item,index) in statusOptions" :label="item.dictLabel" :name="item.dictValue"></el-tab-pane>
    </el-tabs>
    <el-table v-loading="loading" :data="storeextractList" @selection-change="handleSelectionChange">

      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单id" align="center" prop="extractId" />
      <el-table-column label="店铺名称" align="center" prop="name"  width="150px"/>
   <el-table-column label="姓名" align="center" prop="realName" />
     <el-table-column label="提现类型" align="center" prop="extractType">
       <template slot-scope="scope">
         <dict-tag :options="extractTypeOptions" :value="scope.row.extractType"/>
       </template>
     </el-table-column>
     <el-table-column label="银行卡" align="center" prop="bankCode" width="150px"/>
     <el-table-column label="开户地址" align="center" prop="bankAddress" width="150px"/>
     <el-table-column label="支付宝账号" align="center" prop="alipayCode" width="100px"/>
     <el-table-column label="提现状态" align="center" prop="status">
       <template slot-scope="scope">
                  <dict-tag :options="statusOptions" :value="scope.row.status"/>
       </template>
     </el-table-column>
     <el-table-column label="提现金额" align="center" prop="extractPrice" />
     <el-table-column label="备注" align="center" prop="mark" />
     <el-table-column label="余额" align="center" prop="balance" />
     <el-table-column label="审核备注" align="center" prop="failMsg" />
     <el-table-column label="审核时间" align="center" prop="failTime" width="180" />
     <el-table-column label="创建时间" align="center" prop="createTime" width="180" />

     <el-table-column label="微信号" align="center" prop="wechat" width="180"/>
     <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="100px">
       <template slot-scope="scope">
       <el-button
           size="mini"
           type="text"
           @click="handledetails(scope.row)"
         >详情
       </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="extractType">
         <el-radio-group v-model="form.extractType">
                  <el-radio :label="item.dictValue" v-for="item in extractTypeOptions" >{{item.dictLabel}}</el-radio>
         </el-radio-group>
        </el-form-item>
        <el-form-item label="真实姓名" prop="realName">
          <el-input v-model="form.realName" placeholder="请输入真实姓名" />
        </el-form-item>
        <el-form-item label="银行卡" prop="bankCode" v-if="form.extractType=='bank'">
          <el-input v-model="form.bankCode" placeholder="请输入银行卡" />
        </el-form-item>
        <el-form-item label="开户地址" prop="bankAddress" v-if="form.extractType=='bank'">
          <el-input v-model="form.bankAddress" placeholder="请输入开户地址" />
        </el-form-item>
        <el-form-item label="支付宝账号" prop="alipayCode" v-if="form.extractType=='alipay'">
          <el-input v-model="form.alipayCode" placeholder="请输入支付宝账号" />
        </el-form-item>
            <el-form-item label="微信号" prop="wechat" v-if="form.extractType=='wx'">
                  <el-input v-model="form.wechat" placeholder="请输入微信号" />
                </el-form-item>
        <el-form-item label="提现金额" prop="extractPrice">
     <el-input-number v-model="form.extractPrice" :precision="2" :step="0.1" :min="0.0"></el-input-number>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" 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>


    <el-drawer
            :with-header="false"
            size="75%"
             :title="show.title" :visible.sync="show.open">
         <storeExtractDetails  ref="Details" />
       </el-drawer>

  </div>
</template>

<script>
import { listStoreextract, getStoreextract, delStoreextract, addStoreextract, updateStoreextract, exportStoreextract } from "@/api/store/storeExtract";
import storeExtractDetails from '../../components/store/storeExtractDetails.vue';
export default {
  name: "Storeextract",
    components: { storeExtractDetails },
  data() {
    return {
      show:{
              title:"提现管理详情",
              open:false,
            },

      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 店铺提现管理表格数据
      storeextractList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        storeId: null,
        realName: null,
        extractType: null,
        bankCode: null,
        bankAddress: null,
        alipayCode: null,
        extractPrice: null,
        mark: null,
        balance: null,
        failMsg: null,
        failTime: null,
        status: 0,
        wechat: null,
        isDel: null
      },
      // bank = 银行卡 alipay = 支付宝wx=微信字典
      extractTypeOptions: [],
      // -1 未通过 0 审核中 1 已提现字典
      statusOptions: [],
      // 表单参数
      form: {},
      // 表单校验
     // 表单校验
     rules: {
       extractType: [
         { required: true, message: "提现方式不能为空", trigger: "blur" }
       ],
       realName: [
         { required: true, message: "真实姓名不能为空", trigger: "blur" }
       ],
       bankCode: [
         { required: true, message: "银行卡不能为空", trigger: "blur" }
       ],
       bankAddress: [
         { required: true, message: "开户地址不能为空", trigger: "blur" }
       ],
       alipayCode: [
         { required: true, message: "支付宝账号不能为空", trigger: "blur" }
       ],
       extractPrice: [
         { required: true, message: "提现金额不能为空", trigger: "blur" }
       ],
       bankCode: [
         { required: true, message: "真实姓名不能为空", trigger: "blur" }
       ],
       wechat: [
         { required: true, message: "微信号不能为空", trigger: "blur" }
       ],
       remark: [
         { required: true, message: "备注不能为空", trigger: "blur" }
       ],

     }
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_extract_type").then(response => {
      this.extractTypeOptions = response.data;
    });
    this.getDicts("sys_extract").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods: {
    handledetails(row){
        this.show.open=true;
        setTimeout(() => {
             this.$refs.Details.getDetails(row.extractId,row.name);
        }, 1);
    },
    handleClickX(){
      this.handleQuery();
    },
    /** 查询店铺提现管理列表 */
    getList() {
      this.loading = true;
      listStoreextract(this.queryParams).then(response => {
        this.storeextractList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        extractId: null,
        storeId: 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.extractId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "申请提现";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const extractId = row.extractId || this.ids
      getStoreextract(extractId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改店铺提现管理";
           this.form.status="-1"
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.extractId != null) {
            updateStoreextract(this.form).then(response => {
              this.msgSuccess("申请成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStoreextract(this.form).then(response => {
              this.msgSuccess("申请成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const extractIds = row.extractId || this.ids;
      this.$confirm('是否确认删除店铺提现管理编号为"' + extractIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delStoreextract(extractIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有店铺提现管理数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportStoreextract(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
