
<template>
  <div class="usersList PeaceDistribution">
    <div class="head-title">
        和平分销商等级
        <el-button @click="CommonJump('PeaceDistributionSet')" style="float:right;margin-top: -5px;" size="small" type="primary">
            添加分销商等级
        </el-button>
    </div>
    <div class="content">
        <div>
            <el-select class="w120" @change="getList" style="margin-right: 10px;" filterable v-model="msg.CategoryId" size="small" placeholder="请选择">
                <el-option label="全部分类" :value="0"></el-option>
                <el-option
                v-for="item in cateList"
                :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"
            width="80"
            label="ID">
            </el-table-column>
            <el-table-column
            prop="Name"
            width="200"
            label="分销名称">
            </el-table-column>
            <el-table-column
            prop="GradeName"
            width="150"
            label="类型">
                <template slot-scope="scope">
                    <span v-if="scope.row.DecimalType==1">整数</span>
                    <span v-if="scope.row.DecimalType==2">保留两位小数</span>
                </template>  
            </el-table-column>
            <el-table-column
            prop="GradeName"
            width="150"
            label="是否启用">
                <template slot-scope="scope">
                    <el-switch v-model="scope.row.Enabled" active-color="#409EFF" :active-value="1"
                      :inactive-value="2" @change="changeEnabled(scope.row)">
                    </el-switch>
                </template>  
            </el-table-column>
            <el-table-column
            prop="GradeName"
            label="分类">
                <template slot-scope="scope">
                    <el-tag style="margin:0 5px 5px 0" size="mini" v-for="(item,index) in scope.row.CategoryList" :key="index">
                        {{item.CategoryName}}
                    </el-tag>
                </template>  
            </el-table-column>
            <el-table-column
            prop="GradeName"
            label="返佣(名称/比例)">
                <template slot-scope="scope">
                    <p v-for="(item,index) in scope.row.RatioList" :key="index" type="success" style="margin-right:6px">
                        {{item.GradeName}}：{{item.CommissionRatio}}%
                    </p>
                </template>  
            </el-table-column>
            <el-table-column
                prop="address"
                width="150"
                label="操作">
            <template slot-scope="scope">
                <el-tooltip class="item" effect="dark" content="编辑" placement="top">
                    <img @click="CommonJump('PeaceDistributionSet',{UserId:scope.row.Id})" style="width:32px;height:32px" src="../../assets/img/userman/edit.png" alt="">
                </el-tooltip>
                <el-tooltip class="item" effect="dark" content="删除" placement="top">
                    <img @click="Delete(scope.row,1)" style="width:32px;height:32px;margin:0 10px" src="../../assets/img/userman/del.png" alt="">
                </el-tooltip>
            </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,
        value:'',
        options:[],
        tableData:[],
        msg:{
            pageIndex:1,
            pageSize:15,
            Name:'',
            CategoryId:0,
        },
        total:0,
        cateList:[],
      };
    },
    created() {
        this.getList();
        
        this.getCateId();
    },
    methods: {
        changeEnabled(item){
            this.apipost("/api/user/SetGetHpDistributorEnabled",{CommissionId:item.Id}, res => {
                if(res.data.resultCode==1){
                    this.Success(res.data.message)
                    this.getList()
                }
            })
        },
        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/DelHpDistributorInfo",
                {CommissionId:row.Id},
                res => {
                if (res.data.resultCode == 1) {
                    that.Success(res.data.message);
                    that.getList();
                } else {
                    that.Error(res.data.message);
                }
                },
                null
            );
            });
        },
        EditgoUrl(){
            this.$router.push({
                name: 'PsetDistributorLevel',
            });
        },
        getList(){
            this.loading=true;
            this.apipost("/api/user/GetHpDistributorPageList", 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;
                }
                
            })
        },
        getCateId(){
            let msg={
                pageIndex:0,
                pageSize:1000,
                Id:0,
                Name:'',
                Tier:0,
                ParentId:0,
                Enabled:1,
                IsShow:1,
            };
            this.apipost("/api/product/GetProductCategoryPageList", msg, res => {
                if(res.data.resultCode==1){
                    let pageData=res.data.data.pageData;
                    this.cateList=pageData; 
                }
                
            })
        },
       
        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>
