<template>
  <div class="mailRules PeaceDistribution">
    <div class="head-title">
        包邮规则
        <el-button @click="CommonJump('mailRulesSet')" style="float:right;margin-top: -5px;" size="small" type="primary">
            新增包邮规则
        </el-button>
    </div>
    <div class="content">
        <div >
            <span style='margin-right:10px'>是否开启全局分类包邮规则</span>     
             <el-switch v-model="IsFreeShipping" active-color="#409EFF" :active-value="1"
                :inactive-value="0" @change="changeEnabled_all()">
            </el-switch>      
        </div>
        <el-table
            :data="tableData"
            v-loading="loading"
            border
            style="width: 100%;margin:20px 0">
            <el-table-column
            prop="ID"
            width="90"
            label="编号">
            </el-table-column>
           
            <el-table-column
                prop="Name"
                width="180"
                label="包邮名称">
            </el-table-column>
             <el-table-column
                prop="FullNumPinkage"
                width="150"
                label="满件数">
            </el-table-column>
             <el-table-column
                prop="FullMoneyPinkage"
                width="150"
                label="满额金额">
            </el-table-column>
            <el-table-column
            prop="GradeName"
            width="150"
            label="是否启用">
                <template slot-scope="scope">
                    <el-switch v-model="scope.row.IsEnable" active-color="#409EFF" :active-value="1"
                      :inactive-value="0" @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="address"
                width="150"
                label="操作">
            <template slot-scope="scope">
                <el-tooltip class="item" effect="dark" content="编辑" placement="top">
                    <img @click="CommonJump('mailRulesSet',{ID: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"
        :current-page.sync="msg.pageIndex"
        :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,
           
        },
        total:0,
        cateList:[],
        IsFreeShipping:0,
        MallBaseId:0
      };
    },
    created() {
        this.getList();
        this.getSetup();
        this.MallBaseId = this.getLocalStorage()?this.getLocalStorage().MallBaseId:0
        
    },
    methods: {
        changeEnabled(item){
            this.apipost("/api/MallBase/AddOrUpdateIsEnable",{Id:item.ID,IsEnable:item.IsEnable}, res => {
                if(res.data.resultCode==1){
                    this.Success(res.data.message)
                    this.getList()
                }
            })
        },
        changeEnabled_all(){

            this.apipost("/api/MallBase/AddOrUpdateIsFreeShipping",{Id:this.MallBaseId,IsFreeShipping:this.IsFreeShipping}, res => {
                if(res.data.resultCode==1){
                    this.Success(res.data.message)
                    this.getList()
                }else{
                    this.Error(res.data.message);
                     this.getSetup();
                }
            })
        },

        Delete(row){
            let that=this;
            that.Confirm("是否删除?", function () {
            that.apipost(
                "/api/MallBase/DelFreeShipping",
                { Id: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/MallBase/GetFreeShippingList", 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;
                }
                
            })
        },
        getSetup(){
            this.apipost("/api/MallBase/GetMallBaseInfo", {}, res => {
            if (res.data.resultCode == 1) {
                if( res.data.data &&  res.data.data.IsFreeShipping){
                    this.IsFreeShipping = res.data.data.IsFreeShipping
                }
              
            } else {
              this.Info(res.data.message);
            }
          })
        },


        handleCurrentChange(val) {
            this.msg.pageIndex = val;
            this.getList();
        },

    },
    mounted() {
      
    }
  };

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

</style>
