<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="UID" prop="userid">
        <el-input
          v-model="queryParams.userid"
          placeholder="请输入UID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="昵称 " prop="nickname">
        <el-input
          v-model="queryParams.nickname"
          placeholder="请输入昵称 "
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入手机号 "
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="在线状态" prop="onlineStatus">
        <el-select v-model="queryParams.onlineStatus" placeholder="请选择" clearable>
          <el-option
            v-for="dict in dict.type.app_user_online_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <br>
      <el-form-item label="直属上级" prop="pid">
        <el-input
          v-model="queryParams.pid"
          placeholder="请输入直属上级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户身份" prop="role">
        <el-select v-model="queryParams.role" placeholder="请选择用户身份" clearable>
          <el-option
            v-for="dict in dict.type.app_user_role"
            :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-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:user:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:user:edit']"
        >修改</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:user: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:user:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="userList" style="width: 100%" @scroll="handleScroll" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column fixed label="UID" align="center" prop="userid" />
      <el-table-column fixed label="昵称 " align="center" prop="username" />
      <el-table-column label="头像" align="center" prop="avatar" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.avatar" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="金币" align="center" prop="coin" />
      <el-table-column label="余额" align="center" prop="diamondCoin" />
      <el-table-column label=" 手机号" align="center" prop="mobile" />
      <el-table-column label="最大连续签到天数" align="center" prop="maxSignCount" />
      <el-table-column label="主播等级" align="center" prop="anchorGrade" />
      <el-table-column label="主播积分" align="center" prop="anchorPoint" />
      <el-table-column label="连续登录天数" align="center" prop="awardLoginDay" />
      <el-table-column label="魅力等级" align="center" prop="charmGrade" />
      <el-table-column label="魅力积分" align="center" prop="charmPoint" />
      <el-table-column label="可兑换" align="center" prop="coinCash" />
      <el-table-column label="消费总额(财富积分)" align="center" prop="consumption" />
      <el-table-column label="注册时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="邀请码" align="center" prop="inviteCode" />
      <el-table-column label="用户当前的位置" align="center" prop="ipaddr" />
      <el-table-column label="主播是否认证" align="center" prop="isAnchorAuth">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.is_anchor_auth" :value="scope.row.isAnchorAuth"/>
        </template>
      </el-table-column>
      <el-table-column label="最后登录ip" align="center" prop="lastLoginIp" />
      <el-table-column label=" 上次登录时间" align="center" prop="lastLoginTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastLoginTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label=" 离线时间" align="center" prop="lastOffLineTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastOffLineTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="用户在线状态" align="center" prop="onlineStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.app_user_online_status" :value="scope.row.onlineStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="手机厂商" align="center" prop="phoneFirm" />
      <el-table-column label="手机型号" align="center" prop="phoneModel" />
      <el-table-column label="直属上级" align="center" prop="pid" />
      <el-table-column label="用户身份" align="center" prop="role">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.app_user_role" :value="scope.row.role"/>
        </template>
      </el-table-column>
      <el-table-column label="连续签到次数" align="center" prop="signCount" />
      <el-table-column label="上次签到时间" align="center" prop="signTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.signTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="手机号区域" align="center" prop="smsRegion" />
      <el-table-column label="用户状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.app_user_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <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="handleRestPwd(scope.row)"
          >重置密码</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-bank-card"
            @click="handleCharge(scope.row)"
          >充值</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleWithdraw(scope.row)"
          >补足提现流水</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:user:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:user: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"
    />

    <!-- 添加或修改app用户对话框 -->
    <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="appVersion">
          <el-input v-model="form.appVersion" placeholder="请输入当前版本号" />
        </el-form-item>
        <el-form-item label="当前版本code" prop="appVersionCode">
          <el-input v-model="form.appVersionCode" placeholder="请输入当前版本code" />
        </el-form-item>
        <el-form-item label="用户头像" prop="avatar">
          <image-upload v-model="form.avatar"/>
        </el-form-item>
        <el-form-item label="连续登录天数" prop="awardLoginDay">
          <el-input v-model="form.awardLoginDay" placeholder="请输入连续登录天数" />
        </el-form-item>
        <el-form-item label="生日" prop="birthday">
          <el-input v-model="form.birthday" placeholder="请输入生日" />
        </el-form-item>
        <el-form-item label="魅力等级" prop="charmGrade">
          <el-input v-model="form.charmGrade" placeholder="请输入魅力等级" />
        </el-form-item>
        <el-form-item label="魅力积分" prop="charmPoint">
          <el-input v-model="form.charmPoint" placeholder="请输入魅力积分" />
        </el-form-item>
        <el-form-item label="金币 /充值金额" prop="coin">
          <el-input v-model="form.coin" placeholder="请输入金币 /充值金额" />
        </el-form-item>
        <el-form-item label="可兑换" prop="coinCash">
          <el-input v-model="form.coinCash" placeholder="请输入可兑换" />
        </el-form-item>
        <el-form-item label="消费总额(财富积分)" prop="consumption">
          <el-input v-model="form.consumption" placeholder="请输入消费总额(财富积分)" />
        </el-form-item>
        <el-form-item label="邀请码" prop="inviteCode">
          <el-input v-model="form.inviteCode" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label=" 用户当前的位置信息ID" prop="ipaddr">
          <el-input v-model="form.ipaddr" placeholder="请输入 用户当前的位置信息ID" />
        </el-form-item>
        <el-form-item label="主播是否认证 0:未认证 1:已认证  后台添加主播时,如果是认证状态, 需要添加认证记录" prop="isAnchorAuth">
          <el-select v-model="form.isAnchorAuth" placeholder="请选择主播是否认证 0:未认证 1:已认证  后台添加主播时,如果是认证状态, 需要添加认证记录">
            <el-option
              v-for="dict in dict.type.is_anchor_auth"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="上次登录时间(连续登录用)" prop="lastLoginDay">
          <el-date-picker clearable
            v-model="form.lastLoginDay"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择上次登录时间(连续登录用)">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="最后登录ip" prop="lastLoginIp">
          <el-input v-model="form.lastLoginIp" placeholder="请输入最后登录ip" />
        </el-form-item>
        <el-form-item label=" 上次登录时间" prop="lastLoginTime">
          <el-date-picker clearable
            v-model="form.lastLoginTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择 上次登录时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label=" 离线时间" prop="lastOffLineTime">
          <el-date-picker clearable
            v-model="form.lastOffLineTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择 离线时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="最大连续签到天数" prop="maxSignCount">
          <el-input v-model="form.maxSignCount" placeholder="请输入最大连续签到天数" />
        </el-form-item>
        <el-form-item label=" 手机号" prop="mobile">
          <el-input v-model="form.mobile" placeholder="请输入 手机号" />
        </el-form-item>
        <el-form-item label="昵称 " prop="nickname">
          <el-input v-model="form.nickname" placeholder="请输入昵称 " />
        </el-form-item>
        <el-form-item label="用户在线状态 0:离线 1:在线" prop="onlineStatus">
          <el-select v-model="form.onlineStatus" placeholder="请选择用户在线状态 0:离线 1:在线">
            <el-option
              v-for="dict in dict.type.app_user_online_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="手机厂商" prop="phoneFirm">
          <el-input v-model="form.phoneFirm" placeholder="请输入手机厂商" />
        </el-form-item>
        <el-form-item label="手机型号" prop="phoneModel">
          <el-input v-model="form.phoneModel" placeholder="请输入手机型号" />
        </el-form-item>
        <el-form-item label="手机系统" prop="phoneSystem">
          <el-input v-model="form.phoneSystem" placeholder="请输入手机系统" />
        </el-form-item>
        <el-form-item label="手机唯一标识" prop="phoneUuid">
          <el-input v-model="form.phoneUuid" placeholder="请输入手机唯一标识" />
        </el-form-item>
        <el-form-item label="直属上级" prop="pid">
          <el-input v-model="form.pid" placeholder="请输入直属上级" />
        </el-form-item>
        <el-form-item label="用户身份" prop="role">
          <el-select v-model="form.role" placeholder="请选择用户身份">
            <el-option
              v-for="dict in dict.type.app_user_role"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="连续签到次数" prop="signCount">
          <el-input v-model="form.signCount" placeholder="请输入连续签到次数" />
        </el-form-item>
        <el-form-item label="上次签到时间" prop="signTime">
          <el-date-picker clearable
            v-model="form.signTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择上次签到时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="手机号区域 例如:86" prop="smsRegion">
          <el-input v-model="form.smsRegion" placeholder="请输入手机号区域 例如:86" />
        </el-form-item>
        <el-form-item label=" 用户状态 1:禁用 0:正常" prop="status">
          <el-select v-model="form.status" placeholder="请选择 用户状态 1:禁用 0:正常">
            <el-option
              v-for="dict in dict.type.app_user_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="余额/可提现余额" prop="diamondCoin">
          <el-input v-model="form.diamondCoin" 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-dialog :title="title" :visible.sync="resetPwdopen" width="500px" append-to-body>
      <el-form ref="resetPwdForm" :model="resetPwdForm" :rules="resetPwdRules" label-width="80px">
        <el-form-item label="用户id" prop="userId">
          <el-input v-model="resetPwdForm.userId" disabled />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="resetPwdForm.password" placeholder="请输入密码" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitResetPwdForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 充值对话框 -->
    <el-dialog :title="title" :visible.sync="chargeopen" width="700px" append-to-body>
      <el-form ref="chargeForm" :model="chargeForm" :rules="currentRules" :validate-on-rule-change=false label-width="150px">
        <el-form-item label="用户id" prop="userId">
          <el-input v-model="chargeForm.userId" disabled />
        </el-form-item>
        <el-form-item label="货币类型" prop="type">
          <el-select v-model="chargeForm.type" placeholder="请选择" clearable>
            <el-option
              v-for="dict in dict.type.app_user_coin_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="金额" prop="amount">
          <el-input type="text" v-model="chargeForm.amount" placeholder="请输入金额" />
        </el-form-item>
        <el-form-item label="是否扣除手续费" prop="isRate">
          <el-select v-model="chargeForm.isRate" placeholder="请选择" clearable @change="isRateChange">
            <el-option
              v-for="dict in dict.type.app_charge_rate"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="渠道（扣除对应渠道手续费）" prop="channelId" v-if="chargeForm.isRate==1">
          <el-select v-model="chargeForm.channelId" placeholder="请选择" clearable @change="chargeChannel">
            <el-option
              v-for="dict in channelList"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
          <span style="padding-left: 1rem;color: red;font-size: 12px" v-if="null != rate && undefined != rate">手续费：{{(rate*100) + "%"}}</span>
        </el-form-item>
