shopProduct.vue 11 KB

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