shopProduct.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. <template>
  2. <view class="pages">
  3. <!-- head -->
  4. <view class="scrollPage-header">
  5. <view :style="{height:statusBarHeight+'px'}"></view>
  6. <view class="header-title-box">
  7. <view class="header-left" @click="goBack">
  8. <uni-icons type="arrowleft" size="16"></uni-icons>
  9. <text>返回</text>
  10. </view>
  11. <view class="search-head" @click="goSearch">
  12. <uni-search-bar readonly radius="100" placeholder="请输入商品名称/产品编码/原厂编码" textColor="#666" clearButton="auto" cancelButton="none" />
  13. </view>
  14. <view></view>
  15. </view>
  16. <view class="header-title">
  17. <text :max-lines="1" overflow="ellipsis">{{title}}</text>
  18. </view>
  19. </view>
  20. <view class="search-result">
  21. <view class="tab-left" v-if="clzId&&categoryList.length>0">
  22. <scroll-view
  23. :style="{height: (screenHeight - statusBarHeight - 44 - 43) + 'px'}"
  24. scroll-y="true"
  25. :bounces="false"
  26. type="list"
  27. >
  28. <view class="item-clz"
  29. v-for="item in categoryList"
  30. :key="item.categorySn"
  31. :class="item.categorySn==categorySn?'active':''"
  32. @click="handleTab(item)">
  33. {{item.categoryName}}
  34. </view>
  35. </scroll-view>
  36. </view>
  37. <view class="right-box" :style="{width:clzId&&categoryList.length?'75%':'100%'}">
  38. <!-- body -->
  39. <scroll-view
  40. class="scrollPage-body"
  41. :class="clzId&&categoryList.length?'right-item':''"
  42. :style="{height: (screenHeight - statusBarHeight - 44 - 43) + 'px'}"
  43. scroll-y="true"
  44. type="list"
  45. :bounces="false"
  46. :refresher-enabled="enableRefresh"
  47. :refresher-triggered="triggered"
  48. @refresherpulling="onPulling"
  49. @refresherrefresh="onRefresh"
  50. @refresherrestore="onRestore"
  51. @refresherabort="onAbort"
  52. @scrolltolower="reachBottom">
  53. <!-- 产品列表 -->
  54. <chooseProductItem
  55. v-for="(item, index) in list"
  56. :key="item.id"
  57. :index="index"
  58. :list="item"
  59. :isLogin="hasLogin"
  60. @toDetail="viewDetail"
  61. >
  62. </chooseProductItem>
  63. <!-- loading -->
  64. <view class="loading-bar" v-if="total>0 && (loading||loadEnd)">{{loadText}}</view>
  65. <view class="empty-bar" v-if="total==0&&!loading">
  66. <image mode="aspectFit" :src="empty.imgUrl"></image>
  67. <view>{{empty.tip}}</view>
  68. </view>
  69. </scroll-view>
  70. </view>
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. import {
  76. mapState,
  77. mapMutations,
  78. } from 'vuex'
  79. import chooseProductItem from '@/pagesB/components/chooseProductItemSkline.vue'
  80. import { getShopCategory, getShopProductList } from '@/api/shop.js'
  81. export default {
  82. components:{
  83. chooseProductItem
  84. },
  85. data() {
  86. return {
  87. title: '',
  88. loadText: '加载中...',
  89. empty: {
  90. tip: '暂无商品',
  91. imgUrl: '/static/nodata.png'
  92. },
  93. queryWord:'',
  94. screenWidth: 325,
  95. screenHeight: 0,
  96. statusBarHeight: 44,
  97. safeAreaBottom: 0,
  98. pageSize: 10,
  99. pageNo:1,
  100. total:0,
  101. list: [],
  102. loading:false,
  103. loadEnd: false,
  104. focus: false,
  105. expend: false,
  106. clzId: null, // 一级分类
  107. categorySn: null ,// 当前分类sn
  108. categoryList: [], // 二级分类列表
  109. enableRefresh: true,
  110. triggered: false,
  111. pulling: false
  112. };
  113. },
  114. computed: {
  115. ...mapState(['hasLogin']),
  116. // 登录用户信息
  117. userInfo(){
  118. return this.$store.state.vuex_userInfo
  119. },
  120. },
  121. onLoad(opts) {
  122. // 计算区域高度
  123. this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight
  124. this.screenWidth = uni.getSystemInfoSync().windowWidth
  125. this.screenHeight = uni.getSystemInfoSync().windowHeight
  126. this.safeAreaBottom = uni.getSystemInfoSync().safeAreaInsets.bottom
  127. // 一级分类id
  128. this.clzId = opts.clzId
  129. // 一级分类名称
  130. this.title = opts.clzName
  131. // 一级分类下是二级目录
  132. if(opts.shopCategoryCount>0){
  133. // 查二级目录
  134. this.getCategory()
  135. }
  136. // 一级分类下是产品
  137. if(opts.shopProductCount>0){
  138. this.categorySn = opts.clzId
  139. // 目录下商品
  140. this.searchList()
  141. }
  142. },
  143. methods: {
  144. // 返回
  145. goBack(){
  146. uni.navigateBack()
  147. },
  148. // 去搜索产品
  149. goSearch(event){
  150. uni.navigateTo({
  151. url:'/pagesB/shopiing/searchProduct?queryWord='+event.value+'&clzId='
  152. })
  153. },
  154. // 获取二级目录
  155. getCategory(){
  156. getShopCategory({
  157. parentSn: this.clzId,
  158. categoryLevel: 2
  159. }).then(res => {
  160. if(res.status == 200){
  161. // 二级目录
  162. this.categoryList = res.data || []
  163. // 如果有二级目录
  164. if(this.categoryList.length > 0){
  165. // 默认显示第一个
  166. this.categorySn = this.categoryList[0].categorySn
  167. // 目录下商品
  168. this.searchList()
  169. }
  170. }else{
  171. uni.showToast({
  172. title: res.message,
  173. icon: 'none'
  174. })
  175. }
  176. })
  177. },
  178. // 搜索列表
  179. searchList(event) {
  180. this.loadEnd = false
  181. this.loadText = '加载中...'
  182. this.list = []
  183. this.pageNo = 1
  184. this.getList()
  185. },
  186. // 单击二级分类
  187. handleTab(item){
  188. this.categorySn = item.categorySn
  189. this.queryWord = ''
  190. this.searchList()
  191. },
  192. // 自定义下拉刷新控件被下拉
  193. onPulling(e){
  194. console.log('onPulling')
  195. this.triggered = true
  196. this.pulling = true
  197. },
  198. // 自定义下拉刷新被触发
  199. onRefresh(e){
  200. console.log('onRefresh')
  201. setTimeout(() => {
  202. this.triggered = false
  203. }, 500);
  204. },
  205. // 自定义下拉刷新被复位
  206. onRestore(e){
  207. console.log('onRestore')
  208. this.queryWord = ''
  209. this.searchList()
  210. },
  211. // 自定义下拉刷新被中止
  212. onAbort(e){
  213. console.log('onAbort')
  214. this.triggered = false
  215. },
  216. // 滚动到底部
  217. reachBottom() {
  218. console.log('reachBottom',this.pulling)
  219. if(this.enableRefresh){
  220. if(!this.loading && !this.loadEnd && !this.pulling){
  221. this.pageNo++
  222. this.getList()
  223. }
  224. if(this.pulling){
  225. this.pulling = false
  226. }
  227. }
  228. },
  229. // 列表查询
  230. getList(){
  231. this.loading = true
  232. uni.showLoading({
  233. title: '加载中...',
  234. mask: true
  235. })
  236. const dealerSn = this.hasLogin && this.userInfo && this.userInfo.sysUserFlag == '1' ? this.$store.state.vuex_storeShelf.dealerSn : ''
  237. getShopProductList({
  238. pageNo: this.pageNo,
  239. pageSize: this.pageSize,
  240. queryWord: this.queryWord,
  241. categorySn: this.categorySn,
  242. dealerSn: dealerSn,
  243. status: 1
  244. }).then(res => {
  245. if(res.status == 200){
  246. this.total = Number(res.data.count)
  247. if(this.total){
  248. const list = res.data.list || []
  249. // 更新已选状态
  250. const ret = list.map(k => {
  251. return {
  252. id: k.id,
  253. price: k.price,
  254. productCode: k.productCode,
  255. productSn: k.productSn,
  256. productImage: k.productMsg,
  257. productName: k.productName,
  258. productOrigCode: k.productOrigCode,
  259. categorySn: k.categorySn,
  260. hotFlag: k.hotFlag,
  261. productSn: k.productSn,
  262. priceType: k.priceType,
  263. shopProductSn: k.shopProductSn,
  264. status: k.status,
  265. statusDictValue: k.statusDictValue,
  266. dealerScopeFlag: k.dealerScopeFlag
  267. }
  268. })
  269. // 追加数据
  270. this.list.push(ret)
  271. // 判断是否最后一页
  272. const maxPages = Math.ceil(this.total / this.pageSize)
  273. if(this.pageNo >= maxPages){
  274. this.loadEnd = true
  275. this.loadText = '没有更多了'
  276. }
  277. }else{
  278. this.loadEnd = false
  279. this.loadText = '没有找到相关产品'
  280. }
  281. }else{
  282. this.loadEnd = false
  283. this.loadText = res.message
  284. }
  285. uni.hideLoading()
  286. this.loading = false
  287. }).catch(err => {
  288. this.loading = false
  289. })
  290. },
  291. // 产品详情查看
  292. viewDetail(item){
  293. uni.navigateTo({
  294. url:'/pagesB/shopiing/productDetail?sn='+item.shopProductSn
  295. })
  296. }
  297. }
  298. }
  299. </script>
  300. <style lang="less">
  301. .pages{
  302. height: 100vh;
  303. display: flex;
  304. flex-direction: column;
  305. .scrollPage-header{
  306. z-index: 1;
  307. .header-title-box{
  308. display: flex;
  309. align-items: center;
  310. padding: 0 10px;
  311. height: 44px;
  312. background-color: #FFFFFF;
  313. border-bottom: 1px solid #e8e8e8;
  314. .search-head{
  315. flex-grow: 1;
  316. /deep/ .uni-searchbar{
  317. padding: 0 6px;
  318. }
  319. /deep/ .uni-searchbar .uni-searchbar__box{
  320. height: 30px;
  321. }
  322. }
  323. .header-left{
  324. display: flex;
  325. align-items: center;
  326. text{
  327. font-size: 14px;
  328. color: #333333;
  329. margin-left: 5px;
  330. }
  331. }
  332. .header-right{
  333. width: 50px;
  334. }
  335. }
  336. }
  337. .header-title{
  338. background-color: #FFFFFF;
  339. color: #333333;
  340. padding: 10px;
  341. text-align: center;
  342. }
  343. .search-result{
  344. flex-grow: 1;
  345. display: flex;
  346. justify-content: space-between;
  347. .tab-left{
  348. width: 25%;
  349. flex-grow: 1;
  350. background: #FFFFFF;
  351. .item-clz{
  352. font-size: 14px;
  353. padding: 8px 10px;
  354. line-height: 30px;
  355. }
  356. .active{
  357. border-left: 3px solid #00aaff;
  358. background: #f8f8f8;
  359. }
  360. }
  361. .right-box{
  362. width: 75%;
  363. .scrollPage-body{
  364. width:100%;
  365. .uni-searchbar{
  366. background-color: #FFFFFF;
  367. }
  368. /deep/ .choose-product-item{
  369. background-color: #FFFFFF;
  370. margin: 6px 10px;
  371. border-radius: 6px;
  372. }
  373. .loading-bar{
  374. text-align: center;
  375. padding: 10px 0;
  376. color: #999999;
  377. }
  378. .empty-bar{
  379. display: flex;
  380. flex-direction: column;
  381. align-items: center;
  382. justify-content: center;
  383. padding: 20px 0;
  384. image{
  385. width: 100px;
  386. height: 100px;
  387. }
  388. view{
  389. font-size: 12px;
  390. color: #999999;
  391. }
  392. }
  393. .search-history{
  394. padding: 0 1.5rem;
  395. .search-history-title{
  396. display: flex;
  397. align-items: center;
  398. justify-content: space-between;
  399. padding: 6px 0;
  400. font-size: 14px;
  401. color: #333333;
  402. border-bottom: 1px solid #E6E6E6;
  403. }
  404. .search-history-right{
  405. display: flex;
  406. align-items: center;
  407. }
  408. .search-history-expend{
  409. display: flex;
  410. align-items: center;
  411. font-size: 12px;
  412. margin-right: 15px;
  413. }
  414. .search-history-body{
  415. display: flex;
  416. flex-wrap: wrap;
  417. align-items: center;
  418. justify-content: space-between;
  419. padding: 10px 10px;
  420. .item{
  421. padding: 6px 0;
  422. background-color: #f8f8f8;
  423. border-radius: 20px;
  424. font-size: 12px;
  425. color: #333333;
  426. width: 46%;
  427. }
  428. }
  429. }
  430. }
  431. .right-item{
  432. /deep/ .choose-product-item{
  433. margin: 5px 8px;
  434. .choose-product-item-img{
  435. height: 130rpx;
  436. }
  437. .choose-product-item-img .choose-product-item-left-info-code{
  438. font-size:12px;
  439. }
  440. .choose-product-item-info .choose-product-item-left-info-name{
  441. font-weight: normal;
  442. }
  443. }
  444. }
  445. }
  446. }
  447. }
  448. </style>