recommend.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <view>
  3. <!--components/recommend/recommend.wxml-->
  4. <template name="recommend">
  5. <view :class="recommendTemplate.theme==2?'pdlr30':''" v-if="recommendTemplate&&recommendTemplate.state==0&&pageList.products.length>0">
  6. <view class="jishida head">
  7. <!-- <view class="title pdlr20" wx:if="{{!recommendCon}}">推荐产品 -->
  8. <block v-if="recommendTemplate.titleType==1">
  9. <view class="titleNav ddflex">{{recommendTemplate.titleCon}}
  10. <!-- <text>{{about.timely_service_deadline ? about.timely_service_deadline : ''}}</text> -->
  11. <navigator class="ddflex" :url="'/product/list/list?title=' + recommendTemplate.titleCon + '&attr=Recommend' + web" hover-class="none">
  12. <text>全部</text>
  13. <image class="more" src="../../static/pages/images/more.png"></image>
  14. </navigator>
  15. </view>
  16. <!-- <image wx:else src="recommendTemplate.titleCon"></image> -->
  17. <scroll-view scroll-x="true" class="tab dflex" :style="recommendTemplate.theme==2?'':'margin-bottom:25rpx'">
  18. <navigator :url="'/product/list/list?title=' + recommendTemplate.titleCon + '&attr=Recommend' + web" hover-class="none"
  19. class="li active">{{recommendTemplate.titleCon}}</navigator>
  20. <block v-for="(item, index) in categoryList[0]" :key="index">
  21. <navigator :url="'/product/list/list?id=' + item.id + '&title=' + item.title + '' + web" hover-class="none"
  22. class="li" v-if="index < 3">
  23. {{item.title}}
  24. </navigator>
  25. </block>
  26. </scroll-view>
  27. </block>
  28. <block v-if="recommendTemplate.titleType==2">
  29. <navigator :url="'/product/list/list?title=' + recommendTemplate.titleSubtitle + '&attr=Recommend' + web"
  30. hover-class="none">
  31. <image lazy-load="true" :src="recommendTemplate.titleCon + '?x-oss-process=style/w750-auto'" mode="widthFix"
  32. class="imgtit"></image>
  33. </navigator>
  34. </block>
  35. <view :class="recommendTemplate.theme==2?'':' pdlr30'">
  36. <goodsList :pageList="pageList" :about="about" :merchant="web"></goodsList>
  37. </view>
  38. <!-- <view class="nomore dflex" wx:if="{{hasmore}}">亲,没有更多了</view> -->
  39. </view>
  40. </view>
  41. </template>
  42. </view>
  43. </template>
  44. <script>
  45. const route = require("../../utils/route");
  46. const app = getApp();
  47. const req = require("../../utils/request.js"); // components/recommend/recommend.js
  48. import goodsList from "../../components/goodsList/goodsList";
  49. export default {
  50. data() {
  51. return {
  52. };
  53. },
  54. components: {
  55. goodsList
  56. },
  57. props: {
  58. pageList: Object, //{backgroundColor:背景颜色,displayStyle: 样式模板,lineNumber:每行几个,products:产品列表}
  59. web: String,//地址跳转
  60. url: String,//地址跳转
  61. recommendTemplate: Object, //推荐后台配置
  62. about: Object, //参数配置
  63. categoryList:Array //分类列表
  64. },
  65. mounted(){
  66. // console.log(this.categoryList)
  67. },
  68. watch: {},
  69. methods: {
  70. getRqeDatas() {
  71. let that = this; //推荐产品
  72. let recommend = that.homeTemplate.filter(it => it.module == that.templateType.module_recommend);
  73. if (recommend && recommend.length > 0 && recommend[0].state == 0) {
  74. that.setData({
  75. recommendTemplate: recommend[0]
  76. });
  77. // console.log(this.recommendTemplate);
  78. this.getPageList();
  79. }
  80. },
  81. getPageList() {
  82. //Recommend
  83. let that = this; // 类型:1 普通商品 2 社区团购订单 3 秒杀订单 4 拼团订单 5 及时达订单 6 新客特价 7 优惠砍价
  84. if (this.merchant && this.merchant.type == 5 || this.shopId && this.merchantId) {
  85. let from = {
  86. page: that.page,
  87. limit: that.recommendTemplate.number,
  88. type: 1,
  89. merchantId: this.merchant.merchantDTO.id,
  90. sid: this.merchant.id,
  91. attr: 'Recommend'
  92. };
  93. if (this.shopId && this.merchantId) from.merchantId = this.merchantId, from.sid = this.shopId;
  94. route.getShopeList(from, data => {
  95. if (data && data.length >= 10) that.isLoad = true;
  96. if (that.page > 1) data = that.pageList.concat(data);
  97. // console.log(data);
  98. that.setData({
  99. pageList: data,
  100. hasmore: data && data.length > 0
  101. });
  102. });
  103. }
  104. if (this.merchant && this.merchant.type != 5) {
  105. route.getProductList({
  106. page: that.page,
  107. limit: that.recommendTemplate.number,
  108. attr: 'Recommend'
  109. }, res => {
  110. if (res && res.length >= 10) that.isLoad = true;
  111. if (that.page > 1) res = that.pageList.concat(res);
  112. that.setData({
  113. pageList: res,
  114. hasmore: res && res.length > 0
  115. });
  116. });
  117. }
  118. },
  119. toDetail(e) {
  120. // let id = e.currentTarget.dataset.id;
  121. // app.openPage("product/detail/detail?id=" + id + '&&hideShop=' + false)
  122. let id = e.currentTarget.dataset.id;
  123. let merchantId = e.currentTarget.dataset.merchant;
  124. let shopId = e.currentTarget.dataset.shopid;
  125. if (!shopId) {
  126. app.globalData.openPage("product/detail/detail?id=" + id + "&merchantId=" + merchantId);
  127. } else {
  128. app.globalData.openPage("product/detail/detail?id=" + id + "&merchantId=" + merchantId + "&shopId=" + shopId);
  129. }
  130. },
  131. addShopCart(e) {
  132. let skuId = e.currentTarget.dataset.skuid;
  133. let id = e.currentTarget.dataset.id;
  134. let _ts = this;
  135. let params = {
  136. skuId: skuId,
  137. quantity: 1,
  138. merchantId: this.merchant.id,
  139. productId: id
  140. };
  141. route.addShopCart(params, res => {
  142. _ts.setData({
  143. isUpdate: !_ts.isUpdate
  144. });
  145. req.msg('加入购物车成功');
  146. });
  147. }
  148. }
  149. };
  150. </script>
  151. <style>
  152. @import "./recommend.css";
  153. </style>