<template>
  <div class="context">
    <div class="panel">
      <h5>会员管理</h5>
      <div class="panel-body">
        <div>
          <el-row :gutter="20">
            <el-col :span="5" style=" width: 200px">
              <em>姓名:</em>
              <el-input style="margin-left:10px; width: 130px" v-model="panel.name" placeholder="请输入姓名"></el-input>
            </el-col>
            <el-col :span="5" style=" width: 260px">
              <em>手机号:</em>
              <el-input style="margin-left:10px; width: 140px" v-model="panel.phone" placeholder="请输入手机号"
                        type="number"></el-input>
            </el-col>
            <el-col :span="5" style="width: 260px">
              <em>会员类型:</em>
              <el-select style="margin-left:10px; width: 150px" v-model="panel.vipType">
                <el-option v-for="item in panel.vipOptions" :key="item.value" :label="item.label"
                           :value="item.value">
                </el-option>
              </el-select>
            </el-col>
            <el-col :span="5" style=" width: 260px">
              <em>到期日:</em>
              <el-select style="margin-left:10px; width: 150px" v-model="panel.expDay">
                <el-option v-for="item in panel.endTypeOptions" :key="item.value" :label="item.label"
                           :value="item.value">
                </el-option>
              </el-select>
            </el-col>
            <el-col :span="2">
              <el-button size="" type="primary" @click="query" plain :disabled="serachBtnStatus">查询</el-button>
            </el-col>
          </el-row>
        </div>
      </div>
    </div>
    <div class="change">
      <el-button @click="addMember" type="primary" size="mini">新增会员</el-button>
      <el-button @click="lessonChange"  size="mini">课时调整</el-button>
      <el-button @click="lessonStudenChange" size="mini">增删会员可预约课程</el-button>
      <el-button @click="deleteMember"   size="mini">删除会员</el-button>
    </div>
    <div class="table">
      <br>
      <el-table :data="tableData" border is-horizontal-resize :default-sort="{prop: 'date', order: 'descending'}"
                element-loading-background="rgba(0, 0, 0, 0.8)" @selection-change="handleSelectionChange"
                @current-change="clickChange">
        <el-table-column label="选择" width="55" fixed>
          <template slot-scope="scope">
            <el-radio v-model="tableRadio" :label="scope.row"><i></i></el-radio>
          </template>
        </el-table-column>
        <el-table-column label="序号" type="index" width="50" align="center" fixed>
          <template scope="scope">
            <span>{{ (start) + scope.$index + 1 }}</span>
          </template>
        </el-table-column>

        <el-table-column prop="headurl" label="头像" width="50">
          <template slot-scope="scope">
            <div class="demo-image__preview" v-if="scope.row.headurl">
              <el-image style="width: 25px; height: 25px" :src="scope.row.headurl"
                        :preview-src-list="[scope.row.headurl]">
              </el-image>
            </div>
            <img src="../../assets/img/nav/head.png" alt="" v-else width="25px" height="25px">
          </template>
        </el-table-column>
        <el-table-column prop="user_name" label="会员名" width="90" fixed/>
        <el-table-column prop="usercode" label="手机号" width="110" sortable fixed/>
        <el-table-column align="center" label="会员卡信息">
          <el-table-column prop="vip_type" label="类型" align="center" width="80px" sortable>
            <template slot-scope="scope">
              <span v-if="scope.row.vip_type == 1">年费</span>
              <span v-if="scope.row.vip_type == 2">充值</span>
            </template>
          </el-table-column>
          <el-table-column prop="exp_time" label="到期日" width="100" :formatter="filterFmtDate" sortable/>
        </el-table-column>

        <el-table-column align="center" label="剩余课时">
          <el-table-column prop="remain_normalhour" label="普通课时" width="105" align="center" sortable/>
          <el-table-column prop="remain_gifthour" label="赠送课时" width="105" align="center" sortable/>
        </el-table-column>
        <el-table-column align="center" label="消费课时">
          <el-table-column prop="consume_normalhour" label="普通课时" width="105" align="center" sortable/>
          <el-table-column prop="consume_gifthour" label="赠送课时" width="105" align="center" sortable/>
        </el-table-column>

        <el-table-column prop="is_across" label="跨店会员" width="105" sortable>
          <template slot-scope="scope">
            <span v-if="scope.row.is_across == 0" class="green">本店用户</span>
            <span v-else class="red">跨店用户</span>
          </template>
        </el-table-column>
        <el-table-column prop="memo" label="备注">
          <template slot-scope="scope">
            <el-popover placement="top" title="" width="100px" trigger="hover" :content="scope.row.memo">
              <span slot="reference" v-if="scope.row.memo.length > 6">{{ scope.row.memo.substr(0, 6) }} ....</span>
            </el-popover>
            <span v-if="scope.row.memo.length <= 6">{{ scope.row.memo }}</span>
          </template>
        </el-table-column>
        <!--        <el-table-column prop="ClassInfo" label="会员课程" width="180px"/>-->
        <el-table-column prop="en_status" label="操作" width="300px">
          <template slot-scope="scope">
            <el-button class="btn" type="default" size="mini" @click="editMember(scope.row)"  >
              编辑
            </el-button>
            <el-popover placement="left" title="开通课程" width="400" trigger="click">
              <el-button slot="reference" class="btn" type="default" size="mini" @click="queryUserClass(scope.row)">
                会员课程
              </el-button>
              <el-table :data="userClassInfo">
                <el-table-column property="class_name"></el-table-column>
              </el-table>
            </el-popover>
            <el-button class="btn" type="default" size="mini" @click="goRelevance(scope.row)">关联手机</el-button>
            <el-button class="btn" type="success" v-if="scope.row.en_status == 0" size="mini"
                       @click="enableMember(scope.row)">启用
            </el-button>
            <el-button class="btn" type="danger" v-if="scope.row.en_status == 1" size="mini"
                       @click="disableMember(scope.row)">禁用
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div v-if="pageshow">
        <el-pagination background :total="pageination.total" :page-size="pageination.pageItem"
                       @current-change="pageChange" :current-page.sync="cur_page"></el-pagination>
      </div>
    </div>

    <el-dialog :title="dialogTitle" :visible.sync="dialogMemberVisible"
               :width="form.btnType == 1 ?'650px':'1200px'">
      <div class="dialogContent">
        <div :class="['pull-left',{'tabwild':form.btnType == 1}]">
          <el-form ref="form" :model="form" label-width="80px">
            <el-form-item label="手机号" :required="true">
              <el-input v-model="form.phone" @blur="getUsrInfoList()"></el-input>
            </el-form-item>
            <el-form-item label="会员名" :required="true">
              <el-input v-model="form.name"></el-input>
            </el-form-item>
            <el-form-item label="会员类型" v-if="form.btnType == 0">
              <el-select v-model="form.vipType" placeholder="请选择所属门店">
                <el-option v-for="item in memberTypes" :key="item.value" :label="item.label"
                           :value="item.value"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="课时" v-if="form.btnType == 0">
              <el-input-number v-model="form.normalhour " :min="0" :max="99999" label="（天）">
              </el-input-number>
            </el-form-item>
            <el-form-item label="赠送课时" v-if="form.btnType == 0">
              <el-input-number v-model="form.gifthour " :min="0" :max="99999" label="（天）">
              </el-input-number>
            </el-form-item>
            <el-form-item label="备注">
              <el-input v-model="form.memo"></el-input>
            </el-form-item>
            <el-form-item label="身高" :required="true">
              <el-input v-model="form.height" placeholder="cm" type="number"></el-input>
            </el-form-item>
            <el-form-item label="体重" :required="true">
              <el-input v-model="form.weight" placeholder="kg" type="number"></el-input>
            </el-form-item>
            <el-form-item label="静态心率">
              <el-input v-model="form.staticHr" placeholder="请输入" type="number"></el-input>
            </el-form-item>
            <el-form-item label="性别" :required="true">
              <el-select v-model="form.sex " placeholder="">
                <el-option v-for="item in sexOptions" :key="item.value" :label="item.label"
                           :value="item.value"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="出生年份" :required="true">
              <el-date-picker v-model="form.birthday" align="right" type="date" placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="头像" :required="true">
              <div class="upload">
                <img v-if="imageUrl" :src="imageUrl" class="avatar">
                <el-upload class="avatar-uploader" :action=domain :before-upload="beforeUpload" :show-file-list="false">
                  <!--<i v-else class="el-icon-plus avatar-uploader-icon"/>-->
                </el-upload>
                <cropper :width="300" :height="300" :fixed-number="[1,1]" @subUploadSucceed="getShopImages"/>
                <!--<ImgCutter v-on:cutDown="cutDown"></ImgCutter>-->
              </div>
            </el-form-item>

          </el-form>
        </div>
        <div class="pull-right" v-if="form.btnType == 0 && pullRight">
          <el-form ref="form" :model="form" label-width="10px">
            <el-form-item label="">
              <el-transfer filterable v-model="form.classlist" :data="form.dialogdata"
                           :titles="['全部课程','已选课程']"></el-transfer>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <div class="dialogFooter">
        <el-button :disabled="addDisabled" type="primary" size="small" v-if="form.btnType == 0"
                   @click="confirmMember">确定
        </el-button>
        <el-button type="primary" size="small" v-if="form.btnType == 1" @click="confirmEditMember">确定
        </el-button>
        <el-button size="small" @click="dialogMemberVisible = false">取消</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="dialogVisible">
      <div class="dialogTitle">
        <h5>
          <span v-if="dialogLessonTable">编辑会员 <em class="blue">[{{ form.rowName }}]</em>  可预约课程</span>
          <span v-if="dialogLesson">调整会员 <em class="blue">[{{ form.rowName }}]</em>  课时</span>
        </h5>
      </div>
      <div v-if="dialogLesson">
        <span>当前会员类型:</span>
        <el-select v-model="form.vipType" style="width:185px; margin-left:20px; ">
          <el-option v-for="item in memberTypes" :key="item.value" :label="item.label"
                     :value="item.value"></el-option>
        </el-select>
        <br/><br/>
        <div v-if="form.vipType === 1">
          <span>会员到期时间:</span>
          <el-date-picker v-model="form.expTime" type="date" style="width:185px; margin-left:20px; "/>
        </div>
        <br/>

        <span style="margin-right: 15px">剩余普通课时: {{ form.normalhour }}</span>
        <el-input-number v-model="form.newnormalhour" :min="-9999" :max="9999" label="课时调整" style="width:180px"/>
        <br/><br/>
        <span style="margin-right: 20px">剩余赠送课时: {{ form.gifthour }}</span>
        <el-input-number v-model="form.newgifthour" :min="-9999" :max="9999" label="赠送课时调整" style="width:180px"/>
        <br/><br/>

      </div>

      <div v-if="dialogLessonTable">
        <el-transfer filterable v-model="form.dialogValue" :data="form.dialogdata" :titles="['全部课程','已选课程']"/>
      </div>
      <div class="dialogFooter" align="center">
        <!--课时调整-->
        <el-button type="primary" size="small" @click="confirmLesson" v-if="dialogLesson">确定</el-button>
        <!--课程增删-->
        <el-button type="primary" size="small" @click="confirmLessonTable" v-if="dialogLessonTable">确定</el-button>
        <!--取消-->
        <el-button size="small" @click="dialogVisible = false">取消</el-button>
      </div>

    </el-dialog>


  </div>
