酒店桌布为微信小程序
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.

176 lines
3.3 KiB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
  1. <template>
  2. <view class="page">
  3. <view class="submit-unit">
  4. <view class="title">
  5. 颜色选择
  6. </view>
  7. <view class="list">
  8. <view :class="{act : colorIndex == index}"
  9. v-for="(item, index) in colorList"
  10. @click="selectUnit(item, index, 0)" :key="index">
  11. {{ item }}
  12. </view>
  13. </view>
  14. </view>
  15. <view class="submit-unit">
  16. <view class="title">
  17. 尺寸选择
  18. </view>
  19. <view class="list">
  20. <view
  21. :class="{act : sizeIndex == index,
  22. del : getUnitClassDel(item, index)}"
  23. v-for="(item, index) in sizeList"
  24. @click="selectUnit(item, index, 1)" :key="index">
  25. {{ item }}
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. let defaultKey = '默认'
  33. export default {
  34. props : {
  35. list : {
  36. default : []
  37. },
  38. },
  39. computed : {
  40. unitMap(){
  41. let map = {}
  42. this.list.forEach(n => {
  43. let color = n.colour || defaultKey
  44. let title = n.title || defaultKey
  45. let key = color + ':' + title
  46. n.unitKeyName = color + ',' + title
  47. map[key] = n
  48. })
  49. return map
  50. },
  51. // 尺寸列表
  52. sizeList(){
  53. return [...new Set(this.list.map(n => n.title || defaultKey))]
  54. },
  55. // 颜色列表
  56. colorList(){
  57. return [...new Set(this.list.map(n => n.colour || defaultKey))]
  58. },
  59. },
  60. data() {
  61. return {
  62. unitKey : '',
  63. colorIndex : 0,
  64. sizeIndex : 0,
  65. }
  66. },
  67. mounted() {
  68. if(!this.unitKey && this.list.length > 0){
  69. this.selectUnit(this.colorList[0], 0, 0)
  70. }
  71. },
  72. methods: {
  73. selectUnit(item, index, type){
  74. if(type == 0){
  75. let color = this.colorList[index]
  76. for(let key in this.unitMap){
  77. if(key.startsWith(color)){
  78. this.unitKey = key
  79. break
  80. }
  81. }
  82. }else{
  83. // 判断是否有货
  84. if(this.getUnitClassDel(item, index, type)){
  85. return
  86. }
  87. let color = this.colorList[this.colorIndex]
  88. let size = this.sizeList[index]
  89. this.unitKey = color + ':' + item
  90. }
  91. this.updateIndexAll()
  92. this.$emit('selectUnit', this.unitMap[this.unitKey])
  93. },
  94. getUnitClassDel(item, index, type){
  95. let key = this.colorList[this.colorIndex] + ':' + item
  96. return !this.unitMap[key]
  97. },
  98. // 更新索引
  99. updateIndexAll(){
  100. let key = this.unitKey
  101. this.colorList.forEach((n, i) => {
  102. if(key.startsWith(n + ':')){
  103. this.colorIndex = i
  104. }
  105. })
  106. this.sizeList.forEach((n, i) => {
  107. if(key.endsWith(':' + n)){
  108. this.sizeIndex = i
  109. }
  110. })
  111. },
  112. setUnitById(id){
  113. for(let key in this.unitMap){
  114. if(this.unitMap[key].id == id){
  115. this.unitKey = key
  116. }
  117. }
  118. this.updateIndexAll()
  119. },
  120. }
  121. }
  122. </script>
  123. <style scoped lang="scss">
  124. .page{
  125. .submit-unit {
  126. padding: 30rpx;
  127. background-color: #fff;
  128. .title {
  129. font-size: 28rpx;
  130. font-weight: 600;
  131. }
  132. .list {
  133. display: flex;
  134. flex-wrap: wrap;
  135. font-size: 22rpx;
  136. .act {
  137. color: $uni-color;
  138. border: 1px solid $uni-color;
  139. background-color: #F9E7DE;
  140. }
  141. .del{
  142. opacity: 0.3;
  143. &::after{
  144. content: '【无货】';
  145. }
  146. }
  147. view {
  148. border-radius: 15rpx;
  149. width: 320rpx;
  150. background-color: #eee;
  151. border: 1px solid #eee;
  152. margin: 10rpx;
  153. display: flex;
  154. justify-content: center;
  155. padding: 15rpx 0;
  156. overflow: hidden;
  157. }
  158. }
  159. }
  160. }
  161. </style>