index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. <template>
  2. <app-layout :overflow="false">
  3. <view class="banner">
  4. <image v-if="activityBg == 'statics/img/plugins/composition-banner.png'" :src="compositionImg.banner"></image>
  5. <image v-else :src="activityBg"></image>
  6. <view @click="toRule" class="rule">活动规则</view>
  7. </view>
  8. <view class="search" @click="toSearch">
  9. <view class="search-view dir-left-nowrap main-center cross-center">
  10. <image class="image" src="/static/image/icon/icon-search.png"></image>
  11. <view class="text">请输入商品名称搜索</view>
  12. </view>
  13. </view>
  14. <view class='no-tip' v-if="list.length == 0">
  15. <image src="/static/image/no-goods.png"></image>
  16. <view>没有任何套餐哦~</view>
  17. </view>
  18. <view v-else class="list" :style="{ position: position}">
  19. <view class="item" v-for="item in list" :key="item.id">
  20. <app-composition :theme="getTheme" @click="show(item)" @look="toDetail(item)" :item="item" :large="true">
  21. <template>
  22. <view class="look-goods main-center cross-center">
  23. <view>套餐商品</view>
  24. <image src="/static/image/icon/icon-down.png"></image>
  25. </view>
  26. </template>
  27. </app-composition>
  28. </view>
  29. </view>
  30. <view @click="close" class="dialog-bg" v-if="showGoods">
  31. <view @click.stop="" :class="['dialog', `${iphone_x? 'iphone_x':''}`,`${tabbarbool? 'tabbarbool':''}`]" :style="{'bottom':height +'px'}" :animation="animationData">
  32. <view class="dialog-title main-between cross-center">
  33. <view @click="toDetail(detail)" class="toBuy dir-left-nowrap cross-center">
  34. <image :style="{'background-color': getTheme.background}" src="/static/image/icon/goods-cart.png"></image>
  35. <view :style="{'color': getTheme.color}">去购买套餐</view>
  36. </view>
  37. <view class="close">
  38. <image @click="close" src="/static/image/icon/close.png"></image>
  39. </view>
  40. </view>
  41. <view class="dialog-goods-list">
  42. <view @click.stop="toGoods(item.goods_id)" class="dialog-goods dir-left-nowrap" :key="item.id" v-for="item in detail.host_list">
  43. <image :src="item.cover_pic"></image>
  44. <view>
  45. <view class="t-omit-two goods-name">{{item.name}}</view>
  46. <view class="goods-price" :style="{'color': getTheme.color}">¥{{item.min_price}}{{item.max_price != item.min_price ? '~¥'+item.max_price : ''}}</view>
  47. </view>
  48. </view>
  49. <view @click.stop="toGoods(item.goods_id)" class="dialog-goods dir-left-nowrap" :key="item.id" v-for="item in detail.goods_list">
  50. <image :src="item.cover_pic"></image>
  51. <view>
  52. <view class="t-omit-two goods-name">{{item.name}}</view>
  53. <view class="goods-price" :style="{'color': getTheme.color}">¥{{item.min_price}}{{item.max_price != item.min_price ? '~¥'+item.max_price : ''}}</view>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </app-layout>
  60. </template>
  61. <script>
  62. import {mapGetters, mapState} from "vuex";
  63. import appComposition from'../../../components/basic-component/app-composition/app-composition.vue';
  64. export default {
  65. data() {
  66. return {
  67. about: '',
  68. list: [],
  69. detail: {},
  70. position: 'static',
  71. iphone_x: false,
  72. noMore: false,
  73. showGoods: false,
  74. page: 2,
  75. height: 0,
  76. scrollHeight: 0,
  77. tabbarbool: false,
  78. animationData: {},
  79. currentRoute: this.$platDiff.route(),
  80. activityBg: ''
  81. }
  82. },
  83. components: {
  84. 'app-composition': appComposition,
  85. },
  86. computed: {
  87. ...mapState({
  88. tabBarNavs: state => state.mallConfig.navbar.navs,
  89. compositionImg: state => state.mallConfig.__wxapp_img.composition
  90. }),
  91. ...mapGetters('mallConfig', {
  92. getTheme: 'getTheme',
  93. })
  94. },
  95. watch: {
  96. tabBarNavs: {
  97. handler: function() {
  98. this.b();
  99. },
  100. immediate: true,
  101. }
  102. },
  103. methods: {
  104. b() {
  105. // #ifndef H5
  106. let currentRoute = this.currentRoute;
  107. for (let i = 0; i < this.tabBarNavs.length; i++) {
  108. if(currentRoute.includes(this.tabBarNavs[i].url.split('?')[0])) {
  109. return this.tabbarbool = true;
  110. }
  111. }
  112. // #endif
  113. return this.tabbarbool = false;
  114. },
  115. show(e) {
  116. let that = this;
  117. that.detail = e;
  118. that.showGoods = true;
  119. that.position = 'fixed';
  120. let animation = uni.createAnimation({
  121. duration: 1000,
  122. timingFunction: 'ease'
  123. });
  124. that.animationData = animation;
  125. setTimeout(function(){
  126. animation.translateY(that.height).step();
  127. that.animationData = animation.export();
  128. },200)
  129. },
  130. close() {
  131. this.detail = {};
  132. this.showGoods = false;
  133. this.position = 'static'
  134. },
  135. toRule() {
  136. uni.navigateTo({
  137. url: `/pages/rules/index?url=${encodeURIComponent(this.$api.composition.config)}&key=rule`
  138. });
  139. },
  140. toDetail(item) {
  141. uni.navigateTo({
  142. url: '/plugins/composition/detail/detail?composition_id=' + item.id
  143. });
  144. },
  145. toGoods(id) {
  146. uni.navigateTo({
  147. url: '/pages/goods/goods?id=' + id
  148. });
  149. },
  150. toSearch() {
  151. uni.navigateTo({
  152. url: '/plugins/composition/search/search'
  153. });
  154. },
  155. getSetting() {
  156. let that = this;
  157. that.$showLoading({
  158. type: 'global',
  159. text: '加载中...'
  160. });
  161. that.$request({
  162. url: that.$api.composition.config,
  163. }).then(response=>{
  164. if(response.code == 0) {
  165. that.getList();
  166. that.activityBg = response.data.activityBg;
  167. }else {
  168. that.$hideLoading();
  169. uni.showToast({
  170. title: response.msg,
  171. icon: 'none',
  172. duration: 1000
  173. });
  174. }
  175. }).catch(response => {
  176. that.$hideLoading();
  177. });
  178. },
  179. getList() {
  180. let that = this;
  181. that.$request({
  182. url: that.$api.composition.index,
  183. }).then(response=>{
  184. that.$hideLoading();
  185. if(response.code == 0) {
  186. that.list = response.data.list;
  187. if(that.list.length < 5) {
  188. that.noMore = true;
  189. }
  190. for(let i in that.list) {
  191. that.list[i].choose = false;
  192. for(let idx in that.list[i].goods_list) {
  193. that.list[i].goods_list[idx].choose_attr = null;
  194. if(that.list[i].type == 2) {
  195. that.list[i].host_list[0].choose_attr = null;
  196. that.list[i].host_list[0].opacity = 1;
  197. that.list[i].goods_list[idx].choose_goods = false;
  198. that.list[i].host_list[0].choose_goods = false;
  199. }
  200. }
  201. }
  202. uni.setStorage({
  203. key: "composition",
  204. data: that.list
  205. })
  206. }else {
  207. that.$hideLoading();
  208. uni.showToast({
  209. title: response.msg,
  210. icon: 'none',
  211. duration: 1000
  212. });
  213. }
  214. }).catch(response => {
  215. that.$hideLoading();
  216. });
  217. },
  218. getMore() {
  219. let that = this;
  220. uni.showLoading({
  221. mask: true,
  222. title: '加载中'
  223. });
  224. that.$request({
  225. url: that.$api.composition.index,
  226. data: {
  227. page: that.page
  228. }
  229. }).then(response=>{
  230. uni.hideLoading();
  231. if(response.code == 0) {
  232. if(response.data.list.length == 0) {
  233. this.noMore = true;
  234. return false;
  235. }
  236. that.page++;
  237. let list = response.data.list;
  238. for(let i in list) {
  239. list[i].choose = false;
  240. for(let idx in list[i].goods_list) {
  241. list[i].goods_list[idx].choose_attr = null;
  242. if(list[i].type == 2) {
  243. list[i].host_list[0].choose_attr = null;
  244. list[i].host_list[0].opacity = 1;
  245. list[i].goods_list[idx].choose_goods = false;
  246. list[i].host_list[0].choose_goods = false;
  247. }
  248. }
  249. }
  250. that.list = that.list.concat(list);
  251. uni.setStorage({
  252. key: "composition",
  253. data: that.list
  254. })
  255. }else {
  256. uni.hideLoading();
  257. uni.showToast({
  258. title: response.msg,
  259. icon: 'none',
  260. duration: 1000
  261. });
  262. }
  263. }).catch(() => {
  264. that.$hideLoading();
  265. });
  266. },
  267. },
  268. onLoad() { this.$commonLoad.onload();
  269. let that = this;
  270. uni.getSystemInfo({
  271. success: function (res) {
  272. that.height = -res.screenHeight;
  273. if(res.model.indexOf('iPhone X') > -1 || res.model.indexOf('iPhone 11') > -1 || res.model.indexOf('iPhone11') > -1 || res.model.indexOf('iPhone12') > -1 || res.model.indexOf('Unknown Device') > -1) {
  274. that.iphone_x = true;
  275. }
  276. }
  277. });
  278. // #ifdef MP-WEIXIN
  279. wx.showShareMenu({
  280. menus: ['shareAppMessage', 'shareTimeline']
  281. })
  282. // #endif
  283. that.getSetting();
  284. },
  285. // #ifdef MP
  286. onShareAppMessage() {
  287. return this.$shareAppMessage({
  288. title: this.$children[0].navigationBarTitle,
  289. path: "/plugins/composition/index/index",
  290. });
  291. },
  292. // #endif
  293. // #ifdef MP-WEIXIN
  294. onShareTimeline() {
  295. // 分享朋友圈beta
  296. return this.$shareTimeline({
  297. title: this.$children[0].navigationBarTitle,
  298. query: {} // 此处填写页面的参数
  299. });
  300. },
  301. // #endif
  302. onReachBottom() {
  303. if(!this.noMore) {
  304. this.getMore();
  305. }
  306. },
  307. }
  308. </script>
  309. <style scoped lang="scss">
  310. .list {
  311. .item {
  312. margin: 0 #{24rpx} #{20rpx};
  313. background-color: #fff;
  314. border-radius: #{16rpx};
  315. padding: #{24rpx};
  316. padding-bottom: #{16rpx};
  317. .look-goods {
  318. margin-top: #{8rpx};
  319. border-radius: #{8rpx};
  320. height: #{48rpx};
  321. width: #{288rpx};
  322. font-size: #{24rpx};
  323. color: #666666;
  324. background-color: #f7f7f7;
  325. image {
  326. width: #{18rpx};
  327. height: #{10rpx};
  328. margin-left: #{16rpx};
  329. }
  330. }
  331. }
  332. }
  333. .no-tip {
  334. position: fixed;
  335. top: 40%;
  336. left: 0;
  337. right: 0;
  338. margin: 0 auto;
  339. color: #666666;
  340. font-size: #{24rpx};
  341. width: #{240rpx};
  342. text-align: center;
  343. image {
  344. height: #{240rpx};
  345. width: #{240rpx};
  346. margin-bottom: #{20rpx};
  347. }
  348. }
  349. .banner {
  350. height: #{280rpx};
  351. width: 100%;
  352. position: relative;
  353. image {
  354. width: 100%;
  355. height: #{280rpx};
  356. }
  357. .rule {
  358. position: absolute;
  359. right: #{24rpx};
  360. top: #{24rpx};
  361. padding: 0 #{16rpx};
  362. border-radius: #{24rpx};
  363. height: #{48rpx};
  364. line-height: #{48rpx};
  365. font-size: #{22rpx};
  366. color: #fff;
  367. background-color: rgba(0,0,0,.4);
  368. }
  369. }
  370. .search {
  371. width: #{750rpx};
  372. height: #{88rpx};
  373. position: sticky;
  374. top: 0;
  375. left: 0;
  376. z-index: 100;
  377. background-color: #efeff4;
  378. padding: #{15rpx} #{24rpx};
  379. box-sizing: border-box;
  380. .search-view {
  381. width: #{750-48rpx};
  382. height: #{88-30rpx};
  383. background-color: white;
  384. border-radius: #{22rpx};
  385. .image {
  386. width: #{20rpx};
  387. height: #{20rpx};
  388. margin-right: #{11rpx};
  389. }
  390. .text {
  391. font-size: #{26rpx};
  392. color: #999999;
  393. }
  394. }
  395. }
  396. .dialog-bg {
  397. position: fixed;
  398. bottom: 0;
  399. left: 0;
  400. width: 100%;
  401. height: 100%;
  402. background-color: rgba(0,0,0,.3);
  403. z-index: 202;
  404. .dialog {
  405. &.tabbarbool {
  406. padding-bottom: #{110rpx};
  407. }
  408. &.tabbarbool.iphone_x {
  409. padding-bottom: #{160rpx};
  410. }
  411. width: 100%;
  412. position: fixed;
  413. left: 0;
  414. z-index: 210;
  415. background-color: #fff;
  416. border-top-left-radius: #{16rpx};
  417. border-top-right-radius: #{16rpx};
  418. .dialog-title {
  419. padding: #{36rpx} #{24rpx} #{24rpx};
  420. font-size: #{32rpx};
  421. color: #353535;
  422. .toBuy {
  423. font-size: #{28rpx};
  424. image {
  425. width: #{36rpx};
  426. height: #{36rpx};
  427. margin-right: #{12rpx};
  428. display: block;
  429. }
  430. }
  431. .close {
  432. image {
  433. width: #{36rpx};
  434. height: #{36rpx};
  435. }
  436. }
  437. }
  438. .dialog-goods-list {
  439. padding: 0 #{24rpx};
  440. max-height: #{750rpx};
  441. overflow-y: auto;
  442. .dialog-goods {
  443. font-size: #{32rpx};
  444. position: relative;
  445. padding: #{28rpx} 0;
  446. border-top: #{2rpx} solid #e2e2e2;
  447. image {
  448. width: #{180rpx};
  449. height: #{180rpx};
  450. margin-right: #{24rpx};
  451. border-radius: #{8rpx};
  452. }
  453. .goods-name {
  454. color: #353535;
  455. width: #{498rpx};
  456. }
  457. .goods-price {
  458. position: absolute;
  459. bottom: #{50rpx};
  460. left: #{204rpx};
  461. }
  462. }
  463. .dialog-goods:first-of-type {
  464. border-top: 0;
  465. }
  466. }
  467. }
  468. }
  469. </style>