小程序端工程代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
4.1 KiB

  1. <template>
  2. <view>
  3. <view class="product-window" :class="attr.cartAttr === true ? 'on' : ''">
  4. <view class="textpic acea-row row-between-wrapper">
  5. <view class="pictrue">
  6. <image @tap="previewImage" :src="attr.productSelect.image" class="image" />
  7. </view>
  8. <view class="text">
  9. <view class="line1">{{ attr.productSelect.store_name }}</view>
  10. <view class="money font-color-red" v-if="!isIntegral">
  11. <text class="num">{{ attr.productSelect.price }}</text>
  12. <text class="stock">库存: {{ attr.productSelect.stock }}</text>
  13. </view>
  14. <view class="money font-color-red" v-if="isIntegral">
  15. <text class="num">{{ attr.productSelect.integral }}积分</text>
  16. <text class="stock">库存: {{ attr.productSelect.stock }}</text>
  17. </view>
  18. </view>
  19. <view class="iconfont icon-guanbi" @click="closeAttr"></view>
  20. </view>
  21. <view class="productWinList">
  22. <view
  23. class="item"
  24. v-for="(item, indexw) in attr.productAttr"
  25. :key="indexw"
  26. >
  27. <view class="title">{{ item.attrName }}</view>
  28. <view class="listn acea-row row-middle">
  29. <view
  30. class="itemn"
  31. :class="item.index == indexn ? 'on' : ''"
  32. v-for="(itemn, indexn) in item.attrValue"
  33. @click="tapAttr(indexw, indexn)"
  34. :key="indexn"
  35. >{{ itemn.attr }}</view
  36. >
  37. </view>
  38. </view>
  39. </view>
  40. <view class="cart">
  41. <view class="title">数量</view>
  42. <view class="carnum acea-row row-left">
  43. <view
  44. class="item reduce"
  45. :class="cartNum <= 1 ? 'on' : ''"
  46. @click="CartNumDes"
  47. >-</view
  48. >
  49. <view class="item num">{{ cartNum }}</view>
  50. <view
  51. class="item plus"
  52. :class="cartNum >= attr.productSelect.stock ? 'on' : ''"
  53. @click="CartNumAdd"
  54. >+</view
  55. >
  56. </view>
  57. </view>
  58. </view>
  59. <view
  60. class="mask"
  61. @touchmove.prevent
  62. :hidden="attr.cartAttr === false"
  63. @click="closeAttr"
  64. ></view>
  65. </view>
  66. </template>
  67. <script>
  68. export default {
  69. name: "ProductWindow",
  70. props: {
  71. isIntegral:Boolean,
  72. attr: {
  73. type: Object,
  74. default: () => {},
  75. },
  76. cartNum: {
  77. type: Number,
  78. default: () => 1,
  79. },
  80. },
  81. data: function () {
  82. return {};
  83. },
  84. mounted: function () {
  85. console.log(this.attr)
  86. console.log(this);
  87. },
  88. watch: {
  89. attr(nextAttr) {
  90. },
  91. },
  92. methods: {
  93. closeAttr: function () {
  94. this.$emit("changeFun", { action: "changeattr", value: false });
  95. },
  96. CartNumDes: function () {
  97. this.$emit("changeFun", { action: "ChangeCartNum", value: false });
  98. },
  99. CartNumAdd: function () {
  100. this.$emit("changeFun", { action: "ChangeCartNum", value: 1 });
  101. },
  102. tapAttr: function (indexw, indexn) {
  103. // 修改商品规格不生效的原因:
  104. // H5端下面写法,attr更新,但是除H5外其他端不支持,
  105. // 尽量避免下面的骚写法,不要在子组件内更新props
  106. // 这里修改是为了能获取到被选中的属性
  107. this.attr.productAttr[indexw].index = indexn;
  108. let that = this;
  109. let value = that.getCheckedValue().sort().join(",");
  110. that.$emit("changeFun", {
  111. action: "ChangeAttr",
  112. value: {
  113. value,
  114. indexw,
  115. indexn,
  116. },
  117. });
  118. },
  119. //获取被选中属性;
  120. getCheckedValue: function () {
  121. let productAttr = this.attr.productAttr;
  122. let value = [];
  123. for (let i = 0; i < productAttr.length; i++) {
  124. for (let j = 0; j < productAttr[i].attrValueArr.length; j++) {
  125. if (productAttr[i].index === j) {
  126. value.push(productAttr[i].attrValueArr[j]);
  127. }
  128. }
  129. }
  130. return value;
  131. },
  132. previewImage() {
  133. uni.previewImage({
  134. current: 0,
  135. urls: [this.attr.productSelect.image],
  136. });
  137. },
  138. },
  139. };
  140. </script>