commodity.vue 6.9 KB

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