shopProduct.vue 11 KB

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