graceSelectList.vue 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <view class="select-list">
  3. <view v-for="(item, index) in dataIn" :key="index" class="select-list-item" :data-index="index" @tap.stop="choose">
  4. <image :src="item.img" class="select-list-img" v-if="item.img" mode="widthFix"
  5. :style="{width:imgSize[0], height:imgSize[1], borderRadius:imgBorderRadius}"></image>
  6. <view class="select-list-body" :class="[isBorder?'grace-border-b':'']" :style="{borderColor:borderColor}">
  7. <view class="select-list-content">
  8. <view :style="{fontSize:fontSize, lineHeight:lineHeight, color:itemColor}">{{item.title}}</view>
  9. <view class="select-list-desc" v-if="item.desc">{{item.desc}}</view>
  10. </view>
  11. <view class="select-list-icon grace-icons" v-if="item.checked" :style="{color:item.checked ? checkColor : '#A5A7B2'}">&#xe60f;</view>
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default{
  18. props:{
  19. lists : {type:Array, default:function(){return [];}},
  20. checkColor:{type:String, default:"#3688FF"},
  21. type : { type: String, default: "radio"},
  22. imgSize:{type:Array, default:function(){return ['68rpx','68rpx'];}},
  23. imgBorderRadius:{type: String, default: "60rpx"},
  24. fontSize:{type: String, default: "28rpx"},
  25. isBorder:{type:Boolean, default:true},
  26. lineHeight:{type: String, default: "50rpx"},
  27. itemColor:{type:String, default:"#323232"},
  28. borderColor:{type:String, default:"#F6F6F6"}
  29. },
  30. data() {
  31. return {
  32. dataIn: []
  33. }
  34. },
  35. created:function(){
  36. this.dataIn = this.lists;
  37. },
  38. watch:{
  39. lists:function(val){
  40. this.dataIn = val;
  41. }
  42. },
  43. methods:{
  44. choose:function(e){
  45. var index = e.currentTarget.dataset.index;
  46. if(this.type == 'radio'){
  47. if(this.dataIn[index].checked){
  48. this.dataIn[index].checked = false;
  49. this.$emit('change', -1);
  50. }else{
  51. for(let i = 0; i < this.dataIn.length; i++){
  52. this.dataIn[i].checked = false;
  53. }
  54. this.dataIn[index].checked = true;
  55. this.$emit('change', index);
  56. }
  57. }else{
  58. if(this.dataIn[index].checked){
  59. this.dataIn[index].checked = false;
  60. }else{
  61. this.dataIn[index].checked = true;
  62. }
  63. var sedArr = [];
  64. for(let i = 0; i < this.dataIn.length; i++){
  65. if(this.dataIn[i].checked){
  66. sedArr.push(i);
  67. }
  68. }
  69. this.$emit('change', sedArr);
  70. }
  71. }
  72. }
  73. }
  74. </script>
  75. <style>
  76. .select-list{}
  77. .select-list-item{display:flex; flex-direction:row; flex-wrap:nowrap; align-items:center; font-size:0;}
  78. .select-list-icon{width:60rpx; line-height:60rpx; text-align:center; flex-shrink:0; font-size:32rpx; color:#A5A7B2; font-weight:700; margin-left:28rpx;}
  79. .select-list-img{flex-shrink:0; border-radius:60rpx; margin-right:28rpx;}
  80. .select-list-body{width:700rpx; display:flex; flex-wrap:nowrap; flex-direction:row; align-items:center;}
  81. .select-list-content{width:200rpx; flex:1; overflow:hidden; padding:25rpx 0;}
  82. .select-list-desc{font-size:22rpx; color:#828282; line-height:40rpx;}
  83. </style>