index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. this.getUserInfo();
  71. // 测试下分支
  72. if (typeof options.scene !== 'undefined') {
  73. if (options.scene === 'share') {
  74. this.share(options);
  75. } else {
  76. this.qrcode(options);
  77. }
  78. } else {
  79. // this.$showLoading();
  80. }
  81. // #ifdef MP-ALIPAY
  82. let query = this.$store.state.page.query;
  83. if (query && typeof query.scene !== 'undefined') this.qrcode(query);
  84. // #endif
  85. if (typeof options.user_id !== 'undefined') {
  86. this.$store.dispatch('user/setTempParentId', options.user_id);
  87. }
  88. this.page_id = typeof options.page_id !== 'undefined' ? Number(options.page_id) : 0;
  89. // mall
  90. if (this.page_id === 0) {
  91. let storage = this.$storage.getStorageSync('INDEX_MALL');
  92. if (storage) {
  93. let old = new Date(storage.time.replace(/-/g, '/'));
  94. old.setMinutes(old.getMinutes() + 10);
  95. let now = new Date();
  96. let time = now.getTime() - old.getTime();
  97. if (time >= 0) {
  98. this.type = storage.type;
  99. this.homePages = storage.home_pages;
  100. this.loadMall();
  101. } else {
  102. this.type = storage.type;
  103. if (this.type === 'diy') {
  104. this.coupon_req = true;
  105. this.homePages = {}
  106. }
  107. this.$nextTick(() => {
  108. this.homePages = storage.home_pages;
  109. let that = this;
  110. if(this.homePages.navs && this.homePages.navs.length > 0) {
  111. this.homePages.navs.forEach(function(row,inedx){
  112. row.template.data.forEach(function(v,idx){
  113. if(v.id === 'background') {
  114. that.haveBackground = false;
  115. return false;
  116. }
  117. })
  118. })
  119. }
  120. });
  121. this.is_required = false;
  122. }
  123. } else {
  124. this.loadMall();
  125. }
  126. // DIY
  127. } else {
  128. this.coupon_req = true;
  129. this.loadDiy();
  130. }
  131. // #ifdef MP-WEIXIN
  132. wx.showShareMenu({
  133. menus: ['shareAppMessage', 'shareTimeline']
  134. })
  135. const updateManager = wx.getUpdateManager()
  136. if (updateManager) {
  137. updateManager.onCheckForUpdate(function (res) {
  138. // 请求完新版本信息的回调
  139. })
  140. updateManager.onUpdateReady(function () {
  141. wx.showModal({
  142. title: '更新提示',
  143. content: '新版本已经准备好,是否重启应用?',
  144. success(res) {
  145. if (res.confirm) {
  146. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  147. updateManager.applyUpdate()
  148. }
  149. }
  150. })
  151. })
  152. }
  153. // #endif
  154. },
  155. /* #ifdef MP_WEIXIN || MP_BAIDU */
  156. onPageScroll(e) {
  157. this.$store.dispatch('page/actionSetScrollTop', e.scrollTop);
  158. },
  159. /* #endif */
  160. methods: {
  161. async loadMall() {
  162. const e = await this.$request({
  163. url: this.$api.index.tplIndex,
  164. data: {
  165. page_id: 0
  166. },
  167. method: 'get'
  168. });
  169. let { code, data } = e;
  170. this.$hideLoading();
  171. if (code === 0) {
  172. this.is_storage = false;
  173. this.$popupAd.show = null;
  174. this.type = data.type;
  175. let that = this;
  176. this.is_required = true;
  177. if (this.type === 'diy') {
  178. this.coupon_req = true;
  179. this.homePages = {};
  180. }
  181. this.$nextTick(() => {
  182. this.homePages = data.home_pages;
  183. if (this.homePages.navs && that.homePages.navs.length > 0) {
  184. this.homePages.navs.forEach(function(row, inedx) {
  185. row.template.data.forEach(function(v, idx) {
  186. if (v.id === 'background') {
  187. that.haveBackground = false;
  188. return false;
  189. }
  190. })
  191. })
  192. }
  193. });
  194. this.$storage.setStorageSync('INDEX_MALL', data);
  195. }
  196. },
  197. async loadDiy() {
  198. const e = await this.$request({
  199. url: this.$api.index.tplIndex,
  200. data: {
  201. page_id: this.page_id
  202. },
  203. method: 'get'
  204. });
  205. let { code, data } = e;
  206. this.$hideLoading();
  207. if (code === 0) {
  208. this.is_storage = false;
  209. this.$popupAd.show = null;
  210. this.homePages = data.home_pages;
  211. this.type = data.type;
  212. let that = this;
  213. if (this.homePages.navs && that.homePages.navs.length > 0) {
  214. this.homePages.navs.forEach(function(row, inedx) {
  215. row.template.data.forEach(function(v, idx) {
  216. if (v.id === 'background') {
  217. that.haveBackground = false;
  218. return false;
  219. }
  220. })
  221. })
  222. }
  223. }
  224. },
  225. share(options) {
  226. if (typeof options.params !== 'undefined') {
  227. let params = JSON.parse(options.params);
  228. this.$jump({
  229. url: params.path + '?' + this.$utils.objectToUrlParams(params),
  230. open_type: 'navigate'
  231. });
  232. }
  233. },
  234. qrcode(options) {
  235. this.$request({
  236. url: this.$api.default.qrcode_parameter,
  237. data: {
  238. token: options.scene
  239. }
  240. }).then(response => {
  241. if (response.code === 0) {
  242. this.$store.dispatch('page/actionSetQeury', null);
  243. let { data, path } = response.data.detail;
  244. let url = path == 'plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin' ? `${path}` : `/${path}`;
  245. if (data) {
  246. url += '?' + this.$utils.objectToUrlParams(data);
  247. if (typeof data.user_id !== 'undefined') {
  248. this.$store.dispatch('user/setTempParentId', data.user_id)
  249. }
  250. }
  251. if (`/${path}` != '/pages/index/index' || (typeof data.page_id !== 'undefined' && data.page_id !== this.homePages.id !== 0)) {
  252. this.$jump({
  253. url: url,
  254. open_type: 'navigate'
  255. });
  256. }
  257. }
  258. }).catch(() => {});
  259. },
  260. buyProduct(data) {
  261. this.attrGoods.goods = data.goods;
  262. this.attrGoods.attrShow = data.attrShow;
  263. },
  264. getUserInfo(){
  265. let _this = this;
  266. this.$request({
  267. url: this.$api.user.user_info,
  268. }).then(response => {
  269. this.$hideLoading();
  270. console.log('-->',response.data)
  271. if (response.code === 0) {
  272. _this.shareInfo = response.data.identity
  273. }
  274. })
  275. },
  276. },
  277. onShareAppMessage() {
  278. let args = {
  279. path: '/pages/index/index',
  280. params: {}
  281. };
  282. if (this.page_id == 0) {
  283. args.title = this.mall.setting.share_title ? this.mall.setting.share_title : this.mall.name;
  284. args.imageUrl = this.mall.setting.share_pic
  285. } else {
  286. args.title = this.homePages.title;
  287. args.params.page_id = this.page_id;
  288. }
  289. return this.$shareAppMessage(args);
  290. },
  291. computed: {
  292. ...mapGetters('mallConfig', {
  293. tabBarNavs: 'getNavBar',
  294. getTheme: 'getTheme',
  295. }),
  296. ...mapState('mallConfig', {
  297. config: state => state.mall.setting,
  298. mall: state => state.mall,
  299. }),
  300. themeObject:function() {
  301. return {
  302. back: this.getTheme + '-m-back ' + this.getTheme,
  303. backP: this.getTheme + '-m-back-p ' + this.getTheme,
  304. backO: this.getTheme + '-m-back-o ' + this.getTheme,
  305. theme: this.getTheme,
  306. color: this.getTheme + '-m-text ' + this.getTheme,
  307. sBack: this.getTheme + '-s-back ' + this.getTheme,
  308. border: this.getTheme + '-m-border ' + this.getTheme,
  309. }
  310. },
  311. },
  312. // #ifdef MP-WEIXIN
  313. onShareTimeline() {
  314. // 分享朋友圈beta
  315. let query = {};
  316. let title = '';
  317. if (this.page_id == 0) {
  318. title = this.mall.setting.share_title ? this.mall.setting.share_title : this.mall.name;
  319. } else {
  320. title = this.homePages.title;
  321. query.page_id = this.page_id;
  322. }
  323. return this.$shareTimeline({
  324. title: title,
  325. query: query
  326. });
  327. },
  328. // #endif
  329. };
  330. </script>