goods_list.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <view class="pageBg">
  3. <DtCustomBar title="商品列表" showBack="true" :color="dt_custom_bar" :background="dt_custom_bgcolor"></DtCustomBar>
  4. <view class="top" v-if="!hideTop">
  5. <view class="condition">
  6. <view class="item" :class="{'active':curActive==0}" @tap="tapActive(0)">
  7. <view>默认</view>
  8. </view>
  9. <view class="item" :class="{'active':curActive==1}" @tap="tapActive(1)">
  10. <view>销量</view>
  11. <image v-if="curActive!=1" src="http://139.9.103.171:1888/img/image/sort_arrow_icon.png"></image>
  12. <block v-else>
  13. <image v-if="typeList[curActive].v==1" src="http://139.9.103.171:1888/img/image/sort_down_arrow.png"></image>
  14. <image v-else src="http://139.9.103.171:1888/img/image/sort_up_arrow.png"></image>
  15. </block>
  16. </view>
  17. <view class="item" :class="{'active':curActive==2}" @tap="tapActive(2)">
  18. <view>价格</view>
  19. <image v-if="curActive!=2" src="http://139.9.103.171:1888/img/image/sort_arrow_icon.png"></image>
  20. <block v-else>
  21. <image v-if="typeList[curActive].v==1" src="http://139.9.103.171:1888/img/image/sort_down_arrow.png"></image>
  22. <image v-else src="http://139.9.103.171:1888/img/image/sort_up_arrow.png"></image>
  23. </block>
  24. </view>
  25. </view>
  26. </view>
  27. <image
  28. v-if="hideTop"
  29. src="http://139.9.103.171:1888/img/image/goodlist_head_bg.png"
  30. mode="widthFix"
  31. style="
  32. width: 100vw;
  33. position: fixed;
  34. top: 0;
  35. left: 0;
  36. right: 0;">
  37. </image>
  38. <view v-if="hideTop" style="margin: 0 20upx;position: relative; ">
  39. <image :src="path" mode="widthFix" @load="imgload" style="width: 100%;border-radius: 20upx;position: relative;"></image>
  40. </view>
  41. <scroll-view class="swiper-wrapper" scroll-y="true" :style="swiperHeight" @scrolltolower="onReachLower">
  42. <view>
  43. <!-- <image v-if="hideTop&&theme!=1" :src="path" mode="widthFix" style="width: 100%;"></image> -->
  44. <view class="search_results">
  45. <view v-if="!hideTop" class="top_height"></view>
  46. <view v-if="emptyType==0" class="goods_list_result">
  47. <DtGoodsList v-if="!hideTop" :dataList="dataList" />
  48. <DtGoodsListHot v-else :dataList="dataList" :theme="theme" />
  49. </view>
  50. <DtNoMore v-if="isNoMore" />
  51. <DtEmpty :type="emptyType" />
  52. </view>
  53. </view>
  54. </scroll-view>
  55. </view>
  56. </template>
  57. <script>
  58. import DtGoodsList from '../comps/dt_goods_list.vue'
  59. import DtEmpty from '../comps/dt_empty.vue'
  60. import DtNoMore from '../comps/dt_no_more.vue'
  61. import DtCustomBar from '../comps/dt_custom_bar.vue'
  62. import DtGoodsListHot from "../comps/dt_goods_list_hot.vue"
  63. export default {
  64. components: {
  65. DtGoodsList,
  66. DtEmpty,
  67. DtNoMore,
  68. DtCustomBar,
  69. DtGoodsListHot
  70. },
  71. data() {
  72. return {
  73. path:'',
  74. theme:1,
  75. hideTop:false,
  76. memberId: '',
  77. productCategoryId: '',
  78. paramsList: [],
  79. dataList: [],
  80. curActive: 0,
  81. typeList: {
  82. 0: null,
  83. 1: {
  84. k: 'sales',
  85. t: 3,
  86. v: 1
  87. },
  88. 2: {
  89. k: 'price',
  90. t: 3,
  91. v: 1
  92. }
  93. },
  94. dt_custom_bar:'#000000',
  95. dt_custom_bgcolor:'transparent',
  96. winHeight:''
  97. }
  98. },
  99. onReady() {
  100. //swiper高度自适应
  101. this.getElementHeight('.swiper-wrapper')
  102. },
  103. computed: {
  104. swiperHeight() {
  105. return "height:" + this.winHeight + "px;";
  106. }
  107. },
  108. methods: {
  109. onReachLower(ev) {
  110. this.onReachBottomPage();
  111. },
  112. imgload(){
  113. this.getElementHeight('.swiper-wrapper')
  114. },
  115. getElementHeight(element) {
  116. let windowHeight = 0;
  117. uni.getSystemInfo({ //调用uni-app接口获取屏幕高度
  118. success(res) { //成功回调函数
  119. windowHeight=res.windowHeight //windoHeight为窗口高度,主要使用的是这个
  120. }
  121. });
  122. setTimeout(()=>{
  123. // let query = uni.createSelectorQuery().in(this);
  124. // query.select(element).boundingClientRect();
  125. // query.exec((res) => {
  126. // if (!res) {//如果没获取到,再调一次
  127. // this.getElementHeight();
  128. // }else {
  129. // this.swiperHeight = (windowHeight-res[0][0].top)+'px';
  130. // console.log(res[0][0].top,res)
  131. // }
  132. // })
  133. const query = uni.createSelectorQuery().in(this);
  134. query.selectAll(element).boundingClientRect();
  135. query.exec((res) => {
  136. if (!res) {//如果没获取到,再调一次
  137. this.getElementHeight();
  138. }else {
  139. this.winHeight = windowHeight - res[0][0].top;
  140. }
  141. })
  142. },20)
  143. },
  144. // async getSearchProductFilter() {
  145. // let data = {};
  146. // data.productCategoryId = this.productCategoryId;
  147. // let res = await this.$api.getSearchProductFilter(data);
  148. // console.log(res);
  149. // },
  150. tapActive(idx) {
  151. this.curActive = idx
  152. if (idx == 1 || idx == 2) {
  153. let typeList = this.typeList
  154. if (typeList[idx].v == 1) {
  155. typeList[idx].v = -1
  156. } else {
  157. typeList[idx].v = 1
  158. }
  159. this.typeList = typeList
  160. }
  161. this.isNoMore = false
  162. this.pageIndex = 0
  163. this.dataList.length = 0
  164. this.queryDataList()
  165. },
  166. getParams() {
  167. let param = this.typeList[this.curActive]
  168. let paramsList = this.paramsList.slice(0)
  169. console.log(96, paramsList)
  170. if (this.productCategoryId) {
  171. paramsList.unshift({
  172. k: 'productCategoryId',
  173. t: 1,
  174. v: this.productCategoryId
  175. })
  176. }
  177. console.log(104, paramsList, param)
  178. if (param) {
  179. paramsList.unshift(param)
  180. }
  181. console.log(108, paramsList)
  182. return paramsList
  183. },
  184. // 搜索
  185. async queryDataList() {
  186. let params = this.getParams()
  187. console.log(112, params)
  188. let resp = await this.$api.searchProduct({
  189. _isShowLoading: true,
  190. pageNo: this.pageIndex,
  191. pageSize: this.pageSize,
  192. memberId: this.memberId,
  193. params: params
  194. })
  195. let list = this.getDataList(resp)
  196. this.dataList = this.dataList.concat(list)
  197. },
  198. onLoadPage(options) {
  199. wx.hideShareMenu();
  200. console.log(options);
  201. if (this.isLoad) {
  202. this.memberId = this.$auth.getMemberId()
  203. this.paramsList = options.params ? JSON.parse(options.params) : [];
  204. this.productCategoryId = options.id ? options.id : '';
  205. // this.getSearchProductFilter();
  206. if (options.name) {
  207. uni.setNavigationBarTitle({
  208. title: options.name
  209. })
  210. }
  211. if(options.hideTop){
  212. this.hideTop = options.hideTop;
  213. // if(options.theme==1){
  214. // uni.setNavigationBarColor({
  215. // frontColor: '#ffffff',
  216. // backgroundColor:'#ff1104'
  217. // })
  218. this.dt_custom_bar = '#ffffff'
  219. // }
  220. }else{
  221. this.dt_custom_bgcolor= "#ffffff"
  222. }
  223. if(options.theme){
  224. this.theme = options.theme;
  225. }
  226. if(options.path){
  227. this.path = options.path;
  228. }
  229. }
  230. this.queryDataList();
  231. },
  232. },
  233. onReachBottom() {
  234. this.onReachBottomPage()
  235. },
  236. }
  237. </script>
  238. <style lang="scss" scoped>
  239. .top {
  240. position: fixed;
  241. left: 0;
  242. width: 100%;
  243. z-index: 100;
  244. .condition {
  245. display: flex;
  246. flex-direction: row;
  247. align-items: center;
  248. height: 60upx;
  249. justify-content: space-around;
  250. border-bottom: 1upx solid rgb(238, 238, 238);
  251. background: #fff;
  252. .item {
  253. font-size: 28upx;
  254. color: #333333;
  255. display: flex;
  256. flex-direction: row;
  257. align-items: center;
  258. flex: 1;
  259. justify-content: center;
  260. height: 100%;
  261. image {
  262. width: 11upx;
  263. height: 15upx;
  264. margin-left: 10upx;
  265. }
  266. }
  267. .active {
  268. color: $dt-color-primary;
  269. }
  270. }
  271. }
  272. .search_results {
  273. .top_height {
  274. height: 60upx;
  275. }
  276. .goods_list_result {
  277. background: #fff;
  278. }
  279. .no_data_wrap {
  280. height: 100vh;
  281. display: flex;
  282. align-items: center;
  283. justify-content: center;
  284. }
  285. }
  286. </style>