cm-unit-popup.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. <template name="cm-parameter">
  2. <!-- 相关规格 -->
  3. <view>
  4. <tui-bottom-popup :radius="true" :show="popupShow" @close="hidePopup">
  5. <view class="tui-popup-box clearfix">
  6. <view class="tui-shopping-main" :style="{ paddingBottom: isIphoneX ? '68rpx' : '34rpx' }">
  7. <view class="tui-sku-title">
  8. <view class="tui-sku-image"> <image :src="skuProduct.mainImage" mode=""></image> </view>
  9. <view class="tui-sku-price">
  10. <cmUnitPrice :skuProduct="skuProduct" />
  11. </view>
  12. </view>
  13. <view class="tui-sku-unit">
  14. <view class="sku-unit-h1">规格:</view>
  15. <view class="sku-unit-li">
  16. <view
  17. class="unit-li"
  18. v-for="(sku, index) in skuList"
  19. @click="handleChoisSku(sku, index)"
  20. :key="index"
  21. :class="skuIndex === index ? 'active' : ''"
  22. >
  23. {{ sku.unit }}
  24. </view>
  25. </view>
  26. </view>
  27. <view class="sku-unit-nunbox">
  28. <view class="sku-unit-nunbox-t">
  29. <view class="sku-unit-nunbox-text">购买数量:</view>
  30. <view class="sku-unit-nunbox-num">
  31. <view class="number-box">
  32. <view
  33. class="iconfont icon-jianhao"
  34. :class="[isQuantity == true ? 'disabled' : '']"
  35. @click="changeCountSub"
  36. ></view>
  37. <input
  38. class="btn-input"
  39. type="number"
  40. v-model="productCount"
  41. maxlength="4"
  42. @blur="changeNumber($event)"
  43. cursor-spacing="40"
  44. />
  45. <view
  46. class="iconfont icon-jiahao"
  47. :class="[isStock == true ? 'disabled' : '']"
  48. @click="changeCountAdd"
  49. ></view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. <view
  56. class="tui-right-flex tui-popup-btn"
  57. :style="{ paddingBottom: isIphoneX ? '68rpx' : '34rpx' }"
  58. >
  59. <view class="tui-flex-1" v-if="type === 1">
  60. <view
  61. class="tui-button"
  62. :class="[goodsData.disabled ? 'disabled' : '', isBtnDisable ? 'disabled' : '']"
  63. @click="handleBtnConfirm"
  64. >确定</view
  65. >
  66. </view>
  67. <view class="tui-modal-flex" v-else>
  68. <button
  69. class="tui-modal-button cancel"
  70. :disabled="goodsData.disabled"
  71. :class="[goodsData.disabled ? 'disabled' : '', isBtnDisable ? 'disabled' : '']"
  72. @click="handleConfirm('add')"
  73. >
  74. 加入购物车
  75. </button>
  76. <button
  77. class="tui-modal-button confirm"
  78. :disabled="goodsData.disabled"
  79. :class="[goodsData.disabled ? 'disabled' : '', isBtnDisable ? 'disabled' : '']"
  80. @click="handleConfirm('buy')"
  81. >
  82. 立即购买
  83. </button>
  84. </view>
  85. </view>
  86. </view>
  87. </tui-bottom-popup>
  88. </view>
  89. </template>
  90. <script>
  91. import { mapState, mapMutations } from 'vuex'
  92. import uniGrader from '@/components/uni-grade/uni-grade.vue'
  93. import cmUnitPrice from './cm-unit-price.vue'
  94. export default {
  95. name: 'cm-unit-popup',
  96. components: {
  97. uniGrader,
  98. cmUnitPrice,
  99. },
  100. props: {
  101. skuProduct: {
  102. type: Object
  103. },
  104. goodsData: {
  105. type: Object
  106. },
  107. popupShow: {
  108. type: Boolean,
  109. default: false
  110. },
  111. type: {
  112. type: Number,
  113. default: 1
  114. },
  115. btnType: {
  116. type: String
  117. }
  118. },
  119. data() {
  120. return {
  121. skuIndex: 0,
  122. productCount: 0,
  123. ladderPriceList: [],
  124. isStock: false, //
  125. isQuantity: false,
  126. skuList: [],
  127. handleStock: 0, // 规格库存
  128. handleMinNumber: 1, // 规格起订量
  129. isShowLadder: false,
  130. laddePopupShow: false,
  131. isBtnDisable: false,
  132. isIphoneX:this.$store.state.isIphoneX,
  133. }
  134. },
  135. created() {
  136. this.initData()
  137. },
  138. computed: {
  139. ...mapState(['hasLogin'])
  140. },
  141. methods: {
  142. async initData(data) {
  143. this.skuList = this.skuProduct.organizeSkus
  144. this.productCount = this.skuList[0].minBuyNumber
  145. this.handleMinNumber = this.skuList[0].minBuyNumber
  146. this.handleStock = this.skuList[0].stock
  147. },
  148. //popup弹窗数量增加按钮
  149. changeCountAdd() {
  150. if (this.productCount === this.handleStock) {
  151. this.isStock = true
  152. return
  153. }
  154. this.productCount++
  155. },
  156. //popup弹窗数量减按钮
  157. changeCountSub() {
  158. if (this.productCount <= this.handleMinNumber) {
  159. this.productCount = this.handleMinNumber
  160. this.isQuantity = true
  161. return
  162. } else {
  163. this.productCount--
  164. this.isQuantity = false
  165. }
  166. },
  167. changeNumber(e) {
  168. let _value = e.detail.value
  169. if (!this.$api.isNumber(_value)) {
  170. this.productCount = this.handleMinNumber
  171. } else if (_value < this.handleMinNumber) {
  172. this.productCount = this.handleMinNumber
  173. } else {
  174. this.productCount = e.detail.value
  175. }
  176. console.log(this.productCount)
  177. },
  178. handleConfirm(type) {
  179. if (this.hasLogin) {
  180. if (this.isBtnDisable || this.goodsData.disabled) {
  181. return
  182. }
  183. this.$emit('buyConfirm', { type: type, productCount: this.productCount })
  184. this.$parent.popupShow3 = false
  185. } else {
  186. this.handleNavLogin()
  187. }
  188. },
  189. handleNavLogin(){
  190. //未登录跳转
  191. const pages = getCurrentPages()
  192. const page = pages[pages.length - 1]
  193. uni.setStorageSync('LOGIN_REDIRECT_URL', page.$page.fullPath)
  194. this.$api.redirectTo('/pages/login/login')
  195. },
  196. handleBtnConfirm() {
  197. //确定加入购物车或立即购买
  198. if (this.isBtnDisable || this.goodsData.disabled) {
  199. return
  200. }
  201. this.$emit('buyConfirm', { type: this.btnType, productCount: this.productCount })
  202. this.$parent.popupShow3 = false
  203. },
  204. handleChoisSku(sku, index) {
  205. // 选择SKU
  206. this.skuIndex = index
  207. this.productCount = this.handleMinNumber = sku.minBuyNumber
  208. this.handleStock = sku.stock
  209. this.isBtnDisable = sku.stock === 0
  210. this.ladderPriceList = sku.ladderPriceList
  211. this.isShowLadder = sku.ladderPriceList ? true : false
  212. this.$emit('skuClick', sku)
  213. },
  214. showLaddePopup() {
  215. // 点击显示阶梯价
  216. this.laddePopupShow = true
  217. },
  218. hidePopup() {
  219. //隐藏
  220. this.$parent.popupShow3 = false
  221. }
  222. }
  223. }
  224. </script>
  225. <style lang="scss">
  226. .tui-shopping-main {
  227. width: 100%;
  228. .tui-sku-title {
  229. width: 100%;
  230. height: 136rpx;
  231. float: left;
  232. margin-bottom: 30rpx;
  233. .tui-sku-image {
  234. width: 138rpx;
  235. height: 138rpx;
  236. float: left;
  237. border-radius: 8rpx;
  238. margin-right: 30rpx;
  239. box-sizing: border-box;
  240. border: 1px dashed #e1e1e1;
  241. image {
  242. width: 134rpx;
  243. height: 134rpx;
  244. border-radius: 10rpx;
  245. }
  246. }
  247. .tui-sku-price {
  248. height: 136rpx;
  249. float: left;
  250. }
  251. }
  252. .tui-sku-unit {
  253. width: 100%;
  254. height: auto;
  255. float: left;
  256. .sku-unit-h1 {
  257. font-size: 28rpx;
  258. line-height: 40rpx;
  259. color: #333333;
  260. font-weight: bold;
  261. }
  262. .sku-unit-li {
  263. width: 100%;
  264. height: auto;
  265. .unit-li {
  266. padding: 0 24rpx;
  267. line-height: 48rpx;
  268. text-align: center;
  269. font-size: 24rpx;
  270. color: #666666;
  271. background: #f5f5f5;
  272. float: left;
  273. margin-right: 16rpx;
  274. margin-top: 12rpx;
  275. margin-bottom: 12rpx;
  276. border-radius: 24rpx;
  277. position: relative;
  278. box-sizing: border-box;
  279. border: 1px solid #f5f5f5;
  280. &.active {
  281. border-color: $color-system;
  282. background: #FFF8EF;
  283. color: $color-system;
  284. .tips {
  285. background: #FF5B00;
  286. }
  287. }
  288. .tips {
  289. padding: 0 10rpx;
  290. line-height: 32rpx;
  291. text-align: center;
  292. font-size: 22rpx;
  293. color: #ffffff;
  294. background: #cccccc;
  295. float: left;
  296. border-radius: 16rpx;
  297. position: absolute;
  298. right: -12rpx;
  299. top: -15rpx;
  300. }
  301. }
  302. }
  303. }
  304. .sku-unit-nunbox {
  305. justify-content: space-between;
  306. align-items: center;
  307. width: 100%;
  308. height: auto;
  309. float: left;
  310. margin-top: 30rpx;
  311. .sku-unit-nunbox-t {
  312. width: 100%;
  313. height: 44rpx;
  314. position: relative;
  315. margin-bottom: 10rpx;
  316. .text {
  317. font-size: $font-size-24;
  318. line-height: 48rpx;
  319. color: #999999;
  320. }
  321. .sku-unit-nunbox-text {
  322. line-height: 44rpx;
  323. font-size: $font-size-28;
  324. float: left;
  325. font-weight: bold;
  326. }
  327. .sku-unit-nunbox-num {
  328. float: right;
  329. .number-box {
  330. display: flex;
  331. justify-content: center;
  332. align-items: center;
  333. border: 2rpx solid #D5D5D5;
  334. border-radius: 30rpx;
  335. height: 48rpx;
  336. margin-left: 20rpx;
  337. .iconfont {
  338. font-size: $font-size-24;
  339. padding: 0 18rpx;
  340. color: #333333;
  341. text-align: center;
  342. line-height: 48rpx;
  343. font-weight: bold;
  344. background: #F7F7F7;
  345. &.icon-jianhao {
  346. border-radius: 30rpx 0 0 30rpx;
  347. &.disabled {
  348. background: #f5f5f5;
  349. }
  350. }
  351. &.icon-jiahao {
  352. border-radius: 0 30rpx 30rpx 0;
  353. &.disabled {
  354. background: #f5f5f5;
  355. }
  356. }
  357. }
  358. .btn-input {
  359. width: 62rpx;
  360. height: 48rpx;
  361. line-height: 48rpx;
  362. background: #ffffff;
  363. border-radius: 4rpx;
  364. text-align: center;
  365. font-size: $font-size-28;
  366. }
  367. }
  368. }
  369. }
  370. }
  371. .sku-unit-ladel {
  372. width: 100%;
  373. height: 64rpx;
  374. line-height: 64rpx;
  375. float: left;
  376. margin-top: 20rpx;
  377. text-align: center;
  378. font-size: 24rpx;
  379. background: #FFF8EF;
  380. color: #F3B574;
  381. }
  382. }
  383. .tui-flex-1 {
  384. .tui-button {
  385. &.disabled {
  386. background: rgba(243,181,116,0.5);
  387. }
  388. }
  389. }
  390. .tui-modal-flex {
  391. width: 100%;
  392. height: 84rpx;
  393. margin-top: 40rpx;
  394. display: flex;
  395. .tui-modal-button {
  396. flex: 1;
  397. line-height: 84rpx;
  398. font-size: $font-size-28;
  399. text-align: center;
  400. border-radius: 42rpx;
  401. padding: 0;
  402. margin: 0 15rpx;
  403. box-sizing: border-box;
  404. &.cancel {
  405. background: #FFF4E6;
  406. color: #F3B574;
  407. &.disabled {
  408. background-color: #e1e1e1;
  409. color: #ffffff;
  410. }
  411. }
  412. &.confirm {
  413. background: $btn-confirm;
  414. color: #ffffff;
  415. &.disabled {
  416. background: rgba(243,181,116,0.5);
  417. }
  418. }
  419. }
  420. }
  421. </style>