publicCom.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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="u-search-box" @click="searchComm">
  6. <view class="u-search-inner">
  7. <u-icon name="search" color="#909399" :size="28"></u-icon>
  8. <text class="u-search-text">搜索商品</text>
  9. </view>
  10. </view> -->
  11. <view class="search" @click="searchComm">
  12. <view class="search-input">
  13. <u-search placeholder="商品搜索" actionText="取消" :actionStyle="{color:'#2C6FF3'}" :showAction="!leftShow"
  14. :clearabled="false" v-model="keyword" @search="search" @custom="cancle"></u-search>
  15. <view @click="scan" :class="[leftShow?'scan-icon scan-left-show':'scan-icon scan-left-hidden']">
  16. <u-icon name="scan" size="22" color="#909399"></u-icon>
  17. </view>
  18. </view>
  19. <view class="search-history flex flex-wrap flex-start" v-if="!leftShow">
  20. <view class="history-item" v-for="(item,index) in historyList" :key="index" @click="searchFast(item)">
  21. {{item}}
  22. </view>
  23. </view>
  24. </view>
  25. <view class="classify-wrap">
  26. <Classify ref="classify" :storeName="storeName" :selectShow="true" :tabList="tabList" :status="status"
  27. :commList="commList" @switchMenu="switchMenu" @comClick='detail' @lowerBottom="lowerBottom"
  28. :height="fullHeight" :leftShow="leftShow" />
  29. </view>
  30. <view class="btn safe-bottom">
  31. <xbutton delay="1500" size="large" @click="addToPer">添加到商品私库</xbutton>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import Classify from "@/components/classify/index.vue"
  37. import {
  38. goodsCategory,
  39. ownerGoodsList
  40. } from "@/api/commodity/goods.js"
  41. export default {
  42. components: {
  43. Classify
  44. },
  45. data() {
  46. return {
  47. fullHeight: '0',
  48. tabList: [], //商品类目
  49. commList: [], //商品列表
  50. page: 1, //商品分页
  51. size: 10,
  52. status: 'loadmore', //加载更多
  53. storeName: 'pubToPerStor', //存储名称
  54. keyword: '', //搜索
  55. leftShow: true,
  56. historyList: []
  57. }
  58. },
  59. onLoad() {
  60. let _this = this;
  61. const query = uni.createSelectorQuery().in(this);
  62. query.select(".classify-wrap").boundingClientRect((data) => {
  63. _this.top = data.top;
  64. uni.getSystemInfo({
  65. success(res) {
  66. // 针对iPhone X等机型底部安全距离做适配
  67. const model = res.model;
  68. const modelInclude = [
  69. "iPhone X",
  70. 'iPhone XR',
  71. "iPhone XS",
  72. "iPhone XS MAX",
  73. "iPhone 12/13 mini",
  74. "iPhone 12/13 (Pro)",
  75. "iPhone 12/13 Pro Max",
  76. "iPhone 14 Pro Max"
  77. ];
  78. let safeDistance = modelInclude.includes(model)
  79. //动态设置商品区域高度
  80. if (safeDistance) {
  81. _this.fullHeight = res.windowHeight - _this.top - 84 + 'px';
  82. } else {
  83. _this.fullHeight = res.windowHeight - _this.top - 50 + 'px';
  84. }
  85. },
  86. });
  87. }).exec();
  88. if (uni.getStorageSync('goods')) {
  89. this.historyList = JSON.parse(uni.getStorageSync('goods'))
  90. }
  91. this.getCategory()
  92. },
  93. onShow() {
  94. //搜索页来回跳转,刷新已选商品数据
  95. this.$refs.classify.onshow()
  96. },
  97. methods: {
  98. // 搜索商品
  99. // searchComm() {
  100. // this.$tab.navigateTo('/pages/commodity/publicSearch?type=0&storeName=' + this.storeName)
  101. // },
  102. search(val) {
  103. this.saveKeyWord('goods', this.keyword)
  104. this.reset();
  105. this.getCommList()
  106. },
  107. cancle(val) {
  108. this.keyword = ''
  109. this.leftShow = true
  110. this.search()
  111. },
  112. saveKeyWord(type, val) {
  113. if (val) {
  114. let arr = []
  115. if (uni.getStorageSync(type)) {
  116. let arr = JSON.parse(uni.getStorageSync(type))
  117. if (arr.indexOf(val) != -1) {
  118. console.log('arr.indexOf(val)', arr.indexOf(val))
  119. arr.splice(arr.indexOf(val), 1)
  120. }
  121. arr.unshift(val)
  122. if (arr.length > 6) {
  123. arr.pop()
  124. }
  125. this.historyList = JSON.parse(JSON.stringify(arr))
  126. uni.setStorageSync(type, JSON.stringify(arr))
  127. } else {
  128. arr.unshift(val)
  129. this.historyList = JSON.parse(JSON.stringify(arr))
  130. uni.setStorageSync(type, JSON.stringify(arr))
  131. }
  132. } else {
  133. return
  134. }
  135. },
  136. reset() {
  137. this.status == 'loadmore'
  138. this.page = 1;
  139. this.size = 10;
  140. this.commList = [];
  141. },
  142. searchFast(e) {
  143. this.keyword = e
  144. this.search()
  145. },
  146. //扫码
  147. scan() {
  148. uni.scanCode({
  149. success: (res) => {
  150. this.keyword = res.result;
  151. this.search()
  152. }
  153. });
  154. },
  155. searchComm() {
  156. this.leftShow = false
  157. },
  158. //获取类目列表
  159. getCategory() {
  160. goodsCategory({
  161. deviceId:''
  162. }).then(res => {
  163. this.tabList = res.data
  164. if (this.tabList && this.tabList.length > 0) {
  165. this.switchMenu(this.tabList[0])
  166. }
  167. })
  168. },
  169. //商品类目切换
  170. switchMenu(item) {
  171. this.reset()
  172. this.getCommList(item.categoryCode)
  173. },
  174. //根据类目获取商品列表
  175. getCommList(id) {
  176. let params = {}
  177. if (this.leftShow) { //搜索
  178. params = {
  179. categoryCode: id,
  180. page: {
  181. current: this.page,
  182. size: this.size
  183. }
  184. }
  185. } else { //非搜索
  186. params = {
  187. page: {
  188. current: this.page,
  189. size: this.size
  190. },
  191. keyword: this.keyword
  192. }
  193. }
  194. ownerGoodsList(params).then(res => {
  195. let data = res.data.records;
  196. let newData = data.map(i => {
  197. i.noSelect = i.mercGoodsId != null ? true : false;
  198. i.categoryCode = i.categoryCodeLevel1;
  199. return i
  200. })
  201. if (newData.length < 10) {
  202. this.status = "nomore"
  203. } else {
  204. this.status = "loadmore"
  205. }
  206. this.commList = this.commList.concat(newData)
  207. })
  208. },
  209. //触底加载更多
  210. lowerBottom() {
  211. if (this.status == 'nomore') return
  212. this.page++
  213. this.getCommList()
  214. },
  215. //添加商品到私库
  216. addToPer() {
  217. if (uni.getStorageSync(this.storeName) && JSON.parse(uni.getStorageSync(
  218. this.storeName)).length > 0) {
  219. this.$tab.navigateTo(`/pages/equipment/addComList?storeName=${this.storeName}&type=0`)
  220. } else {
  221. uni.$u.toast('请先选择商品!')
  222. }
  223. }
  224. }
  225. }
  226. </script>
  227. <style lang="scss" scoped>
  228. .container {
  229. height: calc(100vh);
  230. /* #ifdef H5 */
  231. height: calc(100vh - var(--window-top));
  232. /* #endif */
  233. display: flex;
  234. flex-direction: column;
  235. .search {
  236. padding: 24rpx 24rpx;
  237. background-color: #fff;
  238. .search-input {
  239. position: relative;
  240. .scan-icon {
  241. position: absolute;
  242. top: 50%;
  243. transform: translateY(-50%);
  244. z-index: 2;
  245. &.scan-left-show {
  246. right: 36rpx;
  247. }
  248. &.scan-left-hidden {
  249. right: 100rpx;
  250. }
  251. }
  252. }
  253. .search-history {
  254. .history-item {
  255. margin-right: 24rpx;
  256. padding: 0 12rpx;
  257. background-color: #f2f2f2;
  258. color: #333;
  259. font-size: 24rpx;
  260. line-height: 40rpx;
  261. border-radius: 40rpx;
  262. margin-top: 24rpx;
  263. }
  264. }
  265. }
  266. }
  267. .classify-wrap {
  268. // padding-bottom: 200rpx;
  269. }
  270. .btn {
  271. width: 100%;
  272. position: fixed;
  273. left: 0;
  274. bottom: 24rpx;
  275. padding: 0 24rpx;
  276. }
  277. </style>