<!--        <el-form-item label="手续费比例" prop="rate" v-show="chargeForm.isRate==1 && chargeForm.channelId == -1">
          <el-input v-model="chargeForm.rate" placeholder="请输入手续费 (比如扣除10%，则填写0.1)" />
        </el-form-item>-->
        <template v-show="!isReadOnly">
          <el-form-item label="手续费比例" prop="rate" >
            <el-input type="number" v-model="chargeForm.rate" placeholder="请输入手续费 (比如扣除10%，则填写0.1)" :disabled="isReadOnly"/>
          </el-form-item>
        </template>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitChargeForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 补足流水对话框 -->
    <el-dialog :title="title" :visible.sync="resetWithdrawopen" width="700px" append-to-body>
      <el-form ref="withdrawForm" :model="resetWithdrawForm" :rules="withdrawRules" :validate-on-rule-change=false label-width="150px">
        <el-form-item label="用户id" prop="userId">
          <el-input v-model="resetWithdrawForm.userId" disabled />
        </el-form-item>
        <el-form-item label="金额" prop="amount">
          <el-input type="text" v-model="resetWithdrawForm.amount" placeholder="请输入金额" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitWithdrawForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listUser, getUser, delUser, addUser, updateUser,resetUser,userCharge,channelList,withdraw } from "@/api/business/user";

