<template>
  <div class="app-container">
    <el-card>
      <div slot="header" class="clearfix" style="display: flex;justify-content: space-between">
        <el-page-header @back="goBack" content="详情页面">
        </el-page-header>
        <div>
          <el-button type="primary" plain round>子卡管理<i class="el-icon-bank-card el-icon--right"></i></el-button>
          <el-button type="primary" plain round>会员码</el-button>
        </div>
      </div>
      <div>基础资料</div>
      <div style="display: flex;margin-top: 20px">
        <div class="left">
          <div>
            <img v-if="form.avatar" :src="form.avatar" style="width: 80px;height: 80px">
            <img v-else src="@/assets/images/avatar.png" style="width: 80px;height: 80px">
          </div>
          <el-button type="warning" plain round size="mini" style="margin: 10px">绑定实体卡</el-button><br>
          <el-button type="primary" icon="el-icon-bank-card" round style="margin: 10px;width: 50%;height: 40px">会员充值</el-button>
        </div>
        <div class="right">
          <el-descriptions>
            <el-descriptions-item label="手机号">{{form.mobile}}
              <el-tag size="mini" @click="replaceMobile">更换</el-tag>
            </el-descriptions-item>
            <el-descriptions-item label="会员昵称">{{form.name}}</el-descriptions-item>
            <el-descriptions-item label="实体卡号">{{form.idcard}}</el-descriptions-item>
            <el-descriptions-item label="绑定信息"></el-descriptions-item>
            <el-descriptions-item label="会员状态">
              <dict-tag :options="dict.type.zhzt" :value="form.status"/>
            </el-descriptions-item>
            <el-descriptions-item label="加油次数">{{form.consumeNum}}</el-descriptions-item>
            <el-descriptions-item label="加油总金额">{{form.refuelMoney}}</el-descriptions-item>
            <el-descriptions-item label="所属油站">{{ store.name }}</el-descriptions-item>
            <el-descriptions-item label="注册时间">{{form.createTime}}</el-descriptions-item>
            <el-descriptions-item label="关联副卡">{{form.secondCard}}</el-descriptions-item>
            <el-descriptions-item label="会员等级">{{ grade.name }}</el-descriptions-item>
            <el-descriptions-item label="储值优惠"></el-descriptions-item>
            <el-descriptions-item label="每日笔数"></el-descriptions-item>
            <el-descriptions-item label="固定等级"></el-descriptions-item>
            <el-descriptions-item label="备注信息">{{ form.description }}</el-descriptions-item>
          </el-descriptions>
        </div>
      </div>
    </el-card>

    <el-card style="margin: 20px 0">
      <div>会员资产</div>
      <div>
        <template>
          <div>
            <el-row :gutter="20">
              <el-col :span="4">
                <div class="sta">
                  <el-statistic
                    group-separator=","
                    :value="form.point"
                    title="累计积分"
                  ></el-statistic>
                </div>
              </el-col>
              <el-col :span="4">
                <div class="sta">
                  <el-statistic
                    group-separator=","
                    :value="form.refuelMoney"
                    title="加油金">
                  </el-statistic>
                </div>
              </el-col>
              <el-col :span="4">
                <div class="sta">
                  <el-statistic
                    group-separator=","
                    :precision="2"
                    :value="form.balance"
                    title="账户余额"
                  ></el-statistic>
                </div>
              </el-col>
              <el-col :span="4">
                <div class="sta">
                  <el-statistic
                    group-separator=","
                    :precision="2"
                    :value="form.literCard"
                    title="升数卡余额"
                  ></el-statistic>
                </div>
              </el-col>
            </el-row>
          </div>
        </template>
      </div>
    </el-card>

    <el-card>
      <template>
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="加油订单" name="refuelOrder">
            <el-table ref="tables" v-loading="loading" :data="list">
              <el-table-column label="所属油站" prop="id" align="center"/>
              <el-table-column label="订单时间" align="center"/>
              <el-table-column label="交易终端" align="center" prop="userNo"/>
              <el-table-column label="油品/油枪" align="center" prop="name" />
              <el-table-column label="订单金额" align="center" prop="mobile"/>
              <el-table-column label="优惠金额" align="center" prop="gradeId"/>
              <el-table-column label="实付金额" align="center" prop="balance"/>
              <el-table-column label="付款类型" align="center" prop="balance"/>
              <el-table-column label="订单号" align="center" prop="balance"/>
              <el-table-column label="订单类型" align="center" prop="point"/>
            </el-table>

            <pagination
              v-show="total>0"
              :total="total"
              :page.sync="queryParams.page"
              :limit.sync="queryParams.pageSize"
              @pagination="getList"
            />
          </el-tab-pane>
          <el-tab-pane label="商品订单" name="shopOrder">
            <el-table ref="tables" v-loading="loading" :data="list">
              <el-table-column label="所属油站" prop="id" align="center"/>
              <el-table-column label="订单时间" align="center"/>
              <el-table-column label="订单金额" align="center" prop="userNo"/>
              <el-table-column label="商品数量" align="center" prop="name" />
              <el-table-column label="储值卡" align="center" prop="mobile"/>
              <el-table-column label="实付金额" align="center" prop="balance"/>
              <el-table-column label="付款类型" align="center" prop="balance"/>
              <el-table-column label="订单号" align="center" prop="balance"/>
              <el-table-column label="订单类型" align="center" prop="point"/>
            </el-table>

            <pagination
              v-show="total>0"
              :total="total"
              :page.sync="queryParams.page"
              :limit.sync="queryParams.pageSize"
              @pagination="getList"
            />
          </el-tab-pane>
          <el-tab-pane label="余额记录" name="balanceRecord">
