promoDetail.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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="getRow" @search="getRow" @custom="getRow"></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.images" height="140px" width="100%"></u-image>
  17. <view class="back-price">返<text>¥15</text></view>
  18. </view>
  19. <view>
  20. <view class="product-name">箭冠轮胎285/70R17LT RT-5900 坦克300、长城炮、牧马人 D</view>
  21. <view class="product-guige">285/70R17LT RT-5900</view>
  22. <view class="product-button">
  23. <view class="price-txt">¥<text>{{item.price}}</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="chooseLength" :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>325.63</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.images" height="200rpx" width="100%"></u-image>
  86. <view class="back-price">返<text>¥15</text></view>
  87. </view>
  88. <view class="choose-product-item-info">
  89. <view class="choose-product-item-left-info-name">箭冠轮胎285/70R17LT RT-5900 坦克300、长城炮、牧马人 D</view>
  90. <view class="choose-product-item-left-info-guige">285/70R17LT RT-5900</view>
  91. <view class="choose-product-item-left-info-price">
  92. <view class="price-txt">¥<text>{{item.price}}</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 { promoTerminalList } from '@/api/video.js'
  114. export default {
  115. data() {
  116. return {
  117. status: 'loading',
  118. noDataText: '暂无数据',
  119. queryWord: '',// 关键词查询列表
  120. // 查询条件
  121. pageNo: 1, // 当前页
  122. pageSize: 10,//每页条数
  123. list: [], // 产品列表
  124. total: 0, // 总记录
  125. showChoosePopu: false,//已选列表弹框
  126. chooseList:[], // 已选数据
  127. chooseAllList:[], // 已选原始所有数据
  128. chooseProductList:[], // 已选弹框中当前数据
  129. chooseOptions:[
  130. {
  131. text: '删除',
  132. style: {
  133. backgroundColor: '#dd524d'
  134. }
  135. }
  136. ], // 左滑删除已选产品
  137. screenWidth: 750, // 屏幕宽度
  138. showSwipeAction: false, // 已选弹框是否一打开
  139. choosePageNo: 1, // 已选产品当前页
  140. choosePageSize: 8, // 已选产品每页数
  141. chooseTotal: 0 // 已选产品总记录数
  142. }
  143. },
  144. computed: {
  145. ...mapState(['hasLogin']),
  146. userInfo(){
  147. return this.$store.state.vuex_userInfo
  148. },
  149. // 已选产品总款数
  150. chooseLength(){
  151. return this.chooseList.length
  152. }
  153. },
  154. onLoad(opts) {
  155. uni.setNavigationBarTitle({
  156. title: opts.title||'促销活动产品'
  157. })
  158. this.pageInit()
  159. },
  160. methods: {
  161. // 初始化页面
  162. pageInit(){
  163. this.screenWidth = uni.getSystemInfoSync().windowWidth
  164. this.total = 0
  165. this.pageNo = 1
  166. // 获取列表数据
  167. // this.getRow()
  168. for(let i=0;i<25;i++){
  169. this.list.push({
  170. id: this.$u.guid(),
  171. title: '长安回望绣成堆,山顶千门次第开,一骑红尘妃子笑,无人知是荔枝来',
  172. images: 'https://cdn.uviewui.com/uview/common/logo.png',
  173. price: Number(Math.random() * 100 + 50).toFixed(2),
  174. checked: false,
  175. show: false,
  176. qty: 1
  177. })
  178. }
  179. },
  180. // 添加已选产品
  181. chooseProduct(item){
  182. if(!item.checked){
  183. item.checked = true
  184. item.qty = 1
  185. item.show = false
  186. this.chooseList.unshift(item)
  187. }else{
  188. // item.qty = item.qty + 1
  189. // 已添加,则增加数量
  190. const row = this.chooseList.find(key => key.id == item.id)
  191. if(row){row.qty = row.qty + 1}
  192. }
  193. },
  194. // 渲染已选产品列表
  195. openRender(){
  196. setTimeout(()=>{
  197. this.showSwipeAction = true
  198. },100)
  199. },
  200. // 关闭已选列表弹框
  201. closePopu(){
  202. this.chooseProductList = []
  203. this.showChoosePopu=false
  204. },
  205. // 打开已选产品列表
  206. openChoose(){
  207. if(this.chooseLength){
  208. this.showChoosePopu = !this.showChoosePopu
  209. if(this.showChoosePopu){
  210. this.chooseAllList = JSON.parse(JSON.stringify(this.chooseList))
  211. // 默认加载第一页数据
  212. this.choosePageNo = 1
  213. this.chooseTotal = this.chooseAllList.length
  214. this.chooseProductList = this.chooseTotal > this.choosePageSize ? this.chooseAllList.slice(0,this.choosePageSize) : this.chooseAllList
  215. }
  216. }else{
  217. this.$u.toast(`请选择产品`);
  218. }
  219. },
  220. // 已选产品滚动到底部
  221. onreachPopuBottom(e){
  222. const totalPages = Math.ceil(this.chooseTotal/this.choosePageSize)
  223. if(this.choosePageNo>=totalPages){
  224. return
  225. }
  226. this.choosePageNo = this.choosePageNo + 1
  227. const start = (this.choosePageNo-1)*this.choosePageSize
  228. const end = this.choosePageNo*this.choosePageSize
  229. const list = this.chooseAllList.slice(start,end>this.chooseTotal?this.chooseTotal:end)
  230. this.chooseProductList = this.chooseProductList.concat(list)
  231. this.chooseProductList.splice()
  232. },
  233. // 已选产品变更数量
  234. changeQty(e){
  235. const _this = this
  236. const rowIndex = this.chooseProductList.findIndex(key => key.id == e.index)
  237. if(e.value>0){
  238. this.chooseProductList[rowIndex].qty = e.value
  239. // 更新原始数据
  240. const rindex = this.chooseList.findIndex(key => key.id == e.index)
  241. this.chooseList[rindex].qty = e.value
  242. this.chooseList.splice()
  243. }else{
  244. // 数量为0时,删除
  245. this.chooseClick(e.index,0)
  246. }
  247. },
  248. //已选产品删除
  249. chooseClick(index, btns){
  250. if(btns == 0) {
  251. // 更新列表已选状态
  252. const row = this.list.find(item => item.id == index)
  253. if(row){row.checked = false}
  254. const rindex = this.chooseProductList.findIndex(item => item.id == index)
  255. console.log(rindex)
  256. this.chooseProductList.splice(rindex, 1);
  257. this.chooseList.splice(rindex, 1);
  258. this.$u.toast(`删除成功!`);
  259. }
  260. },
  261. // 同时打开一个
  262. chooseOpen(index){
  263. // 先将正在被操作的swipeAction标记为打开状态,否则由于props的特性限制,
  264. // 原本为'false',再次设置为'false'会无效
  265. const row = this.chooseProductList.find(item => item.id == index)
  266. if(row) {
  267. row.show = true
  268. }
  269. this.chooseProductList.map((item, idx) => {
  270. if(index != item.id) this.chooseProductList[idx].show = false;
  271. })
  272. },
  273. // 清除滑动按钮
  274. clearAction(){
  275. this.chooseProductList.map(item => {
  276. item.show = false
  277. })
  278. this.chooseProductList.splice()
  279. },
  280. // 清空已选列表
  281. claerChoose(){
  282. const _this = this
  283. uni.showModal({
  284. title: '提示',
  285. content: '确定清空已选列表?',
  286. confirmText: '确定',
  287. success(res) {
  288. if(res.confirm){
  289. _this.chooseList = []
  290. _this.chooseProductList = []
  291. _this.showChoosePopu = false
  292. // 重置已选状态
  293. _this.list.filter(item => item.checked).map(item=>item.checked = false)
  294. }
  295. }
  296. })
  297. },
  298. // scroll-view到底部加载更多
  299. onreachBottom() {
  300. if(this.list.length < this.total){
  301. this.pageNo += 1
  302. this.getRow()
  303. }else{
  304. this.status = "nomore"
  305. }
  306. },
  307. // 查询列表
  308. getRow (pageNo) {
  309. let _this = this
  310. if (pageNo) {
  311. this.pageNo = pageNo
  312. }
  313. let params = {
  314. pageNo: this.pageNo,
  315. pageSize: this.pageSize,
  316. queryWord: this.queryWord
  317. }
  318. const storeShelf = this.$store.state.vuex_storeShelf
  319. this.status = "loading"
  320. promoTerminalList({sn:storeShelf.dealerSn,contentType:'LINK'}).then(res => {
  321. if (res.code == 200 || res.status == 204 || res.status == 200) {
  322. // const list = res.data.list || []
  323. // if(_this.pageNo>1){
  324. // _this.list = _this.list.concat(list)
  325. // }else{
  326. // _this.list = list
  327. // }
  328. // _this.total = res.data.count || 0
  329. _this.list = res.data.filter(item => item.content.indexOf("pages/promo/index") >= 0)
  330. _this.total = _this.list.length
  331. } else {
  332. _this.list = []
  333. _this.total = 0
  334. _this.noDataText = res.message
  335. }
  336. _this.status = _this.total>=_this.list.length ? "nomore" : 'loadmore'
  337. })
  338. },
  339. // 提交订单
  340. submitOrder(){
  341. if(this.showChoosePopu){
  342. console.log(this.chooseList)
  343. uni.navigateTo({
  344. url: '/pagesB/procureOrder?id='
  345. })
  346. }else{
  347. this.openChoose()
  348. }
  349. },
  350. }
  351. }
  352. </script>
  353. <style lang="less">
  354. page{
  355. height: 100vh;
  356. }
  357. .video-pagesCons{
  358. height: 100vh;
  359. display: flex;
  360. flex-direction: column;
  361. .tab-search{
  362. padding: 15rpx 20rpx;
  363. background: #fff;
  364. }
  365. .tab-body{
  366. display: flex;
  367. flex-direction: column;
  368. flex-grow: 1;
  369. overflow: auto;
  370. .bottom-bar{
  371. height: 130upx;
  372. z-index: 500;
  373. background-color: #fff;
  374. display: flex;
  375. align-items: center;
  376. justify-content: space-between;
  377. font-size: 32upx;
  378. .bottom-bar-left{
  379. padding: 0 30upx;
  380. flex-grow: 1;
  381. display: flex;
  382. align-items: center;
  383. }
  384. .bottom-bar-left-item{
  385. padding-right: 20rpx;
  386. font-size: 24rpx;
  387. display: flex;
  388. align-items: center;
  389. }
  390. .bottom-bar-left-item-icon{
  391. position: relative;
  392. background: #2196F3;
  393. padding: 20rpx;
  394. border-radius: 100%;
  395. color: #fff;
  396. }
  397. .bottom-bar-right{
  398. padding: 0 50rpx;
  399. height: 100%;
  400. background: #2196F3;
  401. display: flex;
  402. align-items: center;
  403. .bottom-bar-right-item{
  404. color: #fff;
  405. }
  406. }
  407. .bg-0{
  408. background: #2196F3;
  409. }
  410. .bg-1{
  411. background: #f44336;
  412. }
  413. }
  414. .product-list{
  415. display: flex;
  416. flex-wrap: wrap;
  417. }
  418. .check-order-list{
  419. width: 50%;
  420. padding: 10upx;
  421. .video-item{
  422. background: #ffffff;
  423. border-radius: 10upx;
  424. box-shadow: 1px 1px 3px #EEEEEE;
  425. > view{
  426. &:first-child{
  427. position: relative;
  428. overflow: hidden;
  429. }
  430. &:last-child{
  431. padding: 20rpx;
  432. .product-name{
  433. font-size: 28rpx;
  434. }
  435. .product-guige{
  436. margin: 10rpx 0;
  437. color: #666;
  438. text{
  439. margin-right: 10rpx;
  440. }
  441. }
  442. }
  443. .product-button{
  444. display: flex;
  445. justify-content: space-between;
  446. align-items: center;
  447. }
  448. }
  449. }
  450. }
  451. }
  452. .price-txt{
  453. color: red;
  454. text{
  455. font-size: 36rpx;
  456. }
  457. }
  458. .choose-title{
  459. display: flex;
  460. align-items:center;
  461. padding: 25rpx;
  462. position: fixed;
  463. background: #fff;
  464. width: 100%;
  465. z-index: 3;
  466. .p-nums{
  467. color: #2196F3;
  468. margin: 0 6rpx;
  469. }
  470. .choose-inf{
  471. color: #999;
  472. font-size: 24rpx;
  473. }
  474. }
  475. .choose-product-list{
  476. padding: 100rpx 20rpx 130rpx;
  477. width: 100%;
  478. .choose-product-item{
  479. display: flex;
  480. align-items: center;
  481. justify-content: space-between;
  482. padding: 20rpx 0;
  483. border-bottom: 1px solid #eee;
  484. > view{
  485. display: flex;
  486. align-items: center;
  487. justify-content: space-between;
  488. flex-grow: 1;
  489. width: 100%;
  490. }
  491. .choose-product-item-img{
  492. margin-right: 10rpx;
  493. width: 35%;
  494. position: relative;
  495. overflow: hidden;
  496. .back-price{
  497. zoom: calc(0.8);
  498. }
  499. }
  500. .choose-product-item-info{
  501. margin-right: 10rpx;
  502. width: 65%;
  503. flex-grow: 1;
  504. .choose-product-item-left-info-price{
  505. display: flex;
  506. align-items:center;
  507. justify-content: space-between;
  508. >view{
  509. &:last-child{
  510. display: flex;
  511. align-items:center;
  512. }
  513. }
  514. }
  515. .choose-product-item-left-info-name{
  516. font-size: 28rpx;
  517. }
  518. .choose-product-item-left-info-guige{
  519. color: #666;
  520. margin: 10rpx 0;
  521. text{
  522. margin-right: 10rpx;
  523. }
  524. }
  525. }
  526. }
  527. }
  528. .back-price{
  529. padding: 6rpx 55rpx;
  530. background: rgb(255 87 34 / 0.6);
  531. position: absolute;
  532. top: 16rpx;
  533. left: -50rpx;
  534. color: #fff;
  535. z-index: 2;
  536. font-size: 20rpx;
  537. text-align: center;
  538. transform: rotate(-40deg);
  539. display: flex;
  540. align-items: center;
  541. text{
  542. font-size: 28rpx;
  543. }
  544. }
  545. }
  546. </style>