select.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  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. this.array2 = []
  198. this.array3 = []
  199. this.array4 = []
  200. this.sel1(e.detail.value, false)
  201. },
  202. // 根据参数的值选中
  203. sel1(index, theRoomIsExist) {
  204. // console.log(index)
  205. // console.log(typeof(index))
  206. this.arr1 = this.array1;
  207. //获取选择器1的值
  208. if (typeof(index) == 'string') {
  209. this.index1 = index;
  210. } else {
  211. for (var i = 0; i < this.nschool; i++) {
  212. if (index[0] == this.array1[i]) {
  213. this.index1 = i
  214. }
  215. }
  216. }
  217. //获取选择器二中的值
  218. this.getBuilds(this.array1[this.index1], theRoomIsExist)
  219. if (typeof(index) == 'string') {
  220. this.arr2 = ['请选择楼栋']
  221. this.arr3 = ['请选择楼层']
  222. this.arr4 = ['请选择房间']
  223. this.index2 = 0
  224. this.index3 = 0
  225. this.index4 = 0
  226. this.room = ''
  227. }
  228. this.add_class1 = 1;
  229. this.dis_num2 = 0;
  230. this.chgDisable()
  231. },
  232. /**
  233. * 获取楼栋
  234. * @param {Object} campus
  235. */
  236. async getBuilds(campus, theRoomIsExist) {
  237. const res = await this.$myRequest({
  238. host: this.ceshi,
  239. url: '/HotWaters/buildbuilds.action',
  240. method: 'POST',
  241. header: {
  242. 'content-type': 'application/x-www-form-urlencoded'
  243. },
  244. data: {
  245. school: campus
  246. }
  247. })
  248. // console.log('楼栋:', res.data);
  249. if (res.data.code === 200) {
  250. let tmpData = res.data.data;
  251. // this.allData = rooms
  252. //得到选择器二中值的个数
  253. this.nbuilds = tmpData.length
  254. this.array2 = []
  255. //将数据加入选择器二中
  256. for (var j = 0; j < this.nbuilds; j++) {
  257. this.array2.push(tmpData[j].build)
  258. }
  259. if (theRoomIsExist == true) {
  260. this.sel2(this.arr2, true)
  261. }
  262. } else {
  263. this.array2 = []
  264. uni.showToast({
  265. title: '未获得楼栋',
  266. icon: 'none'
  267. })
  268. }
  269. },
  270. clickSelect2() {
  271. if (this.array2.length == 0) {
  272. uni.showToast({
  273. title: '未获得楼栋,该校区没有楼栋',
  274. icon: 'none'
  275. })
  276. }
  277. },
  278. changeSelect2(e) {
  279. this.array3 = []
  280. this.array4 = []
  281. this.sel2(e.detail.value, false)
  282. },
  283. sel2(index, theRoomIsExist) {
  284. // console.log(index);
  285. // console.log(typeof index);
  286. this.arr2 = this.array2;
  287. if (typeof(index) == 'string') {
  288. this.index2 = index;
  289. } else {
  290. for (var i = 0; i < this.nbuilds; i++) {
  291. if (index[0] == this.array2[i]) {
  292. this.index2 = i
  293. }
  294. }
  295. }
  296. this.getFloors(this.array1[this.index1], this.array2[this.index2], theRoomIsExist)
  297. if (typeof(index) == 'string') {
  298. this.arr3 = ['请选择楼层']
  299. this.arr4 = ['请选择房间']
  300. this.index3 = 0
  301. this.index4 = 0
  302. this.room = ''
  303. }
  304. this.add_class2 = 1;
  305. this.dis_num3 = 0;
  306. this.chgDisable()
  307. },
  308. /**
  309. * 获取楼层
  310. * @param {Object} campus
  311. * @param {Object} build
  312. */
  313. async getFloors(campus, build, theRoomIsExist) {
  314. // console.log(campus, build);
  315. const res = await this.$myRequest({
  316. host: this.ceshi,
  317. url: '/HotWaters/buildFloors.action',
  318. method: 'POST',
  319. header: {
  320. 'content-type': 'application/x-www-form-urlencoded'
  321. },
  322. data: {
  323. school: campus,
  324. build: build
  325. }
  326. })
  327. // console.log('楼层:', res.data);
  328. if (res.data.code === 200) {
  329. let tmpData = res.data.data;
  330. this.floors = tmpData.length
  331. this.array3 = []
  332. for (var j = 0; j < this.floors; j++) {
  333. this.array3.push(tmpData[j].floors)
  334. }
  335. if (theRoomIsExist == true) {
  336. this.sel3(this.arr3, true)
  337. }
  338. } else {
  339. uni.showToast({
  340. title: '未获得楼层',
  341. icon: 'none'
  342. })
  343. }
  344. },
  345. clickSelect3() {
  346. if (this.array3.length == 0) {
  347. uni.showToast({
  348. title: '未获得楼层,请选择楼栋',
  349. icon: 'none'
  350. })
  351. }
  352. },
  353. changeSelect3(e) {
  354. this.array4 = []
  355. this.sel3(e.detail.value, false)
  356. },
  357. sel3(index, theRoomIsExit) {
  358. // console.log(index)
  359. this.arr3 = this.array3;
  360. if (typeof(index) == 'string') {
  361. this.index3 = index;
  362. } else {
  363. for (var i = 0; i < this.floors; i++) {
  364. if (index[0] == this.array3[i]) {
  365. this.index3 = i
  366. }
  367. }
  368. }
  369. this.getDoms(this.array1[this.index1], this.array2[this.index2], this.array3[this.index3], theRoomIsExit)
  370. if (typeof(index) == 'string') {
  371. this.arr4 = ['请选择房间']
  372. this.index4 = 0
  373. this.room = ''
  374. }
  375. this.add_class3 = 1;
  376. this.dis_num4 = 0;
  377. this.chgDisable()
  378. },
  379. /**
  380. * 获取房间
  381. * @param {Object} campus
  382. * @param {Object} build
  383. * @param {Object} floors
  384. */
  385. async getDoms(campus, build, floors, theRoomIsExist) {
  386. // console.log(campus, build, floors);
  387. const res = await this.$myRequest({
  388. host: this.ceshi,
  389. url: '/HotWaters/builddoms.action',
  390. method: 'POST',
  391. header: {
  392. 'content-type': 'application/x-www-form-urlencoded'
  393. },
  394. data: {
  395. school: campus,
  396. build: build,
  397. floors: floors
  398. }
  399. })
  400. // console.log('房间:', res.data);
  401. if (res.data.code === 200) {
  402. let tmpData = res.data.data;
  403. this.rooms = tmpData.length
  404. this.array4 = []
  405. for (var j = 0; j < this.rooms; j++) {
  406. this.array4.push(tmpData[j].dom)
  407. }
  408. if (theRoomIsExist == true) {
  409. this.sel4(this.arr4, true)
  410. }
  411. } else {
  412. uni.showToast({
  413. title: '未获得房间',
  414. icon: 'none'
  415. })
  416. }
  417. },
  418. clickSelect4() {
  419. if (this.array4.length == 0) {
  420. uni.showToast({
  421. title: '未获得房间,请选择楼层',
  422. icon: 'none'
  423. })
  424. }
  425. },
  426. changeSelect4(e) {
  427. this.sel4(e.detail.value, false)
  428. },
  429. sel4(index, theRoomIsExist) {
  430. // console.log(index)
  431. this.arr4 = this.array4;
  432. this.add_class4 = 1;
  433. if (this.room) {
  434. this.room = ''
  435. }
  436. if (typeof(index) == 'string') {
  437. this.index4 = index;
  438. } else {
  439. for (var i = 0; i < this.rooms; i++) {
  440. if (this.array4[i] == index[0]) {
  441. this.index4 = i
  442. }
  443. }
  444. }
  445. this.room = this.array1[this.index1] + this.array4[this.index4];
  446. },
  447. /**
  448. * 下拉框变量数组为空,就禁用
  449. */
  450. chgDisable() {
  451. setTimeout(() => {
  452. if (this.array1.length == 0) {
  453. this.dis_num1 = 1
  454. }
  455. if (this.array2.length == 0) {
  456. this.dis_num2 = 1
  457. }
  458. if (this.array3.length == 0) {
  459. this.dis_num3 = 1
  460. }
  461. if (this.array4.length == 0) {
  462. this.dis_num4 = 1
  463. }
  464. }, 300)
  465. },
  466. /**
  467. * 跳转缴费页面
  468. * @param {Object} e
  469. */
  470. navigateToIndex(e) {
  471. // console.log(e)
  472. var roomSelect = e.currentTarget.dataset.room;
  473. this.storage.roomSelect = roomSelect;
  474. this.storage.dom = this.array4[this.index4];
  475. if (this.room != '') {
  476. this.$store.state.building.roomSelect = this.storage.roomSelect;
  477. this.$store.state.building.add_class = 1;
  478. this.$store.state.building.dorm_number = this.storage.dom;
  479. uni.navigateBack({
  480. delta: 1
  481. })
  482. } else {
  483. uni.showToast({
  484. icon: 'success',
  485. title: '宿舍号不完整'
  486. })
  487. }
  488. },
  489. }
  490. }
  491. </script>
  492. <style>
  493. @import url("select.css");
  494. </style>