select.vue 13 KB

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