index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <template>
  2. <app-layout :haveBackground="haveBackground">
  3. <app-my-share
  4. :shareInfo="shareInfo"
  5. :tabBarNavs="tabBarNavs"
  6. :mall="mall"
  7. :fixed="shareFixed"></app-my-share>
  8. <app-my-app v-if="config.is_add_app == 1"></app-my-app>
  9. <template v-if="type === 'mall'">
  10. <app-index @buyProduct="buyProduct" v-if="destroy" :shareFixed="shareFixed" :page-hide="pageHide" :home-pages="homePages" :is_storage="is_storage" :theme="themeObject" :page_id="page_id" :is_required="is_required" :coupon_req="coupon_req"></app-index>
  11. </template>
  12. <template v-else-if="type === 'diy'">
  13. <app-diy-page @buyProduct="buyProduct" v-if="destroy" :shareFixed="shareFixed" :page-hide="pageHide" :home-pages="homePages" :is_storage="is_storage" :theme="getTheme" :page_id="page_id" :is_required="is_required" :coupon_req="coupon_req"></app-diy-page>
  14. </template>
  15. <app-buy-prompt v-if="config.is_purchase_frame === `1`"></app-buy-prompt>
  16. <app-attr :goods="attrGoods.goods" :attrGroupList="attrGoods.goods.attr_groups" :theme="getTheme" :show="attrGoods.attrShow"></app-attr>
  17. </app-layout>
  18. </template>
  19. <script>
  20. import { mapGetters, mapState } from 'vuex';
  21. import appIndex from '../../components/page-component/index/app-index.vue';
  22. import appDiyPage from '../../components/page-component/index/app-diy-page.vue';
  23. import appBuyPrompt from '../../components/page-component/app-buy-prompt/app-buy-prompt.vue';
  24. import appMyApp from '../../components/page-component/app-my-app/app-my-app.vue';
  25. import appMyShare from '../../components/page-component/app-my-app/app-my-share.vue';
  26. import appAttr from '../../components/page-component/app-attr/app-attr.vue';
  27. export default {
  28. name: 'index',
  29. components: {
  30. appIndex,
  31. 'app-diy-page': appDiyPage,
  32. appBuyPrompt,
  33. appMyApp,
  34. appAttr,
  35. appMyShare,
  36. },
  37. data() {
  38. return {
  39. homePages: [],
  40. type: '',
  41. is_storage: false,
  42. haveBackground: true,
  43. destroy: true,
  44. pageHide: false,
  45. is_required: true,
  46. coupon_req: false,
  47. page_id: 0,
  48. //
  49. attrGoods: {
  50. goods: {},
  51. attrShow: 0
  52. },
  53. shareInfo:'',
  54. shareFixed: true,
  55. }
  56. },
  57. onShow() {
  58. // #ifdef MP-TOUTIAO
  59. this.destroy = true;
  60. // #endif
  61. this.pageHide = false;
  62. },
  63. onHide() {
  64. // #ifdef MP-TOUTIAO
  65. this.destroy = false;
  66. // #endif
  67. this.pageHide = true;
  68. },
  69. onLoad(options) {
  70. console.log('options==>',options)
  71. this.getUserInfo();
  72. // 测试下分支
  73. if (typeof options.scene !== 'undefined') {
  74. if (options.scene === 'share') {
  75. this.share(options);
  76. } else {
  77. this.qrcode(options);
  78. }
  79. } else {
  80. // this.$showLoading();
  81. }
  82. // #ifdef MP-ALIPAY
  83. let query = this.$store.state.page.query;
  84. if (query && typeof query.scene !== 'undefined') this.qrcode(query);
  85. // #endif
  86. if (typeof options.user_id !== 'undefined') {
  87. this.$store.dispatch('user/setTempParentId', options.user_id);
  88. }
  89. this.page_id = typeof options.page_id !== 'undefined' ? Number(options.page_id) : 0;
  90. // mall
  91. if (this.page_id === 0) {
  92. let storage = this.$storage.getStorageSync('INDEX_MALL');
  93. if (storage) {
  94. let old = new Date(storage.time.replace(/-/g, '/'));
  95. old.setMinutes(old.getMinutes() + 10);
  96. let now = new Date();
  97. let time = now.getTime() - old.getTime();
  98. if (time >= 0) {
  99. this.type = storage.type;
  100. this.homePages = storage.home_pages;
  101. this.loadMall();
  102. } else {
  103. this.type = storage.type;
  104. if (this.type === 'diy') {
  105. this.coupon_req = true;
  106. this.homePages = {}
  107. }
  108. this.$nextTick(() => {
  109. this.homePages = storage.home_pages;
  110. let that = this;
  111. if(this.homePages.navs && this.homePages.navs.length > 0) {
  112. this.homePages.navs.forEach(function(row,inedx){
  113. row.template.data.forEach(function(v,idx){
  114. if(v.id === 'background') {
  115. that.haveBackground = false;
  116. return false;
  117. }
  118. })
  119. })
  120. }
  121. });
  122. this.is_required = false;
  123. }
  124. } else {
  125. this.loadMall();
  126. }
  127. // DIY
  128. } else {
  129. this.coupon_req = true;
  130. this.loadDiy();
  131. }
  132. // #ifdef MP-WEIXIN
  133. wx.showShareMenu({
  134. menus: ['shareAppMessage', 'shareTimeline']
  135. })
  136. const updateManager = wx.getUpdateManager()
  137. if (updateManager) {
  138. updateManager.onCheckForUpdate(function (res) {
  139. // 请求完新版本信息的回调
  140. })
  141. updateManager.onUpdateReady(function () {
  142. wx.showModal({
  143. title: '更新提示',
  144. content: '新版本已经准备好,是否重启应用?',
  145. success(res) {
  146. if (res.confirm) {
  147. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  148. updateManager.applyUpdate()
  149. }
  150. }
  151. })
  152. })
  153. }
  154. // #endif
  155. },
  156. /* #ifdef MP_WEIXIN || MP_BAIDU */
  157. onPageScroll(e) {
  158. this.$store.dispatch('page/actionSetScrollTop', e.scrollTop);
  159. },
  160. /* #endif */
  161. methods: {
  162. async loadMall() {
  163. const e = await this.$request({
  164. url: this.$api.index.tplIndex,
  165. data: {
  166. page_id: 0
  167. },
  168. method: 'get'
  169. });
  170. let { code, data } = e;
  171. this.$hideLoading();
  172. if (code === 0) {
  173. this.is_storage = false;
  174. this.$popupAd.show = null;
  175. this.type = data.type;
  176. let that = this;
  177. this.is_required = true;
  178. if (this.type === 'diy') {
  179. this.coupon_req = true;
  180. this.homePages = {};
  181. }
  182. this.$nextTick(() => {
  183. this.homePages = data.home_pages;
  184. if (this.homePages.navs && that.homePages.navs.length > 0) {
  185. this.homePages.navs.forEach(function(row, inedx) {
  186. row.template.data.forEach(function(v, idx) {
  187. if (v.id === 'background') {
  188. that.haveBackground = false;
  189. return false;
  190. }
  191. })
  192. })
  193. }
  194. });
  195. this.$storage.setStorageSync('INDEX_MALL', data);
  196. }
  197. },
  198. async loadDiy() {
  199. const e = await this.$request({
  200. url: this.$api.index.tplIndex,
  201. data: {
  202. page_id: this.page_id
  203. },
  204. method: 'get'
  205. });
  206. let { code, data } = e;
  207. this.$hideLoading();
  208. if (code === 0) {
  209. this.is_storage = false;
  210. this.$popupAd.show = null;
  211. this.homePages = data.home_pages;
  212. this.type = data.type;
  213. let that = this;
  214. if (this.homePages.navs && that.homePages.navs.length > 0) {
  215. this.homePages.navs.forEach(function(row, inedx) {
  216. row.template.data.forEach(function(v, idx) {
  217. if (v.id === 'background') {
  218. that.haveBackground = false;
  219. return false;
  220. }
  221. })
  222. })
  223. }
  224. }
  225. },
  226. share(options) {
  227. if (typeof options.params !== 'undefined') {
  228. let params = JSON.parse(options.params);
  229. this.$jump({
  230. url: params.path + '?' + this.$utils.objectToUrlParams(params),
  231. open_type: 'navigate'
  232. });
  233. }
  234. },
  235. qrcode(options) {
  236. let _this = this;
  237. this.$request({
  238. url: this.$api.default.qrcode_parameter,
  239. data: {
  240. token: options.scene
  241. }
  242. }).then(response => {
  243. if (response.code === 0) {
  244. this.$store.dispatch('page/actionSetQeury', null);
  245. let { data, path } = response.data.detail;
  246. let url = path == 'plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin' ? `${path}` : `/${path}`;
  247. if (data) {
  248. url += '?' + this.$utils.objectToUrlParams(data);
  249. if (typeof data.user_id !== 'undefined') {
  250. console.log(data.user_id)
  251. this.$store.dispatch('user/setTempParentId', data.user_id)
  252. // 绑定上级
  253. this.$request({
  254. url: this.$api.share.bind_parent
  255. }).then(res => {
  256. console.log('bind->',res)
  257. if(res.error){
  258. uni.showToast({
  259. title: res.error,
  260. icon: "none"
  261. });
  262. }
  263. _this.shareInfo = res.userInfo.identity
  264. })
  265. }
  266. }
  267. if (`/${path}` != '/pages/index/index' || (typeof data.page_id !== 'undefined' && data.page_id !== this.homePages.id !== 0)) {
  268. this.$jump({
  269. url: url,
  270. open_type: 'navigate'
  271. });
  272. }
  273. }
  274. }).catch(() => {});
  275. },
  276. buyProduct(data) {
  277. this.attrGoods.goods = data.goods;
  278. this.attrGoods.attrShow = data.attrShow;
  279. },
  280. getUserInfo(){
  281. let _this = this;
  282. this.$request({
  283. url: this.$api.user.user_info,
  284. }).then(response => {
  285. this.$hideLoading();
  286. console.log('-->',response.data)
  287. if (response.code === 0) {
  288. _this.shareInfo = response.data.identity
  289. }
  290. })
  291. },
  292. },
  293. onShareAppMessage() {
  294. let args = {
  295. path: '/pages/index/index',
  296. params: {}
  297. };
  298. if (this.page_id == 0) {
  299. args.title = this.mall.setting.share_title ? this.mall.setting.share_title : this.mall.name;
  300. args.imageUrl = this.mall.setting.share_pic
  301. } else {
  302. args.title = this.homePages.title;
  303. args.params.page_id = this.page_id;
  304. }
  305. return this.$shareAppMessage(args);
  306. },
  307. computed: {
  308. ...mapGetters('mallConfig', {
  309. tabBarNavs: 'getNavBar',
  310. getTheme: 'getTheme',
  311. }),
  312. ...mapState('mallConfig', {
  313. config: state => state.mall.setting,
  314. mall: state => state.mall,
  315. }),
  316. themeObject:function() {
  317. return {
  318. back: this.getTheme + '-m-back ' + this.getTheme,
  319. backP: this.getTheme + '-m-back-p ' + this.getTheme,
  320. backO: this.getTheme + '-m-back-o ' + this.getTheme,
  321. theme: this.getTheme,
  322. color: this.getTheme + '-m-text ' + this.getTheme,
  323. sBack: this.getTheme + '-s-back ' + this.getTheme,
  324. border: this.getTheme + '-m-border ' + this.getTheme,
  325. }
  326. },
  327. },
  328. // #ifdef MP-WEIXIN
  329. onShareTimeline() {
  330. // 分享朋友圈beta
  331. let query = {};
  332. let title = '';
  333. if (this.page_id == 0) {
  334. title = this.mall.setting.share_title ? this.mall.setting.share_title : this.mall.name;
  335. } else {
  336. title = this.homePages.title;
  337. query.page_id = this.page_id;
  338. }
  339. return this.$shareTimeline({
  340. title: title,
  341. query: query
  342. });
  343. },
  344. // #endif
  345. };
  346. </script>