select.vue 13 KB

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