graceCheckList.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <view class="check-list" :style="{height:height+'px'}">
  3. <scroll-view scroll-y="true" :style="{height:height+'px'}">
  4. <view v-for="(item, index) in dataIn" :key="index" class="check-list-item" :data-index="index" @tap.stop="choose">
  5. <view class="check-list-icon grace-icons" v-if="item.checked && batch" :style="{color:checkColor}">&#xe7f8;</view>
  6. <view class="check-list-icon grace-icons" v-if="!item.checked && batch" style="color:#D2D2D2;">&#xe762;</view>
  7. <view class="check-list-body" :class="[isBorder && index < dataIn.length - 1 ? 'grace-border-b':'']">
  8. <image :src="item.img" class="check-list-img" v-if="item.img" mode="widthFix" :style="{width:imgSize[0], height:imgSize[1],borderRadius:imgBordeRadius}"></image>
  9. <view class="check-list-content">
  10. <view class="check-list-content-title" :style="{fontSize:fontSize, color:itemColor}">{{item.title}}</view>
  11. <view class="check-list-content-desc" :style="{color:smallTextColor, fontSize:smallTextSize}">{{item.desc}}</view>
  12. </view>
  13. </view>
  14. </view>
  15. <view style="height:120rpx; width:100%;" v-if="batch"></view>
  16. </scroll-view>
  17. <view class="check-list-footer" v-if="height > 0 && batch">
  18. <view class="check-list-icon" @tap.stop="selectAll">
  19. <text class="grace-icons" v-if="sedAll" :style="{color:checkColor}">&#xe7f8;</text>
  20. <text class="grace-icons" v-if="!sedAll">&#xe762;</text>
  21. </view>
  22. <view class="check-list-footer-text" @tap.stop="selectAll">全选 {{sedNumbers > 0 ? sedNumbers +'/'+ dataIn.length : ''}}</view>
  23. <view class="check-list-footer-btns"><slot></slot></view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. export default{
  29. props:{
  30. height:{type:Number, default:0},
  31. lists : {type:Array, default:function(){return [];}},
  32. checkColor:{type:String, default:"#3688FF"},
  33. imgSize:{type:Array, default:function(){return ['68rpx','68rpx'];}},
  34. isBorder:{type:Boolean, default:true},
  35. fontSize:{type: String, default: "28rpx"},
  36. itemColor:{type:String, default:"#323232"},
  37. imgBordeRadius:{type: String, default: "8rpx"},
  38. smallTextColor:{type:String, default:"#999999"},
  39. smallTextSize:{type:String, default:"24rpx"},
  40. batch:{type:Boolean, default:false}
  41. },
  42. data() {
  43. return {
  44. dataIn: [],
  45. sedAll:false,
  46. sedNumbers:0
  47. }
  48. },
  49. created:function(){
  50. this.dataIn = this.lists;
  51. },
  52. watch:{
  53. lists:function(val){
  54. this.dataIn = val;
  55. },
  56. dataIn:function(val){
  57. var sedNumber = 0;
  58. for(let i = 0; i < this.dataIn.length; i++){
  59. if(this.dataIn[i].checked){
  60. sedNumber++;
  61. }
  62. }
  63. this.sedNumbers = sedNumber;
  64. if(sedNumber >= val.length){this.sedAll = true;}else{this.sedAll = false;}
  65. }
  66. },
  67. methods:{
  68. choose:function(e){
  69. if(!this.batch){return ;}
  70. var index = e.currentTarget.dataset.index;
  71. if(this.dataIn[index].checked){
  72. this.dataIn[index].checked = false;
  73. this.dataIn.splice(index, 1, this.dataIn[index]);
  74. }else{
  75. this.dataIn[index].checked = true;
  76. this.dataIn.splice(index, 1, this.dataIn[index]);
  77. }
  78. this.dataIn = this.dataIn;
  79. var sedArr = [];
  80. for(let i = 0; i < this.dataIn.length; i++){
  81. if(this.dataIn[i].checked){
  82. sedArr.push(i);
  83. }
  84. }
  85. this.$emit('change', sedArr);
  86. },
  87. selectAll : function(){
  88. if(this.sedAll){
  89. for(let i = 0; i < this.dataIn.length; i++){
  90. this.dataIn[i].checked = false;
  91. this.dataIn.splice(i, 1, this.dataIn[i]);
  92. }
  93. this.sedAll = false;
  94. this.$emit('change', []);
  95. }else{
  96. var sedArr = [];
  97. for(let i = 0; i < this.dataIn.length; i++){
  98. this.dataIn[i].checked = true;
  99. this.dataIn.splice(i, 1, this.dataIn[i]);
  100. sedArr.push(i);
  101. }
  102. this.sedAll = true;
  103. this.$emit('change', sedArr);
  104. }
  105. }
  106. }
  107. }
  108. </script>
  109. <style>
  110. .check-list{position:relative;}
  111. .check-list-item{display:flex; flex-direction:row; flex-wrap:nowrap; align-items:center; font-size:0; background-color:#FFFFFF; padding:0 25rpx;}
  112. .check-list-icon{width:60rpx; line-height:60rpx; text-align:center; flex-shrink:0; font-size:36rpx; color:#D2D2D2; font-weight:700; margin-right:15rpx;}
  113. .check-list-img{flex-shrink:0; border-radius:10rpx; margin-right:28rpx;}
  114. .check-list-body{width:700rpx; display:flex; flex-wrap:nowrap; flex-direction:row; align-items:center;}
  115. .check-list-content{width:200rpx; flex:1; overflow:hidden; padding:22rpx 0;}
  116. .check-list-content-title{line-height:44rpx; font-size:28rpx;}
  117. .check-list-content-desc{line-height:36rpx; font-size:22rpx;}
  118. .grace-border-b{border-bottom:1px solid #F4F5F6;}
  119. .check-list-footer{background:#FFFFFF; position:absolute; z-index:1; left:0; bottom:0; padding:20rpx 25rpx; width:100%; box-sizing:border-box; display:flex; flex-direction:row; flex-wrap:nowrap; align-items:center; flex-shrink:0;}
  120. .check-list-footer-text{font-size:28rpx; color:#323232; flex-shrink:0;}
  121. .check-list-footer-btns{width:700rpx; margin-left:28rpx;}
  122. </style>