shopProduct.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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. // 特价
  263. if(k.promoType=='PROMO_PROD'){
  264. k.orginPrice = k.price
  265. // 直降
  266. if(k.discountType == 'STRAIGHT_DOWN'){
  267. k.price = k.price - k.resultValue
  268. }
  269. // 折扣
  270. if(k.discountType == 'DISCOUNT'){
  271. k.price = Number(k.price * k.resultValue).toFixed(2)
  272. }
  273. }
  274. }
  275. return {
  276. id: k.id,
  277. price: k.price,
  278. orginPrice: k.orginPrice,
  279. priceStr: Number(k.price).toFixed(2).toString().split('.'),
  280. productCode: k.productCode,
  281. productSn: k.productSn,
  282. productImage: k.productMsg,
  283. productName: k.productName,
  284. productOrigCode: k.productOrigCode,
  285. categorySn: k.categorySn,
  286. hotFlag: k.hotFlag,
  287. productSn: k.productSn,
  288. priceType: k.priceType,
  289. shopProductSn: k.shopProductSn,
  290. status: k.status,
  291. statusDictValue: k.statusDictValue,
  292. dealerScopeFlag: k.dealerScopeFlag,
  293. promoType: k.promoType,
  294. resultValue: k.resultValue,
  295. conditionValue: k.conditionValue,
  296. discountType: k.discountType,
  297. promoProductSn: k.promoProductSn,
  298. promoSn: k.promoSn
  299. }
  300. })
  301. // 追加数据
  302. this.list.push(ret)
  303. // 判断是否最后一页
  304. const maxPages = Math.ceil(this.total / this.pageSize)
  305. if(this.pageNo >= maxPages){
  306. this.loadEnd = true
  307. this.loadText = '没有更多了'
  308. }
  309. }else{
  310. this.loadEnd = false
  311. this.loadText = '没有找到相关产品'
  312. }
  313. }else{
  314. this.loadEnd = false
  315. this.loadText = res.message
  316. }
  317. uni.hideLoading()
  318. this.loading = false
  319. }).catch(err => {
  320. this.loading = false
  321. })
  322. },
  323. // 产品详情查看
  324. viewDetail(item){
  325. uni.navigateTo({
  326. url:'/pagesB/shopiing/productDetail?sn='+item.shopProductSn
  327. })
  328. }
  329. }
  330. }
  331. </script>
  332. <style lang="less">
  333. .pages{
  334. height: 100vh;
  335. display: flex;
  336. flex-direction: column;
  337. .scrollPage-header{
  338. z-index: 1;
  339. .header-title-box{
  340. display: flex;
  341. align-items: center;
  342. padding: 0 10px;
  343. height: 44px;
  344. background-color: #FFFFFF;
  345. border-bottom: 1px solid #e8e8e8;
  346. .header-title{
  347. flex-grow: 1;
  348. color: #333333;
  349. padding: 10px;
  350. text-align: center;
  351. }
  352. .header-left{
  353. display: flex;
  354. align-items: center;
  355. text{
  356. font-size: 14px;
  357. color: #333333;
  358. margin-left: 5px;
  359. }
  360. }
  361. .header-right{
  362. width: 50px;
  363. }
  364. }
  365. }
  366. .search-head{
  367. background-color: #FFFFFF;
  368. /deep/ .uni-searchbar{
  369. padding: 5px 6px;
  370. }
  371. }
  372. .search-result{
  373. flex-grow: 1;
  374. display: flex;
  375. justify-content: space-between;
  376. .tab-left{
  377. width: 25%;
  378. flex-grow: 1;
  379. background: #FFFFFF;
  380. .item-clz{
  381. font-size: 14px;
  382. padding: 8px 10px;
  383. line-height: 30px;
  384. }
  385. .active{
  386. border-left: 3px solid #00aaff;
  387. background: #f8f8f8;
  388. }
  389. }
  390. .right-box{
  391. width: 75%;
  392. .scrollPage-body{
  393. width:100%;
  394. .uni-searchbar{
  395. background-color: #FFFFFF;
  396. }
  397. /deep/ .choose-product-item{
  398. background-color: #FFFFFF;
  399. margin: 6px 10px;
  400. border-radius: 6px;
  401. }
  402. .loading-bar{
  403. text-align: center;
  404. padding: 10px 0;
  405. color: #999999;
  406. }
  407. .empty-bar{
  408. display: flex;
  409. flex-direction: column;
  410. align-items: center;
  411. justify-content: center;
  412. padding: 20px 0;
  413. image{
  414. width: 100px;
  415. height: 100px;
  416. }
  417. view{
  418. font-size: 12px;
  419. color: #999999;
  420. }
  421. }
  422. .search-history{
  423. padding: 0 1.5rem;
  424. .search-history-title{
  425. display: flex;
  426. align-items: center;
  427. justify-content: space-between;
  428. padding: 6px 0;
  429. font-size: 14px;
  430. color: #333333;
  431. border-bottom: 1px solid #E6E6E6;
  432. }
  433. .search-history-right{
  434. display: flex;
  435. align-items: center;
  436. }
  437. .search-history-expend{
  438. display: flex;
  439. align-items: center;
  440. font-size: 12px;
  441. margin-right: 15px;
  442. }
  443. .search-history-body{
  444. display: flex;
  445. flex-wrap: wrap;
  446. align-items: center;
  447. justify-content: space-between;
  448. padding: 10px 10px;
  449. .item{
  450. padding: 6px 0;
  451. background-color: #f8f8f8;
  452. border-radius: 20px;
  453. font-size: 12px;
  454. color: #333333;
  455. width: 46%;
  456. }
  457. }
  458. }
  459. }
  460. .right-item{
  461. /deep/ .choose-product-item{
  462. margin: 5px 8px;
  463. .choose-product-item-img{
  464. height: 130rpx;
  465. }
  466. .choose-product-item-img .choose-product-item-left-info-code{
  467. font-size:12px;
  468. }
  469. .choose-product-item-info .choose-product-item-left-info-name{
  470. font-weight: normal;
  471. }
  472. }
  473. }
  474. }
  475. }
  476. }
  477. </style>