<!--            <el-tabs v-model="balanceRecord" type="card" @tab-click="handleClick">-->
<!--              <el-tab-pane label="储值卡记录" name="first">储值卡记录</el-tab-pane>-->
<!--              <el-tab-pane label="升数卡记录" name="second">升数卡记录</el-tab-pane>-->
<!--            </el-tabs>-->
            <el-radio-group v-model="tabPosition" size="mini" style="margin-bottom: 30px;">
              <el-radio-button label="giftCard">储值卡记录</el-radio-button>
              <el-radio-button label="literCard">升数卡记录</el-radio-button>
            </el-radio-group>
            <div v-if="tabPosition=='giftCard'">
              <el-table ref="tables" v-loading="loading" :data="list">
                <el-table-column prop="date" label="所属油站"/>
                <el-table-column prop="date" label="变动账户"/>
                <el-table-column prop="date" label="类型"/>
                <el-table-column label="详细信息">
                  <el-table-column prop="name" label="变动金额"/>
                  <el-table-column prop="address" label="变动前余额"/>
                  <el-table-column prop="address" label="变动后余额"/>
                </el-table-column>
                <el-table-column prop="date" label="订单号"/>
                <el-table-column prop="date" label="描述"/>
                <el-table-column prop="date" label="变动时间"/>
              </el-table>

              <pagination
                v-show="total>0"
                :total="total"
                :page.sync="queryParams.page"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"
              />
            </div>
            <div v-else>
              <el-table ref="tables" v-loading="loading" :data="list">
                <el-table-column label="所属油站" prop="id" align="center"/>
                <el-table-column label="变动账户" align="center"/>
                <el-table-column label="类型" align="center" prop="userNo"/>
                <el-table-column label="变动升数" align="center" prop="name" />
                <el-table-column label="订单号" align="center" prop="balance"/>
                <el-table-column label="描述" align="center" prop="balance"/>
                <el-table-column label="变动时间" align="center" prop="point"/>
              </el-table>

              <pagination
                v-show="total>0"
                :total="total"
                :page.sync="queryParams.page"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"
              />
            </div>
          </el-tab-pane>
          <el-tab-pane label="积分记录" name="pointRecord">
            <el-table ref="tables" v-loading="loading" :data="list">
              <el-table-column label="所属油站" prop="id" align="center"/>
              <el-table-column label="变动时间" align="center"/>
              <el-table-column label="类型" align="center" prop="userNo"/>
              <el-table-column label="变动积分" align="center" prop="name" />
              <el-table-column label="描述" align="center" prop="balance"/>
            </el-table>

            <pagination
              v-show="total>0"
              :total="total"
              :page.sync="queryParams.page"
              :limit.sync="queryParams.pageSize"
              @pagination="getList"
            />
          </el-tab-pane>
          <el-tab-pane label="卡券列表" name="cardList">
            <el-radio-group v-model="cardList" size="mini" style="margin-bottom: 30px;">
              <el-radio-button label="notUse">未使用</el-radio-button>
              <el-radio-button label="used">已使用</el-radio-button>
              <el-radio-button label="expired">已过期</el-radio-button>
              <el-radio-button label="whole">全部</el-radio-button>
            </el-radio-group>
            <div>
              <el-table ref="tables" v-loading="loading" :data="list">
                <el-table-column prop="date" label="所属油站"/>
                <el-table-column prop="date" label="优惠券名称"/>
                <el-table-column prop="date" label="卡券类型"/>
                <el-table-column prop="date" label="满减金额"/>
                <el-table-column prop="date" label="券面额"/>
                <el-table-column prop="date" label="适用油品"/>
                <el-table-column prop="date" label="状态"/>
                <el-table-column label="卡券可用规则">
                  <el-table-column prop="name" label="有效期"/>
                  <el-table-column prop="address" label="周期与时段"/>
                </el-table-column>
                <el-table-column prop="date" label="领取时间"/>
                <el-table-column prop="date" label="描述"/>
              </el-table>

              <pagination
                v-show="total>0"
                :total="total"
                :page.sync="queryParams.page"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"
              />
            </div>
          </el-tab-pane>
          <el-tab-pane label="成长值记录" name="growthValue">
            <el-radio-group v-model="growthValue" size="mini" style="margin-bottom: 30px;">
              <el-radio-button label="whole">全部</el-radio-button>
              <el-radio-button label="gasoline">汽油成长值</el-radio-button>
              <el-radio-button label="diesel">柴油成长值</el-radio-button>
              <el-radio-button label="naturalGas">天然气成长值</el-radio-button>
            </el-radio-group>
            <div>
              <el-table ref="tables" v-loading="loading" :data="list">
                <el-table-column label="所属油站" prop="id" align="center"/>
                <el-table-column label="变动时间" align="center"/>
                <el-table-column label="类型" align="center" prop="userNo"/>
                <el-table-column label="变动成长值" align="center" prop="name" />
                <el-table-column label="描述" align="center" prop="balance"/>
              </el-table>

              <pagination
                v-show="total>0"
                :total="total"
                :page.sync="queryParams.page"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"
              />
            </div>
          </el-tab-pane>
          <el-tab-pane label="加油金记录" name="refuelMoney">
            <el-table ref="tables" v-loading="loading" :data="list">
              <el-table-column label="所属油站" prop="id" align="center"/>
              <el-table-column label="变动时间" align="center"/>
              <el-table-column label="类型" align="center" prop="userNo"/>
              <el-table-column label="变动数据" align="center" prop="name" />
              <el-table-column label="记录单号" align="center" prop="name" />
              <el-table-column label="变动描述" align="center" prop="balance"/>
              <el-table-column label="场景来源" align="center" prop="balance"/>
            </el-table>

            <pagination
              v-show="total>0"
              :total="total"
              :page.sync="queryParams.page"
              :limit.sync="queryParams.pageSize"
              @pagination="getList"
            />
          </el-tab-pane>
        </el-tabs>
      </template>
    </el-card>


