select.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <template>
  2. <view class="container">
  3. <picker class="picker-item1" @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/image/school.png"></image>
  7. </view>
  8. <view class="picker-item-label">校区</view>
  9. <view class="picker-item-content" :class="{'font-txt':add_class1==1}">{{arr1[index1]}}</view>
  10. <view class="picker-item-logor">
  11. <image class="picker-item-logo-right" src="/static/image/right.png"></image>
  12. </view>
  13. </view>
  14. </picker>
  15. <picker class="picker-item2" @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/image/building.png"></image>
  19. </view>
  20. <view class="picker-item-label">楼栋</view>
  21. <view class="picker-item-content" :class="{'font-txt':add_class2==1}">{{arr2[index2]}}</view>
  22. <view class="picker-item-logor">
  23. <image class="picker-item-logo-right" src="/static/image/right.png"></image>
  24. </view>
  25. </view>
  26. </picker>
  27. <picker class="picker-item2" @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/image/floor.png"></image>
  31. </view>
  32. <view class="picker-item-label">楼层</view>
  33. <view class="picker-item-content" :class="{'font-txt':add_class3==1}">{{arr3[index3]}}</view>
  34. <view class="picker-item-logor">
  35. <image class="picker-item-logo-right" src="/static/image/right.png"></image>
  36. </view>
  37. </view>
  38. </picker>
  39. <picker class="picker-item2" @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/image/room.png"></image>
  43. </view>
  44. <view class="picker-item-label">房间</view>
  45. <view class="picker-item-content" :class="{'font-txt':add_class4==1}">{{arr4[index4]}}</view>
  46. <view class="picker-item-logor">
  47. <image class="picker-item-logo-right" src="/static/image/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: '', //选择器class属性
  79. add_class2: '',
  80. add_class3: '',
  81. add_class4: '',
  82. dis_num1: 1, //选择器disable属性,是否禁用
  83. dis_num2: 1,
  84. dis_num3: 1,
  85. dis_num4: 1,
  86. // dis_num5: 1,
  87. allData: [], //所有数据
  88. storage: {}, //存放选择数据
  89. ceshi: 'code',
  90. test: this.$store.state.test
  91. }
  92. },
  93. onLoad() {
  94. // 请求校区、楼栋、层好、宿舍号等数据
  95. this.requestAllData()
  96. },
  97. methods: {
  98. /**
  99. * 请求楼栋、楼层、宿舍等信息
  100. */
  101. async requestAllData() {
  102. uni.showLoading({
  103. title: '数据加载中……',
  104. mask: true
  105. });
  106. const res = await this.$myRequest({
  107. host: this.ceshi,
  108. url: '/HotWaters/buildelec.action',
  109. method: 'POST',
  110. header: {
  111. 'content-type': 'application/json'
  112. }
  113. })
  114. // console.log(res.data.data);
  115. let rooms = JSON.parse('[{"data":' + res.data.data + '}]')[0]
  116. // console.log(rooms);
  117. if (typeof(rooms) != 'undefined') {
  118. this.allData = rooms
  119. this.nschool = rooms.data.length
  120. this.array1 = []
  121. for (var i = 0; i < this.nschool; i++) {
  122. this.array1.push(rooms.data[i].school)
  123. }
  124. this.dis_num1 = 0
  125. uni.hideLoading()
  126. }
  127. if (this.$store.state.building.roomSelect != '') {
  128. this.fillData()
  129. }
  130. },
  131. /**
  132. * 填充楼栋号和宿舍号
  133. */
  134. fillData() {
  135. // 拆分之前选好的楼栋和宿舍号
  136. var str = this.$store.state.building.roomSelect;
  137. var arr = new Array();
  138. var i = 0;
  139. while (i < str.length) {
  140. var tmp = str.charCodeAt(i)
  141. var s = "";
  142. while (str.charCodeAt(i) < 256) {
  143. s = s + str.charAt(i);
  144. i++;
  145. }
  146. arr.push(s);
  147. s = "";
  148. while (str.charCodeAt(i) > 256) {
  149. s = s + str.charAt(i);
  150. i++;
  151. }
  152. arr.push(s);
  153. }
  154. // 自动填充
  155. if (arr.length > 0) {
  156. if (arr[1] != null && arr[1].length > 0) {
  157. this.arr1 = [arr[1]]
  158. }
  159. let len = arr[2].length
  160. if (arr[2] != null && len > 0) {
  161. this.arr2 = [arr[2].substring(0, len - 3) + '栋']
  162. this.arr3 = [arr[2].substring(len - 3, len - 2) + '层']
  163. this.arr4 = [arr[2]]
  164. }
  165. this.sel1(this.arr1)
  166. this.sel2(this.arr2)
  167. this.sel3(this.arr3)
  168. this.sel4(this.arr4)
  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. /**
  179. * 选择校区
  180. */
  181. changeSelect1(e) {
  182. this.sel1(e.detail.value)
  183. },
  184. // 根据参数的值选中
  185. sel1(index) {
  186. // console.log(index)
  187. // console.log(typeof(index))
  188. this.arr1 = this.array1;
  189. //获取选择器1的值
  190. for (var i = 0; i < this.nschool; i++) {
  191. // this.array1.push(this.allData.data[i].school)
  192. // console.log(this.allData.data[i].school)
  193. if (typeof(index) == 'string') {
  194. this.index1 = index;
  195. } else if (this.allData.data[i].school == index[0]) {
  196. this.index1 = i
  197. }
  198. //判断是否为空,不为空则继续
  199. if (!this.allData.data[i].builds) {
  200. continue
  201. }
  202. //获取选择器二中的值
  203. if (i == this.index1) {
  204. //得到选择器二中值的个数
  205. this.nbuilds = this.allData.data[i].builds.length
  206. this.array2 = []
  207. //将数据加入选择器二中
  208. for (var j = 0; j < this.nbuilds; j++) {
  209. this.array2.push(this.allData.data[i].builds[j].building)
  210. }
  211. }
  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. }
  222. // this.room = this.room.concat(this.array1[this.index1]);
  223. this.add_class1 = 1;
  224. this.dis_num2 = 0;
  225. // console.log(this.array2)
  226. // console.log(this.room)
  227. },
  228. changeSelect2(e) {
  229. this.sel2(e.detail.value)
  230. },
  231. sel2(index) {
  232. // console.log(index);
  233. this.arr2 = this.array2;
  234. for (var i = 0; i < this.nbuilds; i++) {
  235. // this.array1.push(this.allData.data[i].school)
  236. // console.log(this.allData.data[i].school)
  237. if (typeof(index) == 'string') {
  238. this.index2 = index;
  239. } else if (this.allData.data[this.index1].builds[i].building == index[0]) {
  240. this.index2 = i
  241. }
  242. if (!this.allData.data[this.index1].builds[i].floors) {
  243. continue
  244. }
  245. if (i == this.index2) {
  246. this.floors = this.allData.data[this.index1].builds[i].floors.length
  247. this.array3 = []
  248. // console.log(this.floors)
  249. for (var j = 0; j < this.floors; j++) {
  250. this.array3.push(this.allData.data[this.index1].builds[i].floors[j].floor)
  251. }
  252. }
  253. if (typeof(index) == 'string') {
  254. this.arr3 = ['请选择楼层']
  255. this.arr4 = ['请选择房间']
  256. this.index3 = 0
  257. this.index4 = 0
  258. this.room = ''
  259. }
  260. }
  261. // this.room = this.room.concat(this.array2[this.index2]);
  262. this.add_class2 = 1;
  263. this.dis_num3 = 0;
  264. // console.log(this.room)
  265. },
  266. changeSelect3(e) {
  267. this.sel3(e.detail.value)
  268. },
  269. sel3(index) {
  270. // console.log(index)
  271. this.arr3 = this.array3;
  272. for (var i = 0; i < this.floors; i++) {
  273. // this.array1.push(this.allData.data[i].school)
  274. // console.log(this.allData.data[i].school)
  275. if (typeof(index) == 'string') {
  276. this.index3 = index;
  277. } else if (this.allData.data[this.index1].builds[this.index2].floors[i].floor == index[0]) {
  278. this.index3 = i
  279. }
  280. if (!this.allData.data[this.index1].builds[this.index2].floors[i].rooms) {
  281. continue
  282. }
  283. if (i == this.index3) {
  284. this.rooms = this.allData.data[this.index1].builds[this.index2].floors[i].rooms.length
  285. this.array4 = []
  286. // console.log(this.rooms)
  287. for (var j = 0; j < this.rooms; j++) {
  288. this.array4.push(this.allData.data[this.index1].builds[this.index2].floors[i].rooms[j])
  289. }
  290. }
  291. if (typeof(index) == 'string') {
  292. this.arr4 = ['请选择房间']
  293. this.index4 = 0
  294. this.room = ''
  295. }
  296. }
  297. // this.room = this.room.concat(this.array3[this.index3]);
  298. this.add_class3 = 1;
  299. this.dis_num4 = 0;
  300. // console.log(this.room)
  301. },
  302. changeSelect4(e) {
  303. this.sel4(e.detail.value)
  304. },
  305. sel4(index) {
  306. // console.log(index)
  307. this.arr4 = this.array4;
  308. this.add_class4 = 1;
  309. if (this.room) {
  310. this.room = ''
  311. }
  312. for (var i = 0; i < this.rooms; i++) {
  313. if (typeof(index) == 'string')
  314. this.index4 = index;
  315. else if (this.allData.data[this.index1].builds[this.index2].floors[this.index3].rooms[i] == index[0]) {
  316. this.index4 = i
  317. }
  318. //将选择器中的值加到变量room中,传到下一个页面
  319. // this.room = this.room.concat(this.array1[this.index1], this.array2[this.index2], this.array3[this.index3],
  320. // this.array4[this.index4]);
  321. }
  322. this.room = this.room.concat(this.array1[this.index1], this.array4[this.index4]);
  323. // this.dis_num5 = 0;
  324. // console.log(this.array1[this.index1])
  325. // console.log(this.array2[this.index2])
  326. // console.log(this.array3[this.index3])
  327. // console.log(this.array4[this.index4])
  328. // console.log(this.room)
  329. },
  330. //跳转缴费页面
  331. navigateToIndex(e) {
  332. // console.log(e)
  333. var roomSelect = e.currentTarget.dataset.room;
  334. this.storage.roomSelect = roomSelect;
  335. this.storage.dom = this.array4[this.index4];
  336. if (this.room != '') {
  337. this.$store.state.building.roomSelect = this.storage.roomSelect;
  338. this.$store.state.building.add_class = 1;
  339. this.$store.state.building.dom = this.storage.dom;
  340. uni.navigateBack({
  341. delta: 1
  342. })
  343. } else {
  344. uni.showToast({
  345. icon: 'success',
  346. title: '宿舍号不完整'
  347. })
  348. }
  349. },
  350. }
  351. }
  352. </script>
  353. <style>
  354. @import url("select.css");
  355. </style>