contact.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <view class="list-wrapper">
  3. <view class="list">
  4. <view class="list-item"
  5. v-for="item in items"
  6. :hover-start-time="20"
  7. :hover-stay-time="70"
  8. :key="item.id"
  9. hover-class="commonly-hover"
  10. @tap="handleClick(item)"
  11. >
  12. <image class="avatar"
  13. mode="aspectFill"
  14. :src="item.avatar"
  15. @tap.stop="handleAvatar(item)"
  16. />
  17. <view class="info">
  18. <view class="nickname">{{item.nickname || item.name}}</view>
  19. </view>
  20. <checkbox
  21. v-if="selectMode"
  22. :checked="selectedMap[item.id]"
  23. :disabled="disabledMap[item.id]"
  24. @tap.stop="handleClick(item)"
  25. />
  26. </view>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. const hasOwn = Object.prototype.hasOwnProperty;
  32. export default {
  33. props: {
  34. items: {
  35. required: true,
  36. },
  37. selectMode: {
  38. type: Boolean,
  39. default: false
  40. },
  41. checkedMap: {
  42. type: Object,
  43. default: () => ({})
  44. },
  45. disabledMap: {
  46. type: Object,
  47. default: () => ({})
  48. }
  49. },
  50. data() {
  51. return {
  52. selectedMap: {}
  53. }
  54. },
  55. watch: {
  56. checkedMap() {
  57. this.lookCheckedMap();
  58. },
  59. disabledMap() {
  60. this.lookCheckedMap();
  61. }
  62. },
  63. methods: {
  64. inDisabledMap(id) {
  65. return hasOwn.call(this.disabledMap, id);
  66. },
  67. inCheckedMap(id) {
  68. return hasOwn.call(this.checkedMap, id);
  69. },
  70. inSelected(id) {
  71. return typeof this.selectedMap[id] === 'boolean';
  72. },
  73. setToSelected(id) {
  74. const selected = Boolean(this.selectedMap[id]);
  75. this.$set(this.selectedMap, id, !selected);
  76. },
  77. handleAvatar(item) {
  78. if (this.selectMode) {
  79. this.handleClick(item);
  80. } else {
  81. this.$emit('avatar', item);
  82. }
  83. },
  84. handleClick(item) {
  85. if (!this.inDisabledMap(item.id)) {
  86. if (this.selectMode) {
  87. this.setToSelected(item.id);
  88. item.selected = this.selectedMap[item.id];
  89. this.$emit('select', item);
  90. } else {
  91. this.$emit('click', item);
  92. }
  93. }
  94. },
  95. lookCheckedMap() {
  96. Object.keys(this.checkedMap).forEach(id => {
  97. // if (!this.inDisabledMap(id)) {
  98. this.setToSelected(id);
  99. // }
  100. })
  101. }
  102. },
  103. created() {
  104. console.log(1)
  105. },
  106. onLoad() {
  107. this.lookCheckedMap();
  108. console.log(2)
  109. }
  110. }
  111. </script>
  112. <style lang="scss" scoped>
  113. $list-avatar-width: 88upx;
  114. .list-wrapper {
  115. position:relative;
  116. box-sizing: border-box;
  117. padding: $uni-spacing-col-base $uni-spacing-row-base;
  118. }
  119. .list {
  120. width: 100%;
  121. box-sizing: border-box;
  122. .list-title,
  123. .list-item {
  124. width: 100%;
  125. font-size: 32upx;
  126. padding: 0 20upx;
  127. box-sizing: border-box;
  128. }
  129. .list-title {
  130. background-color: #eee;
  131. height: 92upx;
  132. line-height: 92upx;
  133. font-weight: bold;
  134. }
  135. .list-item {
  136. display: flex;
  137. flex-direction: row;
  138. align-items: center;
  139. background-color: #fff;
  140. position: relative;
  141. padding: $uni-spacing-col-base $uni-spacing-row-base;
  142. .avatar {
  143. width: $list-avatar-width;
  144. height: $list-avatar-width;
  145. margin-right: $uni-spacing-row-base;
  146. border-radius: $uni-border-radius-base;
  147. overflow: hidden;
  148. display: flex;
  149. flex-flow: wrap;
  150. justify-content: center;
  151. background-color: #eee;
  152. align-items: center;
  153. flex-shrink: 0;
  154. &:not(image) {
  155. padding: 1upx;
  156. }
  157. view,
  158. image {
  159. width: ($list-avatar-width - 2upx * 4) / 3;
  160. height: ($list-avatar-width - 2upx * 4) / 3;
  161. margin: 1upx;
  162. }
  163. }
  164. &:last-child {
  165. border-bottom-left-radius: $uni-border-radius-base;
  166. border-bottom-right-radius: $uni-border-radius-base;
  167. }
  168. &:not(:last-child)::before {
  169. display: block;
  170. content: '';
  171. bottom: 0;
  172. left: $uni-spacing-row-base * 2 + $list-avatar-width;
  173. right: $uni-spacing-row-base;
  174. height: 1upx;
  175. position: absolute;
  176. background-color: #E6E6E6;
  177. transform: scaleY(0.5);
  178. }
  179. &.commonly-hover {
  180. background-color: #eee;
  181. }
  182. text {
  183. flex: 1;
  184. }
  185. }
  186. .nickname,
  187. .description {
  188. width: 750upx - $uni-spacing-row-base * 6 - $list-avatar-width - 44upx;
  189. text-overflow: ellipsis;
  190. white-space: nowrap;
  191. overflow: hidden;
  192. }
  193. .description {
  194. font-size: 28upx;
  195. color: #999;
  196. }
  197. .list-title + .list-item {
  198. border-top-left-radius: $uni-border-radius-base;
  199. border-top-right-radius: $uni-border-radius-base;
  200. }
  201. }
  202. </style>