search.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <view class="container">
  3. <u-navbar leftIconColor="#fff" titleStyle="color:#fff;fontSize:36rpx;" :autoBack="true" bgColor="#2C6FF3"
  4. :placeholder="true" title="商品私库"></u-navbar>
  5. <view class="content">
  6. <view class="search">
  7. <u-search animation placeholder="商品搜索" :clearabled="false" v-model="keyword" :showAction="false"
  8. @search="search"></u-search>
  9. <view class="scan-icon" @click="scan">
  10. <u-icon name="scan" size="22" color="#909399"></u-icon>
  11. </view>
  12. <view class="search-history flex flex-wrap flex-start">
  13. <view class="history-item" v-for="(item,index) in historyList" :key="index"
  14. @click="searchFast(item)">
  15. {{item}}
  16. </view>
  17. </view>
  18. </view>
  19. <view class="list">
  20. <u-list @scrolltolower="scrolltolower" :height="fullHeight">
  21. <u-list-item class="list-item" v-for="(item, index) in commList" :key="index">
  22. <view class="comm-item" @click="$tab.navigateTo('/pages/commodity/comEdit?id='+item.id)">
  23. <u--image radius="4" width="110rpx" height="110rpx" :src="item.goodsCover" mode="widthFix"
  24. :lazy-lord="true"></u--image>
  25. <view class="item-content">
  26. <view>
  27. {{item.goodsName}}
  28. </view>
  29. <view>
  30. 69码:{{item.goodsBarcode}}
  31. </view>
  32. <view>
  33. 商品类型:{{item.categoryCode}}
  34. </view>
  35. </view>
  36. <view class="status">
  37. <u-tag text="已上架" type="success" plain v-if="item.status=='1'"> </u-tag>
  38. <u-tag text="已下架" type="error" plain v-else></u-tag>
  39. </view>
  40. </view>
  41. </u-list-item>
  42. <u-loadmore :status="status" v-if="commList.length>0" />
  43. </u-list>
  44. </view>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import {
  50. ownerGoodsList
  51. } from "@/api/commodity/mercGoods.js"
  52. import {
  53. saveKeyWord
  54. } from '@/utils/common.js'
  55. export default {
  56. data() {
  57. return {
  58. keyword: '',
  59. page: 1, //商品分页
  60. size: 10,
  61. status: 'loadmore', //加载更多
  62. commList: [], //商品列表
  63. fullHeight: 0,
  64. historyList: []
  65. }
  66. },
  67. onLoad() {
  68. let _this = this;
  69. const query = uni.createSelectorQuery().in(this);
  70. query.select(".list").boundingClientRect((data) => {
  71. _this.top = data.top;
  72. uni.getSystemInfo({
  73. success(res) {
  74. // 针对iPhone X等机型底部安全距离做适配
  75. const model = res.model;
  76. const modelInclude = [
  77. "iPhone X",
  78. 'iPhone XR',
  79. "iPhone XS",
  80. "iPhone XS MAX",
  81. "iPhone 12/13 mini",
  82. "iPhone 12/13 (Pro)",
  83. "iPhone 12/13 Pro Max",
  84. "iPhone 14 Pro Max"
  85. ];
  86. let safeDistance = modelInclude.includes(model)
  87. //动态设置商品区域高度
  88. if (safeDistance) {
  89. _this.fullHeight = res.windowHeight - _this.top - 34 + 'px';
  90. } else {
  91. _this.fullHeight = res.windowHeight - _this.top + 'px';
  92. }
  93. },
  94. });
  95. }).exec();
  96. if (uni.getStorageSync('goods')) {
  97. this.historyList = JSON.parse(uni.getStorageSync('goods'))
  98. }
  99. },
  100. onShow() {
  101. this.search()
  102. },
  103. methods: {
  104. search(val) {
  105. if(val){
  106. this.historyList = saveKeyWord('goods', this.keyword)
  107. }
  108. this.reset();
  109. this.getCommList()
  110. },
  111. searchFast(e) {
  112. this.keyword = e
  113. this.search()
  114. },
  115. //扫码
  116. scan() {
  117. uni.scanCode({
  118. success: (res) => {
  119. this.keyword = res.result;
  120. this.getCommList()
  121. }
  122. });
  123. },
  124. //根据类目获取商品列表
  125. getCommList(id) {
  126. ownerGoodsList({
  127. page: {
  128. current: this.page,
  129. size: this.size
  130. },
  131. keyword: this.keyword
  132. }).then(res => {
  133. let data = res.data.records;
  134. if (data.length < 10) {
  135. this.status = "nomore"
  136. } else {
  137. this.status = "loadmore"
  138. }
  139. this.commList = this.commList.concat(data)
  140. })
  141. },
  142. reset() {
  143. this.status == 'loadmore'
  144. this.page = 1;
  145. this.size = 10;
  146. this.commList = [];
  147. },
  148. scrolltolower() {
  149. if (this.status == 'nomore') return
  150. this.page++
  151. this.getCommList()
  152. },
  153. }
  154. }
  155. </script>
  156. <style lang="scss" scoped>
  157. .container {
  158. .content {
  159. .search {
  160. padding: 24rpx 24rpx 12rpx;
  161. background-color: #fff;
  162. position: relative;
  163. .scan-icon {
  164. position: absolute;
  165. right: 36rpx;
  166. top: 38rpx;
  167. z-index: 2;
  168. }
  169. .search-history {
  170. .history-item {
  171. margin-right: 12rpx;
  172. padding: 0 12rpx;
  173. background-color: #f2f2f2;
  174. color: #333;
  175. font-size: 24rpx;
  176. line-height: 40rpx;
  177. border-radius: 40rpx;
  178. margin-top: 12rpx;
  179. }
  180. }
  181. }
  182. .list {
  183. width: 100%;
  184. padding: 12rpx 24rpx;
  185. .comm-item {
  186. display: flex;
  187. flex-direction: row;
  188. justify-content: flex-start;
  189. align-items: center;
  190. background-color: #fff;
  191. margin-bottom: 12rpx;
  192. border-radius: 12rpx;
  193. box-sizing: border-box;
  194. padding: 12rpx;
  195. position: relative;
  196. .status {
  197. position: absolute;
  198. right: 12rpx;
  199. top: 12rpx;
  200. }
  201. .image {
  202. width: 110rpx;
  203. }
  204. .item-content {
  205. padding-left: 24rpx;
  206. color: #999;
  207. >view:nth-child(1) {
  208. font-size: 28rpx;
  209. font-weight: bold;
  210. color: #333;
  211. }
  212. >view:nth-child(2) {
  213. font-size: 26rpx;
  214. padding: 12rpx 0;
  215. }
  216. >view:nth-child(3) {
  217. font-size: 26rpx;
  218. }
  219. }
  220. }
  221. }
  222. }
  223. }
  224. </style>