promoDetail.vue 14 KB

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