cm-unit-popup.vue 8.1 KB

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