app-city-swiper.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <view class="app-picker">
  3. <view class="app-mask" :class="{'show': showPicker}" v-if="showPicker" @tap="maskTap" @touchmove.stop.prevent catchtouchmove="true"></view>
  4. <view class="app-picker-cnt" :class="{'show':showPicker}">
  5. <view class="app-picker-hd" @touchmove.stop.prevent catchtouchmove="true">
  6. <view class="app-picker-btn" @tap="pickerCancel">取消</view>
  7. <view class="app-picker-btn" :style="{'color':themeColor}" @tap="pickerConfirm">确定</view>
  8. </view>
  9. <view class="app-picker-view" v-if="mode=='region'">
  10. <picker-view :indicator-style="itemHeight" :value="pickVal" @change="bindChange">
  11. <picker-view-column>
  12. <view class="app-picker-item" v-for="(item,index) in selectData" :key="index">{{item.name}}</view>
  13. </picker-view-column>
  14. <picker-view-column>
  15. <view class="app-picker-item" v-if="provinceId === item.parent_id_id" v-for="(item,index) in selectData[provinceId].list" :key="index">{{item.name}}</view>
  16. </picker-view-column>
  17. <picker-view-column>
  18. <view class="app-picker-item" v-if="cityId === item.parent_id_id" v-for="(item,index) in selectData[provinceId].list[cityId].list" :key="index">{{item.name}}</view>
  19. </picker-view-column>
  20. </picker-view>
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. name: "app-city",
  28. data() {
  29. return {
  30. showPicker: false,
  31. pickVal: [0,0,0],
  32. itemHeight:`height: ${uni.upx2px(88)}px;`,
  33. checkArr:[],
  34. provinceId: 0,
  35. cityId: 0,
  36. }
  37. },
  38. props: {
  39. themeColor:{
  40. type:String,
  41. default(){
  42. return "#f00"
  43. }
  44. },
  45. mode: {
  46. type:String,
  47. default(){
  48. return "region"
  49. }
  50. },
  51. cityData: {
  52. type: Object,
  53. default() {
  54. return {}
  55. }
  56. }
  57. },
  58. methods: {
  59. maskTap(){
  60. this.showPicker = false;
  61. },
  62. bindChange(val) {
  63. let arr = val.detail.value;
  64. this.provinceId = arr[0];
  65. this.cityId = arr[1];
  66. this.$nextTick().then(() => {
  67. this.pickVal = arr;
  68. });
  69. },
  70. pickerCancel() {
  71. this.showPicker = false;
  72. },
  73. pickerConfirm() {
  74. // 返回结果
  75. this.showPicker = false;
  76. },
  77. initData(list) {
  78. for (let i = 0; i < list.length; i++) {
  79. list[i].id_id = i;
  80. for (let j = 0; j < list[i].list.length; j++) {
  81. list[i].list[j].parent_id_id = i;
  82. list[i].list[j].id_id = j;
  83. for (let p = 0; p < list[i].list[j].list.length; p++) {
  84. list[i].list[j].list[p].parent_id_id = j;
  85. list[i].list[j].list[p].id_id = p;
  86. }
  87. }
  88. }
  89. return list;
  90. }
  91. },
  92. computed: {
  93. selectData: function() {
  94. return this.initData(this.cityData);
  95. }
  96. }
  97. }
  98. </script>
  99. <style scoped lang="scss">
  100. .app-picker {
  101. position: relative;
  102. z-index: 1888;
  103. height:100%;
  104. .app-mask {
  105. position: fixed;
  106. z-index: 1000;
  107. top: 0;
  108. right: 0;
  109. left: 0;
  110. bottom: 0;
  111. background: rgba(0, 0, 0, 0.5);
  112. transition: all 0.3s ease;
  113. .app-mask.show{
  114. visibility: visible;
  115. opacity: 1;
  116. }
  117. }
  118. .app-picker-cnt {
  119. position: fixed;
  120. bottom: 0;
  121. left: 0;
  122. width: 100%;
  123. transition: all 0.3s ease;
  124. transform: translateY(100%);
  125. z-index: 1600;
  126. }
  127. .app-picker-cnt.show {
  128. transform: translateY(0);
  129. }
  130. .app-picker-hd {
  131. display: flex;
  132. align-items: center;
  133. padding: 0 #{30rpx};
  134. height: #{88rpx};
  135. background-color: #fff;
  136. position: relative;
  137. text-align: center;
  138. font-size: #{32rpx};
  139. justify-content: space-between;
  140. .app-picker-btn{
  141. font-size: #{30rpx};
  142. }
  143. }
  144. .app-picker-hd:after {
  145. content: ' ';
  146. position: absolute;
  147. left: 0;
  148. bottom: 0;
  149. right: 0;
  150. height: 1px;
  151. border-bottom: 1px solid #e5e5e5;
  152. color: #e5e5e5;
  153. transform-origin: 0 100%;
  154. transform: scaleY(0.5);
  155. }
  156. .app-picker-view {
  157. width: 100%;
  158. height: #{476rpx};
  159. overflow: hidden;
  160. background-color: rgba(255, 255, 255, 1);
  161. z-index: 666;
  162. }
  163. .app-picker-item {
  164. text-align: center;
  165. width: 100%;
  166. height: #{88rpx};
  167. line-height: #{88rpx};
  168. text-overflow: ellipsis;
  169. white-space: nowrap;
  170. font-size: #{30rpx};
  171. }
  172. picker-view{
  173. height: 100%;
  174. }
  175. }
  176. </style>