cpicker.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <view>
  3. <view v-if="show" class="cpicker-mask">
  4. <view class="cpicker-box">
  5. <view class="cpicker-box-header">{{title}}</view>
  6. <scroll-view scroll-y class='main-content'>
  7. <view v-for="(item,index) in list" :key="index" class="cpicker-option" :data-id="item.id" @click="clickOption">
  8. {{item.title}}
  9. <image v-if="item.id == defaultId" class="cpicker-option-checked" src="../../images/duihao-red.png"></image>
  10. </view>
  11. </scroll-view>
  12. <view class='modal-footer'>
  13. <view class='cancel-btn' @click='cancel'>取消</view>
  14. <view class='confirm-btn' @click='confirm'>确定 </view>
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. name: "cpicker",
  23. components: {
  24. },
  25. props: {
  26. title: {
  27. type: String,
  28. default: "请选择"
  29. },
  30. show: {
  31. type: Boolean,
  32. default: false
  33. },
  34. list: {
  35. type: Array,
  36. value: [] //[{id:1,title:'五星花园'},{id:2,title:'陪护单类型选错了陪护单类型选错了'}]
  37. },
  38. did: { //默认值
  39. type: Number,
  40. value: 0,
  41. }
  42. },
  43. data() {
  44. return {
  45. defaultId: 0
  46. }
  47. },
  48. mounted() {
  49. this.defaultId = this.did;
  50. console.log(this.list,this.show);
  51. },
  52. methods: {
  53. // 点击modal的回调函数
  54. clickOption(e) {
  55. this.defaultId = e.currentTarget.dataset.id;
  56. },
  57. // 点击取消按钮的回调函数
  58. cancel() {
  59. // this.show = false;
  60. this.$emit('update:show', false);
  61. // this.triggerEvent('cancel') //triggerEvent触发事件
  62. this.$emit('cancel');
  63. },
  64. // 点击确定按钮的回调函数
  65. confirm() {
  66. this.$emit('update:show', false);
  67. let sinfo = null;
  68. this.list.forEach((item) => {
  69. if(item.id == this.defaultId){
  70. sinfo = item;
  71. }
  72. });
  73. // this.triggerEvent('confirm',sinfo);
  74. this.$emit('confirm',sinfo);
  75. }
  76. }
  77. };
  78. </script>
  79. <style lang="scss" scoped>
  80. /*遮罩层*/
  81. .cpicker-mask{
  82. display: flex;
  83. justify-content: center;
  84. align-items: center;
  85. position: fixed;
  86. left: 0;
  87. right: 0;
  88. top: 0;
  89. bottom: 0;
  90. background-color: rgba(0,0,0,0.6);
  91. z-index: 999999999999;
  92. }
  93. /*遮罩内容*/
  94. .cpicker-box{
  95. display: flex;
  96. flex-direction: column;
  97. width: 600rpx;
  98. background-color: #fff;
  99. border-radius: 10rpx;
  100. /* padding: 20rpx; */
  101. text-align: center;
  102. font-size: 30rpx;
  103. color: #333333;
  104. /* font-weight: bold; */
  105. }
  106. .cpicker-box-header{
  107. height: 90rpx;
  108. line-height: 90rpx;
  109. border-bottom: 1rpx solid #e6e4e4;
  110. }
  111. /*中间内容*/
  112. .main-content{
  113. flex: 1;
  114. /* height: 100%; */
  115. min-height: 200rpx;
  116. overflow-y: hidden;
  117. max-height:40vh;
  118. padding-top: 20rpx;
  119. }
  120. .cpicker-option{
  121. position: relative;
  122. width: 460rpx;
  123. height: 70rpx;
  124. line-height: 70rpx;
  125. /* text-align: left; */
  126. padding: 0 70rpx;
  127. padding-right: 70rpx;
  128. overflow: hidden;
  129. text-overflow: ellipsis;
  130. white-space:nowrap;
  131. }
  132. .cpicker-option-checked{
  133. position: absolute;
  134. z-index: 10;
  135. right: 20rpx;
  136. top: 20rpx;
  137. width: 30rpx;
  138. height: 30rpx;
  139. }
  140. /*底部按钮*/
  141. .modal-footer{
  142. display: flex;
  143. flex-direction: row;
  144. height: 90rpx;
  145. line-height: 90rpx;
  146. border-top: 1rpx solid #e6e4e4;
  147. margin-top: 30rpx;
  148. }
  149. .cancel-btn, .confirm-btn{
  150. flex: 1;
  151. height: 90rpx;
  152. line-height: 90rpx;
  153. text-align: center;
  154. font-size: 32rpx;
  155. }
  156. .cancel-btn{
  157. color: #333333;
  158. border-right: 1rpx solid #e6e4e4;
  159. }
  160. .confirm-btn {
  161. color: var(--themeColor)
  162. }
  163. </style>