cpicker.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <view>
  3. <view v-if="show" class="cpicker-mask">
  4. <view class="cpicker-box">
  5. <view class="cpicker-box-header">
  6. <view class="search-wrapper">
  7. <view class="search-icon">
  8. <svg t="1679886082795" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7388" width="200" height="200"><path d="M465.334857 146.285714c176.201143 0 319.024762 145.091048 319.024762 324.096a325.973333 325.973333 0 0 1-65.560381 196.827429L877.714286 828.611048 829.366857 877.714286l-157.647238-160.182857a314.855619 314.855619 0 0 1-206.384762 76.921904C289.133714 794.453333 146.285714 649.386667 146.285714 470.381714S289.133714 146.285714 465.334857 146.285714z m0 69.436953c-138.459429 0-250.684952 114.029714-250.684952 254.659047 0 140.629333 112.225524 254.634667 250.684952 254.634667 138.435048 0 250.660571-114.005333 250.660572-254.634667 0-140.629333-112.225524-254.659048-250.660572-254.659047z" p-id="7389" fill="#8a8a8a"></path></svg>
  9. </view>
  10. <input class="search-input" placeholder="请输入搜索内容" v-model="keywords" @input="clearInput" />
  11. <view class="search-del" v-if="keywords" @click="clear">
  12. <svg t="1679886219343" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7573" width="200" height="200"><path d="M402.261333 377.880381l0.365715 364.007619h73.142857l-0.341334-364.007619h60.586667L536.380952 741.888h73.142858l-0.365715-364.007619h154.770286L731.91619 832.731429a73.142857 73.142857 0 0 1-72.947809 67.998476H348.306286a73.142857 73.142857 0 0 1-72.94781-68.022857L243.297524 377.904762l158.963809-0.024381zM134.095238 256h731.428572v73.142857h-731.428572v-73.142857z m518.265905-121.904762v73.142857h-292.571429v-73.142857h292.571429z" p-id="7574" fill="#8a8a8a"></path></svg>
  13. </view>
  14. </view>
  15. </view>
  16. <scroll-view scroll-y class='main-content'>
  17. <view v-for="(item,index) in list" :key="index" class="cpicker-option" :data-id="item.id" @click="clickOption">
  18. {{item.title}}
  19. <image v-if="item.id == defaultId" class="cpicker-option-checked" src="../../images/duihao-red.png"></image>
  20. </view>
  21. </scroll-view>
  22. <view class='modal-footer'>
  23. <view class='cancel-btn' @click='cancel'>取消</view>
  24. <view class='confirm-btn' @click='confirm'>确定 </view>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. name: "cpicker",
  33. components: {
  34. },
  35. props: {
  36. title: {
  37. type: String,
  38. default: "请选择"
  39. },
  40. show: {
  41. type: Boolean,
  42. default: false
  43. },
  44. list: {
  45. type: Array,
  46. value: [] //[{id:1,title:'五星花园'},{id:2,title:'陪护单类型选错了陪护单类型选错了'}]
  47. },
  48. did: { //默认值
  49. type: Number,
  50. value: 0,
  51. }
  52. },
  53. data() {
  54. return {
  55. defaultId: 0,
  56. keywords:'',
  57. oldList:[],
  58. }
  59. },
  60. watch: {
  61. keywords (newVal, oldVal) {
  62. this.list = this.oldList;
  63. let resultList = [];
  64. this.list.forEach((item) => {
  65. if (item.title.indexOf(newVal) > -1) {
  66. resultList.push(item);
  67. }
  68. });
  69. this.list = resultList;
  70. }
  71. },
  72. mounted() {
  73. this.defaultId = this.did;
  74. this.oldList = this.list;
  75. // console.log(this.list,this.show);
  76. },
  77. methods: {
  78. search(e){
  79. console.log(e,'1111');
  80. },
  81. clear(e){
  82. this.keywords='';
  83. this.list = this.oldList;
  84. },
  85. // 点击modal的回调函数
  86. clickOption(e) {
  87. this.defaultId = e.currentTarget.dataset.id;
  88. },
  89. // 点击取消按钮的回调函数
  90. cancel() {
  91. // this.show = false;
  92. this.$emit('update:show', false);
  93. // this.triggerEvent('cancel') //triggerEvent触发事件
  94. this.$emit('cancel');
  95. },
  96. // 点击确定按钮的回调函数
  97. confirm() {
  98. this.$emit('update:show', false);
  99. let sinfo = null;
  100. this.list.forEach((item) => {
  101. if(item.id == this.defaultId){
  102. sinfo = item;
  103. }
  104. });
  105. // this.triggerEvent('confirm',sinfo);
  106. this.$emit('confirm',sinfo);
  107. }
  108. }
  109. };
  110. </script>
  111. <style lang="scss" scoped>
  112. /*遮罩层*/
  113. .cpicker-mask{
  114. display: flex;
  115. justify-content: center;
  116. align-items: center;
  117. position: fixed;
  118. left: 0;
  119. right: 0;
  120. top: 0;
  121. bottom: 0;
  122. background-color: rgba(0,0,0,0.6);
  123. z-index: 999999999999;
  124. }
  125. /*遮罩内容*/
  126. .cpicker-box{
  127. display: flex;
  128. flex-direction: column;
  129. width: 600rpx;
  130. background-color: #fff;
  131. border-radius: 10rpx;
  132. /* padding: 20rpx; */
  133. text-align: center;
  134. font-size: 30rpx;
  135. color: #333333;
  136. /* font-weight: bold; */
  137. }
  138. .cpicker-box-header{
  139. height: 120rpx;
  140. line-height: 90rpx;
  141. border-bottom: 1rpx solid #e6e4e4;
  142. }
  143. /*中间内容*/
  144. .main-content{
  145. flex: 1;
  146. /* height: 100%; */
  147. min-height: 200rpx;
  148. overflow-y: hidden;
  149. max-height:40vh;
  150. padding-top: 20rpx;
  151. }
  152. .cpicker-option{
  153. position: relative;
  154. width: 460rpx;
  155. height: 70rpx;
  156. line-height: 70rpx;
  157. /* text-align: left; */
  158. padding: 0 70rpx;
  159. padding-right: 70rpx;
  160. overflow: hidden;
  161. text-overflow: ellipsis;
  162. white-space:nowrap;
  163. }
  164. .cpicker-option-checked{
  165. position: absolute;
  166. z-index: 10;
  167. right: 20rpx;
  168. top: 20rpx;
  169. width: 30rpx;
  170. height: 30rpx;
  171. }
  172. /*底部按钮*/
  173. .modal-footer{
  174. display: flex;
  175. flex-direction: row;
  176. height: 90rpx;
  177. line-height: 90rpx;
  178. border-top: 1rpx solid #e6e4e4;
  179. margin-top: 30rpx;
  180. }
  181. .cancel-btn, .confirm-btn{
  182. flex: 1;
  183. height: 90rpx;
  184. line-height: 90rpx;
  185. text-align: center;
  186. font-size: 32rpx;
  187. }
  188. .cancel-btn{
  189. color: #333333;
  190. border-right: 1rpx solid #e6e4e4;
  191. }
  192. .confirm-btn {
  193. color: var(--themeColor)
  194. }
  195. .search-wrapper{
  196. width: 540rpx;
  197. height: 80rpx;
  198. border: 1rpx solid var(--themeColor);
  199. overflow: hidden;
  200. margin: 20rpx auto;
  201. border-radius: 10rpx;
  202. }
  203. .search-wrapper .search-icon{
  204. display: inline-block;
  205. float: left;
  206. width: 80rpx;
  207. // height: 60rpx;
  208. text-align: center;
  209. margin-top: 10rpx;
  210. // line-height: 80rpx;
  211. // vertical-align: middle;
  212. }
  213. .search-wrapper .search-icon svg{
  214. width: 50rpx;
  215. height: 50rpx;
  216. }
  217. .search-wrapper .search-input{
  218. display: inline-block;
  219. float: left;
  220. width: 380rpx;
  221. height: 60rpx;
  222. text-align: left;
  223. // font-size: 20rpx;
  224. // line-height: 90rpx;
  225. margin-top: 12rpx;
  226. // line-height: 120rpx;
  227. vertical-align: middle;
  228. }
  229. .search-wrapper .search-del{
  230. float: left;
  231. display: inline-block;
  232. width: 80rpx;
  233. text-align: center;
  234. margin-top: 10rpx;
  235. }
  236. .search-wrapper .search-del svg{
  237. width: 50rpx;
  238. height: 50rpx;
  239. }
  240. </style>