uni-multiple-picker.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <u-popup v-model="isShow" class="uni-multiple-picker" @close="cancel" mode="bottom">
  3. <view class="u-multiple-picker-header flex justify_between align_center">
  4. <text class="multiple-picker-btn" @click="cancel">取消</text>
  5. <text class="multiple-picker-btn color-blue" @click="confirm">确定</text>
  6. </view>
  7. <u-row class="choose-info">
  8. <u-col :span="3">当前已选:</u-col>
  9. <u-col :span="9" class="choose-info-item">{{nowChooseItem}}</u-col>
  10. </u-row>
  11. <scroll-view class="picker-content" scroll-y>
  12. <view class="picker-main">
  13. <view class="picker-main-item" v-for="(item, index) in listData" :key="item.id" @click="chooseItem(index)">
  14. <view class="item-name">{{item.name}}</view>
  15. <u-icon v-show="item.checked==true" class="item-icon" name="checkbox-mark" color="#2979ff" size="28"></u-icon>
  16. </view>
  17. <view v-if="listData && listData.length == 0">
  18. <u-empty text="数据为空" mode="list" :img-width="200" :margin-top="-60"></u-empty>
  19. </view>
  20. </view>
  21. </scroll-view>
  22. </u-popup>
  23. </template>
  24. <script>
  25. export default{
  26. props: {
  27. show: {
  28. type: Boolean,
  29. default: false
  30. },
  31. dataList: {
  32. type: Array,
  33. default: ()=>{
  34. return []
  35. }
  36. }
  37. },
  38. watch: {
  39. show (newValue, oldValue) {
  40. this.isShow = newValue
  41. },
  42. dataList (newValue, oldValue) {
  43. console.log(newValue)
  44. this.listData = newValue
  45. },
  46. },
  47. computed: {
  48. nowChooseItem: function() {
  49. let str = ''
  50. this.listData.map(item => {
  51. if(item.checked){
  52. str += item.name + ',';
  53. }
  54. })
  55. str = str == '' ? '' : str.substring(0,str.length - 1)
  56. return str
  57. },
  58. nowChooseItemArr: function() {
  59. let arr = []
  60. this.listData.map(item => {
  61. if(item.checked){
  62. arr.push({id: item.id, name: item.name})
  63. }
  64. })
  65. return arr
  66. },
  67. },
  68. data(){
  69. return{
  70. isShow: this.show,
  71. listData: this.dataList || [],
  72. }
  73. },
  74. methods: {
  75. // 选择
  76. chooseItem(ind){
  77. this.$set(this.listData[ind], 'checked', !this.listData[ind].checked)
  78. },
  79. // 确定
  80. confirm(){
  81. this.$emit('confirm', this.nowChooseItemArr)
  82. },
  83. // 取消
  84. cancel(){
  85. this.$emit('cancel')
  86. },
  87. }
  88. }
  89. </script>
  90. <style lang="scss" scoped>
  91. .uni-multiple-picker{
  92. .u-multiple-picker-header{
  93. padding: 20upx 30upx;
  94. position: relative;
  95. display: flex;
  96. justify-content: space-between;
  97. .multiple-picker-btn{
  98. color: rgb(96, 98, 102);
  99. }
  100. .color-blue{
  101. color: #2979ff;
  102. }
  103. }
  104. .u-multiple-picker-header:after{
  105. content: "";
  106. position: absolute;
  107. border-bottom: 1px solid #eaeef1;
  108. -webkit-transform: scaleY(.5);
  109. transform: scaleY(.5);
  110. bottom: 0;
  111. right: 0;
  112. left: 0;
  113. }
  114. .choose-info{
  115. padding: 14upx 30upx 14upx;
  116. color: rgb(96, 98, 102);
  117. .choose-info-item{
  118. color: #2979ff;
  119. }
  120. }
  121. .picker-content{
  122. height: 300upx;
  123. padding: 6upx 0 20upx;
  124. position: relative;
  125. .picker-main{
  126. position: absolute;
  127. top: 50%;
  128. left: 50%;
  129. transform: translate(-50%,-50%);
  130. width: 100%;
  131. max-height: 300upx;
  132. .picker-main-item{
  133. position: relative;
  134. padding: 0 30upx;
  135. .item-name{
  136. padding: 14upx 0;
  137. text-align: center;
  138. // border-bottom: 1upx dashed #efefef;
  139. }
  140. .item-icon{
  141. position: absolute;
  142. right: 100upx;
  143. top: 19upx;
  144. }
  145. }
  146. }
  147. }
  148. }
  149. </style>