yunmiao-jobSelect.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <template>
  2. <view class="container">
  3. <!-- <u-popup mode="right" width="100%" height="100%"> -->
  4. <view class="u-wrap">
  5. <view class="u-search-box">
  6. <u-search placeholder="请输入关键词" @focus="focus" @change="toSearch" @custom="cancle" v-model="keyword"
  7. :show-action="showAction" action-text="取消"></u-search>
  8. </view>
  9. <view class="search-warp" v-if="showAction">
  10. <scroll-view scroll-y :style="{'height': scrollHeight+'px'}" class="item-container">
  11. <view class="thumb-box" v-for="(item, index) in searchList" :key="index" @click="selval(item)">
  12. <view :class="[value==item[valueName]? 'item-active' : '']">
  13. <text>{{item.pname}}-{{item[labelName]}}</text>
  14. </view>
  15. <u-icon v-if="value==item[valueName]" name="checkbox-mark" :color="iconColor" size="28">
  16. </u-icon>
  17. </view>
  18. </scroll-view>
  19. </view>
  20. <view class="u-menu-wrap">
  21. <scroll-view scroll-y scroll-with-animation class="u-tab-view menu-scroll-view" :scroll-top="scrollTop">
  22. <view v-for="(item,index) in list" :key="index" class="u-tab-item"
  23. :class="[current==index ? 'u-tab-item-active' : '']" :data-current="index"
  24. @tap.stop="swichMenu(index)">
  25. <text class="u-line-2">{{item[labelName]}}</text>
  26. </view>
  27. </scroll-view>
  28. <block v-for="(item,index) in list" :key="index">
  29. <scroll-view scroll-y class="right-box" v-if="current==index">
  30. <view class="page-view">
  31. <view class="class-item">
  32. <view class="item-container">
  33. <view class="thumb-box" v-for="(item1, index1) in item.children" :key="index1"
  34. @click="selval(item1)">
  35. <view :class="[value==item1[valueName] ? 'item-active' : '']"
  36. class="img-content">
  37. <image :src="item2" mode="" v-for="item2 in item1.urlPath.split(',')"
  38. class="img">
  39. </image>
  40. <text class="right-text"
  41. style="margin-left: 20rpx;">{{item1[labelName]}}</text>
  42. </view>
  43. <!-- <u-icon v-if="value==item1[valueName]" name="checkbox-mark" :color="iconColor"
  44. size="28">
  45. </u-icon> -->
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. </scroll-view>
  51. </block>
  52. </view>
  53. </view>
  54. <!-- </u-popup> -->
  55. </view>
  56. </template>
  57. <script>
  58. export default {
  59. name: 'jobSelect',
  60. props: {
  61. //label展示字段
  62. labelName: {
  63. type: String,
  64. default: 'typeName'
  65. },
  66. //value选中字段
  67. valueName: {
  68. type: String,
  69. default: 'id'
  70. },
  71. //初始选中值
  72. selectValue: {
  73. type: Number,
  74. default: 0
  75. },
  76. //选择数据
  77. listData: {
  78. type: Array,
  79. default: () => {
  80. return [];
  81. }
  82. }
  83. },
  84. data() {
  85. return {
  86. showModel: true,
  87. list: JSON.parse(JSON.stringify(this.listData)),
  88. scrollTop: 0, //tab标题的滚动条位置
  89. current: 0, // 预设当前项的值
  90. menuHeight: 0, // 左边菜单的高度
  91. menuItemHeight: 0, // 左边菜单item的高度
  92. value: this.selectValue,
  93. keyword: '',
  94. iconColor: 'primary',
  95. showAction: false,
  96. searchList: [],
  97. scrollHeight: 500
  98. }
  99. },
  100. watch: {
  101. listData: {
  102. handler(newName, oldName) {
  103. this.list = JSON.parse(JSON.stringify(newName))
  104. },
  105. deep: true,
  106. }
  107. },
  108. created() {
  109. var that = this;
  110. uni.getSystemInfo({
  111. success: function(res) {
  112. let windowHeight = res.windowHeight;
  113. let windowWidth = res.windowWidth;
  114. //#ifdef H5
  115. let headHeight = 110 / 750 * windowWidth;
  116. //#endif
  117. //#ifndef H5
  118. let headHeight = 200 / 750 * windowWidth;
  119. //#endif
  120. let scrollHeight = (windowHeight - headHeight);
  121. that.scrollHeight = scrollHeight;
  122. }
  123. });
  124. },
  125. methods: {
  126. show() {
  127. this.showModel = true;
  128. },
  129. hide() {
  130. this.showModel = false;
  131. },
  132. selval(item) {
  133. this.value = item[this.valueName];
  134. // this.showModel = false;
  135. this.keyword = '';
  136. this.showAction = false;
  137. this.$emit('confirem', item);
  138. },
  139. // 点击左边的栏目切换
  140. async swichMenu(index) {
  141. if (index == this.current) return;
  142. this.current = index;
  143. // 如果为0,意味着尚未初始化
  144. if (this.menuHeight == 0 || this.menuItemHeight == 0) {
  145. await this.getElRect('menu-scroll-view', 'menuHeight');
  146. await this.getElRect('u-tab-item', 'menuItemHeight');
  147. }
  148. // 将菜单菜单活动item垂直居中
  149. this.scrollTop = index * this.menuItemHeight + this.menuItemHeight / 2 - this.menuHeight / 2;
  150. },
  151. // 获取一个目标元素的高度
  152. getElRect(elClass, dataVal) {
  153. new Promise((resolve, reject) => {
  154. const query = uni.createSelectorQuery().in(this);
  155. query.select('.' + elClass).fields({
  156. size: true
  157. }, res => {
  158. // 如果节点尚未生成,res值为null,循环调用执行
  159. if (!res) {
  160. setTimeout(() => {
  161. this.getElRect(elClass);
  162. }, 10);
  163. return;
  164. }
  165. this[dataVal] = res.height;
  166. }).exec();
  167. })
  168. },
  169. focus() {
  170. this.showAction = true;
  171. },
  172. cancle() {
  173. this.showAction = false;
  174. this.keyword = '';
  175. },
  176. toSearch() {
  177. let arr = [];
  178. this.list.map((item, index) => {
  179. item.children.map((it, ix) => {
  180. if (it[this.labelName].indexOf(this.keyword) >= 0) {
  181. it['pname'] = item[this.labelName];
  182. arr.push(it);
  183. }
  184. })
  185. })
  186. this.searchList = arr;
  187. }
  188. }
  189. }
  190. </script>
  191. <style lang="scss" scoped>
  192. .u-wrap {
  193. // height: 100%;
  194. // width: 100%;
  195. // display: flex;
  196. // flex-direction: column;
  197. // position: relative;
  198. // overflow: hidden;
  199. }
  200. .u-search-box {
  201. padding: 0rpx 30rpx;
  202. box-sizing: border-box;
  203. background-color: white;
  204. display: flex;
  205. // flex-direction: row;
  206. align-items: center;
  207. height: 100rpx;
  208. width: 100%;
  209. position: fixed;
  210. top: 85px;
  211. z-index: 99;
  212. }
  213. .search-warp {
  214. display: flex;
  215. overflow: hidden;
  216. background-color: #FFFFFF;
  217. position: absolute;
  218. z-index: 10;
  219. top: 200rpx;
  220. left: 0;
  221. width: 100%;
  222. }
  223. .u-menu-wrap {
  224. flex: 1;
  225. display: flex;
  226. overflow: hidden;
  227. background-color: #F8F8F8;
  228. }
  229. .u-tab-view {
  230. width: 300rpx;
  231. height: 100vh;
  232. overflow: hidden;
  233. }
  234. .u-tab-item {
  235. height: 100rpx;
  236. background: #f6f6f6;
  237. box-sizing: border-box;
  238. display: flex;
  239. align-items: center;
  240. font-size: 26rpx;
  241. padding: 0 20rpx;
  242. color: #444;
  243. font-weight: 400;
  244. }
  245. .u-tab-item-active {
  246. position: relative;
  247. color: red;
  248. font-size: 28rpx;
  249. font-weight: 600;
  250. background: #fff;
  251. }
  252. .u-tab-item-active::before {
  253. content: "";
  254. position: absolute;
  255. border-left: 4px solid red;
  256. height: 32rpx;
  257. left: 0;
  258. top: 39rpx;
  259. }
  260. .u-tab-view {
  261. // height: 100%;
  262. }
  263. .right-box {
  264. background-color: white;
  265. height: 93vh;
  266. overflow: hidden;
  267. }
  268. .page-view {
  269. background-color: white;
  270. }
  271. .class-item {
  272. background-color: #fff;
  273. border-radius: 8rpx;
  274. }
  275. .item-menu-name {
  276. font-weight: normal;
  277. font-size: 24rpx;
  278. color: $u-main-color;
  279. }
  280. .item-container {
  281. display: flex;
  282. flex-direction: column;
  283. flex: 1;
  284. }
  285. .item-active {
  286. color: #ccc;
  287. }
  288. .thumb-box {
  289. display: flex;
  290. flex-direction: row;
  291. justify-content: space-between;
  292. padding: 20rpx;
  293. align-items: center;
  294. font-size: 32rpx;
  295. }
  296. .img {
  297. width: 300rpx;
  298. height: 150rpx;
  299. }
  300. .img-content {
  301. width: 100%;
  302. display: flex;
  303. align-items: center;
  304. // justify-content: space-between;
  305. // width: 90%;
  306. .right-text {
  307. width: calc(100% - 320rpx);
  308. }
  309. }
  310. .container {
  311. position: relative;
  312. top: 100px;
  313. }
  314. </style>