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