shopProduct.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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: false,
  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. const dealerSn = this.hasLogin && this.userInfo && this.userInfo.sysUserFlag == '1' ? this.$store.state.vuex_storeShelf.dealerSn : ''
  232. getShopProductList({
  233. pageNo: this.pageNo,
  234. pageSize: this.pageSize,
  235. queryWord: this.queryWord,
  236. categorySn: this.categorySn,
  237. dealerSn: dealerSn,
  238. status: 1
  239. }).then(res => {
  240. if(res.status == 200){
  241. this.total = Number(res.data.count)
  242. if(this.total){
  243. const list = res.data.list || []
  244. // 更新已选状态
  245. const ret = list.map(k => {
  246. return {
  247. id: k.id,
  248. price: k.price,
  249. productCode: k.productCode,
  250. productSn: k.productSn,
  251. productImage: k.productMsg,
  252. productName: k.productName,
  253. productOrigCode: k.productOrigCode,
  254. categorySn: k.categorySn,
  255. hotFlag: k.hotFlag,
  256. productSn: k.productSn,
  257. priceType: k.priceType,
  258. shopProductSn: k.shopProductSn,
  259. status: k.status,
  260. statusDictValue: k.statusDictValue,
  261. dealerScopeFlag: k.dealerScopeFlag
  262. }
  263. })
  264. // 追加数据
  265. this.list.push(ret)
  266. // 判断是否最后一页
  267. const maxPages = Math.ceil(this.total / this.pageSize)
  268. if(this.pageNo >= maxPages){
  269. this.loadEnd = true
  270. this.loadText = '没有更多了'
  271. }
  272. }else{
  273. this.loadEnd = false
  274. this.loadText = '没有找到相关产品'
  275. }
  276. }else{
  277. this.loadEnd = false
  278. this.loadText = res.message
  279. }
  280. this.loading = false
  281. }).catch(err => {
  282. this.loading = false
  283. })
  284. },
  285. // 产品详情查看
  286. viewDetail(item){
  287. uni.navigateTo({
  288. url:'/pagesB/shopiing/productDetail?sn='+item.shopProductSn
  289. })
  290. }
  291. }
  292. }
  293. </script>
  294. <style lang="less">
  295. .pages{
  296. height: 100vh;
  297. display: flex;
  298. flex-direction: column;
  299. .scrollPage-header{
  300. z-index: 1;
  301. .header-title{
  302. display: flex;
  303. align-items: center;
  304. justify-content: space-between;
  305. padding: 0 10px;
  306. height: 44px;
  307. background-color: #FFFFFF;
  308. box-shadow: 0px 1px 0px 0px #E6E6E6;
  309. .header-title{
  310. font-size: 16px;
  311. color: #333333;
  312. max-width: 70%;
  313. }
  314. .header-left{
  315. display: flex;
  316. align-items: center;
  317. text{
  318. font-size: 14px;
  319. color: #333333;
  320. margin-left: 5px;
  321. }
  322. }
  323. .header-right{
  324. width: 50px;
  325. }
  326. }
  327. }
  328. .search-head{
  329. background-color: #FFFFFF;
  330. /deep/ .uni-searchbar{
  331. padding: 5px 6px;
  332. }
  333. }
  334. .search-result{
  335. flex-grow: 1;
  336. display: flex;
  337. justify-content: space-between;
  338. .tab-left{
  339. width: 25%;
  340. flex-grow: 1;
  341. background: #FFFFFF;
  342. .item-clz{
  343. font-size: 14px;
  344. padding: 8px 10px;
  345. line-height: 30px;
  346. }
  347. .active{
  348. border-left: 3px solid #00aaff;
  349. background: #f8f8f8;
  350. }
  351. }
  352. .right-box{
  353. width: 75%;
  354. .scrollPage-body{
  355. width:100%;
  356. .uni-searchbar{
  357. background-color: #FFFFFF;
  358. }
  359. /deep/ .choose-product-item{
  360. background-color: #FFFFFF;
  361. margin: 6px 10px;
  362. border-radius: 10px;
  363. }
  364. .loading-bar{
  365. text-align: center;
  366. padding: 10px 0;
  367. color: #999999;
  368. }
  369. .empty-bar{
  370. display: flex;
  371. flex-direction: column;
  372. align-items: center;
  373. justify-content: center;
  374. padding: 20px 0;
  375. image{
  376. width: 100px;
  377. height: 100px;
  378. }
  379. view{
  380. font-size: 12px;
  381. color: #999999;
  382. }
  383. }
  384. .search-history{
  385. padding: 0 1.5rem;
  386. .search-history-title{
  387. display: flex;
  388. align-items: center;
  389. justify-content: space-between;
  390. padding: 6px 0;
  391. font-size: 14px;
  392. color: #333333;
  393. border-bottom: 1px solid #E6E6E6;
  394. }
  395. .search-history-right{
  396. display: flex;
  397. align-items: center;
  398. }
  399. .search-history-expend{
  400. display: flex;
  401. align-items: center;
  402. font-size: 12px;
  403. margin-right: 15px;
  404. }
  405. .search-history-body{
  406. display: flex;
  407. flex-wrap: wrap;
  408. align-items: center;
  409. justify-content: space-between;
  410. padding: 10px 10px;
  411. .item{
  412. padding: 6px 0;
  413. background-color: #f8f8f8;
  414. border-radius: 20px;
  415. font-size: 12px;
  416. color: #333333;
  417. width: 46%;
  418. }
  419. }
  420. }
  421. }
  422. .right-item{
  423. /deep/ .choose-product-item{
  424. margin: 5px 8px;
  425. .choose-product-item-img{
  426. height: 130rpx;
  427. }
  428. .choose-product-item-info .choose-product-item-left-info-name{
  429. font-weight: normal;
  430. }
  431. }
  432. }
  433. }
  434. }
  435. }
  436. </style>