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*1.5"
  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. this.showSwipeAction = false
  266. if(this.submitOk){
  267. uni.hideLoading()
  268. uni.navigateTo({
  269. url: "/pagesB/procureOrder"
  270. })
  271. }
  272. },
  273. // 更新top值
  274. updateChooseListTop(){
  275. this.chooseList.forEach((item,index)=>{
  276. item.top = (index+1)* this.popuItemHeight
  277. })
  278. this.chooseList.splice()
  279. },
  280. // 打开已选产品列表
  281. openChoose(){
  282. this.submitOk = false
  283. console.log(this.chooseList)
  284. if(this.chooseLength){
  285. this.showChoosePopu = !this.showChoosePopu
  286. }else{
  287. this.$u.toast(`请选择产品`);
  288. }
  289. },
  290. // popu 滚动
  291. onscrollPopu(e){
  292. console.log(e.detail.scrollTop)
  293. this.curScrollPopuTop = e.detail.scrollTop
  294. // 清除计时器
  295. // clearTimeout(this.scrolltimer)
  296. // 如果停留则表示滚动结束
  297. // this.scrolltimer = setTimeout(() => {
  298. // this.curScrollPopuTop = e.detail.scrollTop
  299. // }, 17)
  300. },
  301. // 已选产品变更数量
  302. changeQty(e){
  303. const rowIndex = this.chooseList.findIndex(key => key.id == e.index)
  304. if(rowIndex>=0){
  305. this.chooseList[rowIndex].qty = e.value
  306. this.chooseList.splice()
  307. }
  308. // 更新页面产品数据
  309. const aindex = this.list.findIndex(key => key.id == e.index)
  310. if(aindex>=0){
  311. this.list[aindex].qty = e.value
  312. this.list.splice()
  313. }
  314. },
  315. //已选产品删除
  316. chooseClick(index, btns){
  317. if(btns == 0) {
  318. // 删除项
  319. const aindex = this.chooseList.findIndex(item => item.id == index)
  320. if(aindex>=0){
  321. this.chooseList.splice(aindex, 1);
  322. // 更新top
  323. this.updateChooseListTop()
  324. }
  325. // 更新列表已选状态
  326. const row = this.list.find(item => item.id == index)
  327. if(row){
  328. row.checked = false
  329. row.qty = 0
  330. }
  331. // 如果没有数据了
  332. if(this.chooseList.length==0){
  333. this.clearChooseData()
  334. }
  335. this.$u.toast(`删除成功!`);
  336. }
  337. },
  338. // 同时打开一个
  339. chooseOpen(index){
  340. // 先将正在被操作的swipeAction标记为打开状态,否则由于props的特性限制,
  341. // 原本为'false',再次设置为'false'会无效
  342. const row = this.chooseList.find(item => item.id == index)
  343. if(row) {
  344. row.show = true
  345. }
  346. this.chooseList.map((item, idx) => {
  347. if(index != item.id) this.chooseList[idx].show = false;
  348. })
  349. },
  350. // 清除滑动按钮
  351. clearAction(){
  352. this.chooseList.map(item => {
  353. item.show = false
  354. })
  355. this.chooseList.splice()
  356. },
  357. // 确定清空已选列表
  358. claerChoose(){
  359. const _this = this
  360. uni.showModal({
  361. title: '提示',
  362. content: '确定清空已选列表?',
  363. confirmText: '确定',
  364. success(res) {
  365. if(res.confirm){
  366. _this.clearChooseData()
  367. }
  368. }
  369. })
  370. },
  371. // 清空已选数据
  372. clearChooseData(){
  373. this.chooseList = []
  374. this.showChoosePopu = false
  375. // 重置已选状态
  376. this.list.filter(item => item.checked).map(item=>{
  377. item.checked = false
  378. item.qty = 0
  379. })
  380. },
  381. // 查询列表
  382. getRow () {
  383. let _this = this
  384. let params = {
  385. pageNo: this.pageNo,
  386. pageSize: this.pageSize,
  387. queryWord: this.queryWord,
  388. promoActiveSn: this.promoActiveSn
  389. }
  390. const rowHeight = 287 // 行高
  391. const pageHeight = uni.getSystemInfoSync().windowHeight // 页面高度
  392. const maxShowNums = Math.ceil( pageHeight / rowHeight ) //最大显示行数
  393. console.log(maxShowNums)
  394. this.showScrollHeight = rowHeight * maxShowNums // 可显示区域高度
  395. this.status = "loading"
  396. uni.showLoading({
  397. title: '加载中',
  398. mask: true
  399. })
  400. queryPromoProductByPage(params).then(res => {
  401. if (res.code == 200 || res.status == 204 || res.status == 200) {
  402. const list = res.data.list||[]
  403. const ret = []
  404. let curPageNums = (this.pageNo - 1) * this.pageSize / 2
  405. // 更新已选状态
  406. list.map((k,i) => {
  407. // 如果筛选或分页后,更新页面列表产品数量
  408. const hasChecked = this.chooseList.find(s=>s.id == k.id)
  409. curPageNums = (i+1) % 2 != 0 ? curPageNums + 1 : curPageNums
  410. ret.push({
  411. id: k.id,
  412. cost: k.cost,
  413. checked: hasChecked,
  414. qty: hasChecked ? hasChecked.qty : 0,
  415. productCode: k.productCode,
  416. productSn: k.productSn,
  417. productImage: k.productImage,
  418. productName: k.productName,
  419. productOrigCode: k.productOrigCode,
  420. promoActiveSn: k.promoActiveSn,
  421. promoRuleSn: k.promoRuleSn,
  422. promoRuleValue: k.promoRuleValue,
  423. promoRuleType: k.promoRuleType,
  424. show: false,
  425. top: rowHeight * curPageNums
  426. })
  427. })
  428. _this.list = _this.list.concat(ret)
  429. console.log(_this.list)
  430. _this.total = res.data.count || 0
  431. } else {
  432. _this.list = []
  433. _this.total = 0
  434. _this.noDataText = res.message
  435. }
  436. _this.$nextTick(()=>{
  437. uni.hideLoading()
  438. })
  439. _this.status = _this.total>=_this.list.length ? "nomore" : 'loadmore'
  440. })
  441. },
  442. // 提交订单
  443. submitOrder(){
  444. if(this.showChoosePopu){
  445. uni.showLoading({
  446. title: '提交中...',
  447. mask: true
  448. })
  449. const detailList = []
  450. this.chooseList.map(item => {
  451. detailList.push({
  452. promoActiveSn: this.promoActiveSn,
  453. promoRuleSn:item.promoRuleSn,
  454. productSn:item.productSn,
  455. productCode:item.productCode,
  456. qty:item.qty,
  457. price:item.cost,
  458. giveAmount:item.promoRuleValue
  459. })
  460. })
  461. purchaseSave({
  462. promoActiveSn: this.promoActiveSn,
  463. detailList: detailList
  464. }).then(res => {
  465. if(res.status == 200){
  466. res.data.detailList = []
  467. this.$store.state.vuex_tempData = res.data
  468. this.clearChooseData()
  469. this.submitOk = true
  470. }else{
  471. uni.showToast({
  472. title: res.message,
  473. icon: 'none'
  474. })
  475. }
  476. })
  477. }else{
  478. this.openChoose()
  479. }
  480. },
  481. }
  482. }
  483. </script>
  484. <style lang="less">
  485. page{
  486. height: 100vh;
  487. }
  488. .video-pagesCons{
  489. height: 100vh;
  490. position: relative;
  491. .tab-search{
  492. padding: 15rpx 20rpx;
  493. background: #fff;
  494. position: fixed;
  495. top:0;
  496. left:0;
  497. width:100%;
  498. z-index:20;
  499. }
  500. .tab-body{
  501. display: flex;
  502. flex-direction: column;
  503. flex-grow: 1;
  504. padding: 90rpx 0 170rpx 0;
  505. .product-list{
  506. display: flex;
  507. flex-wrap: wrap;
  508. }
  509. .check-order-list{
  510. width: 50%;
  511. padding: 10upx;
  512. height: 287px;
  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>