promoDetail.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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-2 && 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. this.curScrollPopuTop = e.detail.scrollTop
  293. // 清除计时器
  294. // clearTimeout(this.scrolltimer)
  295. // 如果停留则表示滚动结束
  296. // this.scrolltimer = setTimeout(() => {
  297. // this.curScrollPopuTop = e.detail.scrollTop
  298. // }, 17)
  299. },
  300. // 已选产品变更数量
  301. changeQty(e){
  302. const rowIndex = this.chooseList.findIndex(key => key.id == e.index)
  303. if(rowIndex>=0){
  304. // this.chooseList[rowIndex].qty = e.value
  305. // this.chooseList.splice()
  306. }
  307. // 更新页面产品数据
  308. const aindex = this.list.findIndex(key => key.id == e.index)
  309. if(aindex>=0){
  310. this.list[aindex].qty = e.value
  311. this.list.splice()
  312. }
  313. },
  314. //已选产品删除
  315. chooseClick(index, btns){
  316. if(btns == 0) {
  317. // 删除项
  318. const aindex = this.chooseList.findIndex(item => item.id == index)
  319. if(aindex>=0){
  320. this.chooseList.splice(aindex, 1);
  321. // 更新top
  322. this.updateChooseListTop()
  323. }
  324. // 更新列表已选状态
  325. const row = this.list.find(item => item.id == index)
  326. if(row){
  327. row.checked = false
  328. row.qty = 0
  329. }
  330. // 如果没有数据了
  331. if(this.chooseList.length==0){
  332. this.clearChooseData()
  333. }
  334. this.$u.toast(`删除成功!`);
  335. }
  336. },
  337. // 同时打开一个
  338. chooseOpen(index){
  339. // 先将正在被操作的swipeAction标记为打开状态,否则由于props的特性限制,
  340. // 原本为'false',再次设置为'false'会无效
  341. const row = this.chooseList.find(item => item.id == index)
  342. if(row) {
  343. row.show = true
  344. }
  345. this.chooseList.map((item, idx) => {
  346. if(index != item.id) this.chooseList[idx].show = false;
  347. })
  348. },
  349. // 清除滑动按钮
  350. clearAction(){
  351. this.chooseList.map(item => {
  352. item.show = false
  353. })
  354. this.chooseList.splice()
  355. },
  356. // 确定清空已选列表
  357. claerChoose(){
  358. const _this = this
  359. uni.showModal({
  360. title: '提示',
  361. content: '确定清空已选列表?',
  362. confirmText: '确定',
  363. success(res) {
  364. if(res.confirm){
  365. _this.clearChooseData()
  366. }
  367. }
  368. })
  369. },
  370. // 清空已选数据
  371. clearChooseData(){
  372. this.chooseList = []
  373. this.showChoosePopu = false
  374. // 重置已选状态
  375. this.list.filter(item => item.checked).map(item=>{
  376. item.checked = false
  377. item.qty = 0
  378. })
  379. },
  380. // 查询列表
  381. getRow () {
  382. let _this = this
  383. let params = {
  384. pageNo: this.pageNo,
  385. pageSize: this.pageSize,
  386. queryWord: this.queryWord,
  387. promoActiveSn: this.promoActiveSn
  388. }
  389. const rowHeight = 287 // 行高
  390. const pageHeight = uni.getSystemInfoSync().windowHeight // 页面高度
  391. const maxShowNums = Math.ceil( pageHeight / rowHeight ) //最大显示行数
  392. console.log(maxShowNums)
  393. this.showScrollHeight = rowHeight * maxShowNums // 可显示区域高度
  394. this.status = "loading"
  395. uni.showLoading({
  396. title: '加载中',
  397. mask: true
  398. })
  399. queryPromoProductByPage(params).then(res => {
  400. if (res.code == 200 || res.status == 204 || res.status == 200) {
  401. const list = res.data.list||[]
  402. const ret = []
  403. let curPageNums = (this.pageNo - 1) * this.pageSize / 2
  404. // 更新已选状态
  405. list.map((k,i) => {
  406. // 如果筛选或分页后,更新页面列表产品数量
  407. const hasChecked = this.chooseList.find(s=>s.id == k.id)
  408. curPageNums = (i+1) % 2 != 0 ? curPageNums + 1 : curPageNums
  409. ret.push({
  410. id: k.id,
  411. cost: k.cost,
  412. checked: hasChecked,
  413. qty: hasChecked ? hasChecked.qty : 0,
  414. productCode: k.productCode,
  415. productSn: k.productSn,
  416. productImage: k.productImage,
  417. productName: k.productName,
  418. productOrigCode: k.productOrigCode,
  419. promoActiveSn: k.promoActiveSn,
  420. promoRuleSn: k.promoRuleSn,
  421. promoRuleValue: k.promoRuleValue,
  422. promoRuleType: k.promoRuleType,
  423. show: false,
  424. top: rowHeight * curPageNums
  425. })
  426. })
  427. _this.list = _this.list.concat(ret)
  428. console.log(_this.list)
  429. _this.total = res.data.count || 0
  430. } else {
  431. _this.list = []
  432. _this.total = 0
  433. _this.noDataText = res.message
  434. }
  435. _this.$nextTick(()=>{
  436. uni.hideLoading()
  437. })
  438. _this.status = _this.total>=_this.list.length ? "nomore" : 'loadmore'
  439. })
  440. },
  441. // 提交订单
  442. submitOrder(){
  443. if(this.showChoosePopu){
  444. uni.showLoading({
  445. title: '提交中...',
  446. mask: true
  447. })
  448. const detailList = []
  449. this.chooseList.map(item => {
  450. detailList.push({
  451. promoActiveSn: this.promoActiveSn,
  452. promoRuleSn:item.promoRuleSn,
  453. productSn:item.productSn,
  454. productCode:item.productCode,
  455. qty:item.qty,
  456. price:item.cost,
  457. giveAmount:item.promoRuleValue
  458. })
  459. })
  460. purchaseSave({
  461. promoActiveSn: this.promoActiveSn,
  462. detailList: detailList
  463. }).then(res => {
  464. if(res.status == 200){
  465. res.data.detailList = []
  466. this.$store.state.vuex_tempData = res.data
  467. this.clearChooseData()
  468. this.submitOk = true
  469. }else{
  470. uni.showToast({
  471. title: res.message,
  472. icon: 'none'
  473. })
  474. }
  475. })
  476. }else{
  477. this.openChoose()
  478. }
  479. },
  480. }
  481. }
  482. </script>
  483. <style lang="less">
  484. page{
  485. height: 100vh;
  486. }
  487. .video-pagesCons{
  488. height: 100vh;
  489. position: relative;
  490. .tab-search{
  491. padding: 15rpx 20rpx;
  492. background: #fff;
  493. position: fixed;
  494. top:0;
  495. left:0;
  496. width:100%;
  497. z-index:20;
  498. }
  499. .tab-body{
  500. display: flex;
  501. flex-direction: column;
  502. flex-grow: 1;
  503. padding: 90rpx 0 170rpx 0;
  504. .product-list{
  505. display: flex;
  506. flex-wrap: wrap;
  507. }
  508. .check-order-list{
  509. width: 50%;
  510. padding: 10upx;
  511. height: 287px;
  512. background: url('/static/def_imgs.png') no-repeat center center;
  513. }
  514. }
  515. .bottom-bar{
  516. height: 130upx;
  517. z-index: 200;
  518. background-color: #fff;
  519. display: flex;
  520. align-items: center;
  521. justify-content: space-between;
  522. font-size: 32upx;
  523. position: fixed;
  524. bottom:0;
  525. left:0;
  526. width:100%;
  527. .bottom-bar-left{
  528. padding: 0 30upx;
  529. flex-grow: 1;
  530. display: flex;
  531. align-items: center;
  532. }
  533. .bottom-bar-left-item{
  534. padding-right: 20rpx;
  535. font-size: 24rpx;
  536. display: flex;
  537. align-items: center;
  538. }
  539. .bottom-bar-left-item-icon{
  540. position: relative;
  541. background: #2196F3;
  542. padding: 20rpx;
  543. border-radius: 100%;
  544. color: #fff;
  545. }
  546. .bottom-bar-right{
  547. padding: 0 50rpx;
  548. height: 100%;
  549. background: #2196F3;
  550. display: flex;
  551. align-items: center;
  552. .bottom-bar-right-item{
  553. color: #fff;
  554. }
  555. }
  556. .bg-0{
  557. background: #2196F3;
  558. }
  559. .bg-1{
  560. background: #f44336;
  561. }
  562. }
  563. .price-txt{
  564. color: red;
  565. text{
  566. font-size: 36rpx;
  567. }
  568. }
  569. .choose-title{
  570. display: flex;
  571. align-items:center;
  572. justify-content: space-between;
  573. padding: 0 25rpx;
  574. position: fixed;
  575. background: #fff;
  576. width: 100%;
  577. z-index: 3;
  578. border-bottom: 1px solid #eee;
  579. border-radius: 40rpx 40rpx 0 0;
  580. > view{
  581. padding: 25rpx 0;
  582. }
  583. .p-nums{
  584. color: #2196F3;
  585. margin: 0 6rpx;
  586. }
  587. .choose-inf{
  588. color: #999;
  589. font-size: 24rpx;
  590. }
  591. .choose-close{
  592. padding: 25rpx 20rpx;
  593. }
  594. }
  595. .choose-product-list{
  596. padding: 100rpx 20rpx 150rpx;
  597. width: 100%;
  598. position: relative;
  599. > view{
  600. height: 133px;
  601. }
  602. }
  603. .back-price{
  604. padding: 6rpx 65rpx;
  605. background: rgba(255 ,87 ,34 , 1);
  606. position: absolute;
  607. top: 18rpx;
  608. right: -45rpx;
  609. color: #fff;
  610. z-index: 2;
  611. font-size: 20rpx;
  612. text-align: center;
  613. transform: rotate(40deg);
  614. display: flex;
  615. align-items: center;
  616. text{
  617. font-size: 28rpx;
  618. margin: 0 5rpx;
  619. }
  620. }
  621. }
  622. </style>