promoDetail.vue 17 KB

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