list.vue 12 KB

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