graceSelectList.nvue 2.9 KB

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