index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <template>
  2. <view :style="viewColor">
  3. <view class="product-window" :class="(attr.cartAttr === true ? 'on' : '') + ' ' + (iSbnt || destri?'join':'') + ' ' + (isPresell ?'presell-window':'product-window')">
  4. <view class="textpic acea-row row-between-wrapper">
  5. <view class="pictrue">
  6. <image :src="attr.productSelect.image ? attr.productSelect.image : image" @click="loookImg"></image>
  7. </view>
  8. <view class="text">
  9. <view class="line1">
  10. {{ attr.productSelect.store_name }}
  11. </view>
  12. <view v-if="isPresell" class="money presell_price">
  13. <view>
  14. 预售价
  15. ¥<text class="num">{{ attr.productSelect.price }}</text>
  16. <text v-if="presell_type === 2">定金¥<text class="num">{{ attr.productSelect.down_price }}</text></text>
  17. </view>
  18. <text class="stock" v-if='isShow'>库存: {{ attr.productSelect.stock }}</text>
  19. <text class='stock' v-if="limitNum">限量: {{attr.productSelect.quota_show}}</text>
  20. </view>
  21. <view v-else class="money">
  22. ¥<text class="num">{{ attr.productSelect.price }}</text>
  23. <text class="stock" v-if='isShow'>库存: {{ attr.productSelect.stock }}</text>
  24. <text class='stock' v-if="limitNum">限量: {{attr.productSelect.quota_show}}</text>
  25. </view>
  26. </view>
  27. <view class="iconfont icon-guanbi" @click="closeAttr"></view>
  28. </view>
  29. <view class="productWinList">
  30. <view class="item" v-for="(item, indexw) in attr.productAttr" :key="indexw">
  31. <view class="title">{{ item.attr_name }}</view>
  32. <view class="listn acea-row row-middle">
  33. <view class="itemn" :class="item.index === itemn.attr ? 'on' : ''" v-for="(itemn, indexn) in item.attr_value"
  34. @click="tapAttr(indexw, indexn)" :key="indexn">
  35. {{ itemn.attr }}
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. <view class="cart acea-row">
  41. <view class="title">数量</view>
  42. <view class="carnum acea-row row-left">
  43. <view class="item reduce" :class="attr.productSelect.cart_num <= 1 ? 'on' : ''" @click="CartNumDes">
  44. -
  45. </view>
  46. <view class='item num'>
  47. <input type="number" v-model="attr.productSelect.cart_num" data-name="productSelect.cart_num" @input="bindCode(attr.productSelect.cart_num)" @keydown.native="btKeyDown" @keyup.native="btKeyUp"></input>
  48. </view>
  49. <view v-if="iSplus" class="item plus" :class=" attr.productSelect.cart_num >= attr.productSelect.stock || destri ? 'on' : ''"
  50. @click="CartNumAdd">+</view>
  51. <view v-else class='item plus' :class='(attr.productSelect.cart_num >= attr.productSelect.quota_show)
  52. || (attr.productSelect.cart_num >= attr.productSelect.product_stock)? "on":""'
  53. @click='CartNumAdd'>+</view>
  54. </view>
  55. </view>
  56. <view class="joinBnt b-color" v-if="destri && attr.productSelect.stock>0" @click="goCat">立即购买</view>
  57. <view class="joinBnt on" v-else-if="destri && attr.productSelect.stock<=0">已售罄</view>
  58. <view class="joinBnt b-color" v-if="iSbnt && attr.productSelect.stock>0"
  59. @click="goCat">我要参团</view>
  60. <view class="joinBnt on" v-else-if="(iSbnt && attr.productSelect.stock<=0)">已售罄</view>
  61. </view>
  62. <view class="mask" @touchmove.prevent :hidden="attr.cartAttr === false" @click="closeAttr"></view>
  63. </view>
  64. </template>
  65. <script>
  66. // +----------------------------------------------------------------------
  67. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  68. // +----------------------------------------------------------------------
  69. // | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
  70. // +----------------------------------------------------------------------
  71. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  72. // +----------------------------------------------------------------------
  73. // | Author: CRMEB Team <admin@crmeb.com>
  74. // +----------------------------------------------------------------------
  75. import { mapGetters } from "vuex";
  76. export default {
  77. props: {
  78. attr: {
  79. type: Object,
  80. default: () => {}
  81. },
  82. limitNum: {
  83. type: Number,
  84. value: 0
  85. },
  86. isShow: {
  87. type: Number,
  88. value: 0
  89. },
  90. iSbnt: {
  91. type: Number,
  92. value: 0
  93. },
  94. iSplus: {
  95. type: Number,
  96. value: 0
  97. },
  98. destri: {
  99. type: Number,
  100. value: 0
  101. },
  102. isPresell: {
  103. type: Number,
  104. value: 0
  105. },
  106. presell_type: {
  107. type: Number,
  108. value: 1
  109. },
  110. image: {
  111. type: String,
  112. value: ''
  113. }
  114. },
  115. computed: mapGetters(['viewColor']),
  116. data() {
  117. return {};
  118. },
  119. mounted(){},
  120. methods: {
  121. // 查看大图
  122. loookImg(){
  123. let self = this
  124. let arr = [self.attr.productSelect.image ? self.attr.productSelect.image : self.image]
  125. uni.previewImage({
  126. urls: arr,
  127. });
  128. },
  129. goCat: function() {
  130. this.$emit('goCat');
  131. },
  132. /**
  133. * 购物车手动输入数量
  134. *
  135. */
  136. bindCode: function(e) {
  137. let num = JSON.parse(JSON.stringify(e))
  138. this.$emit('iptCartNum', num);
  139. },
  140. btKeyDown(e) {
  141. e.target.value = e.target.value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5]/g,"");
  142. },
  143. btKeyUp(e) {
  144. e.target.value = e.target.value.replace(/[`~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~!@#¥%……&*()——\-+={}|《》?:“”【】、;‘’,。、]/g,"")
  145. },
  146. closeAttr: function() {
  147. this.$emit('myevent');
  148. },
  149. CartNumDes: function() {
  150. if (!this.destri) {
  151. this.$emit('ChangeCartNum', false);
  152. }
  153. },
  154. CartNumAdd: function() {
  155. if (!this.destri) {
  156. this.$emit('ChangeCartNum', true);
  157. }
  158. },
  159. tapAttr: function(indexw, indexn) {
  160. let that = this;
  161. that.$emit("attrVal", {
  162. indexw: indexw,
  163. indexn: indexn
  164. });
  165. this.$set(this.attr.productAttr[indexw], 'index', this.attr.productAttr[indexw].attr_values[indexn]);
  166. let value = that.getCheckedValue().join(",");
  167. that.$emit("ChangeAttr", value);
  168. },
  169. //获取被选中属性;
  170. getCheckedValue: function() {
  171. let productAttr = this.attr.productAttr;
  172. let value = [];
  173. for (let i = 0; i < productAttr.length; i++) {
  174. for (let j = 0; j < productAttr[i].attr_values.length; j++) {
  175. if (productAttr[i].index === productAttr[i].attr_values[j]) {
  176. value.push(productAttr[i].attr_values[j]);
  177. }
  178. }
  179. }
  180. return value;
  181. }
  182. }
  183. }
  184. </script>
  185. <style scoped lang="scss">
  186. .product-window {
  187. position: fixed;
  188. bottom: 0;
  189. width: 100%;
  190. left: 0;
  191. background-color: #fff;
  192. z-index: 77;
  193. border-radius: 16rpx 16rpx 0 0;
  194. padding-bottom: 140rpx;
  195. transform: translate3d(0, 100%, 0);
  196. transition: all .3s cubic-bezier(.25, .5, .5, .9);
  197. &.presell-window {
  198. padding-bottom: 200rpx;
  199. }
  200. }
  201. .product-window.on {
  202. transform: translate3d(0, 0, 0);
  203. }
  204. .product-window.join {
  205. padding-bottom: 30rpx;
  206. }
  207. .product-window .textpic {
  208. padding: 0 80rpx 0 30rpx;
  209. margin-top: 29rpx;
  210. position: relative;
  211. }
  212. .product-window .textpic .pictrue {
  213. width: 150rpx;
  214. height: 150rpx;
  215. }
  216. .product-window .textpic .pictrue image {
  217. width: 100%;
  218. height: 100%;
  219. border-radius: 10rpx;
  220. }
  221. .product-window .textpic .text {
  222. width: 460rpx;
  223. font-size: 32rpx;
  224. color: #202020;
  225. }
  226. .product-window .textpic .text .money {
  227. font-size: 24rpx;
  228. margin-top: 40rpx;
  229. color: var(--view-priceColor);
  230. }
  231. .product-window .textpic .text .money .num {
  232. font-size: 36rpx;
  233. }
  234. .product-window .textpic .text .money .stock {
  235. color: #999;
  236. margin-left: 18rpx;
  237. }
  238. .product-window .textpic .text .presell_price {
  239. color: #FF7F00;
  240. .num {
  241. display: inline-block;
  242. margin-right: 20rpx;
  243. }
  244. .stock {
  245. margin-left: 0;
  246. }
  247. }
  248. .product-window .textpic .iconfont {
  249. position: absolute;
  250. right: 30rpx;
  251. top: -5rpx;
  252. font-size: 35rpx;
  253. color: #8a8a8a;
  254. }
  255. .product-window .productWinList {
  256. max-height: 395rpx;
  257. overflow: auto;
  258. margin-top: 36rpx;
  259. }
  260. .product-window .productWinList .item~.item {
  261. margin-top: 36rpx;
  262. }
  263. .product-window .productWinList .item .title {
  264. font-size: 30rpx;
  265. color: #999;
  266. padding: 0 30rpx;
  267. }
  268. .product-window .productWinList .item .listn {
  269. padding: 0 30rpx 0 16rpx;
  270. }
  271. .product-window .productWinList .item .listn .itemn {
  272. border: 1px solid #bbb;
  273. font-size: 26rpx;
  274. color: #282828;
  275. padding: 7rpx 33rpx;
  276. border-radius: 6rpx;
  277. margin: 14rpx 0 0 14rpx;
  278. }
  279. .product-window .productWinList .item .listn .itemn.on {
  280. color: #fff;
  281. background-color: var(--view-theme);
  282. border-color: var(--view-theme);
  283. }
  284. .product-window .cart {
  285. margin-top: 36rpx;
  286. padding: 0 30rpx;
  287. display: -webkit-box;
  288. display: -webkit-flex;
  289. display: -ms-flexbox;
  290. display: flex;
  291. -webkit-box-pack: justify;
  292. -webkit-justify-content: space-between;
  293. -ms-flex-pack: justify;
  294. justify-content: space-between;
  295. }
  296. .product-window .cart .title {
  297. font-size: 30rpx;
  298. color: #999;
  299. line-height: 54rpx;
  300. }
  301. .product-window .cart .carnum {
  302. height: 54rpx;
  303. }
  304. .product-window .cart .carnum view {
  305. border: 1px solid #a4a4a4;
  306. width: 84rpx;
  307. text-align: center;
  308. height: 100%;
  309. line-height: 54rpx;
  310. color: #a4a4a4;
  311. font-size: 45rpx;
  312. }
  313. .product-window .cart .carnum .reduce {
  314. border-right: 0;
  315. border-radius: 6rpx 0 0 6rpx;
  316. line-height: 48rpx;
  317. }
  318. .product-window .cart .carnum .reduce.on {
  319. border-color: #e3e3e3;
  320. color: #dedede;
  321. }
  322. .product-window .cart .carnum .plus {
  323. border-left: 0;
  324. border-radius: 0 6rpx 6rpx 0;
  325. line-height: 46rpx;
  326. }
  327. .product-window .cart .carnum .plus.on {
  328. border-color: #e3e3e3;
  329. color: #dedede;
  330. }
  331. .product-window .cart .carnum .num {
  332. color: #282828;
  333. font-size: 28rpx;
  334. }
  335. .product-window .joinBnt {
  336. font-size: 30rpx;
  337. width: 620rpx;
  338. height: 86rpx;
  339. border-radius: 50rpx;
  340. text-align: center;
  341. line-height: 86rpx;
  342. color: #fff;
  343. margin: 21rpx auto 0 auto;
  344. &.b-color{
  345. background-color: var(--view-theme);
  346. }
  347. }
  348. .product-window .joinBnt.on {
  349. background-color: #bbb;
  350. color: #fff;
  351. }
  352. </style>