
<template>
  <div class="usersList PdistributorLevel">
    <div class="head-title">
        和平分销商等级
        <el-button @click="AddDig" 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.GradeName"
                @keyup.enter.native="msg.pageIndex=1,getList()" 
                @clear="msg.pageIndex=1,getList()"
                size="small"
                clearable>
                </el-input>
                <span @click="msg.pageIndex=1,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="address"
            label="是否直客">
                <template slot-scope="scope">
                    <span v-if="scope.row.IsGuest==1">是</span>
                    <span class="blue" v-else>-</span>
                </template>  
            </el-table-column>
            <el-table-column
            prop="GradeName"
            label="分销商等级名称">
            </el-table-column>
            <el-table-column
            prop="UpdateDate"
            label="修改时间">
            </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="Edit(scope.row)" 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"
        :current-page.sync="msg.pageIndex"
        :total="total">
        </el-pagination>
    </div>
    <!-- 修改-->
    <el-dialog title="修改" :visible.sync="dialogVisible" width="500px">
        <el-form :model="addMsg" :rules="rules" ref="addMsg" label-width="150px">
            <p style="padding-left:34px;margin-bottom:15px" class="cred">注：等级需连续，从等级1开始</p>
            <el-form-item label="分销商等级选择" prop="Grade">
                <el-select size="small" v-model="addMsg.Grade" placeholder="请选择">
                    <el-option v-for="(item,index) in numList" 
                    :key="index" :label="`等级${index+1}`" 
                    :value="item.Id"
                    :disabled="item.dis"
                    >
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="分销商等级名称" prop="GradeName">
                <el-input v-model="addMsg.GradeName" size="small"></el-input>
            </el-form-item>
            <el-form-item label="是否直客" prop="IsGuest">
                <el-select size="small" v-model="addMsg.IsGuest" placeholder="请选择">
                    <el-option label="是" :value="1"></el-option>
                    <el-option label="否" :value="2"></el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button size="small" @click="dialogVisible = false">取 消</el-button>
            <el-button size="small" type="primary" @click="Save('addMsg')">确 定</el-button>
        </span>
    </el-dialog>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        dialogVisible:false,
        czType:1,
        czjfDig:false,
        changeState:false,
        loading:false,
        isIndeterminate: true,
        value:'',
        options:[],
        tableData:[],
        msg:{
            pageIndex:1,
            pageSize:15,
            GradeName:'',
        },
        total:0,
        addMsg: {
          Id: 0,
          Grade: 1,
          GradeName: '',
          IsGuest:'',
        },
        rules: {
          Grade: [{
            required: true,
            message: '请选择分销商等级',
            trigger: 'change'
          }],
          GradeName: [{
            required: true,
            message: '请输入分销商等级名称',
            trigger: 'blur'
          }],
          IsGuest: [{
            required: true,
            message: '请选择是否直客',
            trigger: 'change'
          }],
        },
        tierInfo:{},
        numList:[],
        disList:[],
      };
    },
    created() {
        this.getList();
        this.GetTierInfo();
        this.addMsg.MallBaseId=this.getLocalStorage().MallBaseId;
        this.numList=[]
        for(let i=1;i<11;i++){
            let obj={
                Id:i,
                dis:false,
            }
            this.numList.push(obj)
        }
    },
    methods: {
        Save(formName) {
            this.$refs[formName].validate((valid) => {
            if (valid) {
                this.apipost("/api/user/SetHpDistributorGradeInfo", this.addMsg, res => {
                if (res.data.resultCode == 1) {
                    this.getList();
                    this.dialogVisible=false;
                } else {
                    this.Error(res.data.message);
                }
                })
            } else {
                return false;
            }
            });
        },
        AddDig(){
            this.dialogVisible=true;
            this.addMsg= {
                Id: 0,
                Grade: 1,
                GradeName: '',
                IsGuest:'',
            }
        },
        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/DelHpDistributorGradeInfo",
                {GradeId:row.Id},
                res => {
                if (res.data.resultCode == 1) {
                    that.Success(res.data.message);
                    that.getList();
                } else {
                    that.Error(res.data.message);
                }
                },
                null
            );
            });
        },
        Edit(item){
            this.dialogVisible=true;
            this.addMsg=Object.assign({},item);
        },
        EditgoUrl(){
            this.$router.push({
                name: 'PsetDistributorLevel',
            });
        },
        getList(){
            this.loading=true;
            this.apipost("/api/user/GetHpDistributorGradePageList", 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>
