uni-multiple-picker.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. this.listData = newValue
  44. this.init()
  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. init(){
  76. this.listData.map((item, ind) => {
  77. this.$set(this.listData[ind], 'checked', false)
  78. })
  79. },
  80. // 选择
  81. chooseItem(ind){
  82. this.$set(this.listData[ind], 'checked', !this.listData[ind].checked)
  83. },
  84. // 确定
  85. confirm(){
  86. this.$emit('confirm', this.nowChooseItemArr)
  87. },
  88. // 取消
  89. cancel(){
  90. this.$emit('cancel')
  91. },
  92. }
  93. }
  94. </script>
  95. <style lang="scss" scoped>
  96. .uni-multiple-picker{
  97. .u-multiple-picker-header{
  98. padding: 20upx 30upx;
  99. position: relative;
  100. display: flex;
  101. justify-content: space-between;
  102. .multiple-picker-btn{
  103. color: rgb(96, 98, 102);
  104. }
  105. .color-blue{
  106. color: #2979ff;
  107. }
  108. }
  109. .u-multiple-picker-header:after{
  110. content: "";
  111. position: absolute;
  112. border-bottom: 1px solid #eaeef1;
  113. -webkit-transform: scaleY(.5);
  114. transform: scaleY(.5);
  115. bottom: 0;
  116. right: 0;
  117. left: 0;
  118. }
  119. .choose-info{
  120. padding: 14upx 30upx 14upx;
  121. color: rgb(96, 98, 102);
  122. .choose-info-item{
  123. color: #2979ff;
  124. }
  125. }
  126. .picker-content{
  127. height: 300upx;
  128. padding: 6upx 0 20upx;
  129. position: relative;
  130. .picker-main{
  131. position: absolute;
  132. top: 50%;
  133. left: 50%;
  134. transform: translate(-50%,-50%);
  135. width: 100%;
  136. max-height: 300upx;
  137. .picker-main-item{
  138. position: relative;
  139. padding: 0 30upx;
  140. .item-name{
  141. padding: 14upx 0;
  142. text-align: center;
  143. // border-bottom: 1upx dashed #efefef;
  144. }
  145. .item-icon{
  146. position: absolute;
  147. right: 100upx;
  148. top: 19upx;
  149. }
  150. }
  151. }
  152. }
  153. }
  154. </style>