cm-unit-popup.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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 if (_value > this.handleStock) {
  174. this.productCount = this.handleStock
  175. } else {
  176. this.productCount = e.detail.value
  177. }
  178. },
  179. handleConfirm(type) {
  180. if (this.hasLogin) {
  181. if (this.isBtnDisable || this.goodsData.disabled) {
  182. return
  183. }
  184. this.$emit('buyConfirm', { type: type, productCount: this.productCount })
  185. this.$parent.popupShow3 = false
  186. } else {
  187. this.handleNavLogin()
  188. }
  189. },
  190. handleNavLogin(){
  191. //未登录跳转
  192. const pages = getCurrentPages()
  193. const page = pages[pages.length - 1]
  194. uni.setStorageSync('LOGIN_REDIRECT_URL', page.$page.fullPath)
  195. this.$api.redirectTo('/pages/login/login')
  196. },
  197. handleBtnConfirm() {
  198. //确定加入购物车或立即购买
  199. if (this.isBtnDisable || this.goodsData.disabled) {
  200. return
  201. }
  202. this.$emit('buyConfirm', { type: this.btnType, productCount: this.productCount })
  203. this.$parent.popupShow3 = false
  204. },
  205. handleChoisSku(sku, index) {
  206. // 选择SKU
  207. this.skuIndex = index
  208. this.productCount = this.handleMinNumber = sku.minBuyNumber
  209. this.handleStock = sku.stock
  210. this.isBtnDisable = sku.stock === 0
  211. this.ladderPriceList = sku.ladderPriceList
  212. this.isShowLadder = sku.ladderPriceList ? true : false
  213. this.$emit('skuClick', sku)
  214. },
  215. showLaddePopup() {
  216. // 点击显示阶梯价
  217. this.laddePopupShow = true
  218. },
  219. hidePopup() {
  220. //隐藏
  221. this.$parent.popupShow3 = false
  222. }
  223. }
  224. }
  225. </script>
  226. <style lang="scss">
  227. .tui-shopping-main {
  228. width: 100%;
  229. .tui-sku-title {
  230. width: 100%;
  231. height: 136rpx;
  232. float: left;
  233. margin-bottom: 30rpx;
  234. .tui-sku-image {
  235. width: 138rpx;
  236. height: 138rpx;
  237. float: left;
  238. border-radius: 8rpx;
  239. margin-right: 30rpx;
  240. box-sizing: border-box;
  241. border: 1px dashed #e1e1e1;
  242. image {
  243. width: 134rpx;
  244. height: 134rpx;
  245. border-radius: 10rpx;
  246. }
  247. }
  248. .tui-sku-price {
  249. height: 136rpx;
  250. float: left;
  251. }
  252. }
  253. .tui-sku-unit {
  254. width: 100%;
  255. height: auto;
  256. float: left;
  257. .sku-unit-h1 {
  258. font-size: 28rpx;
  259. line-height: 40rpx;
  260. color: #333333;
  261. font-weight: bold;
  262. }
  263. .sku-unit-li {
  264. width: 100%;
  265. height: auto;
  266. .unit-li {
  267. padding: 0 24rpx;
  268. line-height: 48rpx;
  269. text-align: center;
  270. font-size: 24rpx;
  271. color: #666666;
  272. background: #f5f5f5;
  273. float: left;
  274. margin-right: 16rpx;
  275. margin-top: 12rpx;
  276. margin-bottom: 12rpx;
  277. border-radius: 24rpx;
  278. position: relative;
  279. box-sizing: border-box;
  280. border: 1px solid #f5f5f5;
  281. &.active {
  282. border-color: $color-system;
  283. background: #FFF8EF;
  284. color: $color-system;
  285. .tips {
  286. background: #FF5B00;
  287. }
  288. }
  289. .tips {
  290. padding: 0 10rpx;
  291. line-height: 32rpx;
  292. text-align: center;
  293. font-size: 22rpx;
  294. color: #ffffff;
  295. background: #cccccc;
  296. float: left;
  297. border-radius: 16rpx;
  298. position: absolute;
  299. right: -12rpx;
  300. top: -15rpx;
  301. }
  302. }
  303. }
  304. }
  305. .sku-unit-nunbox {
  306. justify-content: space-between;
  307. align-items: center;
  308. width: 100%;
  309. height: auto;
  310. float: left;
  311. margin-top: 30rpx;
  312. .sku-unit-nunbox-t {
  313. width: 100%;
  314. height: 44rpx;
  315. position: relative;
  316. margin-bottom: 10rpx;
  317. .text {
  318. font-size: $font-size-24;
  319. line-height: 48rpx;
  320. color: #999999;
  321. }
  322. .sku-unit-nunbox-text {
  323. line-height: 44rpx;
  324. font-size: $font-size-28;
  325. float: left;
  326. font-weight: bold;
  327. }
  328. .sku-unit-nunbox-num {
  329. float: right;
  330. .number-box {
  331. display: flex;
  332. justify-content: center;
  333. align-items: center;
  334. border: 2rpx solid #D5D5D5;
  335. border-radius: 30rpx;
  336. height: 48rpx;
  337. margin-left: 20rpx;
  338. .iconfont {
  339. font-size: $font-size-24;
  340. padding: 0 18rpx;
  341. color: #333333;
  342. text-align: center;
  343. line-height: 48rpx;
  344. font-weight: bold;
  345. background: #F7F7F7;
  346. &.icon-jianhao {
  347. border-radius: 30rpx 0 0 30rpx;
  348. &.disabled {
  349. background: #f5f5f5;
  350. }
  351. }
  352. &.icon-jiahao {
  353. border-radius: 0 30rpx 30rpx 0;
  354. &.disabled {
  355. background: #f5f5f5;
  356. }
  357. }
  358. }
  359. .btn-input {
  360. width: 62rpx;
  361. height: 48rpx;
  362. line-height: 48rpx;
  363. background: #ffffff;
  364. border-radius: 4rpx;
  365. text-align: center;
  366. font-size: $font-size-28;
  367. }
  368. }
  369. }
  370. }
  371. }
  372. .sku-unit-ladel {
  373. width: 100%;
  374. height: 64rpx;
  375. line-height: 64rpx;
  376. float: left;
  377. margin-top: 20rpx;
  378. text-align: center;
  379. font-size: 24rpx;
  380. background: #FFF8EF;
  381. color: #F3B574;
  382. }
  383. }
  384. .tui-flex-1 {
  385. .tui-button {
  386. &.disabled {
  387. background: rgba(243,181,116,0.5);
  388. }
  389. }
  390. }
  391. .tui-modal-flex {
  392. width: 100%;
  393. height: 84rpx;
  394. margin-top: 40rpx;
  395. display: flex;
  396. .tui-modal-button {
  397. flex: 1;
  398. line-height: 84rpx;
  399. font-size: $font-size-28;
  400. text-align: center;
  401. border-radius: 42rpx;
  402. padding: 0;
  403. margin: 0 15rpx;
  404. box-sizing: border-box;
  405. &.cancel {
  406. background: #FFF4E6;
  407. color: #F3B574;
  408. &.disabled {
  409. background-color: #e1e1e1;
  410. color: #ffffff;
  411. }
  412. }
  413. &.confirm {
  414. background: $btn-confirm;
  415. color: #ffffff;
  416. &.disabled {
  417. background: rgba(243,181,116,0.5);
  418. }
  419. }
  420. }
  421. }
  422. </style>