index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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 :class="getTheme + '-m-back ' + getTheme " src="/static/image/icon/goods-cart.png"></image>
  35. <view :class="getTheme + '-m-text ' + getTheme ">去购买套餐</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" :class="getTheme + '-m-text ' + getTheme ">¥{{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" :class="getTheme + '-m-text ' + getTheme ">¥{{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. let currentRoute = this.currentRoute;
  106. for (let i = 0; i < this.tabBarNavs.length; i++) {
  107. if(currentRoute.includes(this.tabBarNavs[i].url.split('?')[0])) {
  108. return this.tabbarbool = true;
  109. }
  110. }
  111. return this.tabbarbool = false;
  112. },
  113. show(e) {
  114. let that = this;
  115. that.detail = e;
  116. that.showGoods = true;
  117. that.position = 'fixed';
  118. let animation = uni.createAnimation({
  119. duration: 1000,
  120. timingFunction: 'ease'
  121. });
  122. that.animationData = animation;
  123. setTimeout(function(){
  124. animation.translateY(that.height).step();
  125. that.animationData = animation.export();
  126. },200)
  127. },
  128. close() {
  129. this.detail = {};
  130. this.showGoods = false;
  131. this.position = 'static'
  132. },
  133. toRule() {
  134. uni.navigateTo({
  135. url: `/pages/rules/index?url=${encodeURIComponent(this.$api.composition.config)}&key=rule`
  136. });
  137. },
  138. toDetail(item) {
  139. uni.navigateTo({
  140. url: '/plugins/composition/detail/detail?composition_id=' + item.id
  141. });
  142. },
  143. toGoods(id) {
  144. uni.navigateTo({
  145. url: '/pages/goods/goods?id=' + id
  146. });
  147. },
  148. toSearch() {
  149. uni.navigateTo({
  150. url: '/plugins/composition/search/search'
  151. });
  152. },
  153. getSetting() {
  154. let that = this;
  155. that.$showLoading({
  156. type: 'global',
  157. text: '加载中...'
  158. });
  159. that.$request({
  160. url: that.$api.composition.config,
  161. }).then(response=>{
  162. if(response.code == 0) {
  163. that.getList();
  164. that.activityBg = response.data.activityBg;
  165. }else {
  166. that.$hideLoading();
  167. uni.showToast({
  168. title: response.msg,
  169. icon: 'none',
  170. duration: 1000
  171. });
  172. }
  173. }).catch(response => {
  174. that.$hideLoading();
  175. });
  176. },
  177. getList() {
  178. let that = this;
  179. that.$request({
  180. url: that.$api.composition.index,
  181. }).then(response=>{
  182. that.$hideLoading();
  183. if(response.code == 0) {
  184. that.list = response.data.list;
  185. if(that.list.length < 5) {
  186. that.noMore = true;
  187. }
  188. for(let i in that.list) {
  189. that.list[i].choose = false;
  190. for(let idx in that.list[i].goods_list) {
  191. that.list[i].goods_list[idx].choose_attr = null;
  192. if(that.list[i].type == 2) {
  193. that.list[i].host_list[0].choose_attr = null;
  194. that.list[i].host_list[0].opacity = 1;
  195. that.list[i].goods_list[idx].choose_goods = false;
  196. that.list[i].host_list[0].choose_goods = false;
  197. }
  198. }
  199. }
  200. uni.setStorage({
  201. key: "composition",
  202. data: that.list
  203. })
  204. }else {
  205. that.$hideLoading();
  206. uni.showToast({
  207. title: response.msg,
  208. icon: 'none',
  209. duration: 1000
  210. });
  211. }
  212. }).catch(response => {
  213. that.$hideLoading();
  214. });
  215. },
  216. getMore() {
  217. let that = this;
  218. uni.showLoading({
  219. title: '加载中'
  220. });
  221. that.$request({
  222. url: that.$api.composition.index,
  223. data: {
  224. page: that.page
  225. }
  226. }).then(response=>{
  227. uni.hideLoading();
  228. if(response.code == 0) {
  229. if(response.data.list.length == 0) {
  230. this.noMore = true;
  231. return false;
  232. }
  233. that.page++;
  234. let list = response.data.list;
  235. for(let i in list) {
  236. list[i].choose = false;
  237. for(let idx in list[i].goods_list) {
  238. list[i].goods_list[idx].choose_attr = null;
  239. if(list[i].type == 2) {
  240. list[i].host_list[0].choose_attr = null;
  241. list[i].host_list[0].opacity = 1;
  242. list[i].goods_list[idx].choose_goods = false;
  243. list[i].host_list[0].choose_goods = false;
  244. }
  245. }
  246. }
  247. that.list = that.list.concat(list);
  248. uni.setStorage({
  249. key: "composition",
  250. data: that.list
  251. })
  252. }else {
  253. uni.hideLoading();
  254. uni.showToast({
  255. title: response.msg,
  256. icon: 'none',
  257. duration: 1000
  258. });
  259. }
  260. }).catch(() => {
  261. that.$hideLoading();
  262. });
  263. },
  264. },
  265. onLoad() {
  266. let that = this;
  267. uni.getSystemInfo({
  268. success: function (res) {
  269. that.height = -res.screenHeight;
  270. 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) {
  271. that.iphone_x = true;
  272. }
  273. }
  274. });
  275. // #ifdef MP-WEIXIN
  276. wx.showShareMenu({
  277. menus: ['shareAppMessage', 'shareTimeline']
  278. })
  279. // #endif
  280. that.getSetting();
  281. },
  282. onShareAppMessage: function() {
  283. return this.$shareAppMessage({
  284. title: this.$children[0].navigationBarTitle,
  285. path: "/plugins/composition/index/index",
  286. });
  287. },
  288. // #ifdef MP-WEIXIN
  289. onShareTimeline() {
  290. // 分享朋友圈beta
  291. return this.$shareTimeline({
  292. title: this.$children[0].navigationBarTitle,
  293. query: {} // 此处填写页面的参数
  294. });
  295. },
  296. // #endif
  297. onReachBottom() {
  298. if(!this.noMore) {
  299. this.getMore();
  300. }
  301. },
  302. }
  303. </script>
  304. <style scoped lang="scss">
  305. .list {
  306. .item {
  307. margin: 0 #{24rpx} #{20rpx};
  308. background-color: #fff;
  309. border-radius: #{16rpx};
  310. padding: #{24rpx};
  311. padding-bottom: #{16rpx};
  312. .look-goods {
  313. margin-top: #{8rpx};
  314. border-radius: #{8rpx};
  315. height: #{48rpx};
  316. width: #{288rpx};
  317. font-size: #{24rpx};
  318. color: #666666;
  319. background-color: #f7f7f7;
  320. image {
  321. width: #{18rpx};
  322. height: #{10rpx};
  323. margin-left: #{16rpx};
  324. }
  325. }
  326. }
  327. }
  328. .no-tip {
  329. position: fixed;
  330. top: 40%;
  331. left: 0;
  332. right: 0;
  333. margin: 0 auto;
  334. color: #666666;
  335. font-size: #{24rpx};
  336. width: #{240rpx};
  337. text-align: center;
  338. image {
  339. height: #{240rpx};
  340. width: #{240rpx};
  341. margin-bottom: #{20rpx};
  342. }
  343. }
  344. .banner {
  345. height: #{280rpx};
  346. width: 100%;
  347. position: relative;
  348. image {
  349. width: 100%;
  350. height: #{280rpx};
  351. }
  352. .rule {
  353. position: absolute;
  354. right: #{24rpx};
  355. top: #{24rpx};
  356. padding: 0 #{16rpx};
  357. border-radius: #{24rpx};
  358. height: #{48rpx};
  359. line-height: #{48rpx};
  360. font-size: #{22rpx};
  361. color: #fff;
  362. background-color: rgba(0,0,0,.4);
  363. }
  364. }
  365. .search {
  366. width: #{750rpx};
  367. height: #{88rpx};
  368. position: sticky;
  369. top: 0;
  370. left: 0;
  371. z-index: 100;
  372. background-color: #efeff4;
  373. padding: #{15rpx} #{24rpx};
  374. box-sizing: border-box;
  375. .search-view {
  376. width: #{750-48rpx};
  377. height: #{88-30rpx};
  378. background-color: white;
  379. border-radius: #{22rpx};
  380. .image {
  381. width: #{20rpx};
  382. height: #{20rpx};
  383. margin-right: #{11rpx};
  384. }
  385. .text {
  386. font-size: #{26rpx};
  387. color: #999999;
  388. }
  389. }
  390. }
  391. .dialog-bg {
  392. position: fixed;
  393. bottom: 0;
  394. left: 0;
  395. width: 100%;
  396. height: 100%;
  397. background-color: rgba(0,0,0,.3);
  398. z-index: 202;
  399. .dialog {
  400. &.tabbarbool {
  401. padding-bottom: #{110rpx};
  402. }
  403. &.tabbarbool.iphone_x {
  404. padding-bottom: #{160rpx};
  405. }
  406. width: 100%;
  407. position: fixed;
  408. left: 0;
  409. z-index: 210;
  410. background-color: #fff;
  411. border-top-left-radius: #{16rpx};
  412. border-top-right-radius: #{16rpx};
  413. .dialog-title {
  414. padding: #{36rpx} #{24rpx} #{24rpx};
  415. font-size: #{32rpx};
  416. color: #353535;
  417. .toBuy {
  418. font-size: #{28rpx};
  419. image {
  420. width: #{36rpx};
  421. height: #{36rpx};
  422. margin-right: #{12rpx};
  423. display: block;
  424. }
  425. }
  426. .close {
  427. image {
  428. width: #{36rpx};
  429. height: #{36rpx};
  430. }
  431. }
  432. }
  433. .dialog-goods-list {
  434. padding: 0 #{24rpx};
  435. max-height: #{750rpx};
  436. overflow-y: auto;
  437. .dialog-goods {
  438. font-size: #{32rpx};
  439. position: relative;
  440. padding: #{28rpx} 0;
  441. border-top: #{2rpx} solid #e2e2e2;
  442. image {
  443. width: #{180rpx};
  444. height: #{180rpx};
  445. margin-right: #{24rpx};
  446. border-radius: #{8rpx};
  447. }
  448. .goods-name {
  449. color: #353535;
  450. width: #{498rpx};
  451. }
  452. .goods-price {
  453. position: absolute;
  454. bottom: #{50rpx};
  455. left: #{204rpx};
  456. }
  457. }
  458. .dialog-goods:first-of-type {
  459. border-top: 0;
  460. }
  461. }
  462. }
  463. }
  464. </style>