regularPurchase.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <template>
  2. <view class="container all-type-list-wrapper">
  3. <commodity-list ref="childList" :empty-text="emptyText" @operationConfim="hanldOperationConfim"></commodity-list>
  4. <!--底部选择模态层弹窗组件 -->
  5. <view class="popup spec" :class="specClass" @touchmove.stop.prevent="discard" @tap="hideSpec">
  6. <!-- 遮罩层 -->
  7. <view class="mask"></view>
  8. <view class="layer" @tap.stop="discard">
  9. <view class="content">
  10. <view class="layer-smimg">
  11. <image :src="handleData.mainImage" mode=""></image>
  12. </view>
  13. <view class="layer-nunbox">
  14. <view class="layer-nunbox-t">
  15. <view class="layer-nunbox-text">数量:</view>
  16. <view class="number-box">
  17. <view class="iconfont icon-jianhao" :class="[isQuantity==true?'disabled':'']" @click="changeCountSub()"></view>
  18. <input class="btn-input" type="number" v-model="number" maxlength='4' @blur="changeNumber($event)">
  19. <view class="iconfont icon-jiahao" :class="[isStock==true?'disabled':'']" @click="changeCountAdd()"></view>
  20. </view>
  21. </view>
  22. <view class="layer-nunbox-b">
  23. <view class="text">单价:
  24. <text class="p sm">¥</text>
  25. <text class="p bg">{{buyRetailPrice.toFixed(2)}}</text>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. <view class="btn">
  31. <view class="button buy" @click="toConfirmation">立即购买</view>
  32. <view class="button add" @click="getAddProductCart">加入购物车</view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import commodityList from '@/components/module/listTemplate/commodityList'
  40. export default{
  41. components:{
  42. commodityList
  43. },
  44. data(){
  45. return{
  46. userID: '',
  47. serverUrl: '',
  48. emptyText: '',
  49. lastPageType: '',
  50. lastPageVal: '',
  51. specClass: '',//规格弹窗css类,控制开关动画
  52. handleData:{},
  53. isQuantity:false,
  54. isStock:false,
  55. minBuyNumber:0,
  56. number:0,
  57. buyRetailPrice:0
  58. }
  59. },
  60. onShow() {
  61. let pages = getCurrentPages(),
  62. thisPage = pages[pages.length - 1];
  63. if(thisPage.refresh) {
  64. this.setServerUrl(thisPage.listData);
  65. }
  66. this.$api.loginStatus().then((resolveData) => {
  67. this.$refs.childList.loginStatus = resolveData;
  68. });
  69. },
  70. onLoad() {
  71. this.$api.getStorage().then((resolve) =>{
  72. this.userID = resolve.userID
  73. this.setServerUrl();
  74. })
  75. },
  76. methods:{
  77. setServerUrl() {
  78. this.lastPageType = '再次购买';
  79. this.lastPageVal = '再次购买';
  80. // 空内容文案
  81. const emptyTxt = '您还没有购买过任何商品哟~';
  82. this.serverUrl = `/order/purchase?userID=${this.userID}`;
  83. this.$refs.childList.getListFromServer();
  84. },
  85. hanldOperationConfim(data){//显示选择数量确认弹窗
  86. console.log(data)
  87. this.handleData = data
  88. this.number = data.minBuyNumber
  89. this.minBuyNumber = data.minBuyNumber
  90. this.buyRetailPrice = data.retailPrice;
  91. this.specClass = 'show';
  92. },
  93. hideSpec() {//关闭选择数量确认弹窗
  94. this.specClass = 'hide';
  95. setTimeout(() => {
  96. this.specClass = 'none';
  97. }, 200);
  98. },
  99. changeCountAdd(){//popup弹窗数量增加按钮
  100. this.number++
  101. if(this.handleData.ladderPriceFlag == '1'){
  102. this.handleData.productLadderPrices.forEach((item,index)=>{
  103. if(this.number>=item.buyNum){
  104. this.buyRetailPrice = item.buyPrice
  105. }
  106. })
  107. }
  108. },
  109. changeCountSub(){//popup弹窗数量减按钮
  110. if(this.number<=this.minBuyNumber){
  111. this.number= this.minBuyNumber
  112. this.isQuantity =true
  113. this.$util.msg(`该商品最小起订量为${this.minBuyNumber}`,2000);
  114. return
  115. }else{
  116. this.number--
  117. if(this.handleData.ladderPriceFlag == '1'){
  118. this.handleData.productLadderPrices.forEach((item,index)=>{
  119. if(this.number>=item.buyNum){
  120. this.buyRetailPrice = item.buyPrice
  121. }
  122. })
  123. }
  124. this.isQuantity =false
  125. }
  126. },
  127. changeNumber(e){
  128. let _value = e.detail.value;
  129. if(!this.$api.isNumber(_value)){
  130. this.number = this.minBuyNumber
  131. }else if(_value < this.minBuyNumber){
  132. this.$util.msg(`该商品最小起订量为${this.minBuyNumber}`,2000);
  133. this.number = this.minBuyNumber
  134. }else{
  135. this.number = e.detail.value
  136. }
  137. },
  138. toConfirmation(){//跳转确认订单页面
  139. this.specClass = 'hide';
  140. let productStp ={
  141. allPrice:this.number*this.buyRetailPrice,
  142. allCount:this.number,
  143. id:this.handleData.id,
  144. productCount:this.number,
  145. classifyID:this.handleData.classifyID,
  146. }
  147. this.$api.navigateTo(`/pages/user/order/create-order?type=prodcut&data=${JSON.stringify({data:productStp})}`)
  148. setTimeout(() => {
  149. this.specClass = 'none';
  150. }, 200);
  151. },
  152. getAddProductCart(){//增加购物车成功和toast弹窗提示成功
  153. this.$api.post('/details/addCart',
  154. {
  155. productID:this.handleData.productID,
  156. userID:this.userID,
  157. productCount:this.number,
  158. organizeID:this.userOrganizeID
  159. },
  160. response => {
  161. if (response.code == "1") {
  162. this.specClass = 'hide';
  163. this.$util.msg(response.msg,1500,true,'success');
  164. this.isAnimation = true
  165. setTimeout(() => {
  166. this.specClass = 'none';
  167. }, 200);
  168. setTimeout(() => {
  169. this.isAnimation = false;
  170. }, 2000);
  171. this.$refs.childList.cartNum = response.data;
  172. }else{
  173. this.$util.msg(response.msg,2000);
  174. setTimeout(function(){
  175. this.$api.switchTabTo('/pages/tabBar/home/home')
  176. },1000)
  177. }
  178. }
  179. )
  180. },
  181. discard(){
  182. //丢弃
  183. }
  184. }
  185. }
  186. </script>
  187. <style lang="scss">
  188. page {
  189. background: $sub-bg-color;
  190. .all-type-list-wrapper {
  191. display: flex;
  192. flex-direction: column;
  193. }
  194. }
  195. /* 加入购物模态层*/
  196. @keyframes showPopup {
  197. 0% {
  198. opacity: 0;
  199. }
  200. 100% {
  201. opacity: 1;
  202. }
  203. }
  204. @keyframes hidePopup {
  205. 0% {
  206. opacity: 1;
  207. }
  208. 100% {
  209. opacity: 0;
  210. }
  211. }
  212. @keyframes showLayer {
  213. 0% {
  214. transform: translateY(0);
  215. }
  216. 100% {
  217. transform: translateY(-100%);
  218. }
  219. }
  220. @keyframes hideLayer {
  221. 0% {
  222. transform: translateY(-100%);
  223. }
  224. 100% {
  225. transform: translateY(0);
  226. }
  227. }
  228. @keyframes showAmnation {
  229. 0% {
  230. top: -12rpx;
  231. opacity: 0;
  232. }
  233. 50% {
  234. top: -60rpx;
  235. opacity: 1;
  236. }
  237. 100% {
  238. top: -100rpx;
  239. opacity: 0;
  240. }
  241. }
  242. @keyframes hideAmnation {
  243. 0% {
  244. top: -100rpx;
  245. opacity: 0;
  246. }
  247. 100% {
  248. top: -12rpx;
  249. opacity: 0;
  250. }
  251. }
  252. .popup {
  253. position: fixed;
  254. top: 0;
  255. width: 100%;
  256. height: 100%;
  257. z-index: 999;
  258. display: none;
  259. .mask{
  260. position: fixed;
  261. top: 0;
  262. width: 100%;
  263. height: 100%;
  264. z-index: 21;
  265. background-color: rgba(0, 0, 0, 0.6);
  266. }
  267. .layer {
  268. position: fixed;
  269. z-index: 22;
  270. bottom: -294rpx;
  271. width: 702rpx;
  272. padding: 24rpx 24rpx 36rpx 24rpx;
  273. height: 236rpx;
  274. border-radius: 30rpx 30rpx 0 0;
  275. background-color: #fff;
  276. display: flex;
  277. flex-wrap: wrap;
  278. align-content: space-between;
  279. .content {
  280. width: 100%;
  281. }
  282. .btn {
  283. width: 100%;
  284. height: 88rpx;
  285. display: flex;
  286. .button {
  287. width: 340rpx;
  288. height: 88rpx;
  289. color: #fff;
  290. display: flex;
  291. align-items: center;
  292. justify-content: center;
  293. font-size: $font-size-28;
  294. border-radius: 14rpx;
  295. &.buy{
  296. background: $btn-confirm;
  297. }
  298. &.add{
  299. background: rgba(239, 175, 0, 1);
  300. margin-left: 20rpx;
  301. }
  302. }
  303. }
  304. }
  305. &.show {
  306. display: block;
  307. .mask{
  308. animation: showPopup 0.2s linear both;
  309. }
  310. .layer {
  311. animation: showLayer 0.2s linear both;
  312. }
  313. }
  314. &.hide {
  315. display: block;
  316. .mask{
  317. animation: hidePopup 0.2s linear both;
  318. }
  319. .layer {
  320. animation: hideLayer 0.2s linear both;
  321. }
  322. }
  323. &.none {
  324. display: none;
  325. }
  326. &.service {
  327. .row {
  328. margin: 30upx 0;
  329. .title {
  330. font-size: 30upx;
  331. margin: 10upx 0;
  332. }
  333. .description {
  334. font-size: 28upx;
  335. color: #999;
  336. }
  337. }
  338. }
  339. .layer-smimg{
  340. width: 114rpx;
  341. height: 114rpx;
  342. float: left;
  343. border-radius: 10rpx;
  344. margin-right: 24rpx;
  345. image{
  346. width: 114rpx;
  347. height: 114rpx;
  348. border-radius: 10rpx;
  349. }
  350. }
  351. .layer-nunbox{
  352. justify-content: space-between;
  353. align-items: center;
  354. width: 536rpx;
  355. height: 88rpx;
  356. padding: 13rpx 0 0 0;
  357. float: left;
  358. .layer-nunbox-t{
  359. width: 100%;
  360. height:44rpx;
  361. position:relative;
  362. display: flex;
  363. .layer-nunbox-text{
  364. line-height: 44rpx;
  365. font-size: $font-size-28;
  366. }
  367. .number-box{
  368. display: flex;
  369. justify-content: center;
  370. align-items: center;
  371. .iconfont{
  372. font-size: $font-size-32;
  373. padding:0 20rpx;
  374. font-size: $text-color;
  375. }
  376. .btn-input{
  377. width: 62rpx;
  378. height: 48rpx;
  379. line-height: 48rpx;
  380. background: #F8F8F8;
  381. border-radius: 4rpx;
  382. text-align: center;
  383. font-size: $font-size-28;
  384. }
  385. }
  386. .product-step{
  387. position: absolute;
  388. left: 45rpx;
  389. bottom: 0;
  390. height: 44rpx;
  391. background: #FFFFFF;
  392. }
  393. }
  394. .layer-nunbox-b{
  395. width: 100%;
  396. height:44rpx;
  397. margin-top: 13rpx;
  398. }
  399. .text{
  400. line-height: 44rpx;
  401. font-size: $font-size-28;
  402. .p{
  403. color: #FF2A2A;
  404. }
  405. .p:first-child{
  406. margin-left: 30rpx;
  407. }
  408. .p.sm{
  409. font-size: $font-size-24;
  410. }
  411. }
  412. }
  413. }
  414. </style>