select.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. options: '',
  87. // dis_num5: 1,
  88. allData: [], //所有数据
  89. storage: {}, //存放选择数据
  90. test: getApp().globalData.test
  91. }
  92. },
  93. onLoad(options) {
  94. // console.log(options)
  95. this.options = options
  96. // 请求校区、楼栋、层好、宿舍号等数据
  97. this.requestAllData()
  98. },
  99. methods: {
  100. /**
  101. * 请求楼栋、楼层、宿舍等信息
  102. */
  103. async requestAllData() {
  104. uni.showLoading({
  105. title: '数据加载中……',
  106. mask: true
  107. });
  108. let res;
  109. if (this.test) {
  110. res = await this.$myRequest({
  111. host: 'ceshi',
  112. url: 'http://3ft7hs.natappfree.cc',
  113. method: 'POST',
  114. header: {
  115. 'content-type': 'application/json'
  116. }
  117. })
  118. } else {
  119. res = await this.$myRequest({
  120. host: 'code',
  121. url: '/HotWater/buildelec.action',
  122. method: 'POST',
  123. header: {
  124. 'content-type': 'application/json'
  125. }
  126. })
  127. }
  128. if (typeof(res.data) != 'undefined') {
  129. this.allData = res
  130. this.nschool = res.data.length
  131. this.array1 = []
  132. for (var i = 0; i < this.nschool; i++) {
  133. this.array1.push(res.data[i].school)
  134. }
  135. this.dis_num1 = 0
  136. uni.hideLoading()
  137. // 拆分之前选好的楼栋和宿舍号
  138. if (this.options.roomSelect != '') {
  139. var str = this.options.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. this.arr2 = [arr[2].substring(0, len - 3) + '栋']
  165. this.arr3 = [arr[2].substring(len - 3, len - 2) + '层']
  166. this.arr4 = [arr[2]]
  167. }
  168. this.sel1(this.arr1)
  169. this.sel2(this.arr2)
  170. this.sel3(this.arr3)
  171. this.sel4(this.arr4)
  172. this.add_class1 = 1
  173. this.add_class2 = 1
  174. this.add_class3 = 1
  175. this.add_class4 = 1
  176. this.dis_num2 = 0
  177. this.dis_num3 = 0
  178. this.dis_num4 = 0
  179. }
  180. }
  181. }
  182. },
  183. /**
  184. * 选择校区
  185. */
  186. changeSelect1(e) {
  187. this.sel1(e.detail.value)
  188. },
  189. // 根据参数的值选中
  190. sel1(index) {
  191. // console.log(index)
  192. // console.log(typeof(index))
  193. this.arr1 = this.array1;
  194. //获取选择器1的值
  195. for (var i = 0; i < this.nschool; i++) {
  196. // this.array1.push(this.allData.data[i].school)
  197. // console.log(this.allData.data[i].school)
  198. if (typeof(index) == 'string') {
  199. this.index1 = index;
  200. } else if (this.allData.data[i].school == index[0]) {
  201. this.index1 = i
  202. }
  203. //判断是否为空,不为空则继续
  204. if (!this.allData.data[i].builds) {
  205. continue
  206. }
  207. //获取选择器二中的值
  208. if (i == this.index1) {
  209. //得到选择器二中值的个数
  210. this.nbuilds = this.allData.data[i].builds.length
  211. this.array2 = []
  212. //将数据加入选择器二中
  213. for (var j = 0; j < this.nbuilds; j++) {
  214. this.array2.push(this.allData.data[i].builds[j].building)
  215. }
  216. }
  217. if (typeof(index) == 'string') {
  218. this.arr2 = ['请选择楼栋']
  219. this.arr3 = ['请选择楼层']
  220. this.arr4 = ['请选择房间']
  221. this.index2 = 0
  222. this.index3 = 0
  223. this.index4 = 0
  224. this.room = ''
  225. }
  226. }
  227. // this.room = this.room.concat(this.array1[this.index1]);
  228. this.add_class1 = 1;
  229. this.dis_num2 = 0;
  230. // console.log(this.array2)
  231. // console.log(this.room)
  232. },
  233. changeSelect2(e) {
  234. this.sel2(e.detail.value)
  235. },
  236. sel2(index) {
  237. // console.log(index);
  238. this.arr2 = this.array2;
  239. for (var i = 0; i < this.nbuilds; i++) {
  240. // this.array1.push(this.allData.data[i].school)
  241. // console.log(this.allData.data[i].school)
  242. if (typeof(index) == 'string') {
  243. this.index2 = index;
  244. } else if (this.allData.data[this.index1].builds[i].building == index[0]) {
  245. this.index2 = i
  246. }
  247. if (!this.allData.data[this.index1].builds[i].floors) {
  248. continue
  249. }
  250. if (i == this.index2) {
  251. this.floors = this.allData.data[this.index1].builds[i].floors.length
  252. this.array3 = []
  253. // console.log(this.floors)
  254. for (var j = 0; j < this.floors; j++) {
  255. this.array3.push(this.allData.data[this.index1].builds[i].floors[j].floor)
  256. }
  257. }
  258. if (typeof(index) == 'string') {
  259. this.arr3 = ['请选择楼层']
  260. this.arr4 = ['请选择房间']
  261. this.index3 = 0
  262. this.index4 = 0
  263. this.room = ''
  264. }
  265. }
  266. // this.room = this.room.concat(this.array2[this.index2]);
  267. this.add_class2 = 1;
  268. this.dis_num3 = 0;
  269. // console.log(this.room)
  270. },
  271. changeSelect3(e) {
  272. this.sel3(e.detail.value)
  273. },
  274. sel3(index) {
  275. // console.log(index)
  276. this.arr3 = this.array3;
  277. for (var i = 0; i < this.floors; i++) {
  278. // this.array1.push(this.allData.data[i].school)
  279. // console.log(this.allData.data[i].school)
  280. if (typeof(index) == 'string') {
  281. this.index3 = index;
  282. } else if (this.allData.data[this.index1].builds[this.index2].floors[i].floor == index[0]) {
  283. this.index3 = i
  284. }
  285. if (!this.allData.data[this.index1].builds[this.index2].floors[i].rooms) {
  286. continue
  287. }
  288. if (i == this.index3) {
  289. this.rooms = this.allData.data[this.index1].builds[this.index2].floors[i].rooms.length
  290. this.array4 = []
  291. // console.log(this.rooms)
  292. for (var j = 0; j < this.rooms; j++) {
  293. this.array4.push(this.allData.data[this.index1].builds[this.index2].floors[i].rooms[j])
  294. }
  295. }
  296. if (typeof(index) == 'string') {
  297. this.arr4 = ['请选择房间']
  298. this.index4 = 0
  299. this.room = ''
  300. }
  301. }
  302. // this.room = this.room.concat(this.array3[this.index3]);
  303. this.add_class3 = 1;
  304. this.dis_num4 = 0;
  305. // console.log(this.room)
  306. },
  307. changeSelect4(e) {
  308. this.sel4(e.detail.value)
  309. },
  310. sel4(index) {
  311. // console.log(index)
  312. this.arr4 = this.array4;
  313. this.add_class4 = 1;
  314. if (this.room) {
  315. this.room = ''
  316. }
  317. for (var i = 0; i < this.rooms; i++) {
  318. if (typeof(index) == 'string')
  319. this.index4 = index;
  320. else if (this.allData.data[this.index1].builds[this.index2].floors[this.index3].rooms[i] == index[0]) {
  321. this.index4 = i
  322. }
  323. //将选择器中的值加到变量room中,传到下一个页面
  324. // this.room = this.room.concat(this.array1[this.index1], this.array2[this.index2], this.array3[this.index3],
  325. // this.array4[this.index4]);
  326. }
  327. this.room = this.room.concat(this.array1[this.index1], this.array4[this.index4]);
  328. // this.dis_num5 = 0;
  329. // console.log(this.array1[this.index1])
  330. // console.log(this.array2[this.index2])
  331. // console.log(this.array3[this.index3])
  332. // console.log(this.array4[this.index4])
  333. // console.log(this.room)
  334. },
  335. //跳转缴费页面
  336. navigateToIndex(e) {
  337. // console.log(e)
  338. var roomSelect = e.currentTarget.dataset.room;
  339. this.storage.roomSelect = roomSelect;
  340. this.storage.dom = this.array4[this.index4];
  341. if (this.room != '') {
  342. this.$store.state.building.roomSelect = this.storage.roomSelect;
  343. this.$store.state.building.add_class = 1;
  344. this.$store.state.building.dom = this.storage.dom;
  345. uni.navigateBack({
  346. delta: 1
  347. })
  348. } else {
  349. uni.showToast({
  350. icon: 'success',
  351. title: '宿舍号不完整'
  352. })
  353. }
  354. },
  355. }
  356. }
  357. </script>
  358. <style>
  359. @import url("select.css");
  360. </style>