
<style scoped>  
.comp-address {background:#e6e6e9;height:100vh;}
.addressList {background:#Fff;}
.addressList ul {list-style-type:none;margin:0;padding:0;}
.addressList .UserInfo {line-height:1rem;height:1rem;padding:0.2rem;padding-left:1rem;padding-top:1rem;}
.addressList .AddressDetail {padding:0.2rem;padding-left:1rem;padding-bottom:1rem;}
.addressList .UserInfo .mobile {color:#D06B77;}
.addressList .operate {color:#b3b3b3;padding-left:1rem;border-top:0.1rem solid #e6e6e9;border-bottom:0.4rem solid #e6e6e9;padding-bottom:1rem;}
.addressList .operate .setdefault i.defalut {background-image:url('http://image.supercarrier8.com/h5_shop/rideo_true.png');background-size:1rem 1rem;display:inline-block;height:1.5rem;width:1rem;background-repeat:no-repeat;background-position:0.1rem 0.7rem;padding-right:0.5rem;}
.addressList .operate .setdefault i.undefault {background-image:url('http://image.supercarrier8.com/h5_shop/redio_false.png');background-size:1rem 1rem;display:inline-block;height:1.5rem;width:1rem;background-repeat:no-repeat;background-position:0.1rem 0.7rem;padding-right:0.5rem;}
.addressList .operate .operateset {float:right;line-height:2.2rem;padding-right:1rem;}
.addressList .operate .operateset .edit i {background-image:url('https://release-sup8-images.oss-cn-shanghai.aliyuncs.com/h5_shop/edit_gray.png');background-size:1rem 1rem;display:inline-block;height:1.7rem;width:1rem;background-repeat:no-repeat;background-position:0.1rem 0.7rem;padding-right:0.5rem;}
.addressList .operate .operateset .del i {background-image:url('https://release-sup8-images.oss-cn-shanghai.aliyuncs.com/h5_shop/delete_gray.png');background-size:1rem 1rem;display:inline-block;height:1.7rem;width:1rem;background-repeat:no-repeat;background-position:0.1rem 0.7rem;padding-right:0.5rem;}
.footer {position: fixed;;color:#fff;bottom:0;background:#c03546;width:100%;height:2.5rem;text-align:center;line-height:2.5rem;}
.footer .item-btn {font-weight:bold;}
.nodata {width:12rem;height:12rem;background: url(https://release-sup8-images.oss-cn-shanghai.aliyuncs.com/h5_shop/empty_address.png) no-repeat center center;position: absolute;top:45%;margin-top:-6rem;left:50%;margin-left: -6rem;background-size: 12rem 12rem;}

</style>
<template> 
  <div class="container comp-address jfBaseSize" v-cloak>
      <div class="addressList">
          <ul>
            <li v-for="item in DataLit" :key="item.ID">
                <div class="UserInfo" @click="SelectAreaPage(item)">
                  <span class="username">{{item.ConsigneeName}}</span>
                  <span class="mobile">{{item.ConsigneeMobile}}</span>
                </div>
                <div class="AddressDetail"  @click="SelectAreaPage(item)">{{item.ConsigneeProvince}}{{item.ConsigneeCity}}{{item.ConsigneeArea}} {{item.ConsigneeAddress}}</div>
                <div class="operate">  
                  <span class="setdefault" @click="setDefaultShow($event,item.ID)"><i v-bind:class="item.IsDefault==true?'defalut':'undefault'" ></i>设为默认</span> 
                  <span class="operateset">
                    <span class="edit" @click="GoPage('edit',item.ID)"><i></i>编辑</span>
                    <span class="del" @click="OperDel(item.ID)"><i @click="OperDel(item.ID)"></i>删除</span>
                  </span>
                </div>
            </li>
            <li class="nodata" v-show="nodatashow"></li>
          </ul>
      </div> 
      <div class="footercom">
      <div class="footer"><span>+</span> <a class="item-btn"  @click="GoPage('add')">新增地址</a></div>
      </div>
  </div>
</template>
<script>
import { MessageBox } from 'mint-ui';
import JfapiHelper from "../assets/js/JfapiHelper.js";
import { Toast } from 'mint-ui';
export default {
  name: "JfCompAddressList",
  props: ["comp", "cfg", "selectedPage"],
  data() {
    return {
      DataLit:[],
      nodatashow:false
    };
  },
  methods: {
     GoPage(operatetype,ID){
       if(operatetype=="edit")
       {
          //存编辑逻辑
          sessionStorage.setItem("JfCompAddressEditID",ID); 
          this.$parent.changeSelectedPage('25');      
       }
       else if(operatetype=="add")
       { 
         sessionStorage.removeItem("JfCompAddressEditID"); 
          this.$parent.changeSelectedPage('25');    
       }
     },
     setDefaultShow(e,ID){
       $(".addressList .setdefault").find("i").removeClass("defalut").addClass("undefault");
       if($(e.target).html()=="")
       {
           $(e.target).addClass("defalut").removeClass("undefault");this.CompSetDefaultConsigneeAddress(ID);         
       }else{
           $(e.target).find("i").addClass("defalut").removeClass("undefault");this.CompSetDefaultConsigneeAddress(ID);
       }
       
     },
     SelectAreaPage(item){
         if(sessionStorage.getItem("goPageVue")=="JfCompSubOrder")
         {
          sessionStorage.setItem("JfCompAddressObj",JSON.stringify(item));
          sessionStorage.removeItem("goPageVue")
          this.$parent.changeSelectedPage('15');   
         }
     },
     CompSetDefaultConsigneeAddress(ID){
       var that=this;
        var url = "/integral/CompSetDefaultConsigneeAddress";
        var dataParams = {
            EnterpriseNo:that.sup8.context.enterpriseno,
            UserToken:JfapiHelper.GetUserToken(),
            MemberID:JfapiHelper.GetUserLoginInfo().UserId,
            ID:ID,
            LanguageType:JfapiHelper.GetLanguageType()
        };
        var cbSuccess = function(res){
          
        };
        var cbError = function(jqXHR, textStatus, errorThrown){
            MintUI.Toast(jqXHR.responseText);
        };
        //请求后端
        JfapiHelper.CommonCallService(url,dataParams,cbSuccess,cbError,null,null)
     },
     OperDel(ID)
     {
       MessageBox.confirm('是否确认删除?').then(action => {
            var that=this;
            var url = "/integral/CompDeleteConsigneeAddress";
            var dataParams = {
                UserToken:JfapiHelper.GetUserToken(),
                EnterpriseNo:that.sup8.context.enterpriseno,
                ID:ID,
                LanguageType:JfapiHelper.GetLanguageType()
            };
            var cbSuccess = function(res){
              that.LoadList();
            };
            var cbError = function(jqXHR, textStatus, errorThrown){
                MintUI.Toast(jqXHR.responseText);
            };
            //请求后端
            JfapiHelper.CommonCallService(url,dataParams,cbSuccess,cbError,null,null);
        });
     },
     LoadList(){
       var that=this;
        var url = "/integral/CompGetAllConsigneeAddress";
        var dataParams = {
            UserToken:JfapiHelper.GetUserToken(),
            EnterpriseNo:that.sup8.context.enterpriseno,
            MemberID:JfapiHelper.GetUserLoginInfo().UserId,
            LanguageType:JfapiHelper.GetLanguageType()
        };
        var cbSuccess = function(res){
            if (res.flag) {
              that.DataLit=res.data;
              if(that.DataLit==null)
              {
                that.nodatashow=true;
              }
            }else{
              that.nodatashow=true;
            }
        };
        var cbError = function(jqXHR, textStatus, errorThrown){
            MintUI.Toast(jqXHR.responseText);
        };
        //请求后端
        JfapiHelper.CommonCallService(url,dataParams,cbSuccess,cbError,null,null)
     }
  },
  watch: {
  },
  created: function() {
     var that=this;
     JfapiHelper.CheckLogin(this.$parent, that.sup8.context.enterpriseno);
     that.LoadList();
  },
  mounted: function() {
  /**样式兼容设计器 **/
    if(location.pathname.indexOf("/design")!=-1)
    {    
        $(".footercom").css({"position":"absolute","height":"100vh","width":"100%"});
        $("div.footer").css({"position":"absolute","width":"100%"});
    }
  }
};
</script>

