<script>
import {setAttatchParameter} from './plugin/utils.js'
export default {
  data() {
    return {
      basedata: {},
      title: "",
    };
  },
  onLaunch: function () {
    console.log('App Launch')
	this.$utils.setAttatchParameter(this)
    this.init();
    this.formatPlat();
  },
  onLoad(option) {
 //  	console.log('App OnLoad',option)
	// // #ifdef MP-DI
	// this.checkBindParentHandle(option.query)
	// // #endif
  },
  onShow: function (option) {
    console.log('App Show',option)
    this.$utils.VersionUpdate()
	// #ifdef MP-DI
	this.checkBindParentHandle(option.query)
	// #endif
  },
  onHide: function () {
    //console.log('App Hide')
  },
  methods: {
	checkBindParentHandle(query){
		if(query && query.direct_user_id){
			if(uni.getStorageSync('mall_UserInfo')){
				const {OpenId,Unoinid,Name} = uni.getStorageSync('mall_UserInfo')
				if(OpenId && Unoinid) {
					const pid = parseInt(query.direct_user_id)
					if(!isNaN(pid)) this.directUserLoginHandle(OpenId,Unoinid,pid,Name)
					return
				}
			}
			
			uni.setStorageSync('direct_user_id',query.direct_user_id)
		}
	},
	directUserLoginHandle(OpenId,Unoinid,Pid,MallName){
		const parameters={
			OpenId,
			Unoinid,
			Pid
		}
		this.apipost("HePingGuoLvLogin_post", parameters, r =>{
			const u = r.data
			const user = {
				accountId: u.directCustomerId,
				customerId: u.directCustomerId,
				customerInfoChildrenId: u.directCustomerId,
				realNameAuthentication: 0,
				account: "",
				name:u.name,
				customerName: MallName,
				photo: u.photo,
				secretKey: "",
				token: u.token,
				groupId: 0,
				isMember: 0,
				createBy: u.pid,
				EmLoginMobile: u.moblie,
				contactNumber: u.moblie,
				salesBaseInfo: u.erpBaseInfo?u.erpBaseInfo:u.salesBaseInfo,
				pid:u.erpBaseInfo?u.erpBaseInfo.employeeId:u.pid,
				erpBaseInfo: u.erpBaseInfo,
				count: 0,
				isVip:u.isVip,
				customerType: 1, //直客，2-同行  
				directCustomerId: u.directCustomerId //直客Id
			}
			uni.setStorageSync('b2b_user', user)
			this.user = user
			uni.setStorageSync("lastLogin",new Date().getTime())
			this.$utils.setAttatchParameter(this)
		})
	},
    init() {
      if (uni.getStorageSync("basedata")) {
        this.basedata = uni.getStorageSync("basedata");
        this.formatTabbar();
        this.formatNavigation();
      } else {
      this.request2(
        {
          url: "/api/Mall/GetHome",
          data: {},
        },
        (res) => {
          uni.setStorageSync("basedata", res.data);
          uni.setStorageSync('navs', res.data.navbar.navs??[])
          this.basedata = res.data;
          this.$uiConfig.mainColor=res.data.mall.setting.mallStyle.main
          this.$uiConfig.secondary=res.data.mall.setting.mallStyle.secondary
		  if(res.data.mall.setting.mallStyle.pricecolor){
			  this.$uiConfig.pricecolor=res.data.mall.setting.mallStyle.pricecolor
		  }
          this.formatTabbar();
          this.formatNavigation();
        }
      );
     }
    },
    formatPlat() {
      let modelmes = uni.getSystemInfoSync().model;
      let tempMoble = Boolean;
      if (
        modelmes.indexOf("iPhone X") >= 0 ||
        modelmes.indexOf("iPhone XR") >= 0 ||
        modelmes.indexOf("iPhone XS") >= 0 ||
        modelmes.indexOf("iPhone 12") >= 0 ||
        modelmes.indexOf("iPhone 11") >= 0 ||
        modelmes.indexOf("iPhone11") >= 0 ||
        modelmes.indexOf("iPhone12") >= 0 ||
        modelmes.indexOf("iPhoneXR") >= 0 ||
        modelmes.indexOf("iPhoneX") >= 0
      ) {
        tempMoble = true;
      } else {
        tempMoble = false;
      }
      this.$uiConfig.is_bang = tempMoble;
    },
    formatNavigation() {
      uni.setNavigationBarColor({
        frontColor: this.$uiConfig.topstyle.textColor,
        backgroundColor: this.$uiConfig.topstyle.background,
        animation: {
          duration: 400,
          timingFunc: "easeIn",
        },
      });
      // uni.setNavigationBarTitle({
      //   title: this.basedata.mall.name,
      // });
    },
    formatTabbar() {
      let navs = this.basedata.navbar.navs;
      this.$uiConfig.topstyle.background = this.basedata.navbar.top_background_color;
      this.$uiConfig.topstyle.textColor = this.basedata.navbar.top_text_color;

      //   uni.setTabBarStyle({
      //     color: navs[0].color,
      //     selectedColor: navs[0].active_color,
      //     backgroundColor: this.basedata.navbar.bottom_background_color,
      //     borderStyle: "#ccc",
      //   });

      //   navs.forEach((x,i) => {
      //     uni.setTabBarItem({
      //       index: i,
      //       text: x.text,
      //       iconPath: x.icon,
      //       selectedIconPath: x.active_icon,
      //     });
      //   });
    },
  },
};
</script>

<style lang="scss">
@import "uview-ui/index.scss";
@import url("./asset/font/iconfont.css");
@import url('asset/font/tffont.css');
/* 0123456789首页订单我的暂无图片第天 */
@font-face {
  font-family: "nav-font";src: url("//at.alicdn.com/wf/webfont/MQHUV6e56ce5/uWqIjWPWlbHR.woff2") format("woff2"),
  url("//at.alicdn.com/wf/webfont/MQHUV6e56ce5/uBscuKyX34mb.woff") format("woff");
  font-display: swap;
}
@font-face {
  font-family: "logo-font";src: url("//at.alicdn.com/wf/webfont/MQHUV6e56ce5/kznKMVuxE1tP.woff2") format("woff2"),
  url("//at.alicdn.com/wf/webfont/MQHUV6e56ce5/ViySHjFRkPg9.woff") format("woff");
  font-display: swap;
}
@font-face {
  font-family: "DFPLiJinHeiW8-GB";
  src: url("https://im.oytour.com/tripfont/cb76573b1580477fbea1ce0cc0d136e5.woff");
}

// @font-face {
//   font-family: "oswald";
//   src: url("https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/smallapp/Oswald-Regular.ttf");
// }
// html,
// body {
//   font-family: "oswald" !important;
// }
swiper {
  height: unset;
  
}
image{will-change: transform}
</style>
