shopProduct.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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="20"></uni-icons>
  9. <text>返回</text>
  10. </view>
  11. <view class="header-title">
  12. <text :max-lines="1" overflow="ellipsis">{{title}}</text>
  13. </view>
  14. <view class="header-right"></view>
  15. </view>
  16. <view class="search-head" @click="goSearch">
  17. <uni-search-bar readonly radius="100" placeholder="请输入商品名称/产品编码/原厂编码" textColor="#666" clearButton="auto" cancelButton="none" />
  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. if(this.categorySn!=null){
  210. this.searchList()
  211. }
  212. },
  213. // 自定义下拉刷新被中止
  214. onAbort(e){
  215. console.log('onAbort')
  216. this.triggered = false
  217. },
  218. // 滚动到底部
  219. reachBottom() {
  220. if(this.enableRefresh&&this.categorySn!=null){
  221. if(!this.loading && !this.loadEnd){
  222. if(!this.pulling){
  223. this.pageNo++
  224. this.getList()
  225. }
  226. }
  227. if(this.pulling){
  228. this.pulling = false
  229. }
  230. }
  231. },
  232. // 列表查询
  233. getList(){
  234. this.loading = true
  235. uni.showLoading({
  236. title: '加载中...',
  237. mask: true
  238. })
  239. const dealerSn = this.hasLogin && this.userInfo && this.userInfo.sysUserFlag == '1' ? this.$store.state.vuex_storeShelf.dealerSn : ''
  240. getShopProductList({
  241. pageNo: this.pageNo,
  242. pageSize: this.pageSize,
  243. queryWord: this.queryWord,
  244. categorySn: this.categorySn,
  245. dealerSn: dealerSn,
  246. status: 1
  247. }).then(res => {
  248. if(res.status == 200){
  249. this.total = Number(res.data.count)
  250. if(this.total){
  251. const list = res.data.list || []
  252. // 更新已选状态
  253. const ret = list.map(k => {
  254. const a = k.shopPromoProduct
  255. if(a){
  256. k.promoType = a.promoType
  257. k.resultValue = a.resultValue
  258. k.conditionValue = a.conditionValue
  259. k.discountType = a.discountType
  260. k.promoProductSn = a.promoProductSn
  261. k.promoSn = a.promoSn
  262. k.orginPrice = k.price
  263. // 特价
  264. if(k.promoType=='PROMO_PROD'){
  265. k.price = k.conditionValue
  266. }
  267. }
  268. return {
  269. id: k.id,
  270. price: k.price,
  271. orginPrice: k.orginPrice,
  272. priceStr: Number(k.price).toFixed(2).toString().split('.'),
  273. productCode: k.productCode,
  274. productSn: k.productSn,
  275. productImage: k.productMsg,
  276. productName: k.productName,
  277. productOrigCode: k.productOrigCode,
  278. categorySn: k.categorySn,
  279. hotFlag: k.hotFlag,
  280. productSn: k.productSn,
  281. priceType: k.priceType,
  282. shopProductSn: k.shopProductSn,
  283. status: k.status,
  284. statusDictValue: k.statusDictValue,
  285. dealerScopeFlag: k.dealerScopeFlag,
  286. promoType: k.promoType,
  287. resultValue: k.resultValue,
  288. conditionValue: k.conditionValue,
  289. discountType: k.discountType,
  290. promoProductSn: k.promoProductSn,
  291. promoSn: k.promoSn
  292. }
  293. })
  294. // 追加数据
  295. this.list.push(ret)
  296. // 判断是否最后一页
  297. const maxPages = Math.ceil(this.total / this.pageSize)
  298. if(this.pageNo >= maxPages){
  299. this.loadEnd = true
  300. this.loadText = '没有更多了'
  301. }
  302. }else{
  303. this.loadEnd = false
  304. this.loadText = '没有找到相关产品'
  305. }
  306. }else{
  307. this.loadEnd = false
  308. this.loadText = res.message
  309. }
  310. uni.hideLoading()
  311. this.loading = false
  312. }).catch(err => {
  313. this.loading = false
  314. })
  315. },
  316. // 产品详情查看
  317. viewDetail(item){
  318. uni.navigateTo({
  319. url:'/pagesB/shopiing/productDetail?sn='+item.shopProductSn
  320. })
  321. }
  322. }
  323. }
  324. </script>
  325. <style lang="less">
  326. .pages{
  327. height: 100vh;
  328. display: flex;
  329. flex-direction: column;
  330. .scrollPage-header{
  331. z-index: 1;
  332. .header-title-box{
  333. display: flex;
  334. align-items: center;
  335. padding: 0 10px;
  336. height: 44px;
  337. background-color: #FFFFFF;
  338. border-bottom: 1px solid #e8e8e8;
  339. .header-title{
  340. flex-grow: 1;
  341. color: #333333;
  342. padding: 10px;
  343. text-align: center;
  344. }
  345. .header-left{
  346. display: flex;
  347. align-items: center;
  348. text{
  349. font-size: 14px;
  350. color: #333333;
  351. margin-left: 5px;
  352. }
  353. }
  354. .header-right{
  355. width: 50px;
  356. }
  357. }
  358. }
  359. .search-head{
  360. background-color: #FFFFFF;
  361. /deep/ .uni-searchbar{
  362. padding: 5px 6px;
  363. }
  364. }
  365. .search-result{
  366. flex-grow: 1;
  367. display: flex;
  368. justify-content: space-between;
  369. .tab-left{
  370. width: 25%;
  371. flex-grow: 1;
  372. background: #FFFFFF;
  373. .item-clz{
  374. font-size: 14px;
  375. padding: 8px 10px;
  376. line-height: 30px;
  377. }
  378. .active{
  379. border-left: 3px solid #00aaff;
  380. background: #f8f8f8;
  381. }
  382. }
  383. .right-box{
  384. width: 75%;
  385. .scrollPage-body{
  386. width:100%;
  387. .uni-searchbar{
  388. background-color: #FFFFFF;
  389. }
  390. /deep/ .choose-product-item{
  391. background-color: #FFFFFF;
  392. margin: 6px 10px;
  393. border-radius: 6px;
  394. }
  395. .loading-bar{
  396. text-align: center;
  397. padding: 10px 0;
  398. color: #999999;
  399. }
  400. .empty-bar{
  401. display: flex;
  402. flex-direction: column;
  403. align-items: center;
  404. justify-content: center;
  405. padding: 20px 0;
  406. image{
  407. width: 100px;
  408. height: 100px;
  409. }
  410. view{
  411. font-size: 12px;
  412. color: #999999;
  413. }
  414. }
  415. .search-history{
  416. padding: 0 1.5rem;
  417. .search-history-title{
  418. display: flex;
  419. align-items: center;
  420. justify-content: space-between;
  421. padding: 6px 0;
  422. font-size: 14px;
  423. color: #333333;
  424. border-bottom: 1px solid #E6E6E6;
  425. }
  426. .search-history-right{
  427. display: flex;
  428. align-items: center;
  429. }
  430. .search-history-expend{
  431. display: flex;
  432. align-items: center;
  433. font-size: 12px;
  434. margin-right: 15px;
  435. }
  436. .search-history-body{
  437. display: flex;
  438. flex-wrap: wrap;
  439. align-items: center;
  440. justify-content: space-between;
  441. padding: 10px 10px;
  442. .item{
  443. padding: 6px 0;
  444. background-color: #f8f8f8;
  445. border-radius: 20px;
  446. font-size: 12px;
  447. color: #333333;
  448. width: 46%;
  449. }
  450. }
  451. }
  452. }
  453. .right-item{
  454. /deep/ .choose-product-item{
  455. margin: 5px 8px;
  456. .choose-product-item-img{
  457. height: 130rpx;
  458. }
  459. .choose-product-item-img .choose-product-item-left-info-code{
  460. font-size:12px;
  461. }
  462. .choose-product-item-info .choose-product-item-left-info-name{
  463. font-weight: normal;
  464. }
  465. }
  466. }
  467. }
  468. }
  469. }
  470. </style>