specSelect.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <view class="spec-select-conetnt">
  3. <view class="spec-select" v-for="(item,index) in newList" :key="item.key">
  4. <view class="spec-select-title">
  5. <text class="title-1">{{item.shopSpec}}</text>
  6. <text class="title-2">【{{item.featureType==1?'单选':'多选'}}】</text>
  7. </view>
  8. <view class="spec-select-list">
  9. <view v-for="(v,i) in item.params" :key="i"
  10. :class="item.featureType === 1 ? (item.inputValue == v.tagKey ? 'active' : 'list__item') : (item.inputValue.indexOf(v.tagKey) !==-1 ? 'active' : 'list__item')"
  11. @click="handleSelect(item,v)">
  12. {{v.name}}
  13. <image
  14. v-if="item.featureType === 1 ? (item.inputValue == v.tagKey ? 'active' : 'list__item') : (item.inputValue.indexOf(v.tagKey) !==-1 ? 'active' : 'list__item')"
  15. src="../static/xuanzhong.png" class="image_active">
  16. </image>
  17. </view>
  18. </view>
  19. </view>
  20. <view class="spec-btn">
  21. <u-button type="primary" text="确定" @click="submit"></u-button>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. name: "specSelect",
  28. props: {
  29. list: {
  30. type: Array,
  31. default: {}
  32. },
  33. },
  34. data() {
  35. return {
  36. newList: []
  37. };
  38. },
  39. watch: {
  40. list: {
  41. handler(value) {
  42. if (!!value.length) {
  43. this.newList = value
  44. // console.log(value.length)
  45. }
  46. },
  47. immediate: true,
  48. deep: true
  49. }
  50. },
  51. methods: {
  52. handleSelect(item, value) {
  53. if (item.featureType == 1) {
  54. if (item.inputValue !== value.tagKey) {
  55. item.inputValue = value.tagKey
  56. } else {
  57. item.inputValue = ''
  58. }
  59. } else {
  60. const index = item.inputValue.indexOf(value.tagKey)
  61. if (index == -1) {
  62. item.inputValue.push(value.tagKey);
  63. } else {
  64. item.inputValue.splice(index, 1);
  65. }
  66. }
  67. },
  68. submit() {
  69. const values = this.newList.map(item => {
  70. return {
  71. ...item,
  72. selectData: item.params.filter(v => {
  73. if (item.featureType == 1) {
  74. return v.tagKey == item.inputValue;
  75. } else {
  76. // console.log(item, v);
  77. return item.inputValue.includes(v.tagKey);
  78. }
  79. })
  80. }
  81. })
  82. // console.log(values)
  83. this.$emit('changeSelect', values)
  84. }
  85. }
  86. }
  87. </script>
  88. <style lang="scss" scoped>
  89. .spec-select-conetnt {
  90. padding: 4px;
  91. .spec-select {
  92. .spec-select-title {
  93. .title-1 {
  94. color: #333;
  95. font-size: 17px;
  96. font-weight: 500;
  97. }
  98. .title-2 {
  99. color: #606266;
  100. font-size: 15px;
  101. font-weight: 400;
  102. }
  103. }
  104. .spec-select-list {
  105. display: flex;
  106. justify-content: space-between;
  107. align-items: center;
  108. width: 100%;
  109. flex-wrap: wrap;
  110. margin-top: 5.5px;
  111. .list__item {
  112. width: 158px;
  113. line-height: 43px;
  114. text-align: center;
  115. height: 43px;
  116. border-radius: 8px;
  117. background: #F3F4F6;
  118. margin-bottom: 12px;
  119. color: #333;
  120. font-size: 15px;
  121. font-weight: 400;
  122. overflow: hidden;
  123. }
  124. .active {
  125. width: 155px;
  126. height: 40px;
  127. line-height: 40px;
  128. text-align: center;
  129. border-radius: 8px;
  130. border: 1.5px solid #4C96FF;
  131. position: relative;
  132. background: #F3F4F6;
  133. margin-bottom: 12px;
  134. color: #333;
  135. font-size: 15px;
  136. font-weight: 400;
  137. overflow: hidden;
  138. .image_active {
  139. width: 20px;
  140. height: 16px;
  141. position: absolute;
  142. right: 0;
  143. bottom: 0;
  144. }
  145. }
  146. }
  147. }
  148. .spec-btn {
  149. padding: 0 10px;
  150. margin-top: 112px;
  151. margin-bottom: 32px;
  152. }
  153. }
  154. </style>