zhilin-picker.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <view class="zhilin-picker">
  3. <uni-popup ref="popup" type="top" @change="popupChange">
  4. <uni-nav-bar @clickLeft="clickLeft" @clickRight="tapOK" rightText="确定" left-icon="closeempty" :title="title" :border="null"></uni-nav-bar>
  5. <view class="usb"><uni-search-bar v-if="showSearch" :radius="100" cancelButton="none" v-model="searchVal"></uni-search-bar></view>
  6. <view class="main" v-if="list.length">
  7. <scroll-view scroll-y="true" @scrolltolower="lower" :lower-threshold="1">
  8. <view class="scroll-view-item flex" v-for="(v, i) in list" :key="i" @tap="tapItem(v.id, v.name, v)" :class="selected.indexOf(v.id) > -1 ? 'selected' : null">
  9. <view>
  10. <view>{{ v.name }}</view>
  11. <text class="detail_address">{{ v.province }}{{ v.city }}{{ v.district }}{{ v.detail_address }}</text>
  12. </view>
  13. <view><icon v-show="selected.indexOf(v.id) > -1" type="success_no_circle" size="22" /></view>
  14. </view>
  15. <view v-if="showBottom" class="isBottom">已经到底啦~</view>
  16. <view v-if="!showBottom" class="isBottom">下拉刷新~</view>
  17. </scroll-view>
  18. <view class="loadingBox" v-show="loading"><uni-load-more status="loading"></uni-load-more></view>
  19. </view>
  20. <view v-else class="empty"><xw-empty text="暂无选项" textColor="#777777"></xw-empty></view>
  21. </uni-popup>
  22. </view>
  23. </template>
  24. <script>
  25. import uniPopup from '../uni-popup/uni-popup.vue';
  26. import uniNavBar from '../uni-nav-bar/uni-nav-bar.vue';
  27. import xwEmpty from '../xw-empty/xw-empty.vue';
  28. import uniSearchBar from '../uni-search-bar/uni-search-bar.vue';
  29. import uniLoadMore from '../more/uni-load-more.vue';
  30. export default {
  31. name: 'zhilin-select',
  32. components: {
  33. uniPopup,
  34. uniNavBar,
  35. xwEmpty,
  36. uniSearchBar,
  37. uniLoadMore
  38. },
  39. props: {
  40. title: {
  41. type: String,
  42. default: '请选择'
  43. },
  44. value: {
  45. type: Boolean,
  46. required: true
  47. },
  48. data: {
  49. type: Array,
  50. required: true
  51. },
  52. multiple: {
  53. type: Boolean,
  54. default: false
  55. },
  56. showSearch: {
  57. type: Boolean,
  58. default: false
  59. },
  60. searchInput: Function,
  61. initSelected: Array
  62. },
  63. data() {
  64. return {
  65. list: [],
  66. selected: [],
  67. showBottom: false,
  68. loading: false,
  69. searchVal: ''
  70. };
  71. },
  72. created() {
  73. this.dataInit();
  74. },
  75. watch: {
  76. value(n, o) {
  77. if (n) this.$refs.popup.open();
  78. else this.$refs.popup.close();
  79. },
  80. data(n, o) {
  81. this.loading = false;
  82. this.showBottom = false;
  83. this.dataInit();
  84. },
  85. searchVal() {
  86. this.$emit('searchInput', this.searchVal);
  87. this.inputSearch();
  88. },
  89. initSelected(n) {
  90. this.selected = n;
  91. }
  92. },
  93. methods: {
  94. lower: function(e) {
  95. this.showBottom = true;
  96. this.$emit('shua');
  97. },
  98. dataInit() {
  99. this.list = this.data;
  100. },
  101. clickLeft() {
  102. this.$emit('input', false);
  103. },
  104. tapItem(val, name, v) {
  105. console.log(val, name, v);
  106. if (this.multiple) {
  107. let idx = this.selected.indexOf(val);
  108. if (idx == -1) {
  109. this.selected.push(val);
  110. } else {
  111. this.selected.splice(idx, 1);
  112. }
  113. } else {
  114. this.selected = [val, name, v.city, v.city_id, v.district, v.district_id, v.province, v.province_id];
  115. }
  116. this.$emit('change', this.selected.join());
  117. },
  118. tapOK() {
  119. if (this.selected.join() == '' && this.list != '') {
  120. this.$api.msg('请先点击医院列表选择医院!');
  121. return;
  122. }
  123. this.$emit('input', false);
  124. this.$emit('confirm', this.selected.join());
  125. },
  126. popupChange(e) {
  127. this.$emit('input', e.show);
  128. },
  129. inputSearch() {
  130. let val = this.searchVal;
  131. if (this.searchInput) {
  132. this.loading = true;
  133. this.searchInput(val);
  134. return;
  135. }
  136. this.showBottom = false;
  137. if (this.list == '') {
  138. } else {
  139. this.list = this.list.map((v, i) => ({
  140. label: v,
  141. value: v
  142. }));
  143. }
  144. }
  145. }
  146. };
  147. </script>
  148. <style lang="scss">
  149. .zhilin-picker {
  150. font-size: 28rpx;
  151. uni-popup /deep/ .uni-popup {
  152. width: 750rpx;
  153. background: #fff;
  154. height: 1056rpx;
  155. overflow: hidden;
  156. display: flex;
  157. flex-direction: column;
  158. z-index: 999 !important;
  159. }
  160. uni-popup {
  161. .usb {
  162. padding: 0 32rpx;
  163. background: #fff;
  164. }
  165. }
  166. }
  167. .main {
  168. height: calc(800rpx - 192rpx);
  169. flex: 1;
  170. position: relative;
  171. background: #fff;
  172. scroll-view {
  173. height: 100%;
  174. .scroll-view-item {
  175. box-sizing: border-box;
  176. padding: 18rpx 44rpx !important;
  177. display: flex;
  178. justify-content: space-between;
  179. align-items: center;
  180. min-height: 80rpx;
  181. &.selected {
  182. background: rgba(0, 122, 255, 0.1);
  183. }
  184. uni-text {
  185. width: 85%;
  186. }
  187. }
  188. .isBottom {
  189. display: flex;
  190. justify-content: center;
  191. color: #777;
  192. position: relative;
  193. padding: 18rpx 44rpx;
  194. font-size: 24rpx;
  195. &::after {
  196. content: '';
  197. position: absolute;
  198. bottom: 10rpx;
  199. width: 60rpx;
  200. height: 4rpx;
  201. left: 50%;
  202. transform: translateX(-51%);
  203. background: #777;
  204. }
  205. }
  206. }
  207. .loadingBox {
  208. height: 100%;
  209. width: 100%;
  210. position: absolute;
  211. top: 0;
  212. left: 0;
  213. background: rgba(255, 255, 255, 0.7);
  214. z-index: 2;
  215. uni-load-more {
  216. display: flex;
  217. justify-content: center;
  218. position: absolute;
  219. width: 100%;
  220. top: 35%;
  221. left: 50%;
  222. transform: translate(-50%);
  223. }
  224. }
  225. }
  226. .detail_address {
  227. color: #969696;
  228. font-size: 24rpx;
  229. padding-top: 10rpx;
  230. }
  231. .empty {
  232. background: #fff;
  233. }
  234. </style>