index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <template>
  2. <view>
  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 font-color">
  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)"></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 bg-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 bg-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. export default {
  67. props: {
  68. attr: {
  69. type: Object,
  70. default: () => {}
  71. },
  72. limitNum: {
  73. type: Number,
  74. value: 0
  75. },
  76. isShow: {
  77. type: Number,
  78. value: 0
  79. },
  80. iSbnt: {
  81. type: Number,
  82. value: 0
  83. },
  84. iSplus: {
  85. type: Number,
  86. value: 0
  87. },
  88. destri: {
  89. type: Number,
  90. value: 0
  91. },
  92. isPresell: {
  93. type: Number,
  94. value: 0
  95. },
  96. presell_type: {
  97. type: Number,
  98. value: 1
  99. },
  100. image: {
  101. type: String,
  102. value: ''
  103. }
  104. },
  105. data() {
  106. return {};
  107. },
  108. mounted(){
  109. console.log(this.attr);
  110. },
  111. methods: {
  112. // 查看大图
  113. loookImg(){
  114. let self = this
  115. let arr = [self.attr.productSelect.image ? self.attr.productSelect.image : self.image]
  116. console.log(arr,'arr')
  117. uni.previewImage({
  118. urls: arr,
  119. });
  120. },
  121. goCat: function() {
  122. this.$emit('goCat');
  123. },
  124. /**
  125. * 购物车手动输入数量
  126. *
  127. */
  128. bindCode: function(e) {
  129. let num = JSON.parse(JSON.stringify(e))
  130. this.$emit('iptCartNum', num);
  131. },
  132. closeAttr: function() {
  133. this.$emit('myevent');
  134. },
  135. CartNumDes: function() {
  136. if (!this.destri) {
  137. this.$emit('ChangeCartNum', false);
  138. }
  139. },
  140. CartNumAdd: function() {
  141. if (!this.destri) {
  142. this.$emit('ChangeCartNum', true);
  143. }
  144. },
  145. tapAttr: function(indexw, indexn) {
  146. let that = this;
  147. that.$emit("attrVal", {
  148. indexw: indexw,
  149. indexn: indexn
  150. });
  151. this.$set(this.attr.productAttr[indexw], 'index', this.attr.productAttr[indexw].attr_values[indexn]);
  152. let value = that.getCheckedValue().join(",");
  153. that.$emit("ChangeAttr", value);
  154. },
  155. //获取被选中属性;
  156. getCheckedValue: function() {
  157. console.log(this.attr)
  158. let productAttr = this.attr.productAttr;
  159. let value = [];
  160. for (let i = 0; i < productAttr.length; i++) {
  161. for (let j = 0; j < productAttr[i].attr_values.length; j++) {
  162. if (productAttr[i].index === productAttr[i].attr_values[j]) {
  163. value.push(productAttr[i].attr_values[j]);
  164. }
  165. }
  166. }
  167. return value;
  168. }
  169. }
  170. }
  171. </script>
  172. <style scoped lang="scss">
  173. .product-window {
  174. position: fixed;
  175. bottom: 0;
  176. width: 100%;
  177. left: 0;
  178. background-color: #fff;
  179. z-index: 77;
  180. border-radius: 16rpx 16rpx 0 0;
  181. padding-bottom: 140rpx;
  182. transform: translate3d(0, 100%, 0);
  183. transition: all .3s cubic-bezier(.25, .5, .5, .9);
  184. &.presell-window {
  185. padding-bottom: 200rpx;
  186. }
  187. }
  188. .product-window.on {
  189. transform: translate3d(0, 0, 0);
  190. }
  191. .product-window.join {
  192. padding-bottom: 30rpx;
  193. }
  194. .product-window .textpic {
  195. padding: 0 80rpx 0 30rpx;
  196. margin-top: 29rpx;
  197. position: relative;
  198. }
  199. .product-window .textpic .pictrue {
  200. width: 150rpx;
  201. height: 150rpx;
  202. }
  203. .product-window .textpic .pictrue image {
  204. width: 100%;
  205. height: 100%;
  206. border-radius: 10rpx;
  207. }
  208. .product-window .textpic .text {
  209. width: 460rpx;
  210. font-size: 32rpx;
  211. color: #202020;
  212. }
  213. .product-window .textpic .text .money {
  214. font-size: 24rpx;
  215. margin-top: 40rpx;
  216. }
  217. .product-window .textpic .text .money .num {
  218. font-size: 36rpx;
  219. }
  220. .product-window .textpic .text .money .stock {
  221. color: #999;
  222. margin-left: 18rpx;
  223. }
  224. .product-window .textpic .text .presell_price {
  225. color: #FF7F00;
  226. .num {
  227. display: inline-block;
  228. margin-right: 20rpx;
  229. }
  230. .stock {
  231. margin-left: 0;
  232. }
  233. }
  234. .product-window .textpic .iconfont {
  235. position: absolute;
  236. right: 30rpx;
  237. top: -5rpx;
  238. font-size: 35rpx;
  239. color: #8a8a8a;
  240. }
  241. .product-window .productWinList {
  242. max-height: 395rpx;
  243. overflow: auto;
  244. margin-top: 36rpx;
  245. }
  246. .product-window .productWinList .item~.item {
  247. margin-top: 36rpx;
  248. }
  249. .product-window .productWinList .item .title {
  250. font-size: 30rpx;
  251. color: #999;
  252. padding: 0 30rpx;
  253. }
  254. .product-window .productWinList .item .listn {
  255. padding: 0 30rpx 0 16rpx;
  256. }
  257. .product-window .productWinList .item .listn .itemn {
  258. border: 1px solid #bbb;
  259. font-size: 26rpx;
  260. color: #282828;
  261. padding: 7rpx 33rpx;
  262. border-radius: 6rpx;
  263. margin: 14rpx 0 0 14rpx;
  264. }
  265. .product-window .productWinList .item .listn .itemn.on {
  266. color: #fff;
  267. background-color: #ff3700;
  268. border-color: #ff3700;
  269. }
  270. .product-window .cart {
  271. margin-top: 36rpx;
  272. padding: 0 30rpx;
  273. display: -webkit-box;
  274. display: -webkit-flex;
  275. display: -ms-flexbox;
  276. display: flex;
  277. -webkit-box-pack: justify;
  278. -webkit-justify-content: space-between;
  279. -ms-flex-pack: justify;
  280. justify-content: space-between;
  281. }
  282. .product-window .cart .title {
  283. font-size: 30rpx;
  284. color: #999;
  285. line-height: 54rpx;
  286. }
  287. .product-window .cart .carnum {
  288. height: 54rpx;
  289. }
  290. .product-window .cart .carnum view {
  291. border: 1px solid #a4a4a4;
  292. width: 84rpx;
  293. text-align: center;
  294. height: 100%;
  295. line-height: 54rpx;
  296. color: #a4a4a4;
  297. font-size: 45rpx;
  298. }
  299. .product-window .cart .carnum .reduce {
  300. border-right: 0;
  301. border-radius: 6rpx 0 0 6rpx;
  302. line-height: 48rpx;
  303. }
  304. .product-window .cart .carnum .reduce.on {
  305. border-color: #e3e3e3;
  306. color: #dedede;
  307. }
  308. .product-window .cart .carnum .plus {
  309. border-left: 0;
  310. border-radius: 0 6rpx 6rpx 0;
  311. line-height: 46rpx;
  312. }
  313. .product-window .cart .carnum .plus.on {
  314. border-color: #e3e3e3;
  315. color: #dedede;
  316. }
  317. .product-window .cart .carnum .num {
  318. color: #282828;
  319. font-size: 28rpx;
  320. }
  321. .product-window .joinBnt {
  322. font-size: 30rpx;
  323. width: 620rpx;
  324. height: 86rpx;
  325. border-radius: 50rpx;
  326. text-align: center;
  327. line-height: 86rpx;
  328. color: #fff;
  329. margin: 21rpx auto 0 auto;
  330. }
  331. .product-window .joinBnt.on {
  332. background-color: #bbb;
  333. color: #fff;
  334. }
  335. </style>