金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
5.4 KiB

  1. <template>
  2. <view id="brand-list">
  3. <view class="banner" v-if="brand && brand.brand_img" @tap="jumpBrandDetail">
  4. <image mode="widthFix" :src="brand.brand_img"></image>
  5. </view>
  6. <view class="hot-sale" v-if="commend_goods && commend_goods.length">
  7. <view class="title mx-1px-bottom">明星热卖</view>
  8. <view class="ul-content">
  9. <view class="li-item" v-for="(item, index) in commend_goods" :key="index" :data-id="item.id" @tap="jump" >
  10. <view class="img-box">
  11. <image mode="widthFix" :src="item.img"></image>
  12. </view>
  13. <view class="name">
  14. {{item.name}}
  15. </view>
  16. <view class="money">
  17. 新品促销价 {{item.sell_price}}
  18. </view>
  19. <view class="origin-sale mx-1px-bottom">
  20. 原价 {{item.market_price}}
  21. </view>
  22. <view class="buy-btn">
  23. <span class="iconfont icon-gouwuche"></span>
  24. 立即购买
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="all-products" v-if="list && list[0] && list[0].length">
  30. <view class="title mx-1px-bottom">所有产品</view>
  31. <view class="ul-content">
  32. <block v-for="(items, idx) in list" :key="idx" >
  33. <view class="li-item" v-for="(item, index) in items" :key="index" :data-id="item.id" @tap="jump" >
  34. <view class="detail-info mx-1px-bottom">
  35. <view class="img-box">
  36. <image :src="item.img"></image>
  37. </view>
  38. <view class="goods-right">
  39. <view class="name">
  40. {{item.name}}
  41. </view>
  42. <view class="money">新品促销价 {{item.sell_price}}</view>
  43. <view class="origin-sale">原价 {{item.market_price}}</view>
  44. </view>
  45. </view>
  46. <view class="buy-btn">
  47. <span class="iconfont icon-gouwuche"></span>
  48. 立即购买
  49. </view>
  50. </view>
  51. </block>
  52. </view>
  53. </view>
  54. </view>
  55. </template>
  56. <script>
  57. import {pageLogin, getUrl,config,is} from '@/common/js/utils.js';
  58. export default {
  59. data() {
  60. return {
  61. list: '',
  62. commend_goods: [],
  63. id: '',
  64. more: true,
  65. page: 1,
  66. brand: ''
  67. };
  68. },
  69. //下拉刷新
  70. onReachBottom() {
  71. if (this.more) {
  72. let page = this.page + 1;
  73. this.getBrandGoodsList(this.id, page);
  74. } else {
  75. wx.showToast({
  76. image: '../../../static/error.png',
  77. title: '再拉也没有啦'
  78. });
  79. }
  80. },
  81. onLoad(e) {
  82. if (e.id) {
  83. this.setData({
  84. id: e.id
  85. });
  86. this.getBrandGoodsList(e.id);
  87. }
  88. },
  89. components: {},
  90. props: {},
  91. methods: {
  92. jump(e) {
  93. let id = e.currentTarget.dataset.id;
  94. wx.navigateTo({
  95. url: '/pages/store/detail/detail?id=' + id
  96. });
  97. },
  98. jumpBrandDetail() {
  99. wx.navigateTo({
  100. url: '/pages/brand/detail/detail?id=' + this.brand.id
  101. });
  102. },
  103. getBrandGoodsList(id, page = 1) {
  104. wx.showLoading({
  105. title: "加载中",
  106. mask: true
  107. });
  108. this.$http.get({
  109. api: 'api/brand/goods/list/' + id,
  110. data: {
  111. page: page
  112. }
  113. }).then(res => {
  114. if (res.statusCode == 200) {
  115. res = res.data;
  116. if (res.status) {
  117. var pages = res.meta.pagination;
  118. var current_page = pages.current_page;
  119. var total_pages = pages.total_pages;
  120. this.setData({
  121. //[`list[${page - 1}]`]: res.data,
  122. more: current_page < total_pages,
  123. page: current_page,
  124. commend_goods: res.meta.commend_goods,
  125. brand: res.meta.brand
  126. });
  127. this.$set(this.list, page -1, res.data);
  128. wx.setNavigationBarTitle({
  129. title: res.meta.brand.name
  130. });
  131. } else {
  132. wx.showModal({
  133. content: res.message || '请求失败',
  134. showCancel: false
  135. });
  136. }
  137. } else {
  138. wx.showModal({
  139. content: res.message || '请求失败',
  140. showCancel: false
  141. });
  142. }
  143. this.setData({
  144. show: false
  145. });
  146. wx.hideLoading();
  147. }).catch(rej => {
  148. wx.hideLoading();
  149. wx.showModal({
  150. content: res.message || '请求失败',
  151. showCancel: false
  152. });
  153. });
  154. },
  155. setData: function (obj) {
  156. let that = this;
  157. let keys = [];
  158. let val, data;
  159. Object.keys(obj).forEach(function (key) {
  160. keys = key.split('.');
  161. val = obj[key];
  162. data = that.$data;
  163. keys.forEach(function (key2, index) {
  164. if (index + 1 == keys.length) {
  165. that.$set(data, key2, val);
  166. } else {
  167. if (!data[key2]) {
  168. that.$set(data, key2, {});
  169. }
  170. }
  171. data = data[key2];
  172. });
  173. });
  174. }
  175. },
  176. computed: {},
  177. watch: {}
  178. };
  179. </script>
  180. <style rel="stylesheet/less" lang="less">
  181. @import "brandList";
  182. </style>