select.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. <template>
  2. <view class="container">
  3. <picker class="picker-item1" @tap="clickSelect1" @change="changeSelect1" :range="array1" :value="index1"
  4. :disabled="dis_num1">
  5. <view class="select-item">
  6. <view class="picker-item-logol">
  7. <image class="picker-item-logo-left" src="../static/images/school.png"></image>
  8. </view>
  9. <view class="picker-item-label">校区</view>
  10. <view class="picker-item-content" :class="{'font-txt':add_class1==1}">{{arr1[index1]}}</view>
  11. <view class="picker-item-logor">
  12. <image class="picker-item-logo-right" src="../static/images/right.png"></image>
  13. </view>
  14. </view>
  15. </picker>
  16. <picker class="picker-item2" @tap="clickSelect2" @change="changeSelect2" :range="array2" :value="index2"
  17. :disabled="dis_num2">
  18. <view class="select-item">
  19. <view class="picker-item-logol">
  20. <image class="picker-item-logo-left" src="../static/images/building.png"></image>
  21. </view>
  22. <view class="picker-item-label">楼栋</view>
  23. <view class="picker-item-content" :class="{'font-txt':add_class2==1}">{{arr2[index2]}}</view>
  24. <view class="picker-item-logor">
  25. <image class="picker-item-logo-right" src="../static/images/right.png"></image>
  26. </view>
  27. </view>
  28. </picker>
  29. <picker class="picker-item2" @tap="clickSelect3" @change="changeSelect3" :range="array3" :value="index3"
  30. :disabled="dis_num3">
  31. <view class="select-item">
  32. <view class="picker-item-logol">
  33. <image class="picker-item-logo-left" src="../static/images/floor.png"></image>
  34. </view>
  35. <view class="picker-item-label">楼层</view>
  36. <view class="picker-item-content" :class="{'font-txt':add_class3==1}">{{arr3[index3]}}</view>
  37. <view class="picker-item-logor">
  38. <image class="picker-item-logo-right" src="../static/images/right.png"></image>
  39. </view>
  40. </view>
  41. </picker>
  42. <picker class="picker-item2" @tap="clickSelect4" @change="changeSelect4" :range="array4" :value="index4"
  43. :disabled="dis_num4">
  44. <view class="select-item">
  45. <view class="picker-item-logol">
  46. <image class="picker-item-logo-left" src="../static/images/room.png"></image>
  47. </view>
  48. <view class="picker-item-label">房间</view>
  49. <view class="picker-item-content" :class="{'font-txt':add_class4==1}">{{arr4[index4]}}</view>
  50. <view class="picker-item-logor">
  51. <image class="picker-item-logo-right" src="../static/images/right.png"></image>
  52. </view>
  53. </view>
  54. </picker>
  55. <view class="submit-item">
  56. <button @tap="navigateToIndex" class="submit" :data-room='room'>完成</button>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. // import sortdata from '../../static/test.js'
  62. export default {
  63. data() {
  64. return {
  65. index1: 0, //选择器选择
  66. index2: 0,
  67. index3: 0,
  68. index4: 0,
  69. nschool: 0, //选择器中各个值的个数
  70. nbuilds: 0,
  71. floors: 0,
  72. rooms: 0,
  73. arr1: ['请选择校区'], //初始选择
  74. arr2: ['请选择楼栋'],
  75. arr3: ['请选择楼层'],
  76. arr4: ['请选择房间'],
  77. array1: [], //选择器的值
  78. array2: [],
  79. array3: [],
  80. array4: [],
  81. room: '', //存储选择器选择的所有值
  82. add_class1: '', //选择器class属性
  83. add_class2: '',
  84. add_class3: '',
  85. add_class4: '',
  86. dis_num1: 1, //选择器disable属性,是否禁用
  87. dis_num2: 1,
  88. dis_num3: 1,
  89. dis_num4: 1,
  90. // dis_num5: 1,
  91. allData: [], //所有数据
  92. storage: {}, //存放选择数据
  93. ceshi: 'code',
  94. test: this.$store.state.test
  95. }
  96. },
  97. onLoad() {
  98. // 获取校区
  99. this.getCampus()
  100. },
  101. methods: {
  102. /**
  103. * 获取校区
  104. */
  105. async getCampus() {
  106. const res = await this.$myRequest({
  107. host: this.ceshi,
  108. url: '/HotWaters/buildschools.action',
  109. method: 'POST',
  110. header: {
  111. 'content-type': 'application/json'
  112. }
  113. })
  114. // console.log(res.data);
  115. if (res.data.code === 200) {
  116. let tmpData = res.data.data;
  117. this.nschool = tmpData.length
  118. this.array1 = []
  119. for (var i = 0; i < this.nschool; i++) {
  120. this.array1.push(tmpData[i].school)
  121. }
  122. this.dis_num1 = 0
  123. } else {
  124. uni.showToast({
  125. title: '未获得校区',
  126. icon: 'none'
  127. })
  128. }
  129. if (this.$store.state.building.roomSelect != '') {
  130. this.fillData()
  131. }
  132. },
  133. /**
  134. * 填充楼栋号和宿舍号
  135. */
  136. fillData() {
  137. // 拆分之前选好的楼栋和宿舍号
  138. var str = this.$store.state.building.roomSelect;
  139. var arr = new Array();
  140. var i = 0;
  141. while (i < str.length) {
  142. var tmp = str.charCodeAt(i)
  143. var s = "";
  144. while (str.charCodeAt(i) < 256) {
  145. s = s + str.charAt(i);
  146. i++;
  147. }
  148. arr.push(s);
  149. s = "";
  150. while (str.charCodeAt(i) > 256) {
  151. s = s + str.charAt(i);
  152. i++;
  153. }
  154. arr.push(s);
  155. }
  156. // 自动填充
  157. if (arr.length > 0) {
  158. if (arr[1] != null && arr[1].length > 0) {
  159. this.arr1 = [arr[1]]
  160. }
  161. let len = arr[2].length
  162. if (arr[2] != null && len > 0) {
  163. let a = arr[2].split('-')
  164. this.arr2 = [a[0] + '栋']
  165. this.arr3 = [a[1].substring(0, a[1].length - 2) + '层']
  166. this.arr4 = [arr[2]]
  167. }
  168. this.sel1(this.arr1, true);
  169. this.add_class1 = 1
  170. this.add_class2 = 1
  171. this.add_class3 = 1
  172. this.add_class4 = 1
  173. this.dis_num2 = 0
  174. this.dis_num3 = 0
  175. this.dis_num4 = 0
  176. }
  177. },
  178. clickSelect1() {
  179. if (this.array1.length == 0) {
  180. uni.showToast({
  181. title: '未获得校区,可能网络异常',
  182. icon: 'none'
  183. })
  184. }
  185. },
  186. /**
  187. * 选择校区
  188. */
  189. changeSelect1(e) {
  190. this.array2 = []
  191. this.array3 = []
  192. this.array4 = []
  193. this.sel1(e.detail.value, false)
  194. },
  195. // 根据参数的值选中
  196. sel1(index, theRoomIsExist) {
  197. // console.log(index)
  198. // console.log(typeof(index))
  199. this.arr1 = this.array1;
  200. //获取选择器1的值
  201. if (typeof(index) == 'string') {
  202. this.index1 = index;
  203. } else {
  204. for (var i = 0; i < this.nschool; i++) {
  205. if (index[0] == this.array1[i]) {
  206. this.index1 = i
  207. }
  208. }
  209. }
  210. //获取选择器二中的值
  211. this.getBuilds(this.array1[this.index1], theRoomIsExist)
  212. if (typeof(index) == 'string') {
  213. this.arr2 = ['请选择楼栋']
  214. this.arr3 = ['请选择楼层']
  215. this.arr4 = ['请选择房间']
  216. this.index2 = 0
  217. this.index3 = 0
  218. this.index4 = 0
  219. this.room = ''
  220. }
  221. this.add_class1 = 1;
  222. this.dis_num2 = 0;
  223. this.chgDisable()
  224. },
  225. /**
  226. * 获取楼栋
  227. * @param {Object} campus
  228. */
  229. async getBuilds(campus, theRoomIsExist) {
  230. const res = await this.$myRequest({
  231. host: this.ceshi,
  232. url: '/HotWaters/buildbuilds.action',
  233. method: 'POST',
  234. header: {
  235. 'content-type': 'application/x-www-form-urlencoded'
  236. },
  237. data: {
  238. school: campus
  239. }
  240. })
  241. // console.log('楼栋:', res.data);
  242. if (res.data.code === 200) {
  243. let tmpData = res.data.data;
  244. // this.allData = rooms
  245. //得到选择器二中值的个数
  246. this.nbuilds = tmpData.length
  247. this.array2 = []
  248. //将数据加入选择器二中
  249. for (var j = 0; j < this.nbuilds; j++) {
  250. this.array2.push(tmpData[j].build)
  251. }
  252. if (theRoomIsExist == true) {
  253. this.sel2(this.arr2, true)
  254. }
  255. } else {
  256. this.array2 = []
  257. uni.showToast({
  258. title: '未获得楼栋',
  259. icon: 'none'
  260. })
  261. }
  262. },
  263. clickSelect2() {
  264. if (this.array2.length == 0) {
  265. uni.showToast({
  266. title: '未获得楼栋,该校区没有楼栋',
  267. icon: 'none'
  268. })
  269. }
  270. },
  271. changeSelect2(e) {
  272. this.array3 = []
  273. this.array4 = []
  274. this.sel2(e.detail.value, false)
  275. },
  276. sel2(index, theRoomIsExist) {
  277. // console.log(index);
  278. // console.log(typeof index);
  279. this.arr2 = this.array2;
  280. if (typeof(index) == 'string') {
  281. this.index2 = index;
  282. } else {
  283. for (var i = 0; i < this.nbuilds; i++) {
  284. if (index[0] == this.array2[i]) {
  285. this.index2 = i
  286. }
  287. }
  288. }
  289. this.getFloors(this.array1[this.index1], this.array2[this.index2], theRoomIsExist)
  290. if (typeof(index) == 'string') {
  291. this.arr3 = ['请选择楼层']
  292. this.arr4 = ['请选择房间']
  293. this.index3 = 0
  294. this.index4 = 0
  295. this.room = ''
  296. }
  297. this.add_class2 = 1;
  298. this.dis_num3 = 0;
  299. this.chgDisable()
  300. },
  301. /**
  302. * 获取楼层
  303. * @param {Object} campus
  304. * @param {Object} build
  305. */
  306. async getFloors(campus, build, theRoomIsExist) {
  307. // console.log(campus, build);
  308. const res = await this.$myRequest({
  309. host: this.ceshi,
  310. url: '/HotWaters/buildFloors.action',
  311. method: 'POST',
  312. header: {
  313. 'content-type': 'application/x-www-form-urlencoded'
  314. },
  315. data: {
  316. school: campus,
  317. build: build
  318. }
  319. })
  320. // console.log('楼层:', res.data);
  321. if (res.data.code === 200) {
  322. let tmpData = res.data.data;
  323. this.floors = tmpData.length
  324. this.array3 = []
  325. for (var j = 0; j < this.floors; j++) {
  326. this.array3.push(tmpData[j].floors)
  327. }
  328. if (theRoomIsExist == true) {
  329. this.sel3(this.arr3, true)
  330. }
  331. } else {
  332. uni.showToast({
  333. title: '未获得楼层',
  334. icon: 'none'
  335. })
  336. }
  337. },
  338. clickSelect3() {
  339. if (this.array3.length == 0) {
  340. uni.showToast({
  341. title: '未获得楼层,请选择楼栋',
  342. icon: 'none'
  343. })
  344. }
  345. },
  346. changeSelect3(e) {
  347. this.array4 = []
  348. this.sel3(e.detail.value, false)
  349. },
  350. sel3(index, theRoomIsExit) {
  351. // console.log(index)
  352. this.arr3 = this.array3;
  353. if (typeof(index) == 'string') {
  354. this.index3 = index;
  355. } else {
  356. for (var i = 0; i < this.floors; i++) {
  357. if (index[0] == this.array3[i]) {
  358. this.index3 = i
  359. }
  360. }
  361. }
  362. this.getDoms(this.array1[this.index1], this.array2[this.index2], this.array3[this.index3], theRoomIsExit)
  363. if (typeof(index) == 'string') {
  364. this.arr4 = ['请选择房间']
  365. this.index4 = 0
  366. this.room = ''
  367. }
  368. this.add_class3 = 1;
  369. this.dis_num4 = 0;
  370. this.chgDisable()
  371. },
  372. /**
  373. * 获取房间
  374. * @param {Object} campus
  375. * @param {Object} build
  376. * @param {Object} floors
  377. */
  378. async getDoms(campus, build, floors, theRoomIsExist) {
  379. // console.log(campus, build, floors);
  380. const res = await this.$myRequest({
  381. host: this.ceshi,
  382. url: '/HotWaters/builddoms.action',
  383. method: 'POST',
  384. header: {
  385. 'content-type': 'application/x-www-form-urlencoded'
  386. },
  387. data: {
  388. school: campus,
  389. build: build,
  390. floors: floors
  391. }
  392. })
  393. // console.log('房间:', res.data);
  394. if (res.data.code === 200) {
  395. let tmpData = res.data.data;
  396. this.rooms = tmpData.length
  397. this.array4 = []
  398. for (var j = 0; j < this.rooms; j++) {
  399. this.array4.push(tmpData[j].dom)
  400. }
  401. if (theRoomIsExist == true) {
  402. this.sel4(this.arr4, true)
  403. }
  404. } else {
  405. uni.showToast({
  406. title: '未获得房间',
  407. icon: 'none'
  408. })
  409. }
  410. },
  411. clickSelect4() {
  412. if (this.array4.length == 0) {
  413. uni.showToast({
  414. title: '未获得房间,请选择楼层',
  415. icon: 'none'
  416. })
  417. }
  418. },
  419. changeSelect4(e) {
  420. this.sel4(e.detail.value, false)
  421. },
  422. sel4(index, theRoomIsExist) {
  423. // console.log(index)
  424. this.arr4 = this.array4;
  425. this.add_class4 = 1;
  426. if (this.room) {
  427. this.room = ''
  428. }
  429. if (typeof(index) == 'string') {
  430. this.index4 = index;
  431. } else {
  432. for (var i = 0; i < this.rooms; i++) {
  433. if (this.array4[i] == index[0]) {
  434. this.index4 = i
  435. }
  436. }
  437. }
  438. this.room = this.array1[this.index1] + this.array4[this.index4];
  439. },
  440. /**
  441. * 下拉框变量数组为空,就禁用
  442. */
  443. chgDisable() {
  444. setTimeout(() => {
  445. if (this.array1.length == 0) {
  446. this.dis_num1 = 1
  447. }
  448. if (this.array2.length == 0) {
  449. this.dis_num2 = 1
  450. }
  451. if (this.array3.length == 0) {
  452. this.dis_num3 = 1
  453. }
  454. if (this.array4.length == 0) {
  455. this.dis_num4 = 1
  456. }
  457. }, 300)
  458. },
  459. /**
  460. * 跳转缴费页面
  461. * @param {Object} e
  462. */
  463. navigateToIndex(e) {
  464. // console.log(e)
  465. var roomSelect = e.currentTarget.dataset.room;
  466. this.storage.roomSelect = roomSelect;
  467. this.storage.dom = this.array4[this.index4];
  468. if (this.room != '') {
  469. this.$store.state.building.roomSelect = this.storage.roomSelect;
  470. this.$store.state.building.add_class = 1;
  471. this.$store.state.building.dorm_number = this.storage.dom;
  472. uni.navigateBack({
  473. delta: 1
  474. })
  475. } else {
  476. uni.showToast({
  477. icon: 'success',
  478. title: '宿舍号不完整'
  479. })
  480. }
  481. },
  482. }
  483. }
  484. </script>
  485. <style>
  486. @import url("select.css");
  487. </style>