
<template>
  <div class="usersList">
    <div class="head-title">
        用户管理
        <el-button @click="dialogVisible=true" style="float:right;margin-top: -5px;" size="small" type="primary">批量导出</el-button>
    </div>
    <div class="content">
        <div>
            <el-select class="w100" @change="getList" style="margin-right: 10px;" v-model="msg.MemberGrade" size="small" placeholder="请选择">
                <el-option label="全部会员" :value="0"></el-option>              
                <el-option
                v-for="item in memberGradeList"
                :key="item.Id"
                :label="item.Name"
                :value="item.Id">
                </el-option>
            </el-select>
            <el-select class="w100" @change="getList" style="margin-right: 10px;" v-model="msg.Source" size="small" placeholder="请选择">
                <el-option label="全部平台" :value="0"></el-option>
                <el-option
                v-for="item in platList"
                :key="item.Id"
                :label="item.Name"
                :value="item.Id">
                </el-option>
            </el-select>
            <div class="searchInput" style="width:150px">
                <el-input style="display:inline-block;width:125px;height:30px"
                placeholder="请输入ID"
                v-model="msg.Id"
                size="small"
                clearable>
                </el-input>
                <span @click="getList" class="el-icon-search" style="color:#979dad;font-size:14px;position:relative;top:1px"></span>
            </div>
            <div class="searchInput" style="width:150px">
                <el-input style="display:inline-block;width:125px;height:30px"
                placeholder="请输入昵称"
                v-model="msg.Name"
                size="small"
                clearable>
                </el-input>
                <span @click="getList" class="el-icon-search" style="color:#979dad;font-size:14px;position:relative;top:1px"></span>
            </div>
            <div class="searchInput" style="width:150px">
                <el-input style="display:inline-block;width:125px;height:30px"
                placeholder="请输入手机号"
                v-model="msg.Moblie"
                size="small"
                clearable>
                </el-input>
                <span @click="getList" class="el-icon-search" style="color:#979dad;font-size:14px;position:relative;top:1px"></span>
            </div>
        </div>
        <el-table
            :data="tableData"
            v-loading="loading"
            border
            style="width: 100%;margin:20px 0">
            <el-table-column
            prop="Id"
            label="ID">
            </el-table-column>
            <el-table-column
            prop="address"
            width="280"
            label="头像">
                <template slot-scope="scope">
                    <div class="app-image" :style="{backgroundImage:'url(' + scope.row.Photo + ')',backgroundSize:'cover'}"></div> 
                    <div flex="dir:left cross:center">{{scope.row.Name}}</div> 
                    <img v-if="scope.row.Source==1" style="width:24px;height:24px" src="../../assets/img/userman/wx.png" alt="" class="platform-img">
                    <button type="button" class="el-button el-button--success" style="float: right; padding: 5px !important;">
                        <span @click="ChangeOpenidState(scope.$index, scope.row)">显示OpenId</span>
                    </button>
                    <div v-show="scope.row.OpenIdState">{{scope.row.OpenId}}</div> 
                </template>  
            </el-table-column>
            <el-table-column
            prop="Moblie"
            label="手机号">
            </el-table-column>
            <el-table-column
            prop="MemberGradeName"
            label="会员类型">
            </el-table-column>
            <el-table-column
            prop="name"
            label="订单数">
                <template slot-scope="scope">
                    <span class="blue">{{scope.row.OrderNum}}</span>
                </template>
            </el-table-column>
            <el-table-column
            prop="name"
            label="优惠券数量">
                <template slot-scope="scope">
                    <span class="blue">{{scope.row.CouponsNum}}</span>
                </template>
            </el-table-column>
            <el-table-column
            prop="name"
            label="卡券数量">
                <template slot-scope="scope">
                    <span class="blue">{{scope.row.CardVolumeNum}}</span>
                </template>
            </el-table-column>
            <el-table-column
            prop="name"
            label="余额">
                <template slot-scope="scope">
                    <span class="blue">{{scope.row.Balance}}</span>
                </template>
            </el-table-column>
            <el-table-column
            prop="name"
            label="积分">
                <template slot-scope="scope">
                    <span class="blue">{{scope.row.Integral}}</span>
                </template>
            </el-table-column>
            <el-table-column
            prop="CreateDate"
            width="150"
            label="加入时间">
            </el-table-column>
            <el-table-column
            prop="address"
            width="200"
            label="操作">
            <template slot-scope="scope">
                <img style="width:32px;height:32px" src="../../assets/img/userman/edit.png" alt="">
                <img style="width:32px;height:32px;margin:0 10px" src="../../assets/img/userman/integral.png" alt="">
                <img style="width:32px;height:32px" src="../../assets/img/userman/balance.png" alt="">
            </template>    
            </el-table-column>
        </el-table>
        <el-pagination style="text-align:right"
        background
        @current-change="handleCurrentChange"
        :page-size="msg.pageSize"
        layout="prev, pager, next"
        :total="total">
        </el-pagination>
    </div>
    <!-- 选择导出信息 -->
    <el-dialog
        title="选择导出信息"
        :visible.sync="dialogVisible"
        width="960px">
        <el-form style="border: 1px solid #F0F2F7;" :model="addMsg" ref="addMsg" label-width="100px">
            <div style="box-sizing: border-box;background-color: #F3F5F6;width: 100%;padding-left: 20px;height: 50px;line-height: 50px;">
                <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
            </div>
            <div style="margin: 15px 0;"></div>
            <div style="padding: 10px 25px 20px;">
                <el-checkbox-group v-model="checkedCities" @change="handleCheckedCitiesChange">
                    <el-checkbox style="margin-bottom:10px" v-for="city in cities" :label="city.Id" :key="city.Name">{{city.Name}}</el-checkbox>
                </el-checkbox-group>
            </div>
            
        </el-form> 
        <div style="text-align:right;margin-top:20px">
            <el-button size="small" type="primary" @click="Export">导出</el-button>
        </div>
    </el-dialog>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        loading:false,
        checkAll: false,
        checkedCities: [],
        cities: [],
        cityOptions: [],
        isIndeterminate: true,
        addMsg:{},
        dialogVisible:true,
        value:'',
        options:[],
        tableData:[],
        msg:{
            pageIndex:1,
            pageSize:15,
            Name:'',
            Source:0,
            MemberGrade:0,
            Id:0,
            Moblie:''
        },
        total:0,
        platList:[],
        memberGradeList:[],
        
      };
    },
    created() {
        this.getList();
        this.getplat();
        this.getDown();
        this.GetMemberGradeList();
    },
    methods: {
        Export(){
            this.msg.ExcelEnumIds=this.checkedCities;
            console.log("this.msg",this.msg)
            let msg = JSON.parse(JSON.stringify(this.msg));
            this.JavaGetLocalFile(
            "/api/user/GetMemberUserListToExcel",
            msg,
            "用户管理.xls"
            );
        },
        ChangeOpenidState(index,row){
            this.tableData[index].OpenIdState=!this.tableData[index].OpenIdState;
        },
        getList(){
            this.loading=true;
            this.apipost("/api/user/GetMemberUserPageList", this.msg, res => {
                this.loading=false;
                if(res.data.resultCode==1){
                    this.total=res.data.data.count;
                    let pageData=res.data.data.pageData;
                    pageData.forEach(item=>{
                        item.OpenIdState=false;
                    })
                    this.tableData=pageData;
                }
                
            })
        },
        getDown(){
            this.cityOptions=[];
            this.apipost("/api/user/GetMemberUserExcelEnumList",{}, res => {
                this.cities=res.data.data;
                let data=res.data.data;
                data.forEach(item=>{
                    this.cityOptions.push(item.Id)
                })
                
            })
        },
        GetMemberGradeList(){
            let msg={
                Grade:0,
                Name:'',
                Enabled:0,
            };
            this.apipost("/api/user/GetMemberGradeList",{msg}, res => {
                this.memberGradeList=res.data.data;
            })
        },
        getplat(){
            this.apipost("/api/user/GetMemberUserSourceEnumList",{}, res => {
                this.platList=res.data.data;
            })
        },
        handleCheckAllChange(val) {
            this.checkedCities = val ? this.cityOptions : [];
            this.isIndeterminate = false;
        },
        handleCheckedCitiesChange(value) {
            let checkedCount = value.length;
            this.checkAll = checkedCount === this.cities.length;
            this.isIndeterminate = checkedCount > 0 && checkedCount < this.cities.length;
        },
        handleCurrentChange(val) {
            this.msg.pageIndex = val;
            this.getList();
        },

    },
    mounted() {
      
    }
  };

</script>
<style>
.usersList .app-image{
    background-position: center center; 
    width: 50px; 
    height: 50px;
     border-radius:0%; 
     float: left;
      margin-right: 8px;
}
.usersList .blue{
    color:#409EFF;
    
}
.usersList .content .searchInput{
    border: 1px solid #DCDFE6;
    border-radius: 4px;
}
.usersList .content .searchInput .el-input__inner{
    border:none;outline:none;
    height: 30px;
    line-height: 30px;
}
.usersList .content .searchInput{
    line-height: normal;
    display: inline-table;
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    width:250px;
    margin-right: 20px;
}
.usersList .content{
    background: #fff;
    margin-top:10px;
    padding: 20px;
    box-sizing: border-box;
}

</style>
