app-goods-attr.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <view>
  3. <view class="dir-left-nowrap cross-center app-goods-attr">
  4. <view class="box-grow-0">选择</view>
  5. <view class="box-grow-1 attr" v-if="selectAttr">
  6. <text v-for="(item, index) in selectAttr.attr_list" :key="index">
  7. {{item.attr_group_name}}:{{item.attr_name}}
  8. </text>
  9. </view>
  10. <view class="box-grow-1 attr" v-else>
  11. <view>请选择规格</view>
  12. </view>
  13. <image src="../../../static/image/icon/arrow-right.png"></image>
  14. </view>
  15. <view v-if="newAttrGroups.length > 0 && attrCount > 1" class="goods-attr-box dir-left-nowrap">
  16. <div class="attr-list dir-left-wrap cross-center">
  17. <template v-if="pictureList.length > 0">
  18. <image class="attr-img" v-for="(picture, index) in pictureList" :key="index" :src="picture"></image>
  19. </template>
  20. <template v-else>
  21. <view v-for="attrItem in newAttrGroups" :key="attrItem.attr_name"
  22. class="attr-btn t-omit main-center cross-center">
  23. {{attrItem.attr_name}}
  24. </view>
  25. </template>
  26. </div>
  27. <view v-if="attrCount > 0" class="attr-btn cross-center t-omit">
  28. 共{{attrCount}}个{{attrName}}可选
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. name: 'app-goods-attr',
  36. props: {
  37. selectAttr: {
  38. type: Object,
  39. default() {
  40. return {};
  41. }
  42. },
  43. attrGroups: {
  44. type: Array,
  45. default() {
  46. return [];
  47. }
  48. },
  49. attr: {
  50. type: Array,
  51. default() {
  52. return [];
  53. }
  54. }
  55. },
  56. data() {
  57. return {
  58. newAttrGroups: [],
  59. pictureList: [],
  60. attrCount: 0,
  61. attrName: '',
  62. }
  63. },
  64. watch: {
  65. attrGroups() {
  66. this.getData();
  67. }
  68. },
  69. methods: {
  70. getData() {
  71. let self = this;
  72. self.newAttrGroups = [];
  73. self.pictureList = [];
  74. self.attrCount = 0;
  75. self.attrName = '';
  76. self.attrGroups.forEach((item, index) => {
  77. if (!self.attrName) {
  78. self.attrName = item.attr_group_name;
  79. item.attr_list.forEach( item2 => {
  80. self.attrCount += 1;
  81. })
  82. }
  83. if (index === 0) {
  84. item.attr_list.forEach( item2 => {
  85. if (self.newAttrGroups.length < 3) {
  86. self.newAttrGroups.push(item2)
  87. }
  88. if (item2.pic_url && self.pictureList.length < 5) {
  89. self.pictureList.push(item2.pic_url);
  90. }
  91. })
  92. }
  93. });
  94. }
  95. },
  96. mounted() {
  97. this.getData();
  98. }
  99. }
  100. </script>
  101. <style scoped lang="scss">
  102. .app-goods-attr {
  103. background-color: #ffffff;
  104. padding: 0 #{24rpx};
  105. height: #{100rpx};
  106. .attr {
  107. margin: 0 #{40rpx};
  108. color: $uni-general-color-two;
  109. font-size: $uni-font-size-weak-one;
  110. display: inline-block;
  111. white-space: nowrap;
  112. overflow: hidden;
  113. text-overflow: ellipsis;
  114. text {
  115. margin-right: #{10rpx};
  116. }
  117. }
  118. image {
  119. width: #{12rpx};
  120. height: #{22rpx};
  121. display: block;
  122. }
  123. }
  124. .goods-attr-box {
  125. background-color: #ffffff;
  126. padding: 0 #{24rpx} #{24rpx} #{130rpx};
  127. .attr-list {
  128. overflow: hidden;
  129. .attr-btn {
  130. width: #{100rpx};
  131. text-align: center;
  132. }
  133. .attr-img {
  134. width: #{56rpx};
  135. height: #{56rpx};
  136. margin-right: #{8rpx};
  137. }
  138. }
  139. .attr-btn {
  140. max-width: #{200rpx};
  141. background: #f7f7f7;
  142. color: #999999;
  143. font-size: #{24rpx};
  144. padding: 0 #{20rpx};
  145. margin-right: #{8rpx};
  146. -webkit-border-radius: #{8rpx};
  147. -moz-border-radius: #{8rpx};
  148. border-radius: #{8rpx};
  149. height: #{56rpx};
  150. line-height: #{56rpx};
  151. }
  152. }
  153. </style>