</template>

<script>
import {
  StandardRequest
} from "@/grpc/base_pb";


import cropper from '@/components/cropper.vue'

let qs = require('qs');
export default {
  data() {
    return {
      imageUrl: '',
      token: {}, // 七牛云的上传地址，根据自己所在地区选择，我这里是华南区
      domain: 'https://up-z1.qiniup.com', // 这是七牛云空间的外链默认域名
      qiniuaddr: 'xhead.beswell.com',//xhead.beswell.com 旧的 qjzpcd34v.hb-bkt.clouddn.com
      pullRight: true,//其他dialog
      addDisabled: true,//禁止添加新用户
      dialogVisible: false,//其他dialog
      TakeVisible: false,//take dialog
      dialogMemberVisible: false,//新增会员dialog
      dialogLesson: false,//课时调整
      dialogGift: false,//赠送课时调整
      dialogExpTime: false,//有效期调整
      dialogLessonTable: false,//会员课程
      dialogTitle: '新增会员',
      dialogValue: [],
      Takevalue: 0,
      Takeoptions: [],
      TakeHid: 0,
      start: 0,
      draw: 1,
      cur_page: 1,
      pageshow: true,
      sexOptions: [
        {value: 1, label: '男'},//性别 1：男， 2：女
        {value: 2, label: '女'},
      ],
      yearOptions: getyearOptions(15),
      userClassInfo: [],
      // panel 配置项目
      panel: {
        usercode: '',
        username: '',
        compname: '',
        keyword: '',
        USERCODE: '',
        endType: '',
        taskstatus: 99,
        draw: 1,
        start: 0,
        recordsTotal: 0,
        tableData: [],
        allTableData: [],
        limit: '10',
        multipleSort: false,
        loading: false,
        fileList: [],
        multipleSelection: [],
        detectedmac: '',
        vipType: -99,
        expDay: -99999,
        vipOptions: vipOptions(0),
        endTypeOptions: endTypeOptions(),
        time1: globalBt(),
      },
      multipleSelection: [],
      //分页数据
      pageination: {
        pageItem: 10,//每页的条数
        pageoptions: pageOptions(),
        total: 10,
        pageIndex: 1,
      },
      form: {
        phone: '',
        name: '',
        userCode: '',
        shopId: '',
        Id: '',
        userId: '',
        height: '',
        weight: '',
        staticHr: '',
        head: '',
        birthday: '',
        sex: 1,
        vipType: 1,
        normalhour: 0,
        newnormalhour: 0,
        gifthour: 0,
        newgifthour: 0,
        btnType: 0,//0新建，1编辑编辑
        memo: '',
        expTime: '',
        classlist: [],
        dialogdata: [],//穿梭待选
        dialogValue: [],//穿梭已选
      },
      memberTypes: vipOptions(1),
      tableData: [],
      tableRadio: [],
      serachBtnStatus: false
    }
  },
  mounted() {
    // 加载课程选项
    this.panelSelect();
    // 读取列表
    this.getTableQuery();
  },
  watch: {
    $route(to) {
      if (to.name == 'Member') {
        // 加载课程选项
        this.panelSelect();
        // 读取列表
        this.getTableQuery();
      }
    },
  },
  methods: {
    // 查询用户是否乃跨店用户
    // todo 逻辑
    //  1.新用户正常注册
    //  2.

    getUsrInfoList() {
      let that = this;
      // 只有新增的时候启用当前功能
      if (this.form.btnType == 1) {
        return false
      }

      const jsonStr = {
        shopId: localStorage.shopId,
        phone: this.form.phone
      };

      let standardReq = new StandardRequest();
      standardReq.setShopid(localStorage.shopId);
      standardReq.setSign(getSignStr(jsonStr));
      standardReq.setJsonstr(JSON.stringify(jsonStr));
      console.log(standardReq.getJsonstr());
      that.client.vipMainPhoneCheck(standardReq, {"Token": localStorage.token}, (err, StandardReply) => {
        if (err == null) {
          console.log(StandardReply.getJsonrst());
          let res = JSON.parse(StandardReply)
          console.log(res);
          if (res.code == 20101) {//该手机号在本店已存在
            that.$message.error('用户已存在，手机号不能重复添加');
            that.addDisabled = true;
          }
          if (res.code == 20102) {//该手机号在分店作为副手机号存在
            that.$message.error('手机号已经关联其他用户不能重复添加');
            that.addDisabled = true;
          }
          if (res.code == 0) {
            that.pullRight = true;
            that.addDisabled = false;
            that.pullRight = true;
            that.form.name = '';
            that.form.height = '';
            that.form.weight = '';
            that.form.birthday = '';
            that.imageUrl = '';
            that.form.head = '';
            this.form.sex = 1;

            if (res.usertype == 3) {//其他分店存在用户信息，反填入输入框
              let userInfo = res.rs[0];

              that.$message.success('已读取到当前用户信息');
              // 关掉右侧
              that.pullRight = false;
              that.form.name = userInfo.user_name;
              that.form.height = userInfo.height;
              that.form.weight = parseInt(userInfo.weight);
              that.form.birthday = userInfo.birthday;
              that.imageUrl = userInfo.headurl;
              that.form.head = userInfo.headurl;
              that.form.sex = userInfo.sex;
              that.form.staticHr = userInfo.static_hr;
            }
            if (res.usertype == 4) {//不存在用户信息
              // 该手机号不存在，可正常录入信息
            }
          }
        } else {
          let res = err;
          that.$message.error(res.message + ',错误代码：' + res.code);
          console.log(res);
        }
      })
    },
    // 关联手机号跳转
    goRelevance(row) {
      this.$router.push({path: '/relevancePhone', query: {userId: row.uu_user_id,shopId: row.shop_id}});
    },
    cutDown(e) {
      console.log(e);
      this.imageUrl = e.dataURL;
      this.upqiniu(e);
    },
    // 验证文件合法性
    beforeUpload(file) {
      const isJPG = file.type === 'image/jpeg' || file.type === 'image/png';
      const isLt2M = file.size / 1024 / 1024 < 70;
      if (!isJPG) {
        this.$message.error('上传头像图片只能是 JPG 格式!')
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 70MB!')
      }
      return isJPG && isLt2M
    },

    clickChange(item) {
      this.tableRadio = item
    },
    // 查询会员开通课程信息
    queryUserClass(row) {
      let that = this;
      that.userClassInfo = [];//清空之前加载出的数据
      const jsonStr = {
        shopId: localStorage.shopId,
        UuUserId: row.uu_user_id
      };

      let standardReq = new StandardRequest();
      standardReq.setShopid(localStorage.shopId);
      standardReq.setJsonstr(JSON.stringify(jsonStr));
      standardReq.setSign(getSignStr(jsonStr));
      console.log(standardReq.getJsonstr());
      that.client.vipUserClassQuery(standardReq, {"Token": localStorage.token}, (err, StandardReply) => {
        if (err == null) {
          console.log(StandardReply.getJsonrst());
          let res = JSON.parse(StandardReply);
          if (res.code == 0) {
            console.log(res);
            that.userClassInfo = res.rs;
          } else {
            that.$message.error(res.memo + ',错误代码：' + res.code);
          }
        } else {
          let res = err;
          that.$message.error(res.message + ',错误码：' + res.code);
          console.log("err:" + err);
        }
      })


    },
    // 编辑会员信息
    editMember(row) {
      let that = this;
      this.clearForm();
      this.form.Id = row.uu_user_id;
      this.form.shopId = row.shop_id;
      this.form.phone = row.usercode;
      this.form.name = row.user_name;
      this.form.memo = row.memo;
      this.imageUrl = row.headurl;
      this.form.head = row.headurl;
      this.form.height = row.height;
      this.form.weight = parseInt(row.weight);
      this.form.staticHr = row.static_hr;
      this.form.sex = row.sex;
      this.form.birthday = row.birthday;
      // this.form.ubId = row.UserInfo.UbId;
      this.form.btnType = 1;
      this.dialogMemberVisible = true;
      this.dialogTitle = '编辑会员'
    },
    // 禁用账户
    disableMember(row) {
      let that = this;
      this.$confirm('是否禁用用户' + row.user_name + '？', '禁用操作', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const jsonStr = {
          UuHId: row.uu_h_id,
          status: 0,//状态 0：禁用 1：启用 9：删除
        };

        let standardReq = new StandardRequest();
        standardReq.setShopid(localStorage.shopId);
        standardReq.setJsonstr(JSON.stringify(jsonStr));
        standardReq.setSign(getSignStr(jsonStr));
        console.log(standardReq.getJsonstr());
        that.client.shopVipUserStatusEdit(standardReq, {"Token": localStorage.token}, (err, StandardReply) => {
          if (err == null) {
            console.log(StandardReply.getJsonrst());
            let res = JSON.parse(StandardReply);

            if (res.code == 0) {
              that.$message({
                showClose: true,
                message: row.user_name + '禁用成功！',
                type: 'success'
              });
              // table 重载
              that.getTableQuery();
            } else {
              that.$message({
                showClose: true,
                message: row.user_name + '禁用失败',
                type: 'fail'
              });
            }
          } else {
            let res = err;
            that.$message.error(res.message + ',错误码：' + res.code);
            console.log("err:" + err);
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消禁用'
        });
      });
    },
    // 启用账户
    enableMember(row) {
      let that = this;
      this.$confirm('是否启用用户' + row.user_name + '？', '启用操作', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const jsonStr = {
          UuHId: row.uu_h_id,
          status: 1,//状态 0：禁用 1：启用 9：删除
        };

        let standardReq = new StandardRequest();
        standardReq.setShopid(localStorage.shopId);
        standardReq.setJsonstr(JSON.stringify(jsonStr));
        standardReq.setSign(getSignStr(jsonStr));
        console.log(standardReq.getJsonstr());
        that.client.shopVipUserStatusEdit(standardReq, {"Token": localStorage.token}, (err, StandardReply) => {
          if (err == null) {
            console.log(StandardReply.getJsonrst());
            let res = JSON.parse(StandardReply);

            if (res.code == 0) {
              that.$message({
                showClose: true,
                message: row.user_name + '启用成功！',
                type: 'success'
              });
              // table 重载
              that.getTableQuery();
            } else {
              that.$message({
                showClose: true,
                message: row.user_name + '启用失败',
                type: 'fail'
              });
            }
          } else {
            let res = err;
            that.$message.error(res.message + ',错误码：' + res.code);
            console.log("err:" + err);
          }
        })

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消启用'
        });
      });
    },
    // 删除
    deleteMember() {
      let that = this;
      let row = this.tableRadio;
      if (that.tableRadio.length == 0) {
        that.$message.error("请先选中一条记录");
        return false
      }
      const jsonStr = {
        UuHId: row.uu_h_id,
        status: 9,//状态 0：禁用 1：启用 9：删除
      };

      let standardReq = new StandardRequest();
      standardReq.setShopid(localStorage.shopId);
      standardReq.setJsonstr(JSON.stringify(jsonStr));
      standardReq.setSign(getSignStr(jsonStr));
      console.log(standardReq.getJsonstr());

      this.$confirm('此操作将永久删除该会员, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        that.client.shopVipUserStatusEdit(standardReq, {"Token": localStorage.token}, (err, StandardReply) => {
          if (err == null) {
            console.log(StandardReply.getJsonrst());
            let res = JSON.parse(StandardReply);

            if (res.code == 0) {
              that.$message({
                showClose: true,
                message: '选中的会员已删除！',
                type: 'success'
              });
              // table 重载
              that.getTableQuery();
            } else {
              that.$message({
                showClose: true,
                message: row.user_name + '删除失败',
                type: 'fail'
              });
            }
          } else {
            let res = err;
            that.$message.error(res.message + ',错误码：' + res.code);
            console.log("err:" + err);
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    // 关闭所有对话框
    allDialogClose() {
      this.dialogVisible = false;
      this.dialogGift = false;
      this.dialogLesson = false;
      this.dialogExpTime = false;
      this.dialogLessonTable = false;
    },
    // 有效期调整
    ExpTimeChange() {
      // 仅针对年费用户，使用日期格式
      this.allDialogClose();
      if (this.tableRadio.length == 0) {
        this.$message.error("请先选中一条记录");
        return false
      }
      let row = this.tableRadio;
      if (parseInt(row.vip_type) == 2) {
        this.$message({
          showClose: true,
          message: '错了哦，充值会员不能调整有效期',
          type: 'error'
        });
        return false
      }
      this.form.rowName = row.user_name;
      this.form.userId = row.uu_user_id;
      this.dialogVisible = true;
      this.dialogExpTime = true;
    },
    // 课时调整
    lessonChange() {
      this.allDialogClose();
      if (this.tableRadio.length == 0) {
        this.$message.error("请先选中一条记录");
        return false
      }
      let row = this.tableRadio;
      this.form.userId = row.uu_h_id;//调整课时使用
      this.form.rowName = row.user_name;//赋值操作的用户名
      this.form.expTime = row.exp_time//赋值当前用户的到期时间
      this.form.normalhour = row.remain_normalhour;//赋值当前用户的课时
      this.form.gifthour = row.remain_gifthour;//赋值当前用户的赠送课时
      this.form.vipType = row.vip_type;//赋值当前用户的会员类型
      this.form.newnormalhour = 0;//赋值新增加的课时
      this.form.newgifthour = 0;//赋值新增加的赠送课时
      this.dialogLesson = true;
      this.dialogVisible = true;
    },

    // 增删会员课程
    lessonStudenChange() {
      let that = this;
      this.allDialogClose();
      // 重载课程列表选项
      this.form.dialogValue = [];
      this.panelSelect();
      if (this.tableRadio.length == 0) {
        that.$message.error("请先选中一条记录");
        return false
      }
      let row = this.tableRadio;
      this.form.rowName = row.user_name;
      this.form.userId = row.uu_user_id;
      //查询该用户开通课程
      const jsonStr = {
        shopId: localStorage.shopId,
        UuUserId: row.uu_user_id
      };

      let standardReq = new StandardRequest();
      standardReq.setShopid(localStorage.shopId);
      standardReq.setJsonstr(JSON.stringify(jsonStr));
      standardReq.setSign(getSignStr(jsonStr));
      console.log(standardReq.getJsonstr());
      that.client.vipUserClassQuery(standardReq, {"Token": localStorage.token}, (err, StandardReply) => {
        if (err == null) {
          console.log(StandardReply.getJsonrst());
          let res = JSON.parse(StandardReply);

          if (res.rs) {
            console.log(res);
            res.rs.map(function (item) {
              that.form.dialogValue.push(item.class_id)
            })
          }
        } else {
          let res = err;
          that.$message.error(res.message + ',错误码：' + res.code);
          console.log("err:" + JSON.parse(err));
        }
      })

      this.dialogVisible = true;
      this.dialogLessonTable = true;
    },
    // 确认提交新增会员
    confirmMember() {
      let that = this;
      // checkNum
      if (!that.form.phone) {
        this.$message.error('错了哦，手机号不能为空');
        return false
      }
      if (!globalCheckPhone(that.form.phone)) {
        this.$message.error('错了哦，手机号格式不正确');
        return false
      }
      if (!that.form.name) {
        this.$message.error('错了哦，会员名不能为空');
        return false
      }
      if (that.form.name.length > 8) {
        this.$message.error('错了哦，会员名字数超过8个字');
        return false
      }
      if (that.form.memo) {
        if (that.form.memo.length > 200) {
          this.$message.error('错了哦，备注字数超过200个字');
          return false
        }
      }

      if (!that.form.height) {
        this.$message.error('错了哦，身高不能为空');
        return false
      }
      if (!that.form.weight) {
        this.$message.error('错了哦，体重不能为空');
        return false
      }
      if (!that.form.birthday) {
        this.$message.error('错了哦，出生年份不能为空');
        return false
      }

      // 课程添加使用字符串形式
      let curClasslist = '';
      if (that.form.classlist) {
        curClasslist = that.form.classlist.toString();
      }

      const jsonStr = {
        shopId: localStorage.shopId,
        phone: that.form.phone,
        name: that.form.name,
        vipType: that.form.vipType,
        normalhour: that.form.normalhour,
        gifthour: that.form.gifthour,
        classList: curClasslist,
        memo: that.form.memo,
        height: that.form.height,
        weight: that.form.weight,
        staticHr: that.form.staticHr,
        sex: that.form.sex,
        expTime: getDate(1, 0),
        headIconUrl: that.form.head,
        birthday: nonTfmtDatetoLength(that.form.birthday, 10)
      };

      let standardReq = new StandardRequest();
      standardReq.setShopid(localStorage.shopId);
      standardReq.setSign(getSignStr(jsonStr));
      standardReq.setJsonstr(JSON.stringify(jsonStr));
      console.log(standardReq.getJsonstr());
      that.client.shopVipUserAdd(standardReq, {"Token": localStorage.token}, (err, StandardReply) => {
        if (err == null) {
          console.log(StandardReply.getJsonrst());
          let res = JSON.parse(StandardReply);

          if (res.code == 0) {
            // 关闭弹窗
            that.dialogMemberVisible = false;
            // 重载列表
            that.getTableQuery();
            that.$message({
              showClose: true,
              message: '会员添加成功！',
              type: 'success'
            });
          } else {
            that.$message.error(res.memo + ',错误代码：' + res.code);
          }
        } else {
          let res = err;
          that.$message.error(res.message + ',错误代码：' + res.code);
          console.log(res);
        }
      })
    },
    confirmEditMember() {
      let that = this;
      // checkNum
      if (!that.form.phone) {
        this.$message.error('错了哦，手机号不能为空');
        return false
      }
      if (!globalCheckPhone(that.form.phone)) {
        this.$message.error('错了哦，手机号格式不正确');
        return false
      }
      if (!that.form.name) {
        this.$message.error('错了哦，会员名不能为空');
        return false
      }
      if (that.form.name.length > 8) {
        this.$message.error('错了哦，会员名字数超过8个字');
        return false
      }
      if (that.form.memo) {
        if (that.form.memo.length > 200) {
          this.$message.error('错了哦，备注字数超过200个字');
          return false
        }
      }
      if (!that.form.height) {
        this.$message.error('错了哦，身高不能为空');
        return false
      }
      if (!that.form.weight) {
        this.$message.error('错了哦，体重不能为空');
        return false
      }
      if (!that.form.birthday) {
        this.$message.error('错了哦，出生年份不能为空');
        return false
      }

      const jsonStr = {
        shopId: localStorage.shopId,
        uuUserId: that.form.Id,
        phone: that.form.phone,
        name: that.form.name,
        memo: that.form.memo,
        height: that.form.height,
        weight: that.form.weight,
        staticHr: that.form.staticHr,
        sex: that.form.sex,
        headIconUrl: that.form.head,
        birthday: nonTfmtDatetoLength(that.form.birthday, 10)
      };

      let standardReq = new StandardRequest();
      standardReq.setShopid(localStorage.shopId);
      standardReq.setSign(getSignStr(jsonStr));
      standardReq.setJsonstr(JSON.stringify(jsonStr));
      console.log(standardReq.getJsonstr());
      that.client.shopVipUserEdit(standardReq, {"Token": localStorage.token}, (err, StandardReply) => {
        if (err == null) {
          console.log(StandardReply.getJsonrst());
          let res = JSON.parse(StandardReply);

          if (res.code == 0) {
            // 关闭弹窗
            that.dialogMemberVisible = false;
            // 重载列表
            that.getTableQuery();
            that.$message({
              showClose: true,
              message: '会员信息修改成功！',
              type: 'success'
            });
          } else {
            that.$message.error(res.memo + ',错误代码：' + res.code);
          }
        } else {
          let res = err;
          console.log(err);
          that.$message.error(res.message + ',错误码：' + res.code);
        }
      })
    },
    // 确认提交课时
    confirmLesson() {
      let that = this;
      const jsonStr = {
        UuHId: that.form.userId,
        chgVipType: that.form.vipType,
        chgNormalHour: that.form.newnormalhour,
        chgGiftHour: that.form.newgifthour,
        chgExpTime: nonTfmtDatetoLength(that.form.expTime, 10),
      };
      let standardReq = new StandardRequest();
      standardReq.setShopid(localStorage.shopId);
      standardReq.setSign(getSignStr(jsonStr));
      standardReq.setJsonstr(JSON.stringify(jsonStr));
      console.log(standardReq.getJsonstr());
      that.client.vipHourEdit(standardReq, {"Token": localStorage.token}, (err, StandardReply) => {
        if (err == null) {
          console.log(StandardReply.getJsonrst());
          let res = JSON.parse(StandardReply);

          if (res.code == 0) {
            // 关闭弹窗
            that.dialogVisible = false;
            // 重载列表
            that.getTableQuery();
            that.$message({
              showClose: true,
              message: '课时调整成功！',
              type: 'success'
            });
          } else {
            that.$message.error(res.memo + ',错误代码：' + res.code);
          }
        } else {
          let res = err;
          that.$message.error(res.message + ',错误代码：' + res.code);
          console.log(res);
        }
      })
    },
    // 确认提交会员课程
    confirmLessonTable() {
      let that = this;
      // checkNum
      let classList = that.form.dialogValue ? that.form.dialogValue.toString() : '';

      //含参数调用过程
      const jsonStr = {
        shopId: localStorage.shopId,
        UuUserId: that.form.userId,
        classList: classList
      };

      let standardReq = new StandardRequest();
      standardReq.setShopid(localStorage.shopId);
      standardReq.setSign(getSignStr(jsonStr));
      standardReq.setJsonstr(JSON.stringify(jsonStr));
      console.log(standardReq.getJsonstr());
      that.client.vipClassRelationEdit(standardReq, {"Token": localStorage.token}, (err, StandardReply) => {
        if (err == null) {
          console.log(StandardReply.getJsonrst());
          let res = JSON.parse(StandardReply);

          if (res.code == 0) {
            console.log(res);
            // 关闭弹窗
            that.dialogVisible = false;
            // 重载列表
            that.getTableQuery();
            that.$message({
              showClose: true,
              message: '会员课程调整成功！',
              type: 'success'
            });
          } else {
            that.$message.error(res.memo + ',错误代码：' + res.code);
          }
        } else {
          let res = err;
          that.$message.error(res.message + ',错误码：' + res.code);
          console.log("err:" + err);
        }
      })
    },
    // 加载课程列表选项
    panelSelect() {
      let that = this;
      let jsonStr = {
        shopId: localStorage.shopId,
        classType: 1,    //课程类型 0:选课时不显示 1:选课显示 ,基本上都是选1
        start: 1,
        tableMax: 99
      };

      let standardReq = new StandardRequest();
      standardReq.setShopid(localStorage.shopId);
      standardReq.setSign(getSignStr(jsonStr));
      standardReq.setJsonstr(JSON.stringify(jsonStr));

      that.client.classQuery(standardReq, {"Token": localStorage.token}, (err, StandardReply) => {
        if (err == null) {
          console.log(StandardReply.getJsonrst());
          let res = JSON.parse(StandardReply);
          if (res.code ==0) {
            that.form.dialogdata = turnClassResToOption(res.rs);
          } else {
            that.$message.error(res.memo + ',错误代码：' + res.code);
          }
        } else {
          console.log("err:" + err.toObject);
          let res = JSON.parse(err);
          that.$message.error(res.message + ',错误代码：' + res.code);
        }
      })
    },
    // 新增会员
    addMember() {
      this.clearForm();
      this.panelSelect();
      this.dialogMemberVisible = true;
      this.btnType = 0;
      this.form.btnType = 0;
      this.dialogTitle = '新增会员'
      this.pullRight = true;
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 查询按钮
    query() {
      let that = this;
      that.start = 0;
      that.cur_page = 1;
      that.serachBtnStatus = true;
      that.getTableQuery();
      this.pageshow = false;//让分页隐藏
      this.$nextTick(() => {//重新渲染分页
        this.pageshow = true;
      });
      that.$message.success('查询完毕');
      let totalTime = 2;
      let clock = window.setInterval(() => {
        totalTime--;
        if (totalTime < 0) {
          totalTime = 2;
          that.serachBtnStatus = false;
        }
      }, 1000)
    },
    clearForm() {
      // clear
      this.form.name = '';
      this.form.head = '';
      this.imageUrl = '';
      this.form.phone = '';
      this.form.memo = '';
      this.form.normalhour = 0;
      this.form.gifthour = 0;
      this.form.height = '';
      this.form.weight = '';
      this.form.staticHr = '';
      this.form.sex = 1;
      this.form.birthday = '';
      this.form.userCode = '';
      this.form.shopId = '';
      this.form.classlist = [];
    },
    // 页面数据查询
     getTableQuery() {
      let that = this;
      that.loading = true;
      that.allTableData = [];
      that.recordsTotal = 0;
      let jsonStr = {
        shopId: localStorage.shopId,
        vipType: that.panel.vipType,
        name: that.panel.name,
        phone: that.panel.phone,
        expDay: that.panel.expDay,
        start: that.start,
        tableMax: that.pageination.pageItem
      };

      let standardReq = new StandardRequest();
      standardReq.setShopid(localStorage.shopId);
      standardReq.setSign(getSignStr(jsonStr));
      standardReq.setJsonstr(JSON.stringify(jsonStr));
      console.log(standardReq.getJsonstr());
      console.log(localStorage.token);

      that.allTableData = [];
      that.recordsTotal = 0;

      that.client.shopVipUserQuery(standardReq, {"Token": localStorage.token}, (err, StandardReply) => {
        if (err == null) {
          console.log(StandardReply.getJsonrst());
          let res = JSON.parse(StandardReply);

          that.loading = false;
          if (res.rs) {
            that.allTableData = res.rs;
            that.recordsTotal = res.pagecount * that.pageination.pageItem;
          } else {
            that.allTableData = [];
            that.recordsTotal = 0;
          }
          // 设置分页数据
          that.setPaginations();
        } else {
          let res = err;
          that.$message.error(res.message + ',错误代码：' + res.code);
          console.log(res);
        }
      })
    },
    // 设置分页数据
    setPaginations() {
      // 分页属性
      let that = this;
      that.pageination.total = that.recordsTotal;
      // 默认分页
      that.tableData = that.allTableData.filter((item, index) => {
        return index < that.pageination.pageItem;
      });
    },
    // 每页显示数量
    handleSizeChange() {
      let that = this;
      that.tableData = that.allTableData.filter((item, index) => {
        return index < that.pageination.pageItem;
      });
      that.draw = that.pageination.pageItem;
      that.getTableQuery();
    },
    // 翻页
    pageChange(pageIndex) {
      let that = this;
      // 获取当前页
      let index = that.pageination.pageItem * (pageIndex - 1);
      // 数据总数
      let nums = that.pageination.pageItem * pageIndex;
      // 容器
      let tables = [];
      for (var i = index; i < nums; i++) {
        if (that.allTableData[i]) {
          tables.push(that.allTableData[i])
        }
        this.tableData = tables;
      }
      that.start = index * that.draw;
      that.getTableQuery();
    },
    // 过滤时间
    filterFmtDate(value, row, column) {
      let that = this;
      if (column == "0001-01-01T08:05:43+08:05" || column == "0001-01-01T00:00:00Z") {
        return '无有效期';
      } else {
        return nonTfmtDatetoLength(column, 10);
      }
    },
    // 海报上传成功
    getShopImages(url) {
      this.imageUrl = url;
      this.form.head = url;
    }
  },
  components: {
    cropper
  }
}
</script>

<style scoped>
@import "../../assets/css/panel.css";

.context {
  border-radius: 12px;
  /*  height: 770px;*/
  overflow-y: scroll;
  display: block;
  margin: 0 auto;
  background-color: #fff !important;
  padding: 30px;
  padding-bottom: 30px;
}

.panel-body {
  padding: 20px;
  background: #F0F2F5;
}

.change {
  width: 100%;
  overflow: hidden;
  display: block;
  margin: 0 auto;
  padding-top: 10px;
  padding-bottom: 10px;
}

.change button {
  float: left;
}

.change button.pull-right {
  float: right;
}

.dialogTitle {
  width: 100%;
  overflow: hidden;
  display: block;
  margin: 0 auto;
  color: #000000;
  font-size: 18px;
  text-align: center;
}

.dialogTitle em {
  float: none;
  font-style: normal;
  color: #3799FF;
  margin: 0;
}

/deep/ .el-transfer-panel__item .el-checkbox__input {
  left: 40px;
}

.dialogFooter {
  width: 100%;
  overflow: hidden;
  display: block;
  margin-top: 20px;
}

.dialogFooter button {
  margin-left: 10px;
}

.dialogContent {
  width: 100%;
  overflow: hidden;
  display: block;
  margin: 0 auto;
}

.dialogContent .pull-left {
  width: 40%;
  float: left;
}

.dialogContent .pull-right {
  width: 60%;
  float: right;
}

.tabwild {
  width: 100% !important;
  overflow: hidden;
  display: block;
  margin: 0 auto;
}

.lessonSpan {
  width: 78px;
  height: 22px;
  border-radius: 11px;
  margin-right: 5px;
  float: left;
  margin-bottom: 3px;
  text-align: center;
  color: #000;
  font-size: 12px;
}

.btn {
  float: left !important;
  margin-right: 5px;
}

/deep/ table .el-button + .el-button {
  margin-left: 0;
  margin-right: 3px;
  /*float: left;*/
  padding: 7px 6px;
}

table {
  width: 100%;
  display: block;
  margin: 0 auto;
  overflow: scroll;

}

.pull-left /deep/ .el-form .el-form-item {
  width: 50%;
  float: left;
}

.pull-left /deep/ .el-form-item__content {
  margin-left: 20px;
}

.pull-left .el-input-number {
  width: 130px;
}

.cell img {
  overflow: hidden;
  display: block;
  margin: 0 auto;
}

.el-date-editor.el-input__inner {
  width: 156px;
}

.avatar-uploader {
  /*border: 1px solid #ccc;*/
  cursor: pointer;
  border-radius: 5px;
}

/deep/ .el-upload {
  width: 100%;
  overflow: hidden;
  display: block;
  margin: 0 auto;
}

/deep/ .el-upload img {
  width: 70px;
  height: 70px;
  float: left;
}

.relevance {
  margin-top: 10px;
}
</style>