export default {
  name: "User",
  dicts: ['is_anchor_auth', 'app_user_role', 'app_user_status', 'app_user_online_status','app_user_coin_type','app_charge_rate'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // app用户表格数据
      userList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层
      resetPwdopen: false,
      // 是否显示弹出层
      resetWithdrawopen: false,
      // 是否显示弹出层
      chargeopen: false,
      channelList:[],
      isReadOnly:true,
      rate:null,
      channelMap:{},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userid: null,
        anchorGrade: null,
        anchorPoint: null,
        appVersion: null,
        appVersionCode: null,
        avatar: null,
        awardLoginDay: null,
        birthday: null,
        charmGrade: null,
        charmPoint: null,
        coin: null,
        coinCash: null,
        consumption: null,
        createTime: null,
        ipaddr: null,
        isAnchorAuth: null,
        nickname: null,
        onlineStatus: null,
        phoneFirm: null,
        phoneModel: null,
        phoneSystem: null,
        phoneUuid: null,
        pid: null,
        role: null,
        diamondCoin: null,
        mobile:null,
      },
      // 表单参数
      form: {},
      //重置密码
      resetPwdForm:{},
      //补足流水
      resetWithdrawForm:{},
      //充值
      chargeForm:{},
      // 表单校验
      rules: {
        level: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
      },
      resetPwdRules: {
        password: [
          { required: true, message: "密码不能为空", trigger: "blur" }
        ],
      },
      chargeRules: {
        amount: [
          { required: true, message: "金额不能为空", trigger: "blur" }
        ],
        type: [
          { required: true, message: "类型不能为空", trigger: "blur" }
        ],
        isRate: [
          { required: true, message: "请选择是否扣除手续费", trigger: "blur" }
        ]
      },
      withdrawRules: {
        amount: [
          { required: true, message: "金额不能为空", trigger: "blur" }
        ]
      },
      scrollLeft: 0
    };
  },
  created() {
    this.getList();
  },
  computed: {
    currentRules:function(){
      if(this.chargeForm.isRate == 1){
        this.chargeRules["channelId"] = [
          { required: true, message: "请选择充值渠道", trigger: "blur" }
        ];
      }else{
        delete this.chargeRules["channelId"]
      }
      return this.chargeRules;
    },
  },
  methods: {
    /** 查询app用户列表 */
    getList() {
      this.loading = true;
      listUser(this.queryParams).then(response => {
        this.userList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.resetPwdopen = false;
      this.chargeopen = false;
      this.resetWithdrawopen = false;
      this.reset();
      this.resetPwd();
      this.resetCharge();
      this.resetWithdraw();
    },
    // 表单重置
    reset() {
      this.form = {
        userid: null,
        address: null,
        agentId: null,
        amount: null,
        anchorGrade: null,
        anchorPoint: null,
        appVersion: null,
        appVersionCode: null,
        avatar: null,
        awardLoginDay: null,
        birthday: null,
        broadCast: null,
        channelId: null,
        chargeShow: null,
        charmGrade: null,
        charmPoint: null,
        city: null,
        cityEdit: null,
        coin: null,
        coinCash: null,
        constellation: null,
        consumption: null,
        createTime: null,
        dealScalePlan: null,
        delFlag: null,
        deviceId: null,
        devoteShow: null,
        giftGlobalBroadcast: null,
        goodnum: null,
        groupId: null,
        gsRoomId: null,
        gsRoomType: null,
        guildId: null,
        headNo: null,
        height: null,
        hideDistance: null,
        inviteCode: null,
        bindCode: null,
        ipaddr: null,
        isAnchorAuth: null,
        isAutomatic: null,
        isJoinJg: null,
        isLiveAccount: null,
        isNotDisturb: null,
        isOooAccount: null,
        isPush: null,
        isRecommend: null,
        isShowHomePage: null,
        isSvip: null,
        isTone: null,
        isYouthModel: null,
        ishot: null,
        isrecord: null,
        issuper: null,
        iszombie: null,
        iszombiep: null,
        joinRoomShow: null,
        kickTime: null,
        lastGameNum: null,
        lastLoginDay: null,
        lastLoginIp: null,
        lastLoginTime: null,
        lastOffLineTime: null,
        lat: null,
        level: null,
        liveFunction: null,
        liveStatus: null,
        liveThumb: null,
        liveThumbs: null,
        lng: null,
        lockReason: null,
        lockTime: null,
        loginType: null,
        managerCoId: null,
        managerId: null,
        maxSignCount: null,
        mobile: null,
        nickname: null,
        nobleGrade: null,
        onlineStatus: null,
        oooHomePageSortNo: null,
        oooLiveStatus: null,
        oooTwoClassifyId: null,
        openLiveZombieNum: null,
        openid: null,
        optUserName: null,
        password: null,
        phoneFirm: null,
        phoneModel: null,
        phoneSystem: null,
        phoneUuid: null,
        pid: null,
        portrait: null,
        poster: null,
        province: null,
        pushPlatform: null,
        pushRegisterId: null,
        readShortVideoNumber: null,
        regType: null,
        registerIp: null,
        role: null,
        roomId: null,
        roomTitle: null,
        roomType: null,
        roomTypeVal: null,
        salt: null,
        sanwei: null,
        score: null,
        sex: null,
        signCount: null,
        signTime: null,
        signature: null,
        smsRegion: null,
        source: null,
        starId: null,
        status: null,
        totalAmount: null,
        totalAmountCash: null,
        totalCash: null,
        totalCharge: null,
        unionid: null,
        updatePwdTime: null,
        userActivationKey: null,
        userEmail: null,
        userGrade: null,
        userPoint: null,
        userSetOnlineStatus: null,
        userType: null,
        userUrl: null,
        username: null,
        video: null,
        videoCoin: null,
        videoImg: null,
        vocation: null,
        voice: null,
        voiceCoin: null,
        voiceStatus: null,
        voipToken: null,
        votes: null,
        votestotal: null,
        wealthGrade: null,
        wechat: null,
        weight: null,
        whetherEnablePositioningShow: null,
        youthPassword: null,
        zombieMaxNum: null,
        zombieRatio: null,
        agentGrade: null,
        liveDividedInto: null,
        gameDividedInto: null,
        inviteBindTime: null,
        fundPassword: null,
        diamondCoin: null,
        diamondCoinTotal: null,
        diamondCoinCashTotal: null,
        agentFlag: null,
        diamondCoinCash: null,
        otherPid: null
      };
      this.resetForm("form");
    },// 表单重置
    resetPwd() {
      this.resetPwdForm = {
        userId: null,
        password: null
      };
      this.resetForm("restPwdForm");
    },// 表单重置
    resetWithdraw() {
      this.resetWithdrawForm = {
        userId: null,
        amount: null
      };
      this.resetForm("restWithdraoForm");
    },// 表单重置
    resetCharge() {
      this.chargeForm = {
        userId: null,
        amount: null,
        type:null,
        isRate:null,
        rate:null,
        channelId:null
      };
      this.resetForm("restPwdForm");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.userid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加app用户";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const userid = row.userid || this.ids
      getUser(userid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改app用户";
      });
    },
    /** 重置密码按钮操作 */
    handleRestPwd(row) {
      this.resetPwd();
      const userid = row.userid;
      this.resetPwdForm = {
        userId:userid,
        password:""
      };
      this.resetPwdopen = true;
      this.title = "重置密码";
    },
    /** 补足流水按钮操作 */
    handleWithdraw(row) {
      this.resetWithdraw();
      const userid = row.userid;
      this.resetWithdrawForm = {
        userId:userid,
        password:""
      };
      this.resetWithdrawopen = true;
      this.title = "补足提现流水";
    },
    /** 充值按钮操作 */
    handleCharge(row) {
      var that = this;
      that.channelList = [];
      that.channelMap = {};
      channelList().then(response => {
        if(response.data){
          for(var i in response.data){
            var item = response.data[i];
            that.channelMap[item.id] = item.rate;
            that.channelList.push({
              value:item.id,
              label:item.name,
              rate:item.rate
            })
          }
        }
      });
      this.resetCharge();
      const userid = row.userid;
      this.chargeForm = {
        userId:userid,
        type: null,
        amount:null
      };
      this.chargeopen = true;
      this.title = "充值";

      /*this.$nextTick(()=>{
        // 重置当前页面的所有字段值
        this.$refs['chargeForm'].resetFields();

        if (data){
          // 模式1
          this.form.patternType = 1;
        }else{
          // 模式2
          this.form.patternType = 2;
        }
        // 设置校验规则
        this.setValidRules(this.form.patternType);
      })*/
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.userid != null) {
            updateUser(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addUser(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 重置密码提交按钮 */
    submitResetPwdForm() {
      this.$refs["resetPwdForm"].validate(valid => {
        if (valid) {
          resetUser(this.resetPwdForm).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.resetPwdopen = false;
            this.getList();
          });
        }
      });
    },
    /** 补足流水提交按钮 */
    submitWithdrawForm() {
      var that =this;
      this.$refs["withdrawForm"].validate(valid => {
        if (valid) {
          withdraw(this.resetWithdrawForm).then(response => {
            this.$modal.msgSuccess("补足流水成功");
            this.resetWithdrawopen = false;
            this.getList();
          });
        }
      });
    },
    /** 充值提交按钮 */
    submitChargeForm() {
      var that =this;
      this.$refs["chargeForm"].validate(valid => {
        if (valid) {
          if(that.chargeForm.isRate != 1){
            that.chargeForm.rate = null;
          }
          if(that.chargeForm.channelId == -1 && (undefined == that.chargeForm.rate || null == that.chargeForm.rate)){
            this.$modal.msgError("请输入手续费比例");
            return;
          }
          if(that.chargeForm.channelId == -1 &&  that.chargeForm.rate >= 1){
            this.$modal.msgError("手续费比例超过最大值");
            return;
          }
          userCharge(this.chargeForm).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.chargeopen = false;
            this.getList();
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const userids = row.userid || this.ids;
      this.$modal.confirm('是否确认删除app用户编号为"' + userids + '"的数据项？').then(function() {
        return delUser(userids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/user/export', {
        ...this.queryParams
      }, `user_${new Date().getTime()}.xlsx`)
    },
    handleScroll(event) {
      // 当滚动时同步左右滚动
      this.scrollLeft = event.target.scrollLeft;
    },
    isRateChange(val){
      let rule = {};
      for(var i in this.chargeRules){
        rule[i] = this.chargeRules[i];
      }
      this.chargeRules = {};
      if(this.chargeForm.isRate == 1){
        rule["channelId"] = [
          { required: true, message: "请选择充值渠道", trigger: "blur" }
        ];
        /*rule["rate"] = [
          { required: true, message: "请输入手续费比例", trigger: "blur" }
        ];*/
      }else{
          delete rule["channelId"];
          // delete rule["rate"];
      }
      this.chargeRules = rule;
    },
    chargeChannel(val){
      let rule = {};
      for(var i in this.chargeRules){
        rule[i] = this.chargeRules[i];
      }
      this.chargeRules = {};
      if(this.chargeForm.channelId == -1){
        /*this.chargeForm.rate = null;
        rule["rate"] = [
          { required: true, message: "请输入手续费比例", trigger: "blur" }
        ];*/
        this.isReadOnly = false;
        this.rate = null;
      }else{
        let rate = this.channelMap[this.chargeForm.channelId];
        this.chargeForm.rate = rate;
        // delete rule["rate"];
        this.isReadOnly = true;
        this.rate = rate;
      }
      // this.chargeRules = rule;
    }
  }
};
</script>
