regularPurchase.vue 9.2 KB

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