choice.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <template>
  2. <view class="page">
  3. <scroll-view class="scrollList" scroll-y :scroll-into-view="scrollViewId" :style="{height:winHeight+'px'}">
  4. <view class="search-bar">
  5. <view class="search-bar-form">
  6. <view class="search-bar-box">
  7. <!-- <icon class="icon-search-in-box" type="search" size="16"></icon> -->
  8. <input confirm-type="search" class="search-bar-input" placeholder="输入城市名称或首字母查询" placeholder-class="phcolor"/>
  9. </view>
  10. <label class="search-bar-label" v-if="!inputShowed" @tap="showInput">
  11. <!-- <icon class="icon-search" type="search" size="16"></icon> -->
  12. <view class="search-bar-text">输入家族ID查询</view>
  13. </label>
  14. <view style="font-weight: 400;font-size: 30rpx;color: rgb(199, 69, 71);position: absolute;right: 20rpx;top: 10rpx;z-index: 2;" @tap="maps">
  15. <tui-icon name="position" color="#C74547" :size="18"></tui-icon>
  16. 地图
  17. </view>
  18. </view>
  19. </view>
  20. <view v-if="!inputVal">
  21. <view class="tui-list city-list">
  22. <block v-for="(list,index) in lists" :key="index" v-if="list.data[0]">
  23. <view class="tui-list-cell-divider" :id="index === 0 ? 'suoyin' : list.letter">
  24. {{list.letter}}
  25. </view>
  26. <view class="tui-flex">
  27. <view class="tui-center tui-col-4">家族ID</view>
  28. <view class="tui-center tui-col-4">所在地</view>
  29. <view class="tui-center tui-col-4">族长</view>
  30. <view class="tui-center tui-col-4">操作</view>
  31. </view>
  32. <view v-for="(item,index2) in list.data" :key="index2"
  33. :data-name="item.id" :hover-stay-time='150'>
  34. <view class="tui-flex" :class="[list.data.length-1==index?'last':'']">
  35. <view class="tui-center tui-col-4">{{item.surname}}{{item.id}}</view>
  36. <view class="tui-center tui-col-4">{{item.address}}</view>
  37. <view class="tui-center tui-col-4">{{item.patriarch}}</view>
  38. <view class="tui-center tui-col-4"><tui-button margin="20rpx 0 " plain width="100rpx" height="50rpx" :size="24" @tap="details">加入</tui-button></view>
  39. </view>
  40. </view>
  41. </block>
  42. </view>
  43. </view>
  44. </scroll-view>
  45. <view class="tui-indexed-list-bar" :style="{height:indexBarHeight+'px'}" @touchstart="touchStart" @touchmove.stop="touchMove"
  46. @touchend.stop="touchEnd" @touchcancel.stop="touchCancel" v-if="!inputVal">
  47. <text v-for="(items,index) in lists" :key="index" class="tui-indexed-list-text" :style="{height:indexBarItemHeight+'px'}">
  48. {{index==0?"索引":items.letter}}
  49. </text>
  50. </view>
  51. <view class="tui-indexed-list-alert" v-if="touchmove && lists[touchmoveIndex].letter">
  52. {{lists[touchmoveIndex].letter}}
  53. </view>
  54. </view>
  55. </template>
  56. <script>
  57. import tuiIcon from "@/components/thorui/tui-icon/tui-icon"
  58. import tuiButton from "@/components/thorui/tui-button/tui-button"
  59. const cityData = require('@/utils/family.js')
  60. export default {
  61. components: {
  62. tuiIcon,
  63. tuiButton
  64. },
  65. data() {
  66. return {
  67. lists: [],
  68. touchmove: false, // 是否在索引表上滑动
  69. touchmoveIndex: -1,
  70. titleHeight: 0, // 索引二字距离窗口顶部的高度
  71. indexBarHeight: 0, // 索引表高度
  72. indexBarItemHeight: 0, // 索引表子项的高度
  73. scrollViewId: '', // scroll-view滚动到的子元素的id
  74. winHeight: 0,
  75. inputShowed: false, // 输入框是否显示
  76. inputVal: '', // 搜索框输入的内容
  77. searchResult: [], // 搜索城市的结果
  78. localCity: ''
  79. }
  80. },
  81. onLoad: function(options) {
  82. const that = this;
  83. that.localCity = options.currentCity || "深圳";
  84. setTimeout(() => {
  85. uni.getSystemInfo({
  86. success: function(res) {
  87. let winHeight = res.windowHeight
  88. let barHeight = winHeight - uni.upx2px(204);
  89. that.winHeight = winHeight;
  90. that.indexBarHeight = barHeight;
  91. that.indexBarItemHeight = barHeight / 25;
  92. that.titleHeight = uni.upx2px(132);
  93. that.lists = cityData.list
  94. }
  95. })
  96. }, 50)
  97. },
  98. methods: {
  99. details: function() {
  100. uni.navigateTo({
  101. url: './details'
  102. });
  103. },
  104. maps: function() {
  105. uni.navigateTo({
  106. url: './maps'
  107. });
  108. },
  109. showInput() {
  110. this.inputShowed = true
  111. },
  112. clearInput() {
  113. this.inputVal = "";
  114. this.inputShowed = false;
  115. this.searchResult = [];
  116. uni.hideKeyboard() //强行隐藏键盘
  117. },
  118. inputTyping(e) {
  119. this.inputVal = e.detail.value;
  120. this.searchCity()
  121. },
  122. // 搜索城市
  123. searchCity() {
  124. let result = []
  125. cityData.list.forEach((item1, index1) => {
  126. item1.data.forEach((item2, index2) => {
  127. if (item2.id.indexOf(this.inputVal.toLocaleUpperCase()) !== -1) {
  128. result.push(item2.id+item2.surname+item2.address)
  129. }
  130. })
  131. })
  132. this.searchResult = result
  133. },
  134. touchStart(e) {
  135. this.touchmove = true
  136. let pageY = e.touches[0].pageY
  137. let index = Math.floor((pageY - this.titleHeight) / this.indexBarItemHeight)
  138. let item = this.lists[index === 0 ? 1 : index]
  139. if (item) {
  140. this.scrollViewId = item.letter;
  141. this.touchmoveIndex = index;
  142. }
  143. },
  144. touchMove(e) {
  145. let pageY = e.touches[0].pageY;
  146. let index = Math.floor((pageY - this.titleHeight) / this.indexBarItemHeight)
  147. let item = this.lists[index === 0 ? 1 : index]
  148. if (item) {
  149. this.scrollViewId = item.letter;
  150. this.touchmoveIndex = index
  151. }
  152. },
  153. touchEnd() {
  154. this.touchmove = false;
  155. this.touchmoveIndex = -1;
  156. },
  157. touchCancel() {
  158. this.touchmove = false;
  159. this.touchmoveIndex = -1;
  160. }
  161. }
  162. }
  163. </script>
  164. <style>
  165. @import '../../../static/style/thorui.css';
  166. page {
  167. height: 100%;
  168. overflow: hidden;
  169. }
  170. .page {
  171. height: 100%;
  172. width: 100%;
  173. overflow: hidden;
  174. }
  175. .scrollList {
  176. flex: 1;
  177. }
  178. .tui-flex{
  179. margin: 20rpx 0;
  180. }
  181. .search-bar {
  182. display: flex;
  183. align-items: center;
  184. position: relative;
  185. padding: 27rpx 30rpx 35rpx;
  186. background-color: #fff;
  187. }
  188. .search-bar-form {
  189. flex: 1;
  190. position: relative;
  191. border-radius: 32rpx;
  192. background: #f2f5f7;
  193. }
  194. .search-bar-box {
  195. display: flex;
  196. align-items: center;
  197. position: relative;
  198. padding-left: 20rpx;
  199. padding-right: 20rpx;
  200. height: 64rpx;
  201. z-index: 1;
  202. }
  203. .search-bar-input {
  204. line-height: normal;
  205. width: 100%;
  206. padding-left: 20rpx;
  207. font-size: 30rpx;
  208. color: #333;
  209. }
  210. .phcolor {
  211. font-size: 30rpx;
  212. }
  213. .icon-clear {
  214. height: 38rpx;
  215. }
  216. .icon-clear .tui-icon-class {
  217. display: block
  218. }
  219. .search-bar-label {
  220. height: 64rpx;
  221. display: flex;
  222. justify-content: center;
  223. align-items: center;
  224. position: absolute;
  225. top: 0;
  226. right: 0;
  227. bottom: 0;
  228. left: 0;
  229. z-index: 2;
  230. border-radius: 32rpx;
  231. color: #ccc;
  232. background: #f2f5f7;
  233. }
  234. .icon-search {
  235. position: relative;
  236. height: 26rpx;
  237. margin-right: 20rpx;
  238. font-size: inherit;
  239. }
  240. .search-bar-text {
  241. font-size: 30rpx;
  242. line-height: 32rpx;
  243. }
  244. .cancel-btn {
  245. padding-left: 30rpx;
  246. }
  247. .search-result::before {
  248. display: none;
  249. }
  250. .search-result::after {
  251. display: none;
  252. }
  253. .tui-list-cell {
  254. display: flex;
  255. flex-direction: row;
  256. justify-content: space-between;
  257. align-items: center;
  258. width: 100%;
  259. }
  260. .tui-list-cell-hover {
  261. background-color: #eee !important;
  262. }
  263. .tui-list-cell-navigate {
  264. width: 100%;
  265. position: relative;
  266. padding: 30rpx 0 30rpx 30rpx;
  267. font-size: 28rpx;
  268. color: #333;
  269. }
  270. .tui-list-cell-navigate::after {
  271. content: '';
  272. position: absolute;
  273. border-bottom: 1rpx solid #eaeef1;
  274. -webkit-transform: scaleY(0.5);
  275. transform: scaleY(0.5);
  276. bottom: 0;
  277. right: 0;
  278. left: 30rpx;
  279. }
  280. .current-city {
  281. padding: 0 30rpx 30rpx;
  282. background: #fff;
  283. }
  284. .tui-icon-class {
  285. margin-right: 10rpx;
  286. }
  287. .current-city .title {
  288. font-size: 24rpx;
  289. line-height: 24rpx;
  290. color: #999;
  291. }
  292. .city-name {
  293. display: inline;
  294. align-items: center;
  295. margin-top: 17rpx;
  296. font-size: 30rpx;
  297. font-weight: bold;
  298. line-height: 30rpx;
  299. color: #333;
  300. }
  301. .hot-city .title {
  302. height: 48rpx !important;
  303. padding-left: 30rpx;
  304. font-size: 24rpx !important;
  305. line-height: 48rpx !important;
  306. color: #999;
  307. background: #f2f5f7 !important;
  308. }
  309. .city-names {
  310. display: flex;
  311. flex-wrap: wrap;
  312. justify-content: space-between;
  313. align-content: space-between;
  314. width: 630rpx;
  315. padding: 12rpx 90rpx 26rpx 30rpx;
  316. background: #fff;
  317. }
  318. .city-name-item {
  319. display: flex;
  320. justify-content: center;
  321. align-items: center;
  322. width: 140rpx;
  323. height: 56rpx;
  324. margin-top: 16rpx;
  325. /* border: solid 1rpx #ccc; */
  326. border-radius: 28rpx;
  327. font-size: 28rpx;
  328. color: #333;
  329. position: relative;
  330. }
  331. .city-name-item::before {
  332. content: "";
  333. position: absolute;
  334. width: 200%;
  335. height: 200%;
  336. -webkit-transform-origin: 0 0;
  337. transform-origin: 0 0;
  338. -webkit-transform: scale(0.5, 0.5);
  339. transform: scale(0.5, 0.5);
  340. -webkit-box-sizing: border-box;
  341. box-sizing: border-box;
  342. left: 0;
  343. top: 0;
  344. border-radius: 56rpx;
  345. border: 1px solid #ccc;
  346. }
  347. .tap-city {
  348. color: #fff;
  349. background: #aa0000;
  350. /* border: solid 1rpx #5677fc; */
  351. }
  352. .tui-list {
  353. background-color: #fff;
  354. position: relative;
  355. width: 100%;
  356. display: flex;
  357. flex-direction: column;
  358. padding-bottom: env(safe-area-inset-bottom);
  359. }
  360. .tui-list-cell-divider {
  361. height: 48rpx;
  362. padding-left: 30rpx;
  363. font-size: 24rpx;
  364. color: #999;
  365. background: #f2f5f7;
  366. padding: 0 30rpx;
  367. display: flex;
  368. align-items: center;
  369. }
  370. .tui-indexed-list-bar {
  371. display: flex;
  372. flex-direction: column;
  373. align-items: center;
  374. justify-content: flex-start;
  375. z-index: 9999;
  376. position: absolute;
  377. top: 132rpx;
  378. right: 0;
  379. padding-right: 10rpx;
  380. width: 44rpx;
  381. }
  382. .tui-indexed-list-text {
  383. font-size: 22rpx;
  384. white-space: nowrap;
  385. }
  386. .tui-indexed-list-bar.active {
  387. background-color: rgb(200, 200, 200);
  388. }
  389. .tui-indexed-list-alert {
  390. position: absolute;
  391. z-index: 20;
  392. width: 160rpx;
  393. height: 160rpx;
  394. left: 50%;
  395. top: 50%;
  396. margin-left: -80rpx;
  397. margin-top: -80rpx;
  398. border-radius: 80rpx;
  399. text-align: center;
  400. line-height: 160rpx;
  401. font-size: 70rpx;
  402. color: #fff;
  403. background-color: rgba(0, 0, 0, 0.5);
  404. }
  405. </style>