shopProduct.vue 12 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">
  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 { getShopCategoryExt, 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. if(opts.clzId==''){
  130. this.title = '商城商品搜索'
  131. this.focus = true
  132. }else{
  133. // 分类下产品
  134. this.title = opts.clzName
  135. // 查二级目录
  136. this.getCategory()
  137. }
  138. },
  139. methods: {
  140. // 返回
  141. goBack(){
  142. uni.navigateBack()
  143. },
  144. // 去搜索产品
  145. goSearch(event){
  146. uni.navigateTo({
  147. url:'/pagesB/shopiing/searchProduct?queryWord='+event.value+'&clzId='
  148. })
  149. },
  150. // 获取二级目录
  151. getCategory(){
  152. getShopCategoryExt({
  153. categorySn: this.clzId,
  154. status: 1
  155. }).then(res => {
  156. if(res.status == 200){
  157. // 二级目录
  158. this.categoryList = res.data && res.data.shopCategoryList ? res.data.shopCategoryList : []
  159. // 如果有二级目录
  160. if(this.categoryList.length > 0){
  161. // this.categoryList.unshift({
  162. // categorySn: this.clzId,
  163. // categoryName: '全部'
  164. // })
  165. // 默认显示第一个
  166. this.categorySn = this.categoryList[0].categorySn
  167. // 目录下商品
  168. this.searchList()
  169. }else{
  170. // 禁用下拉刷新
  171. this.enableRefresh = false
  172. // 只有产品
  173. const list = res.data && res.data.shopProductList ? res.data.shopProductList : []
  174. this.total = list.length
  175. // 更新已选状态
  176. for(let i=0;i<list.length;i=i+this.pageSize){
  177. // 追加数据
  178. this.list.push(list.slice(i,(i+this.pageSize)>list.length?list.length:(i+this.pageSize)).map(k=>{
  179. return {
  180. id: k.id,
  181. price: k.price,
  182. productCode: k.productCode,
  183. productSn: k.productSn,
  184. productImage: k.productMsg,
  185. productName: k.productName,
  186. productOrigCode: k.productOrigCode,
  187. categorySn: k.categorySn,
  188. hotFlag: k.hotFlag,
  189. productSn: k.productSn,
  190. priceType: k.priceType,
  191. shopProductSn: k.shopProductSn,
  192. status: k.status,
  193. statusDictValue: k.statusDictValue,
  194. dealerScopeFlag: k.dealerScopeFlag
  195. }
  196. }))
  197. }
  198. this.loadEnd = true
  199. this.loadText = '没有更多了'
  200. }
  201. }else{
  202. uni.showToast({
  203. title: res.message,
  204. icon: 'none'
  205. })
  206. }
  207. })
  208. },
  209. // 搜索列表
  210. searchList(event) {
  211. this.loadEnd = false
  212. this.loadText = '加载中...'
  213. this.list = []
  214. this.pageNo = 1
  215. this.getList()
  216. },
  217. // 单击二级分类
  218. handleTab(item){
  219. this.categorySn = item.categorySn
  220. this.queryWord = ''
  221. this.searchList()
  222. },
  223. // 自定义下拉刷新控件被下拉
  224. onPulling(e){
  225. console.log('onPulling')
  226. this.triggered = true
  227. this.pulling = true
  228. },
  229. // 自定义下拉刷新被触发
  230. onRefresh(e){
  231. console.log('onRefresh')
  232. setTimeout(() => {
  233. this.triggered = false
  234. }, 500);
  235. },
  236. // 自定义下拉刷新被复位
  237. onRestore(e){
  238. console.log('onRestore')
  239. this.queryWord = ''
  240. this.searchList()
  241. },
  242. // 自定义下拉刷新被中止
  243. onAbort(e){
  244. console.log('onAbort')
  245. this.triggered = false
  246. },
  247. // 滚动到底部
  248. reachBottom() {
  249. console.log('reachBottom',this.pulling)
  250. if(this.enableRefresh){
  251. if(!this.loading && !this.loadEnd && !this.pulling){
  252. this.pageNo++
  253. this.getList()
  254. }
  255. if(this.pulling){
  256. this.pulling = false
  257. }
  258. }
  259. },
  260. // 列表查询
  261. getList(){
  262. this.loading = true
  263. const dealerSn = this.hasLogin && this.userInfo && this.userInfo.sysUserFlag == '1' ? this.$store.state.vuex_storeShelf.dealerSn : ''
  264. getShopProductList({
  265. pageNo: this.pageNo,
  266. pageSize: this.pageSize,
  267. queryWord: this.queryWord,
  268. categorySn: this.categorySn,
  269. dealerSn: dealerSn,
  270. categoryStatus : 1,
  271. status: 1
  272. }).then(res => {
  273. this.loading = false
  274. if(res.status == 200){
  275. this.total = Number(res.data.count)
  276. if(this.total){
  277. const list = res.data.list || []
  278. const ret = []
  279. // 更新已选状态
  280. list.forEach(k => {
  281. ret.push({
  282. id: k.id,
  283. price: k.price,
  284. productCode: k.productCode,
  285. productSn: k.productSn,
  286. productImage: k.productMsg,
  287. productName: k.productName,
  288. productOrigCode: k.productOrigCode,
  289. categorySn: k.categorySn,
  290. hotFlag: k.hotFlag,
  291. productSn: k.productSn,
  292. priceType: k.priceType,
  293. shopProductSn: k.shopProductSn,
  294. status: k.status,
  295. statusDictValue: k.statusDictValue,
  296. dealerScopeFlag: k.dealerScopeFlag
  297. })
  298. })
  299. // 追加数据
  300. this.list.push(ret)
  301. // 判断是否最后一页
  302. const maxPages = Math.ceil(this.total / this.pageSize)
  303. if(this.pageNo >= maxPages){
  304. this.loadEnd = true
  305. this.loadText = '没有更多了'
  306. }
  307. }else{
  308. this.loadEnd = false
  309. this.loadText = '没有找到相关产品'
  310. }
  311. }else{
  312. this.loadEnd = false
  313. this.loadText = res.message
  314. }
  315. }).catch(err => {
  316. this.loading = false
  317. })
  318. },
  319. // 产品详情查看
  320. viewDetail(item){
  321. uni.navigateTo({
  322. url:'/pagesB/shopiing/productDetail?sn='+item.shopProductSn
  323. })
  324. }
  325. }
  326. }
  327. </script>
  328. <style lang="less">
  329. .pages{
  330. height: 100vh;
  331. display: flex;
  332. flex-direction: column;
  333. .scrollPage-header{
  334. z-index: 1;
  335. .header-title{
  336. display: flex;
  337. align-items: center;
  338. justify-content: space-between;
  339. padding: 0 10px;
  340. height: 44px;
  341. background-color: #FFFFFF;
  342. box-shadow: 0px 1px 0px 0px #E6E6E6;
  343. .header-title{
  344. font-size: 16px;
  345. color: #333333;
  346. max-width: 70%;
  347. }
  348. .header-left{
  349. display: flex;
  350. align-items: center;
  351. text{
  352. font-size: 14px;
  353. color: #333333;
  354. margin-left: 5px;
  355. }
  356. }
  357. .header-right{
  358. width: 50px;
  359. }
  360. }
  361. }
  362. .search-head{
  363. background-color: #FFFFFF;
  364. /deep/ .uni-searchbar{
  365. padding: 5px 6px;
  366. }
  367. }
  368. .search-result{
  369. flex-grow: 1;
  370. display: flex;
  371. justify-content: space-between;
  372. .tab-left{
  373. width: 25%;
  374. flex-grow: 1;
  375. background: #FFFFFF;
  376. .item-clz{
  377. font-size: 14px;
  378. padding: 8px 10px;
  379. line-height: 30px;
  380. }
  381. .active{
  382. border-left: 3px solid #00aaff;
  383. background: #f8f8f8;
  384. }
  385. }
  386. .right-box{
  387. width: 75%;
  388. .scrollPage-body{
  389. width:100%;
  390. .uni-searchbar{
  391. background-color: #FFFFFF;
  392. }
  393. /deep/ .choose-product-item{
  394. background-color: #FFFFFF;
  395. margin: 6px 10px;
  396. border-radius: 10px;
  397. }
  398. .loading-bar{
  399. text-align: center;
  400. padding: 10px 0;
  401. color: #999999;
  402. }
  403. .empty-bar{
  404. display: flex;
  405. flex-direction: column;
  406. align-items: center;
  407. justify-content: center;
  408. padding: 20px 0;
  409. image{
  410. width: 100px;
  411. height: 100px;
  412. }
  413. view{
  414. font-size: 12px;
  415. color: #999999;
  416. }
  417. }
  418. .search-history{
  419. padding: 0 1.5rem;
  420. .search-history-title{
  421. display: flex;
  422. align-items: center;
  423. justify-content: space-between;
  424. padding: 6px 0;
  425. font-size: 14px;
  426. color: #333333;
  427. border-bottom: 1px solid #E6E6E6;
  428. }
  429. .search-history-right{
  430. display: flex;
  431. align-items: center;
  432. }
  433. .search-history-expend{
  434. display: flex;
  435. align-items: center;
  436. font-size: 12px;
  437. margin-right: 15px;
  438. }
  439. .search-history-body{
  440. display: flex;
  441. flex-wrap: wrap;
  442. align-items: center;
  443. justify-content: space-between;
  444. padding: 10px 10px;
  445. .item{
  446. padding: 6px 0;
  447. background-color: #f8f8f8;
  448. border-radius: 20px;
  449. font-size: 12px;
  450. color: #333333;
  451. width: 46%;
  452. }
  453. }
  454. }
  455. }
  456. .right-item{
  457. /deep/ .choose-product-item{
  458. margin: 5px 8px;
  459. .choose-product-item-img{
  460. height: 130rpx;
  461. }
  462. .choose-product-item-info .choose-product-item-left-info-name{
  463. font-weight: normal;
  464. }
  465. }
  466. }
  467. }
  468. }
  469. }
  470. </style>