<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户电话" prop="realName">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入电话号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <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 v-model="createTime" size="small" style="width: 220px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" @change="change"></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="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['his:userExtract:export']"
        >导出</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" border :data="userextractList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="用户姓名" align="center" prop="userName" />
      <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="wechat" />
      <el-table-column label="联系电话" align="center" prop="phone" />
      <el-table-column label="银行卡" align="center" prop="bankNo" />

      <el-table-column label="开户行" align="center" prop="bankName" />
      <el-table-column label="支行" align="center" prop="bankSubName" />
      <el-table-column label="支付宝账号" align="center" prop="alipayAccount" 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="remark" />
      <el-table-column label="余额" align="center" prop="balance" />
      <el-table-column label="无效原因" align="center" prop="failMsg" />
      <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" class-name="small-padding fixed-width" fixed="right" width="100px">
        <template slot-scope="scope">
          <el-button v-show="scope.row.status==0"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['his:userExtract:edit']"
          >审核</el-button>
        <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="80px">


        <el-form-item label="审核" prop="status">
           <el-radio v-model="form.status" label="-1">未通过</el-radio>
            <el-radio v-model="form.status" label="1">通过</el-radio>
        </el-form-item>

        <el-form-item label="备注" prop="failMsg">
          <el-input v-model="form.failMsg" placeholder="请输入备注" type="textarea"/>
        </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">
         <userExtractDetails  ref="Details" />
       </el-drawer>
  </div>
</template>

<script>
import { listUserextract, getUserextract, delUserextract, addUserextract, updateUserextract, exportUserextract } from "@/api/his/userExtract";
import userExtractDetails from '../../../components/his/userExtractDetails.vue';
export default {
  name: "Userextract",
  components: { userExtractDetails },
  data() {
    return {
      show:{
              title:"提现管理详情",
              open:false,
            },
       createTime:null,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 医生提现管理表格数据
      userextractList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // bank = 银行卡 alipay = 支付宝wx=微信字典
      extractTypeOptions: [],
      // -1 未通过 0 审核中 1 已提现字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        phone: null,
        extractType: null,
        bankCode: null,
        bankAddress: null,
        alipayCode: null,
        extractPrice: null,
        mark: null,
        balance: null,
        failMsg: null,
        failTime: null,
        createTime: null,
        status: "0",
        wechat: null,
        sTime:null,
        eTime:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        status: [
          { 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);
            }, 1);
        },
    /** 查询医生提现管理列表 */
    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 = {
        extractId: 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();
    },
    handleClickX(){
      this.handleQuery();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
       this.createTime=null;
      this.queryParams.sTime=null;
      this.queryParams.eTime=null;
      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
      getUserextract(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) {
            updateUserextract(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addUserextract(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },

    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有医生提现管理数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportuserextract(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
