<template>
	<div style="background: #ffffff;height: 100vh;line-height: 50px">
		<van-sticky>
			<view class="top-bar top_bar justify-center bg-white sh">
				<van-icon class="top-left" name="arrow-left" @tap="goback" />
				<p>分享详情</p>
			</view>
		</van-sticky>
		<div style="padding: 20px">
			<p>标题：商城- {{userData.brandName}}</p>
			<p>商品描述：{{userData.title}}</p>
			<p>商品图片：<img style="width: 120px;vertical-align: top" :src="userData.mainImg" alt=""></p>
		</div>
	</div>
</template>
<script>
  import api from "@/api";

  export default {
    name: "technicalSupport",
    data() {
      return {
        userData:{},
	  url:'',
      };
    },
    onLoad: function (option) { //option为object类型，会序列化上个页面传递的参数
      window.location.href = `https://redirectwx.edstao.com/#/pages/good/share?etaomallId=${option.etaomallId}&link=${option.link}&title=${option.title}&skuId=${option.skuId}&brandName=${option.brandName}&mainImg=${option.mainImg}`
    },
    mounted(){
      this.getUrl()
	this.wxSign()
    },
    beforeDestroy(){
      window.location.href = `https://${this.userData.link}.edstao.com/#/pages/good/detail?skuId=${this.userData.skuId}`
    },
    methods: {
      goback() {
        window.location.href = `https://${this.userData.link}.edstao.com/#/pages/good/detail?skuId=${this.userData.skuId}`
      },
      getUrl() {
        let url = decodeURIComponent(window.location.href);
        const q = {};
        url.replace(/([^?&=]+)=([^&]+)/g, (_, k, v) => q[k] = v);
        console.log(q,'qqqqqqqqqq');
        this.userData = q;
      },
      wxSign() {
        let that = this
        api.wxSign({
          skuId: this.userData.skuId,
          etaomallId: this.userData.etaomallId,
          url: window.location.href,
        }).then((data) => {
          that.url = data.redirecturl
          that.initWX(data);
        });
      },
      initWX(data) {
        let that = this
        const wx = window._wx;
        const wxConfig = {
          debug: false, // 上生产，时设置成false
          appId: data.appid,
          timestamp: data.timestamp,
          nonceStr: data.nonceStr,
          signature: data.signature,
          jsApiList: ["updateAppMessageShareData"],
        };
        console.log(wxConfig);
        wx.config(wxConfig);
        wx.ready(function () {
          wx.updateAppMessageShareData({
            title: '商城-'+ that.userData.brandName, // 分享标题
            desc: that.userData.title, // 分享描述
            link: data.redirecturl, // 分享链接
            imgUrl: that.userData.mainImg, // 分享图标
            success: function (res) {
              // console.log("分享成功返回的信息为:", res);;
            },
          });
        });
        wx.error(function (data) {
        });
      },
    },
  };
</script>


<style scoped>

</style>