<!--    更换手机号对话框-->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="openMobile" style="margin-top: 200px" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="新手机号" prop="mobile" style="width: 420px">
              <el-input v-model="form.mobile" placeholder="请输入新手机号" maxlength="30" />
              <span style="font-size: 12px;color: grey">
                手机号更换后,旧手机号将无法使用,更换后实时生效
              </span>
            </el-form-item>
          </el-col>
        </el-row>
      </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>
  </div>
</template>

<script>
import {getUser, updateUser} from "@/api/staff/user/user";
import {ljStoreInfo} from "@/api/staff/store";
import {getUserGrade} from "@/api/staff/user/usergrade";

export default {
  dicts: ['official','zhzt'],
  data(){
    return{
      title:'',
      // 是否显示修改对话框
      openMobile: false,
      growthValue:'whole',
      cardList:'notUse',
      tabPosition: 'giftCard',
      balanceRecord: 'first',
      // 遮罩层
      loading: false,
      id:'',
      // 会员信息
      form:{},
      // 店铺信息
      store:'',
      // 会员等级信息
      grade:'',
      activeName: 'refuelOrder',
      tableData:[],
      total:'',
      queryParams: {
        page: 1,
        pageSize: 10,
        mobile: '',
        id: '',
        name: '',
        status: '',
      },
      list: [],
      // 表单校验
      rules: {
        mobile: [{ required: true, message: "请输入手机号", trigger: "blur" }],
      }
    }
  },
  created() {
    this.id = this.$route.query.id;
    this.getUserInfo();
  },
  methods: {
    // 更换手机号
    replaceMobile(){
      this.openMobile = true;
      this.title = '更换手机号'
    },
    getList(){

    },
    // 获取详情
    getUserInfo(){
      let _this = this;
      // 获取会员详情
      getUser(this.id).then(response => {
        this.form = response.data;
        this.getGrade(response.data.gradeId);
      });
      // 获取店铺详情
      ljStoreInfo().then(response => {
        this.store = response.data;
      });
    },
    getGrade(id){
      getUserGrade(id).then(response => {
        this.grade = response.data;
      });
    },
    // 提交按钮
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id) {
            updateUser(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.openMobile = false;
              this.getUserInfo();
            });
          } else {
            // addUser(this.form).then(response => {
            //   this.$modal.msgSuccess("新增成功");
            //   this.open = false;
            //   this.getList();
            // });
          }
        }
      });
    },
    // 表单重置
    reset() {
      this.resetForm("form");
      this.form= {}
    },
    // 取消按钮
    cancel() {
      this.openMobile = false;
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
    // 返回
    goBack() {
      this.$router.back(-1);
    }
  }
}
</script>

<style lang="scss" scoped>
  .app-container{
    width: 100%;
    height: 100%;
    background: #f6f8f9;
  }
  .left{
    width: 20%;
    display: table-cell;
    /*垂直居中 */
    vertical-align: middle;
    /*水平居中*/
    text-align: center;
  }
  .right{
    flex: 1;
  }
  .sta{
    height: 100px;
    margin-top: 10px;
    padding-top: 30px;
  }
</style>
