cpicker.vue 4.1 KB

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