cm-unit-popup.vue 8.9 KB

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