promoDetail.vue 18 KB

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