searchResult.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <view class="searchResult">
  3. <!-- <zs-choose-tab :tabList="tabList" @choose="chooseTab"></zs-choose-tab> -->
  4. <zs-choose-tab-union :level="2" :tabList="tabList" @choose="chooseTab">
  5. </zs-choose-tab-union>
  6. <view class="goods-list">
  7. <zs-list class="store-box" mt="0" @load="loadMore" :status="status">
  8. <view class="left">
  9. <view
  10. class="store-item"
  11. v-for="(item, index) in list"
  12. :key="index"
  13. @click="goGoodsDetail(item)"
  14. >
  15. <zs-img
  16. :src="item.goodsImg"
  17. width="340rpx"
  18. height="340rpx"
  19. mode="widthFix"
  20. ></zs-img>
  21. <view class="info">
  22. <view class="title">
  23. {{ item.goodsName }}
  24. </view>
  25. <view class="goods-price">
  26. <view> ¥{{ item.realPrice }} </view>
  27. <view class="distance"> 销售{{ item.saleNum }} </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. <view class="right">
  33. <view
  34. class="store-item"
  35. v-for="(item, index) in list1"
  36. :key="index"
  37. @click="goGoodsDetail(item)"
  38. >
  39. <zs-img
  40. :src="item.goodsImg"
  41. width="340rpx"
  42. height="340rpx"
  43. mode="widthFix"
  44. ></zs-img>
  45. <view class="info">
  46. <view class="title">
  47. {{ item.goodsName }}
  48. </view>
  49. <view class="goods-price">
  50. <!-- <image
  51. class="position"
  52. src="../../static/position.png"
  53. mode=""
  54. ></image> -->
  55. <view> ¥{{ item.realPrice }}</view>
  56. <view class="distance"> 销售{{ item.saleNum }} </view>
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. </zs-list>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. import { appSearch, getSearchTypeData } from "@/api/shop.js";
  67. export default {
  68. data() {
  69. return {
  70. location: "",
  71. query: {
  72. district: "",
  73. pageCurrent: 1,
  74. pageSize: 10,
  75. "location.lat": 0,
  76. "location.lon": 0,
  77. range: "",
  78. goodsCateId: "",
  79. goodsName: "",
  80. realPriceOrder: "", //desc,asc
  81. shopId: "",
  82. status: 3,
  83. currentPage: 0,
  84. },
  85. status: "more",
  86. list: [],
  87. list1: [],
  88. tabList: [],
  89. };
  90. },
  91. methods: {
  92. goShopDetail(item) {
  93. uni.setStorageSync("shopInfo", JSON.stringify(item));
  94. uni.navigateTo({
  95. url: "/detail/shopDetail/shopDetail",
  96. });
  97. },
  98. goGoodsDetail(item, i) {
  99. uni.setStorageSync("shopInfo", JSON.stringify(item));
  100. uni.navigateTo({
  101. url: `/detail/goodsDetail/index?id=${item.goodsId}`,
  102. });
  103. },
  104. chooseTab(val) {
  105. this.query.goodsCateId = val[0].id;
  106. this.query.realPriceOrder = val[1].id || "";
  107. this.query.pageCurrent = 1;
  108. this.status = "more";
  109. this.list = [];
  110. this.list1 = [];
  111. this.search();
  112. },
  113. search() {
  114. // if(this.status == 'noMore') return
  115. this.status = "loading";
  116. let obj = JSON.parse(JSON.stringify(this.query));
  117. if (!obj.range) {
  118. delete obj.range;
  119. }
  120. appSearch(obj).then((res) => {
  121. if (res.state == "Success") {
  122. this.loading = false;
  123. let list = [];
  124. let list1 = [];
  125. res.content.records.map((item, index) => {
  126. if (index % 2) {
  127. list1.push(item);
  128. } else {
  129. list.push(item);
  130. }
  131. });
  132. this.list = this.list.concat(list);
  133. this.list1 = this.list1.concat(list1);
  134. let total = this.list.length + this.list1.length;
  135. console.log("list", this.list, this.list1);
  136. if (total >= res.content.total) {
  137. this.status = "noMore";
  138. } else {
  139. this.status = "more";
  140. this.query.currentPage++;
  141. }
  142. }
  143. });
  144. },
  145. loadMore() {
  146. this.search();
  147. },
  148. getTabList() {
  149. // 如果是栏目点进来则更新标题
  150. let query = this.query.itemId;
  151. let str = "";
  152. if(query){
  153. str="?columnId="+query;
  154. this.query.columnId=query;
  155. }
  156. getSearchTypeData(str).then((res) => {
  157. this.tabList = [
  158. {
  159. id: 0,
  160. cateName: "全部分类",
  161. child: res.content,
  162. },
  163. {
  164. id: 1,
  165. cateName: "价格排序",
  166. child: [
  167. {
  168. id: "asc",
  169. cateName: "价格升序",
  170. },
  171. {
  172. id: "desc",
  173. cateName: "价格降序",
  174. },
  175. ],
  176. },
  177. ];
  178. });
  179. },
  180. },
  181. onLoad(options) {
  182. // let list = uni.getStorageSync("districtList") || "[]";
  183. // this.tabList[0].list = JSON.parse(list);
  184. this.location = JSON.parse(uni.getStorageSync("location"));
  185. if(options.shopId){
  186. this.query.shopId = options.shopId;
  187. }else{
  188. this.query.shopId = uni.getStorageSync("gdShopId");
  189. }
  190. this.query["location.lat"] = this.location.latitude;
  191. this.query["location.lon"] = this.location.longitude;
  192. this.query.goodsName = options?.search || "";
  193. if (!this.query.goodsName) {
  194. this.query.columnId = options.columnId || "";
  195. this.query.itemId = options.columnId || "";
  196. uni.setNavigationBarTitle({
  197. title: options.column || "搜索结果",
  198. });
  199. }
  200. this.search();
  201. this.getTabList();
  202. },
  203. };
  204. </script>
  205. <style lang="scss" scoped>
  206. .searchResult {
  207. padding: 100rpx 24rpx 20rpx;
  208. background: #f9f9f9;
  209. height: 100%;
  210. .goods-list {
  211. border-radius: 16rpx 16rpx 0 0;
  212. margin-bottom: 60rpx;
  213. }
  214. }
  215. ::v-deep .zs-list {
  216. display: flex;
  217. flex-wrap: wrap;
  218. justify-content: space-between;
  219. .left {
  220. .adv-swiper {
  221. width: 340rpx;
  222. height: 444rpx;
  223. margin-bottom: 25rpx;
  224. .adv-item {
  225. width: 340rpx;
  226. height: 444rpx;
  227. }
  228. }
  229. }
  230. .right {
  231. }
  232. .store-item {
  233. width: 340rpx;
  234. margin-bottom: 25rpx;
  235. // box-shadow: 0rpx 0rpx 24rpx 2rpx rgba(0, 0, 0, 0.08);
  236. border-radius: 16rpx;
  237. background: #fff;
  238. .icon {
  239. width: 100%;
  240. height: 300rpx;
  241. border-radius: 16rpx 16rpx 0 0;
  242. }
  243. .info {
  244. padding: 20rpx;
  245. background: #fff;
  246. border-radius: 0 0 16rpx 16rpx;
  247. position: relative;
  248. .title {
  249. // font-weight: bold;
  250. width: 100%;
  251. white-space: nowrap;
  252. text-overflow: ellipsis;
  253. overflow: hidden;
  254. }
  255. .tags {
  256. display: flex;
  257. align-items: center;
  258. .tag-item {
  259. line-height: 50rpx;
  260. border-radius: 8rpx;
  261. padding: 6rpx 0;
  262. font-size: 24rpx;
  263. margin-left: 10rpx;
  264. display: flex;
  265. .label {
  266. background: #fff;
  267. color: #fe5b47;
  268. padding: 0 10rpx;
  269. border-radius: 8rpx 0 0 8rpx;
  270. }
  271. .value {
  272. color: #fff;
  273. background: rgba(255, 255, 255, 0.2);
  274. padding: 0 14rpx;
  275. border-radius: 0 8rpx 8rpx 0;
  276. }
  277. }
  278. }
  279. .goods-price {
  280. display: flex;
  281. align-items: center;
  282. margin-top: 15rpx;
  283. justify-content: space-between;
  284. color: #ff4d3a;
  285. font-weight: bold;
  286. font-size: 30rpx;
  287. .distance {
  288. font-weight: normal;
  289. font-size: 20rpx;
  290. color: #999;
  291. }
  292. .position {
  293. color: 999;
  294. width: 25rpx;
  295. height: 29rpx;
  296. margin-right: 8rpx;
  297. }
  298. }
  299. }
  300. }
  301. }
  302. </style>