promoDetail.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. <template>
  2. <view class="video-pagesCons">
  3. <view class="tab-search">
  4. <u-search placeholder="请输入产品名称/轮胎规格" shape="round" :clearabled="true" show-action v-model="queryWord" @clear="pageInit" @search="pageInit" @custom="pageInit"></u-search>
  5. </view>
  6. <view class="tab-body">
  7. <view class="product-list" id="list">
  8. <view
  9. class="check-order-list"
  10. v-for="(item,index) in list"
  11. :key="item.id"
  12. >
  13. <productItem
  14. v-if="item.top > curScrollTop-showScrollHeight*2 && item.top < curScrollTop + showScrollHeight*3"
  15. :item="item"
  16. :checked="item.checked"
  17. @chooseProduct="chooseProduct"
  18. ></productItem>
  19. </view>
  20. </view>
  21. <view style="padding: 20upx;">
  22. <u-empty :src="`/static/nodata.png`" icon-size="180" :text="noDataText" img-width="120" v-if="list.length==0 && status!='loading'" mode="list"></u-empty>
  23. <u-loadmore v-if="(total>=list.length&&list.length)||status=='loading'" :status="status" />
  24. </view>
  25. </view>
  26. <!-- 底部栏 -->
  27. <view class="bottom-bar" @click="clearAction" v-if="total>0">
  28. <view class="bottom-bar-left">
  29. <view class="bottom-bar-left-item">
  30. <view class="bottom-bar-left-item-icon" @click="openChoose">
  31. <u-icon name="shopping-cart" size="40"></u-icon>
  32. <u-badge type="error" :count="totalNum" :offset="[-7,-8]"></u-badge>
  33. </view>
  34. </view>
  35. <view class="bottom-bar-left-item" v-if="showChoosePopu">
  36. 合计:<view class="price-txt">¥<text>{{totalAmount}}</text></view>
  37. </view>
  38. </view>
  39. <view :class="'bottom-bar-right bg-'+(showChoosePopu?'1':'0')" @click="submitOrder">
  40. <view class="bottom-bar-right-item">{{showChoosePopu?'确认采购':'去结算'}}</view>
  41. </view>
  42. </view>
  43. <!-- 已选列表 -->
  44. <page-container
  45. :show="showChoosePopu"
  46. :round="true"
  47. position="bottom"
  48. custom-style="height:90%"
  49. @enter="openRender"
  50. @afterleave="closePopu">
  51. <scroll-view
  52. :style="{width:screenWidth + 'px',height:'100%'}"
  53. scroll-y="true"
  54. @scroll="onscrollPopu"
  55. id="popuScroll"
  56. >
  57. <view class="choose-title">
  58. <view class="flex align_center">
  59. <view>已选<text class="p-nums">{{chooseLength}}</text>款产品 </view>
  60. <u-button @click="claerChoose" size="mini" type="error" plain style="margin: 0 20upx;">清空列表</u-button>
  61. <text class="choose-inf">左滑删除产品</text>
  62. </view>
  63. <view class="choose-close" @click="showChoosePopu=false">
  64. <u-icon name="close" size="30"></u-icon>
  65. </view>
  66. </view>
  67. <view class="choose-product-list" v-if="showSwipeAction">
  68. <view
  69. v-for="(item, index) in chooseList"
  70. :key="item.id"
  71. >
  72. <u-swipe-action
  73. :show="item.show"
  74. :index="item.id"
  75. @click="chooseClick"
  76. @open="chooseOpen"
  77. :options="chooseOptions"
  78. v-if="item.top > curScrollPopuTop-showScrollPopuHeight && item.top < curScrollPopuTop + showScrollPopuHeight*2"
  79. >
  80. <chooseProductItem
  81. :item="item"
  82. :width="screenWidth-20"
  83. @changeQty="changeQty"></chooseProductItem>
  84. </u-swipe-action>
  85. </view>
  86. </view>
  87. </scroll-view>
  88. </page-container>
  89. </view>
  90. </template>
  91. <script>
  92. import {
  93. mapState,
  94. mapMutations,
  95. } from 'vuex'
  96. import { queryPromoProductByPage } from '@/api/video.js'
  97. import { purchaseSave } from '@/api/purchase.js'
  98. import productItem from '@/pagesB/components/productItem.vue'
  99. import chooseProductItem from '@/pagesB/components/chooseProductItem.vue'
  100. export default {
  101. components:{
  102. productItem,
  103. chooseProductItem
  104. },
  105. data() {
  106. return {
  107. status: 'loading',
  108. noDataText: '暂无数据',
  109. promoActiveSn: null, // 活动sn
  110. submitOk: false, // 是否提交
  111. queryWord: '',// 关键词查询列表
  112. pageNo: 1, // 当前页
  113. pageSize: 6,//每页条数
  114. list: [], // 产品列表
  115. total: 0, // 总记录
  116. // 已选列表
  117. showChoosePopu: false,//已选列表弹框
  118. chooseList:[], // 已选数据
  119. chooseOptions:[
  120. {
  121. text: '删除',
  122. style: {
  123. backgroundColor: '#dd524d'
  124. }
  125. }
  126. ], // 左滑删除已选产品
  127. screenWidth: 750, // 屏幕宽度
  128. showSwipeAction: false, // 已选弹框是否已经打开
  129. curScrollPopuTop:0, // 当前滚动条top
  130. showScrollPopuHeight:0, // 可显示区域实际高度
  131. popuItemHeight: 133, // 已选产品列表项高度
  132. // 虚拟滚动
  133. showScrollHeight: 0, // 模块可显示区域高度
  134. curScrollTop: 0 ,// 当前滚动条top
  135. scrolltimer: null, // 滚动定时器
  136. }
  137. },
  138. computed: {
  139. ...mapState(['hasLogin']),
  140. userInfo(){
  141. return this.$store.state.vuex_userInfo
  142. },
  143. // 已选产品总款数
  144. chooseLength(){
  145. return this.chooseList.length
  146. },
  147. // 已选产品总金额
  148. totalAmount(){
  149. let total = 0
  150. this.chooseList.forEach(key => {
  151. total = total + key.cost * key.qty
  152. })
  153. return total.toFixed(2)
  154. },
  155. // 已选产品总数量
  156. totalNum(){
  157. let total = 0
  158. this.chooseList.forEach(key => {
  159. total = total + key.qty
  160. })
  161. return total
  162. },
  163. },
  164. onLoad(opts) {
  165. uni.setNavigationBarTitle({
  166. title: opts.title||'促销活动产品'
  167. })
  168. this.screenWidth = uni.getSystemInfoSync().windowWidth
  169. this.$store.state.vuex_tempData = null
  170. this.promoActiveSn = opts.promoActiveSn
  171. // 购物车是否有缓存
  172. const cacheList = this.$store.state.vuex_cartList.find(k => k.sn == this.promoActiveSn)
  173. this.chooseList = cacheList ? JSON.parse(JSON.stringify(cacheList.list)) : []
  174. if(this.chooseList.length){
  175. this.updateChooseListTop()
  176. }
  177. // 查询产品列表
  178. this.pageInit()
  179. },
  180. onShow() {
  181. this.showChoosePopu=false
  182. },
  183. onUnload() {
  184. // 存储已选列表值
  185. const hasCache = this.$store.state.vuex_cartList.find(k => k.sn == this.promoActiveSn)
  186. if(hasCache){
  187. hasCache.list = this.chooseList
  188. }else{
  189. this.$store.state.vuex_cartList.push({sn:this.promoActiveSn,list: this.chooseList})
  190. }
  191. this.$u.vuex('vuex_cartList', this.$store.state.vuex_cartList)
  192. // 清空数据
  193. this.chooseList = null
  194. this.list = null
  195. },
  196. // 到底部加载更多
  197. onReachBottom() {
  198. if(this.list.length < this.total){
  199. this.pageNo += 1
  200. this.getRow()
  201. }else{
  202. this.status = "nomore"
  203. }
  204. },
  205. // 页面滚动
  206. onPageScroll(e){
  207. console.log(e,'----')
  208. // 已选列表未打开时,更新当前滚动高度
  209. if(!this.showChoosePopu){
  210. // 清除计时器
  211. clearTimeout(this.scrolltimer)
  212. // 如果停留则表示滚动结束
  213. this.scrolltimer = setTimeout(() => {
  214. this.curScrollTop = e.scrollTop
  215. }, 17)
  216. }
  217. },
  218. methods: {
  219. // 初始化页面
  220. pageInit(){
  221. // 重置分页
  222. this.total = 0
  223. this.pageNo = 1
  224. this.list = []
  225. // 获取列表数据
  226. this.getRow()
  227. },
  228. // 添加已选产品
  229. chooseProduct(item){
  230. const rowItem = this.list.find(k => k.id == item.id)
  231. if(!rowItem.checked){
  232. rowItem.checked = true
  233. rowItem.qty = 1
  234. rowItem.show = false
  235. this.chooseList.unshift(this.$u.deepClone(rowItem))
  236. // 更新top值
  237. this.updateChooseListTop()
  238. }else{
  239. rowItem.qty = rowItem.qty + 1
  240. // 已添加,则增加已选列表中的数量
  241. const row = this.chooseList.find(key => key.id == rowItem.id)
  242. if(row){
  243. row.qty = row.qty + 1
  244. }
  245. this.chooseList.splice()
  246. }
  247. },
  248. // 渲染已选产品列表
  249. openRender(){
  250. const query = uni.createSelectorQuery().in(this);
  251. query.select('#popuScroll').boundingClientRect(data => {
  252. if (data) {
  253. const maxRows = Math.ceil(data.height/this.popuItemHeight)
  254. this.showScrollPopuHeight = this.popuItemHeight * maxRows
  255. // console.log(this.showScrollPopuHeight,maxRows)
  256. setTimeout(()=>{
  257. this.showSwipeAction = true
  258. },100)
  259. }
  260. }).exec();
  261. },
  262. // 关闭已选列表弹框
  263. closePopu(){
  264. this.showChoosePopu=false
  265. if(this.submitOk){
  266. uni.hideLoading()
  267. uni.navigateTo({
  268. url: "/pagesB/procureOrder"
  269. })
  270. }
  271. },
  272. // 更新top值
  273. updateChooseListTop(){
  274. this.chooseList.forEach((item,index)=>{
  275. item.top = (index+1)* this.popuItemHeight
  276. })
  277. this.chooseList.splice()
  278. },
  279. // 打开已选产品列表
  280. openChoose(){
  281. this.submitOk = false
  282. console.log(this.chooseList)
  283. if(this.chooseLength){
  284. this.showChoosePopu = !this.showChoosePopu
  285. }else{
  286. this.$u.toast(`请选择产品`);
  287. }
  288. },
  289. // popu 滚动
  290. onscrollPopu(e){
  291. console.log(e.detail.scrollTop)
  292. // 清除计时器
  293. clearTimeout(this.scrolltimer)
  294. // 如果停留则表示滚动结束
  295. this.scrolltimer = setTimeout(() => {
  296. this.curScrollPopuTop = e.detail.scrollTop
  297. }, 17)
  298. },
  299. // 已选产品变更数量
  300. changeQty(e){
  301. const rowIndex = this.chooseList.findIndex(key => key.id == e.index)
  302. if(rowIndex>=0){
  303. this.chooseList[rowIndex].qty = e.value
  304. this.chooseList.splice()
  305. }
  306. // 更新页面产品数据
  307. const aindex = this.list.findIndex(key => key.id == e.index)
  308. if(aindex>=0){
  309. this.list[aindex].qty = e.value
  310. this.list.splice()
  311. }
  312. },
  313. //已选产品删除
  314. chooseClick(index, btns){
  315. if(btns == 0) {
  316. // 删除项
  317. const aindex = this.chooseList.findIndex(item => item.id == index)
  318. if(aindex>=0){
  319. this.chooseList.splice(aindex, 1);
  320. // 更新top
  321. this.updateChooseListTop()
  322. }
  323. // 更新列表已选状态
  324. const row = this.list.find(item => item.id == index)
  325. if(row){
  326. row.checked = false
  327. row.qty = 0
  328. }
  329. // 如果没有数据了
  330. if(this.chooseList.length==0){
  331. this.clearChooseData()
  332. }
  333. this.$u.toast(`删除成功!`);
  334. }
  335. },
  336. // 同时打开一个
  337. chooseOpen(index){
  338. // 先将正在被操作的swipeAction标记为打开状态,否则由于props的特性限制,
  339. // 原本为'false',再次设置为'false'会无效
  340. const row = this.chooseList.find(item => item.id == index)
  341. if(row) {
  342. row.show = true
  343. }
  344. this.chooseList.map((item, idx) => {
  345. if(index != item.id) this.chooseList[idx].show = false;
  346. })
  347. },
  348. // 清除滑动按钮
  349. clearAction(){
  350. this.chooseList.map(item => {
  351. item.show = false
  352. })
  353. this.chooseList.splice()
  354. },
  355. // 确定清空已选列表
  356. claerChoose(){
  357. const _this = this
  358. uni.showModal({
  359. title: '提示',
  360. content: '确定清空已选列表?',
  361. confirmText: '确定',
  362. success(res) {
  363. if(res.confirm){
  364. _this.clearChooseData()
  365. }
  366. }
  367. })
  368. },
  369. // 清空已选数据
  370. clearChooseData(){
  371. this.chooseList = []
  372. this.showChoosePopu = false
  373. // 重置已选状态
  374. this.list.filter(item => item.checked).map(item=>{
  375. item.checked = false
  376. item.qty = 0
  377. })
  378. },
  379. // 查询列表
  380. getRow () {
  381. let _this = this
  382. let params = {
  383. pageNo: this.pageNo,
  384. pageSize: this.pageSize,
  385. queryWord: this.queryWord,
  386. promoActiveSn: this.promoActiveSn
  387. }
  388. const rowHeight = 287 // 行高
  389. const pageHeight = uni.getSystemInfoSync().windowHeight // 页面高度
  390. const maxShowNums = Math.ceil( pageHeight / rowHeight ) //最大显示行数
  391. console.log(maxShowNums)
  392. this.showScrollHeight = rowHeight * maxShowNums // 可显示区域高度
  393. this.status = "loading"
  394. uni.showLoading({
  395. title: '加载中',
  396. mask: true
  397. })
  398. queryPromoProductByPage(params).then(res => {
  399. if (res.code == 200 || res.status == 204 || res.status == 200) {
  400. const list = res.data.list||[]
  401. const ret = []
  402. let curPageNums = (this.pageNo - 1) * this.pageSize / 2
  403. // 更新已选状态
  404. list.map((k,i) => {
  405. // 如果筛选或分页后,更新页面列表产品数量
  406. const hasChecked = this.chooseList.find(s=>s.id == k.id)
  407. curPageNums = (i+1) % 2 != 0 ? curPageNums + 1 : curPageNums
  408. ret.push({
  409. id: k.id,
  410. cost: k.cost,
  411. checked: hasChecked,
  412. qty: hasChecked ? hasChecked.qty : 0,
  413. productCode: k.productCode,
  414. productSn: k.productSn,
  415. productImage: k.productImage,
  416. productName: k.productName,
  417. productOrigCode: k.productOrigCode,
  418. promoActiveSn: k.promoActiveSn,
  419. promoRuleSn: k.promoRuleSn,
  420. promoRuleValue: k.promoRuleValue,
  421. promoRuleType: k.promoRuleType,
  422. show: false,
  423. top: rowHeight * curPageNums
  424. })
  425. })
  426. _this.list = _this.list.concat(ret)
  427. console.log(_this.list)
  428. _this.total = res.data.count || 0
  429. } else {
  430. _this.list = []
  431. _this.total = 0
  432. _this.noDataText = res.message
  433. }
  434. _this.$nextTick(()=>{
  435. uni.hideLoading()
  436. })
  437. _this.status = _this.total>=_this.list.length ? "nomore" : 'loadmore'
  438. })
  439. },
  440. // 提交订单
  441. submitOrder(){
  442. if(this.showChoosePopu){
  443. uni.showLoading({
  444. title: '提交中...',
  445. mask: true
  446. })
  447. const detailList = []
  448. this.chooseList.map(item => {
  449. detailList.push({
  450. promoActiveSn: this.promoActiveSn,
  451. promoRuleSn:item.promoRuleSn,
  452. productSn:item.productSn,
  453. productCode:item.productCode,
  454. qty:item.qty,
  455. price:item.cost,
  456. giveAmount:item.promoRuleValue
  457. })
  458. })
  459. purchaseSave({
  460. promoActiveSn: this.promoActiveSn,
  461. detailList: detailList
  462. }).then(res => {
  463. if(res.status == 200){
  464. res.data.detailList = []
  465. this.$store.state.vuex_tempData = res.data
  466. this.clearChooseData()
  467. this.submitOk = true
  468. }else{
  469. uni.showToast({
  470. title: res.message,
  471. icon: 'none'
  472. })
  473. }
  474. })
  475. }else{
  476. this.openChoose()
  477. }
  478. },
  479. }
  480. }
  481. </script>
  482. <style lang="less">
  483. page{
  484. height: 100vh;
  485. }
  486. .video-pagesCons{
  487. height: 100vh;
  488. position: relative;
  489. .tab-search{
  490. padding: 15rpx 20rpx;
  491. background: #fff;
  492. position: fixed;
  493. top:0;
  494. left:0;
  495. width:100%;
  496. z-index:20;
  497. }
  498. .tab-body{
  499. display: flex;
  500. flex-direction: column;
  501. flex-grow: 1;
  502. padding: 90rpx 0 170rpx 0;
  503. .product-list{
  504. display: flex;
  505. flex-wrap: wrap;
  506. }
  507. .check-order-list{
  508. width: 50%;
  509. padding: 10upx;
  510. height: 287px;
  511. background: url('/static/def_imgs.png') no-repeat center center;
  512. }
  513. }
  514. .bottom-bar{
  515. height: 130upx;
  516. z-index: 200;
  517. background-color: #fff;
  518. display: flex;
  519. align-items: center;
  520. justify-content: space-between;
  521. font-size: 32upx;
  522. position: fixed;
  523. bottom:0;
  524. left:0;
  525. width:100%;
  526. .bottom-bar-left{
  527. padding: 0 30upx;
  528. flex-grow: 1;
  529. display: flex;
  530. align-items: center;
  531. }
  532. .bottom-bar-left-item{
  533. padding-right: 20rpx;
  534. font-size: 24rpx;
  535. display: flex;
  536. align-items: center;
  537. }
  538. .bottom-bar-left-item-icon{
  539. position: relative;
  540. background: #2196F3;
  541. padding: 20rpx;
  542. border-radius: 100%;
  543. color: #fff;
  544. }
  545. .bottom-bar-right{
  546. padding: 0 50rpx;
  547. height: 100%;
  548. background: #2196F3;
  549. display: flex;
  550. align-items: center;
  551. .bottom-bar-right-item{
  552. color: #fff;
  553. }
  554. }
  555. .bg-0{
  556. background: #2196F3;
  557. }
  558. .bg-1{
  559. background: #f44336;
  560. }
  561. }
  562. .price-txt{
  563. color: red;
  564. text{
  565. font-size: 36rpx;
  566. }
  567. }
  568. .choose-title{
  569. display: flex;
  570. align-items:center;
  571. justify-content: space-between;
  572. padding: 0 25rpx;
  573. position: fixed;
  574. background: #fff;
  575. width: 100%;
  576. z-index: 3;
  577. border-bottom: 1px solid #eee;
  578. border-radius: 40rpx 40rpx 0 0;
  579. > view{
  580. padding: 25rpx 0;
  581. }
  582. .p-nums{
  583. color: #2196F3;
  584. margin: 0 6rpx;
  585. }
  586. .choose-inf{
  587. color: #999;
  588. font-size: 24rpx;
  589. }
  590. .choose-close{
  591. padding: 25rpx 20rpx;
  592. }
  593. }
  594. .choose-product-list{
  595. padding: 100rpx 20rpx 150rpx;
  596. width: 100%;
  597. position: relative;
  598. > view{
  599. height: 133px;
  600. }
  601. }
  602. .back-price{
  603. padding: 6rpx 65rpx;
  604. background: rgba(255 ,87 ,34 , 1);
  605. position: absolute;
  606. top: 18rpx;
  607. right: -45rpx;
  608. color: #fff;
  609. z-index: 2;
  610. font-size: 20rpx;
  611. text-align: center;
  612. transform: rotate(40deg);
  613. display: flex;
  614. align-items: center;
  615. text{
  616. font-size: 28rpx;
  617. margin: 0 5rpx;
  618. }
  619. }
  620. }
  621. </style>