select.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  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. if (this.test == 'weihuzhong') {
  100. uni.redirectTo({
  101. url: '../../pages/index/index'
  102. })
  103. return;
  104. }
  105. // 获取校区
  106. this.getCampus()
  107. },
  108. methods: {
  109. /**
  110. * 获取校区
  111. */
  112. async getCampus() {
  113. const res = await this.$myRequest({
  114. host: this.ceshi,
  115. url: '/HotWaters/buildschools.action',
  116. method: 'POST',
  117. header: {
  118. 'content-type': 'application/json'
  119. }
  120. })
  121. // console.log(res.data);
  122. if (res.data.code === 200) {
  123. let tmpData = res.data.data;
  124. this.nschool = tmpData.length
  125. this.array1 = []
  126. for (var i = 0; i < this.nschool; i++) {
  127. this.array1.push(tmpData[i].school)
  128. }
  129. this.dis_num1 = 0
  130. } else {
  131. uni.showToast({
  132. title: '未获得校区',
  133. icon: 'none'
  134. })
  135. }
  136. if (this.$store.state.building.roomSelect != '') {
  137. this.fillData()
  138. }
  139. },
  140. /**
  141. * 填充楼栋号和宿舍号
  142. */
  143. fillData() {
  144. // 拆分之前选好的楼栋和宿舍号
  145. var str = this.$store.state.building.roomSelect;
  146. var arr = new Array();
  147. var i = 0;
  148. while (i < str.length) {
  149. var tmp = str.charCodeAt(i)
  150. var s = "";
  151. while (str.charCodeAt(i) < 256) {
  152. s = s + str.charAt(i);
  153. i++;
  154. }
  155. arr.push(s);
  156. s = "";
  157. while (str.charCodeAt(i) > 256) {
  158. s = s + str.charAt(i);
  159. i++;
  160. }
  161. arr.push(s);
  162. }
  163. // 自动填充
  164. if (arr.length > 0) {
  165. if (arr[1] != null && arr[1].length > 0) {
  166. this.arr1 = [arr[1]]
  167. }
  168. let len = arr[2].length
  169. if (arr[2] != null && len > 0) {
  170. let a = arr[2].split('-')
  171. this.arr2 = [a[0] + '栋']
  172. this.arr3 = [a[1].substring(0, a[1].length - 2) + '层']
  173. this.arr4 = [arr[2]]
  174. }
  175. this.sel1(this.arr1, true);
  176. this.add_class1 = 1
  177. this.add_class2 = 1
  178. this.add_class3 = 1
  179. this.add_class4 = 1
  180. this.dis_num2 = 0
  181. this.dis_num3 = 0
  182. this.dis_num4 = 0
  183. }
  184. },
  185. clickSelect1() {
  186. if (this.array1.length == 0) {
  187. uni.showToast({
  188. title: '未获得校区,可能网络异常',
  189. icon: 'none'
  190. })
  191. }
  192. },
  193. /**
  194. * 选择校区
  195. */
  196. changeSelect1(e) {
  197. // console.log(e);
  198. this.array2 = []
  199. this.array3 = []
  200. this.array4 = []
  201. this.sel1(e.detail.value, false)
  202. },
  203. // 根据参数的值选中
  204. sel1(index, theRoomIsExist) {
  205. // console.log(index)
  206. // console.log(typeof(index))
  207. this.arr1 = this.array1;
  208. //获取选择器1的值
  209. if (typeof index == 'string') {
  210. this.index1 = index;
  211. } else {
  212. for (var i = 0; i < this.nschool; i++) {
  213. if (index[0] == this.array1[i]) {
  214. this.index1 = i
  215. }
  216. }
  217. }
  218. //获取选择器二中的值
  219. this.getBuilds(this.array1[this.index1], theRoomIsExist)
  220. if (typeof index == 'string') {
  221. this.arr2 = ['请选择楼栋']
  222. this.arr3 = ['请选择楼层']
  223. this.arr4 = ['请选择房间']
  224. this.index2 = 0
  225. this.index3 = 0
  226. this.index4 = 0
  227. this.room = ''
  228. }
  229. this.add_class1 = 1;
  230. this.dis_num2 = 0;
  231. this.chgDisable()
  232. },
  233. /**
  234. * 获取楼栋
  235. * @param {Object} campus
  236. */
  237. async getBuilds(campus, theRoomIsExist) {
  238. const res = await this.$myRequest({
  239. host: this.ceshi,
  240. url: '/HotWaters/buildbuilds.action',
  241. method: 'POST',
  242. header: {
  243. 'content-type': 'application/x-www-form-urlencoded'
  244. },
  245. data: {
  246. school: campus
  247. }
  248. })
  249. // console.log('楼栋:', res.data);
  250. if (res.data.code === 200) {
  251. let tmpData = res.data.data;
  252. // this.allData = rooms
  253. //得到选择器二中值的个数
  254. this.nbuilds = tmpData.length
  255. this.array2 = []
  256. //将数据加入选择器二中
  257. for (var j = 0; j < this.nbuilds; j++) {
  258. this.array2.push(tmpData[j].build)
  259. }
  260. if (theRoomIsExist == true) {
  261. this.sel2(this.arr2, true)
  262. }
  263. } else {
  264. this.array2 = []
  265. uni.showToast({
  266. title: '未获得楼栋',
  267. icon: 'none'
  268. })
  269. }
  270. },
  271. clickSelect2() {
  272. if (this.array2.length == 0) {
  273. uni.showToast({
  274. title: '未获得楼栋,该校区没有楼栋',
  275. icon: 'none'
  276. })
  277. }
  278. },
  279. changeSelect2(e) {
  280. // console.log(e);
  281. this.array3 = []
  282. this.array4 = []
  283. this.sel2(e.detail.value, false)
  284. },
  285. sel2(index, theRoomIsExist) {
  286. // console.log(index);
  287. // console.log(typeof index);
  288. this.arr2 = this.array2;
  289. if (typeof index == 'string') {
  290. this.index2 = index;
  291. } else {
  292. for (var i = 0; i < this.nbuilds; i++) {
  293. if (index[0] == this.array2[i]) {
  294. this.index2 = i
  295. }
  296. }
  297. }
  298. this.getFloors(this.array1[this.index1], this.array2[this.index2], theRoomIsExist)
  299. if (typeof index == 'string') {
  300. this.arr3 = ['请选择楼层']
  301. this.arr4 = ['请选择房间']
  302. this.index3 = 0
  303. this.index4 = 0
  304. this.room = ''
  305. }
  306. this.add_class2 = 1;
  307. this.dis_num3 = 0;
  308. this.chgDisable()
  309. },
  310. /**
  311. * 获取楼层
  312. * @param {Object} campus
  313. * @param {Object} build
  314. */
  315. async getFloors(campus, build, theRoomIsExist) {
  316. // console.log(campus, build);
  317. const res = await this.$myRequest({
  318. host: this.ceshi,
  319. url: '/HotWaters/buildFloors.action',
  320. method: 'POST',
  321. header: {
  322. 'content-type': 'application/x-www-form-urlencoded'
  323. },
  324. data: {
  325. school: campus,
  326. build: build
  327. }
  328. })
  329. // console.log('楼层:', res.data);
  330. if (res.data.code === 200) {
  331. let tmpData = res.data.data;
  332. this.floors = tmpData.length
  333. this.array3 = []
  334. for (var j = 0; j < this.floors; j++) {
  335. this.array3.push(tmpData[j].floors)
  336. }
  337. if (theRoomIsExist == true) {
  338. this.sel3(this.arr3, true)
  339. }
  340. } else {
  341. uni.showToast({
  342. title: '未获得楼层',
  343. icon: 'none'
  344. })
  345. }
  346. },
  347. clickSelect3() {
  348. if (this.array3.length == 0) {
  349. uni.showToast({
  350. title: '未获得楼层,请选择楼栋',
  351. icon: 'none'
  352. })
  353. }
  354. },
  355. changeSelect3(e) {
  356. // console.log(e);
  357. this.array4 = []
  358. this.sel3(e.detail.value, false)
  359. },
  360. sel3(index, theRoomIsExit) {
  361. // console.log(index)
  362. this.arr3 = this.array3;
  363. if (typeof index == 'string') {
  364. this.index3 = index;
  365. } else {
  366. for (var i = 0; i < this.floors; i++) {
  367. if (index[0] == this.array3[i]) {
  368. this.index3 = i
  369. }
  370. }
  371. }
  372. this.getDoms(this.array1[this.index1], this.array2[this.index2], this.array3[this.index3], theRoomIsExit)
  373. if (typeof index == 'string') {
  374. this.arr4 = ['请选择房间']
  375. this.index4 = 0
  376. this.room = ''
  377. }
  378. this.add_class3 = 1;
  379. this.dis_num4 = 0;
  380. this.chgDisable()
  381. },
  382. /**
  383. * 获取房间
  384. * @param {Object} campus
  385. * @param {Object} build
  386. * @param {Object} floors
  387. */
  388. async getDoms(campus, build, floors, theRoomIsExist) {
  389. // console.log(campus, build, floors);
  390. const res = await this.$myRequest({
  391. host: this.ceshi,
  392. url: '/HotWaters/builddoms.action',
  393. method: 'POST',
  394. header: {
  395. 'content-type': 'application/x-www-form-urlencoded'
  396. },
  397. data: {
  398. school: campus,
  399. build: build,
  400. floors: floors
  401. }
  402. })
  403. // console.log('房间:', res.data);
  404. if (res.data.code === 200) {
  405. let tmpData = res.data.data;
  406. this.rooms = tmpData.length
  407. this.array4 = []
  408. for (var j = 0; j < this.rooms; j++) {
  409. this.array4.push(tmpData[j].dom)
  410. }
  411. if (theRoomIsExist == true) {
  412. this.sel4(this.arr4, true)
  413. }
  414. } else {
  415. uni.showToast({
  416. title: '未获得房间',
  417. icon: 'none'
  418. })
  419. }
  420. },
  421. clickSelect4() {
  422. if (this.array4.length == 0) {
  423. uni.showToast({
  424. title: '未获得房间,请选择楼层',
  425. icon: 'none'
  426. })
  427. }
  428. },
  429. changeSelect4(e) {
  430. // console.log(e);
  431. this.sel4(e.detail.value, false)
  432. },
  433. sel4(index, theRoomIsExist) {
  434. // console.log(index)
  435. this.arr4 = this.array4;
  436. this.add_class4 = 1;
  437. if (this.room) {
  438. this.room = ''
  439. }
  440. if (typeof index == 'string') {
  441. this.index4 = index;
  442. } else {
  443. for (var i = 0; i < this.rooms; i++) {
  444. if (this.array4[i] == index[0]) {
  445. this.index4 = i
  446. }
  447. }
  448. }
  449. this.room = this.array1[this.index1] + this.array4[this.index4];
  450. },
  451. /**
  452. * 下拉框变量数组为空,就禁用
  453. */
  454. chgDisable() {
  455. setTimeout(() => {
  456. if (this.array1.length == 0) {
  457. this.dis_num1 = 1
  458. }
  459. if (this.array2.length == 0) {
  460. this.dis_num2 = 1
  461. }
  462. if (this.array3.length == 0) {
  463. this.dis_num3 = 1
  464. }
  465. if (this.array4.length == 0) {
  466. this.dis_num4 = 1
  467. }
  468. }, 300)
  469. },
  470. /**
  471. * 跳转缴费页面
  472. * @param {Object} e
  473. */
  474. navigateToIndex(e) {
  475. // console.log(e)
  476. var roomSelect = e.currentTarget.dataset.room;
  477. this.storage.roomSelect = roomSelect;
  478. this.storage.dom = this.array4[this.index4];
  479. if (this.room != '') {
  480. this.$store.state.building.roomSelect = this.storage.roomSelect;
  481. this.$store.state.building.add_class = 1;
  482. this.$store.state.building.dorm_number = this.storage.dom;
  483. uni.navigateBack({
  484. delta: 1
  485. })
  486. } else {
  487. uni.showToast({
  488. icon: 'success',
  489. title: '宿舍号不完整'
  490. })
  491. }
  492. },
  493. }
  494. }
  495. </script>
  496. <style>
  497. @import url("select.css");
  498. </style>