recommend.vue 5.3 KB

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