notStarted.vue 5.51 KB
Newer Older
李嘉林 committed
1 2
<template>
  <div class="notStarted">
程智春 committed
3
    <div class="title">{{info.title}}</div>
李嘉林 committed
4 5 6 7
    <p class="tit">直播倒计时</p>
    <div class="time">
      <timeDown v-if="startTime" :startTime="startTime"></timeDown>
    </div>
李嘉林 committed
8
    <div class="remindBtn" @click="isLogin">开播提醒</div>
李嘉林 committed
9 10 11 12
  </div>
</template>

<script type="text/ecmascript-6">
李嘉林 committed
13
import live from "@/api/live";
李嘉林 committed
14 15 16 17 18 19
import timeDown from "@/components/livedModel/timeDown";
export default {
  props: ["info"],
  name: "",
  data() {
    return {
李嘉林 committed
20 21
      liveId: 0,
      startTime: null
李嘉林 committed
22 23 24 25 26 27 28
    };
  },
  components: {
    timeDown
  },
  computed: {},
  created() {},
李嘉林 committed
29
  onLoad(options) {
程智春 committed
30 31 32 33 34 35 36 37 38 39 40
    
    if(options.params){
      let params = JSON.parse(options.params);
      this.liveId = params.liveId;  
    }else if(options.scene){
      var scene = decodeURIComponent(options.scene); //参数二维码传递过来的参数
      console.log(scene)
      let sceneInfo = scene.split(',')
      console.log('sceneInfo',sceneInfo)
      this.liveId = sceneInfo[0].split('=')[1]
    }
李嘉林 committed
41
    this.startTime = this.info.startTime;
程智春 committed
42
    console.log(this.info)
李嘉林 committed
43 44 45 46 47
  },
  mounted() {},
  methods: {
    // 开播提醒
    remind() {
程智春 committed
48

李嘉林 committed
49
      let _this = this;
程智春 committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88

      wx.getSetting({
        withSubscriptions: true,
        success (res) {
          console.log(res.subscriptionsSetting,'subscriptionsSetting')

          if(!res.subscriptionsSetting.mainSwitch){

            wx.showModal({
                content: '检测到您没打开订阅消息的权限,是否去设置打开?',
                confirmText : '确认',
                confirmColor : '#07c160',
                success : (res2) => {
                    if (res2.confirm) {
                        wx.openSetting({
                          withSubscriptions : true,
                          success (res1) {
                            console.log(res1.authSetting,'authSetting')
                          }
                        })
                    }
                }
            })

            
          }else{
            try {
              const subscribeMessageObj = _this.$store.state.subscribeMessageObj;
              if (
                subscribeMessageObj &&
                Object.keys(subscribeMessageObj).length > 0
              ) {
                // TODO 开播订阅
                const tmplIds = [];
                for (var key in subscribeMessageObj) {
                  // 改成开播key
                  if (key == "start_live") {
                    tmplIds.push(subscribeMessageObj[key]);
                  }
李嘉林 committed
89
                }
程智春 committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
                if (tmplIds.length > 0) {
                  wx.requestSubscribeMessage({
                    tmplIds: tmplIds,
                    success:(res)=> {
                      console.log(res,res[tmplIds[0]],'---------------------58')
                      if(res[tmplIds[0]]=="accept"){
                        wx.showToast({
                          title: "您已成功订阅~",
                          icon: "success"
                        });
                        let query = {
                          liveBroadcastId: Number(_this.liveId),
                          openId: wx.getStorageSync("openid"),
                          subMessageTemplateId:tmplIds[0],
                        };
                        live.addLiveNoticeByCustomer(query).then(res => {});
                      }
                      console.log("message success response: ", res);
                    },
                    fail(res) {
                      console.log("message fail response: ", res);
程智春 committed
111

程智春 committed
112 113 114 115 116 117 118 119
                      wx.showToast({
                        title: '订阅失败,是否授权或者网络错误',
                        icon: "none"
                      });
                    }
                  });
                }
              }else{
程智春 committed
120
                wx.showToast({
程智春 committed
121
                  title: '订阅失败,是否授权或者网络错误',
程智春 committed
122 123
                  icon: "none"
                });
程智春 committed
124
                console.log('开播失败')
李嘉林 committed
125
              }
程智春 committed
126 127 128 129 130 131 132
            } catch (err) {
              wx.showToast({
                title: '订阅失败,是否授权或者网络错误',
                icon: "none"
              });
              console.error("subscribeMessage-err", err);
            }
李嘉林 committed
133 134
          }
        }
程智春 committed
135 136 137
      })
      
      
李嘉林 committed
138 139
    },
    // 是否登录
李嘉林 committed
140 141
    isLogin() {
      let _this = this;
李嘉林 committed
142 143 144 145 146 147
      wx.getStorage({
        key: "sessionid",
        success(res) {
          _this.remind();
        },
        fail(res) {
李嘉林 committed
148
          console.log("未登录------150");
李嘉林 committed
149
          // 跳转登录页
李嘉林 committed
150 151 152 153 154 155 156 157
          let backUrl = "/lived/main";
          let query = {
            liveId: _this.liveId,
            fromType: "mini"
          };
          let url = `/pages/login/main?back=${backUrl}&params=${JSON.stringify(
            query
          )}`;
李嘉林 committed
158 159 160 161 162
          wx.navigateTo({
            url: url
          });
        }
      });
李嘉林 committed
163 164 165 166 167 168 169 170
    }
  }
};
</script>

<style lang="scss" scoped>
.notStarted {
  position: absolute;
李嘉林 committed
171
  width: 70vw;
程智春 committed
172
  top: 35%;
李嘉林 committed
173
  left: 15vw;
李嘉林 committed
174 175 176 177
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
程智春 committed
178
  z-index: 2;
程智春 committed
179 180 181 182 183 184
  .title{
    font-size: 18px;
    font-weight: bold;
    color: #fff;
    margin-bottom: 20px;
  }
李嘉林 committed
185 186 187 188 189
  .tit {
    font-size: 16px;
    color: #fff;
  }
  .time {
李嘉林 committed
190
    margin-top: 16px;
李嘉林 committed
191 192
  }
  .remindBtn {
李嘉林 committed
193 194 195
    margin-top: 16px;
    height: 20px;
    line-height: 20px;
李嘉林 committed
196 197 198 199
    text-align: center;
    border-radius: 6px;
    color: #fff;
    font-size: 18px;
李嘉林 committed
200
    padding: 14px 40px;
李嘉林 committed
201 202 203 204
    background: linear-gradient(to right, #ff877d, #fb566d);
  }
}
</style>