pCategoryList.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <view>
  3. <!--components/pCategoryList/pCategoryList.wxml-->
  4. <!-- 动态分类产品数据 -->
  5. <template name="p_list">
  6. <block v-if="pCategorShow">
  7. <!-- <view :class="categoryItem.productList.displayStyle==2?'':'bgfff pdlr20'" v-if="categoryItem.productList.products.length>0"> -->
  8. <view v-for="(categoryItem, index) in pCategoryList" :key="index"
  9. :class="categoryItem.productList.displayStyle==2?'jishida head pdlr20':'bgfff pdlr20 jishida head'"
  10. v-if="categoryItem.productList.products.length>0"
  11. >
  12. <view class="titleNav pdlr20" v-if="categoryItem.titleType==1">
  13. {{categoryItem.titleCon?categoryItem.titleCon:""}}</view>
  14. <navigator
  15. :url="'/product/list/list?id=' + categoryItem.contentId + '&title=' + categoryItem.titleSubtitle + '' +web"
  16. hover-class="none">
  17. <image lazy-load="true" v-if="categoryItem.titleType==2"
  18. :src="categoryItem.titleCon+ '?x-oss-process=style/w750-auto'" mode="widthFix"
  19. class="imgtit"></image>
  20. </navigator>
  21. <!-- <view :class="categoryItem.productList.displayStyle==2?' dflex':'dflex pdlr20'"> -->
  22. <goodsList :pageList="categoryItem.productList" :about="about" :merchant="web"></goodsList>
  23. <!-- </view> -->
  24. </view>
  25. <!-- </view> -->
  26. </block>
  27. </template>
  28. </view>
  29. </template>
  30. <script>
  31. // components/pCategoryList/pCategoryList.js
  32. const route = require("../../utils/route");
  33. const app = getApp();
  34. const req = require("../../utils/request.js");
  35. import goodsList from "../../components/goodsList/goodsList";
  36. export default {
  37. data() {
  38. return {
  39. freshen: true,
  40. // pCategoryList: [],
  41. List: [],
  42. // pCategorShow: false
  43. };
  44. },
  45. components: {
  46. goodsList
  47. },
  48. props: {
  49. pCategoryList: Array,
  50. homeTemplate: Array,
  51. templateType: Object,
  52. url: String,
  53. web: String,
  54. about: Object,
  55. merchant: Object,
  56. pCategorShow:Boolean
  57. },
  58. mounted() {
  59. // console.log(this.pCategoryList, this.freshen, this.pCategorShow)
  60. // this.pCategoryList.forEach(it=>{
  61. // })
  62. // this.getRqeDatas()
  63. // console.log(this.pCategoryList, this.freshen, this.pCategorShow)
  64. },
  65. watch: {
  66. },
  67. methods: {
  68. getRqeDatas() {
  69. let that = this; //底部推荐列表
  70. let p_list = that.homeTemplate.filter(it => it.module == that.templateType.module_p_list && it.state == 0);
  71. that.List = p_list
  72. if (that.freshen) {
  73. if (!that.pCategorShow) {
  74. for (var i = 0; i < that.List.length; i++) {
  75. // console.log(i)
  76. that.getPListProduct(that.List[i], i);
  77. }
  78. }
  79. that.freshen = false
  80. }
  81. },
  82. // 动态产品分类
  83. getPListProduct(pCategory, idx) {
  84. // console.log(idx)
  85. let that = this;
  86. let form = {
  87. limit: pCategory.number,
  88. categoryId: pCategory.contentId // isRecommend:1
  89. };
  90. form.merchantId = this.merchant.id;
  91. req.getRequest('/api/product/list', form, data => {
  92. data = data.map(it => {
  93. if (it.deliverWay && JSON.parse(it.deliverWay).indexOf(3) != -1) it.isJs = true;
  94. return it;
  95. });
  96. var res = {
  97. displayStyle: pCategory.theme,
  98. lineNumber: pCategory.lineNumber,
  99. products: data
  100. }
  101. // console.log(data, that.pCategoryList, idx, that.pCategoryList[idx])
  102. that.List[idx].productList = res
  103. // console.log(that.List[idx].productList)
  104. // if (++idx < that.List.length) {
  105. // that.getPListProduct(that.List[idx], idx);
  106. // } else {
  107. that.setData({
  108. pCategoryList: that.List,
  109. });
  110. // console.log("]]]]]]]]]]]]]]]", that.pCategoryList, idx)
  111. let arr = []
  112. that.List.forEach(it => {
  113. if(it.productList){
  114. arr.push(it)
  115. }
  116. })
  117. if(arr.length==that.List.length){
  118. that.pCategorShow=true
  119. }
  120. // }
  121. });
  122. },
  123. toDetail(e) {
  124. let id = e.currentTarget.dataset.id;
  125. let url = e.currentTarget.dataset.url;
  126. app.globalData.openPage("product/detail/detail?id=" + id +
  127. url); // app.openPage("product/detail/detail?id=" + id)
  128. },
  129. addShopCart(e) {
  130. let skuId = e.currentTarget.dataset.skuid;
  131. let id = e.currentTarget.dataset.id;
  132. let _ts = this;
  133. let params = {
  134. skuId: skuId,
  135. quantity: 1,
  136. merchantId: this.merchant.id,
  137. productId: id
  138. };
  139. route.addShopCart(params, res => {
  140. _ts.setData({
  141. isUpdate: !_ts.isUpdate
  142. });
  143. req.msg('加入购物车成功');
  144. });
  145. }
  146. }
  147. };
  148. </script>
  149. <style>
  150. @import "./pCategoryList.css";
  151. </style>