1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
   | <template>   <view class="zh-picker">     <div class="slot" @click="openPicker">       <slot></slot>     </div>     <uni-popup ref="popup" type="bottom" @change="onPopupChange">       <view class="popup">         <view class="actions">           <view class="cancel" @click="onCancel">取消</view>           <view class="sure" @click="onSure">完成</view>         </view>         <picker-view           class="picker-view"           :value="indexs"           @change="onPickerViewChange"         >           <picker-view-column>             <view class="item" v-for="(item,index) in range" :key="index"               >{{getText(item)}}</view             >           </picker-view-column>         </picker-view>       </view>     </uni-popup>   </view> </template>
  <script>   export default {     name: "zh-picker",     props: {       range: {         type: Array,         default: () => [],       },       rangeText: {         type: String,         default: "text",       },     },     data() {       return {         visible: false,         indexs: [0],       };     },     methods: {       openPicker() {         this.$refs.popup.open();       },       onPopupChange({ show }) {         this.visible = show;       },       getText(item) {         if (item[this.rangeText]) return item[this.rangeText];         return JSON.stringify(item);       },       onPickerViewChange(ev) {         this.indexs = JSON.parse(JSON.stringify(ev.detail.value));       },       onSure() {         let _ev = {           detail: {                          value: this.indexs[0],           },         };         this.$emit("change", _ev);         this.$refs.popup.close();       },       onCancel() {         this.$refs.popup.close();       },     },   }; </script>
  <style scoped lang="scss">   .zh-picker {     .popup {       border-top-left-radius: 20rpx;       border-top-right-radius: 20rpx;       background-color: white;       overflow: hidden;
        > .actions {         position: relative;         display: flex;         justify-content: space-between;         align-items: center;
          &::after {           content: "";           position: absolute;           left: 0;           bottom: 0;           right: 0;           height: 1px;           clear: both;           border-bottom: 1px solid #e5e5e5;           color: #e5e5e5;           transform-origin: 0 100%;           transform: scaleY(0.5);         }
          > view {           width: 120rpx;           height: 90rpx;           line-height: 90rpx;           text-align: center;           font-size: 34rpx;
            &.cancel {             color: #888;           }
            &.sure {             color: #30ac8f;           }         }       }
        .picker-view {         width: 750rpx;         height: 30vh;
          .item {           display: flex;           justify-content: center;           align-items: center;         }       }     }   } </style>
   |