index.vue 9.6 KB

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