
<template>
  <div class="usersList">
    <div class="head-title">
        分销商等级
        <el-button @click="EditgoUrl" 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.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:230px">
                <el-input style="display:inline-block;width:205px;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>
        <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"
            label="分销商等级">
                <template slot-scope="scope">
                    等级{{scope.row.Grade}}
                </template>  
            </el-table-column>
            <el-table-column
            prop="Name"
            label="分销商等级名称">
            </el-table-column>
            <el-table-column
            prop="UpGradeCondition"
            label="升级条件">
                <template slot-scope="scope">
                    <el-tag v-if="scope.row.IsAutoUpGrade==2" type="warning">不可自动升级</el-tag>
                    <el-tag v-if="scope.row.IsAutoUpGrade==1" type="success">可自动升级</el-tag>
                </template>  
            </el-table-column>
            <el-table-column
            prop="OneCommission"
            label="一级佣金">
                <template slot-scope="scope">
                    <span v-if="scope.row.DistributionCommissionType==1">{{scope.row.OneCommission}}%</span>
                    <span v-if="scope.row.DistributionCommissionType==2">{{scope.row.OneCommission}}</span>
                </template>
            </el-table-column>
            <el-table-column
            prop="name"
            label="二级佣金">
                <template slot-scope="scope">
                    <span v-if="tierInfo.DistributorTier==2 || tierInfo.DistributorTier==3">
                        <span v-if="scope.row.DistributionCommissionType==1">{{scope.row.TwoCommission}}%</span>
                        <span v-if="scope.row.DistributionCommissionType==2">{{scope.row.TwoCommission}}</span>
                    </span>
                    <span v-else>-</span>
                </template>
            </el-table-column>
            <el-table-column
            prop="name"
            label="三级佣金">
                <template slot-scope="scope">
                    <span v-if="tierInfo.DistributorTier==3">
                        <span v-if="scope.row.DistributionCommissionType==1">{{scope.row.ThreeCommission}}%</span>
                        <span v-if="scope.row.DistributionCommissionType==2">{{scope.row.ThreeCommission}}</span>
                    </span>
                    <span v-else>-</span>
                    
                </template>
            </el-table-column>
            <el-table-column
            prop="name"
            label="启用状态">
                <template slot-scope="scope">
                    <el-switch 
                    @change="SetEnabled(scope.row)"
                    v-model="scope.row.Enabled"
                    active-color="#409EFF"
                    :active-value="1"
                    :inactive-value="2">
                </el-switch>
                </template>
            </el-table-column>
            <el-table-column
            prop="address"
            width="150"
            label="操作">
            <template slot-scope="scope">
                <img @click="EditgoUrl(scope.row)" style="width:32px;height:32px" src="../../assets/img/userman/edit.png" alt="">
                <img v-if="scope.row.Enabled==2" @click="Delete(scope.row,1)" style="width:32px;height:32px;margin:0 10px" src="../../assets/img/userman/del.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>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        czType:1,
        czjfDig:false,
        changeState:false,
        loading:false,
        isIndeterminate: true,
        addMsg:{},
        dialogVisible:false,
        value:'',
        options:[],
        tableData:[],
        msg:{
            pageIndex:1,
            pageSize:15,
            Name:'',
            Grade:0,
            MemberGrade:0,
            Enabled:0,
        },
        total:0,
        addMsg:{
            MallBaseId:0,
            Type:1,
            UserId:0,
            Integral:0,
            Image:'',
            Description:'',
        },
        tierInfo:{},
      };
    },
    created() {
        this.getList();
        this.GetTierInfo();
        this.addMsg.MallBaseId=this.getLocalStorage().MallBaseId;
    },
    methods: {
        SetEnabled(row){
            let that=this;
            that.apipost(
                "/api/user/SetDistributorGradeEnabledStatus",
                {GradeId:row.Id},
                res => {
                if (res.data.resultCode == 1) {
                    that.Success(res.data.message);
                    that.getList();
                } else {
                    that.Error(res.data.message);
                }
                },
                null
            );
        },
        Delete(row){
            let that=this;
            that.Confirm("是否删除?", function () {
            that.apipost(
                "/api/user/DelDistributorGradeInfo",
                {GradeId:row.Id},
                res => {
                if (res.data.resultCode == 1) {
                    that.Success(res.data.message);
                    that.getList();
                } else {
                    that.Error(res.data.message);
                }
                },
                null
            );
            });
        },
        EditgoUrl(row){
            if(row){
                this.$router.push({
                    name: 'setDistributorLevel',
                    query: {
                        UserId:row.Id
                    }
                });
            }else{
                this.$router.push({
                name: 'setDistributorLevel',
            });
            }
            
        },
        getList(){
            this.loading=true;
            this.apipost("/api/user/GetDistributorGradePageList", this.msg, res => {
                this.loading=false;
                if(res.data.resultCode==1){
                    this.total=res.data.data.count;
                    let pageData=res.data.data.pageData;
                    this.tableData=pageData;
                }
                
            })
        },
        GetTierInfo(){
            this.apipost("/api/user/GetDistributorTierInfo",{}, res => {
                this.tierInfo=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 .remark_name {
    color: #888888;
    font-size: 12px;
    margin-left: 10px;
    float: right;
}
.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>
