index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <view class="search_top">
  3. <view class="search_content">
  4. <input class="search_input" type="text" v-model="requestParam.name" @input="searchChange" placeholder="请输入产品名称搜索" />
  5. <button class="search_btn" @click.stop="searchOpen()" data-eventsync="true">搜索</button>
  6. </view>
  7. </view>
  8. <view class="search_find" v-if="requestParam.name.length == 0">
  9. <view class="title">搜索发现</view>
  10. <view class="list_content">
  11. <view v-for="(item, index) in findList" :key="index" class="list_content_main" @click="chooseProduct(item.label)">{{ item.label }}</view>
  12. </view>
  13. </view>
  14. <view class="search_result">
  15. <view @click="toDetail(item)" v-if="productList.length !== 0" data-eventsync="true" class="product_item" v-for="(item, index) in productList" :key="index">
  16. <image class="product_image" :src="item.thumb" mode=""></image>
  17. <view class="product_name">
  18. <text>{{ item.name }}</text>
  19. </view>
  20. <view class="product_spec">
  21. <text>{{ item.spec }}</text>
  22. </view>
  23. <view class="stock_price">
  24. <view class="product_price" v-if="isShowPrice">
  25. <text>¥{{ item.price }}</text>
  26. </view>
  27. <view class="product_stock">剩{{ item.stock }}个</view>
  28. </view>
  29. </view>
  30. <view v-if="productList.length == 0 && requestParam.name.length !== 0" class="to_bottom">-----还没有产品啦-----</view>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. navHeight: '', // 导航栏高度
  38. statusBarHeight: '', // 状态栏高度
  39. menuWidth: '', //导航栏宽度
  40. findList: [
  41. { label: '感冒灵颗粒', index: 0 },
  42. { label: '999皮炎平', index: 1 },
  43. { label: '养胃舒颗粒', index: 2 },
  44. { label: '感冒灵颗粒', index: 3 },
  45. { label: '999皮炎平', index: 4 },
  46. { label: '养胃舒颗粒', index: 5 },
  47. { label: '感冒灵颗粒', index: 6 },
  48. { label: '999皮炎平', index: 7 },
  49. { label: '养胃舒颗粒', index: 8 },
  50. { label: '藿香正气液', index: 9 }
  51. ],
  52. requestParam: {
  53. name: '',
  54. page: 1
  55. },
  56. productList: []
  57. };
  58. },
  59. onLoad() {
  60. //初始化一些导航栏的高度与宽度
  61. let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
  62. //获取手机系统的信息 里面有状态栏高度和设备型号
  63. let { statusBarHeight, system } = uni.getSystemInfoSync();
  64. // 注意返回的单位是px 不是rpx
  65. this.statusBarHeight = statusBarHeight;
  66. this.navHeight = statusBarHeight + (system.indexOf('iOS') > -1 ? 40 : 44);
  67. this.menuWidth = menuButtonInfo.width + 16;
  68. },
  69. methods: {
  70. backIndex: () => {
  71. uni.navigateBack({
  72. delta: '2'
  73. });
  74. },
  75. chooseProduct(label) {
  76. this.requestParam.name = label;
  77. this.searchOpen();
  78. },
  79. searchChange(e) {
  80. // 如果没有搜索词
  81. if (!this.requestParam.name) {
  82. // this.searchOpen();
  83. this.productList = [];
  84. }
  85. },
  86. searchOpen() {
  87. // 请求中,不再请求
  88. if (this.isReqing) return;
  89. // 是否是最后一页
  90. this.isLast = false;
  91. // 初始化页码为1
  92. this.requestParam.page = 1;
  93. // 设置请求中
  94. this.isReqing = true;
  95. // 请求列表
  96. this.$http.request('api/product/get_list', this.requestParam).then((re) => {
  97. // 设置非请求中
  98. this.isReqing = false;
  99. // 成功结果
  100. if (re.code == 'success') {
  101. this.productList = re.data.data;
  102. if (re.data.data.length && re.data.last_page >= this.requestParam.page) this.isLast = true;
  103. }
  104. });
  105. },
  106. toDetail(item) {
  107. uni.navigateTo({
  108. url: '/pages/product/index?product_id=' + item.id
  109. });
  110. }
  111. }
  112. };
  113. </script>
  114. <style scoped lang="less">
  115. .search_top {
  116. display: flex;
  117. align-items: center;
  118. padding: 0 16rpx;
  119. .back_icon {
  120. width: 36rpx;
  121. height: 36rpx;
  122. }
  123. .search_content {
  124. flex: 1;
  125. position: relative;
  126. .search_input {
  127. z-index: 0;
  128. float: left;
  129. width: 100%;
  130. height: 56rpx;
  131. display: block;
  132. font-size: 24rpx;
  133. padding-left: 20rpx;
  134. position: relative;
  135. border-top-left-radius: 40rpx;
  136. border-bottom-left-radius: 40rpx;
  137. border: 2rpx solid #dddddd;
  138. }
  139. .search_btn {
  140. top: 0rpx;
  141. z-index: 9;
  142. right: 0rpx;
  143. color: #ffffff;
  144. position: absolute;
  145. display: block;
  146. width: 120rpx;
  147. height: 60rpx;
  148. font-size: 24rpx;
  149. line-height: 60rpx;
  150. border-radius: 40rpx;
  151. background-color: #e03519;
  152. }
  153. }
  154. }
  155. .search_find {
  156. margin-top: 20px;
  157. padding: 0 16px;
  158. .title {
  159. font-size: 28rpx;
  160. color: gray;
  161. }
  162. .list_content {
  163. margin-top: 16rpx;
  164. display: flex;
  165. flex-wrap: wrap;
  166. gap: 16rpx;
  167. .list_content_main {
  168. display: flex;
  169. align-items: center;
  170. justify-content: center;
  171. padding: 16rpx;
  172. border-radius: 60rpx;
  173. color: #587bb3;
  174. }
  175. }
  176. }
  177. .search_result {
  178. display: block;
  179. overflow: hidden;
  180. margin: 0rpx auto;
  181. padding: 16px;
  182. .product_item {
  183. float: left;
  184. width: 320rpx;
  185. height: 520rpx;
  186. display: block;
  187. overflow: hidden;
  188. margin: 20rpx 0rpx;
  189. margin-right: 40rpx;
  190. background-color: #ffffff;
  191. border-radius: 20rpx;
  192. .product_image {
  193. width: 320rpx;
  194. height: 320rpx;
  195. }
  196. .product_name {
  197. height: 80rpx;
  198. font-size: 30rpx;
  199. line-height: 40rpx;
  200. overflow: hidden;
  201. margin: 10rpx 0rpx;
  202. padding: 0rpx 10rpx;
  203. text-overflow: ellipsis;
  204. }
  205. .product_spec {
  206. height: 30rpx;
  207. color: #999999;
  208. font-size: 24rpx;
  209. line-height: 30rpx;
  210. padding: 0rpx 10rpx;
  211. overflow: hidden;
  212. white-space: nowrap;
  213. text-overflow: ellipsis;
  214. }
  215. .stock_price {
  216. color: #dddddd;
  217. font-size: 20rpx;
  218. overflow: hidden;
  219. line-height: 30rpx;
  220. padding: 0rpx 10rpx;
  221. .product_price {
  222. float: left;
  223. color: red;
  224. font-size: 30rpx;
  225. line-height: 60rpx;
  226. .product_market {
  227. font-size: 24rpx;
  228. color: #999999;
  229. line-height: 30rpx;
  230. vertical-align: top;
  231. text-decoration: line-through;
  232. }
  233. }
  234. .product_stock {
  235. float: right;
  236. font-size: 20rpx;
  237. line-height: 60rpx;
  238. }
  239. }
  240. }
  241. .product_item:nth-child(even) {
  242. margin-right: 0rpx;
  243. }
  244. }
  245. </style>