select.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <template>
  2. <view class="container">
  3. <picker class="picker-item1" @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/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_num2: 1, //选择器disable属性,是否禁用
  83. dis_num3: 1,
  84. dis_num4: 1,
  85. // dis_num5: 1,
  86. allData: [], //所有数据
  87. storage: {} //存放选择数据
  88. }
  89. },
  90. onLoad(options) {
  91. // console.log(options)
  92. // 拆分楼栋和宿舍号
  93. var str = options.roomSelect;
  94. var arr = new Array();
  95. var i = 0;
  96. while (i < str.length) {
  97. var tmp = str.charCodeAt(i)
  98. var s = "";
  99. while (str.charCodeAt(i) < 256) {
  100. s = s + str.charAt(i);
  101. i++;
  102. }
  103. arr.push(s);
  104. s = "";
  105. while (str.charCodeAt(i) > 256) {
  106. s = s + str.charAt(i);
  107. i++;
  108. }
  109. arr.push(s);
  110. }
  111. // for (i = 0; i < arr.length; i++) {
  112. // console.log(arr[i], i);
  113. // }
  114. this.requestAllData()
  115. // this.nschool = this.allData.data.length
  116. // 自动填充
  117. if (arr.length > 0) {
  118. if (arr[1] != null && arr[1].length > 0) {
  119. this.arr1 = [arr[1]]
  120. }
  121. let len = arr[2].length
  122. if (arr[2] != null && len > 0) {
  123. this.arr2 = [arr[2].substring(0, len - 3) + '栋']
  124. this.arr3 = [arr[2].substring(len - 3, len - 2) + '层']
  125. this.arr4 = [arr[2]]
  126. }
  127. this.sel1(this.arr1)
  128. this.sel2(this.arr2)
  129. this.sel3(this.arr3)
  130. this.sel4(this.arr4)
  131. this.add_class1 = 1
  132. this.add_class2 = 1
  133. this.add_class3 = 1
  134. this.add_class4 = 1
  135. this.dis_num2 = 0
  136. this.dis_num3 = 0
  137. this.dis_num4 = 0
  138. }
  139. },
  140. methods: {
  141. async requestAllData() {
  142. const res = await this.$myRequest({
  143. host: 'code',
  144. url: '',
  145. // method: 'POST',
  146. header: {
  147. 'content-type': 'application/json'
  148. },
  149. data: {
  150. // 'access_token': this.access_token
  151. }
  152. })
  153. console.log(res)
  154. // this.allData = res.data.data
  155. },
  156. changeSelect1(e) {
  157. this.sel1(e.detail.value)
  158. },
  159. // 根据参数的值选中
  160. sel1(index) {
  161. // console.log(index)
  162. this.arr1 = this.array1;
  163. //获取选择器1的值
  164. for (var i = 0; i < this.nschool; i++) {
  165. // this.array1.push(this.allData.data[i].school)
  166. // console.log(this.allData.data[i].school)
  167. if (typeof(index) == 'string') {
  168. this.index1 = index;
  169. } else if (this.allData.data[i].school == index[0]) {
  170. this.index1 = i
  171. }
  172. //判断是否为空,不为空则继续
  173. if (!this.allData.data[i].builds) {
  174. continue
  175. }
  176. //获取选择器二中的值
  177. if (i == this.index1) {
  178. //得到选择器二中值的个数
  179. this.nbuilds = this.allData.data[i].builds.length
  180. this.array2 = []
  181. //将数据加入选择器二中
  182. for (var j = 0; j < this.nbuilds; j++) {
  183. this.array2.push(this.allData.data[i].builds[j].building)
  184. }
  185. }
  186. if (typeof(index) == 'string') {
  187. this.arr2 = ['请选择楼栋']
  188. this.arr3 = ['请选择楼层']
  189. this.arr4 = ['请选择房间']
  190. this.index2 = 0
  191. this.index3 = 0
  192. this.index4 = 0
  193. this.room = ''
  194. }
  195. }
  196. // this.room = this.room.concat(this.array1[this.index1]);
  197. this.add_class1 = 1;
  198. this.dis_num2 = 0;
  199. // console.log(this.array2)
  200. // console.log(this.room)
  201. },
  202. changeSelect2(e) {
  203. this.sel2(e.detail.value)
  204. },
  205. sel2(index) {
  206. // console.log(index);
  207. this.arr2 = this.array2;
  208. for (var i = 0; i < this.nbuilds; i++) {
  209. // this.array1.push(this.allData.data[i].school)
  210. // console.log(this.allData.data[i].school)
  211. if (typeof(index) == 'string') {
  212. this.index2 = index;
  213. } else if (this.allData.data[this.index1].builds[i].building == index[0]) {
  214. this.index2 = i
  215. }
  216. if (!this.allData.data[this.index1].builds[i].floors) {
  217. continue
  218. }
  219. if (i == this.index2) {
  220. this.floors = this.allData.data[this.index1].builds[i].floors.length
  221. this.array3 = []
  222. // console.log(this.floors)
  223. for (var j = 0; j < this.floors; j++) {
  224. this.array3.push(this.allData.data[this.index1].builds[i].floors[j].floor)
  225. }
  226. }
  227. if (typeof(index) == 'string') {
  228. this.arr3 = ['请选择楼层']
  229. this.arr4 = ['请选择房间']
  230. this.index3 = 0
  231. this.index4 = 0
  232. this.room = ''
  233. }
  234. }
  235. // this.room = this.room.concat(this.array2[this.index2]);
  236. this.add_class2 = 1;
  237. this.dis_num3 = 0;
  238. // console.log(this.room)
  239. },
  240. changeSelect3(e) {
  241. this.sel3(e.detail.value)
  242. },
  243. sel3(index) {
  244. this.arr3 = this.array3;
  245. for (var i = 0; i < this.floors; i++) {
  246. // this.array1.push(this.allData.data[i].school)
  247. // console.log(this.allData.data[i].school)
  248. if (typeof(index) == 'string') {
  249. this.index3 = index;
  250. } else if (this.allData.data[this.index1].builds[this.index2].floors[i].floor == index[0]) {
  251. this.index3 = i
  252. }
  253. if (!this.allData.data[this.index1].builds[this.index2].floors[i].rooms) {
  254. continue
  255. }
  256. if (i == this.index3) {
  257. this.rooms = this.allData.data[this.index1].builds[this.index2].floors[i].rooms.length
  258. this.array4 = []
  259. // console.log(this.rooms)
  260. for (var j = 0; j < this.rooms; j++) {
  261. this.array4.push(this.allData.data[this.index1].builds[this.index2].floors[i].rooms[j])
  262. }
  263. }
  264. if (typeof(index) == 'string') {
  265. this.arr4 = ['请选择房间']
  266. this.index4 = 0
  267. this.room = ''
  268. }
  269. }
  270. // this.room = this.room.concat(this.array3[this.index3]);
  271. this.add_class3 = 1;
  272. this.dis_num4 = 0;
  273. // console.log(this.room)
  274. },
  275. changeSelect4(e) {
  276. this.sel4(e.detail.value)
  277. },
  278. sel4(index) {
  279. // console.log(index)
  280. this.arr4 = this.array4;
  281. this.add_class4 = 1;
  282. if (this.room) {
  283. this.room = ''
  284. }
  285. for (var i = 0; i < this.rooms; i++) {
  286. if (typeof(index) == 'string')
  287. this.index4 = index;
  288. else if (this.allData.data[this.index1].builds[this.index2].floors[this.index3].rooms[i] == index[0]) {
  289. this.index4 = i
  290. }
  291. //将选择器中的值加到变量room中,传到下一个页面
  292. // this.room = this.room.concat(this.array1[this.index1], this.array2[this.index2], this.array3[this.index3],
  293. // this.array4[this.index4]);
  294. }
  295. this.room = this.room.concat(this.array1[this.index1], this.array4[this.index4]);
  296. // this.dis_num5 = 0;
  297. // console.log(this.array1[this.index1])
  298. // console.log(this.array2[this.index2])
  299. // console.log(this.array3[this.index3])
  300. // console.log(this.array4[this.index4])
  301. // console.log(this.room)
  302. },
  303. //跳转页面
  304. navigateToIndex(e) {
  305. // console.log(e)
  306. var roomSelect = e.currentTarget.dataset.room;
  307. this.storage.roomSelect = roomSelect;
  308. this.storage.dom = this.array4[this.index4];
  309. // console.log(roomSelect)
  310. if (this.room != '') {
  311. uni.redirectTo({
  312. url: '../jiaofei/jiaofei?o=select&item=' + encodeURIComponent(JSON.stringify(this.storage)),
  313. })
  314. } else {
  315. uni.showToast({
  316. icon:'success',
  317. title:'请选择'
  318. })
  319. }
  320. },
  321. }
  322. }
  323. </script>
  324. <style>
  325. @import url("select.css");
  326. </style>