select.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <view class="container">
  3. <!-- 选择校区区域 -->
  4. <picker class="picker-item" @change="changeSelect" :range="array" :value="index">
  5. <view class="select-item">
  6. <view class="picker-item-logol">
  7. <image class="picker-item-logo-left" src="../../static/school.png"></image>
  8. </view>
  9. <view class="picker-item-label">校区</view>
  10. <view class="picker-item-content" :class="value!='请选择校区'?'color':''">{{value}}</view>
  11. <view class="picker-item-logor">
  12. <image class="picker-item-logo-right" src="../../static/right.png"></image>
  13. </view>
  14. </view>
  15. </picker>
  16. <!-- 选择楼栋区域 -->
  17. <picker class="picker-item" @click="handleBuild" @change="changeSelect_build" :range="array_build"
  18. range-key="buildName" :value="index_build" :disabled="disabled_build">
  19. <view class="select-item">
  20. <view class="picker-item-logol">
  21. <image class="picker-item-logo-left" src="../../static/building.png"></image>
  22. </view>
  23. <view class="picker-item-label">楼栋</view>
  24. <view class="picker-item-content" :class="value_build!='请选择楼栋'?'color':''">{{value_build}}</view>
  25. <view class="picker-item-logor">
  26. <image class="picker-item-logo-right" src="../../static/right.png"></image>
  27. </view>
  28. </view>
  29. </picker>
  30. <!-- 选择楼层区域 -->
  31. <picker class="picker-item" @click="handleFloor" @change="changeSelect_floor" :range="array_floor"
  32. range-key="floorName" :value="index_floor" :disabled="disabled_floor">
  33. <view class="select-item">
  34. <view class="picker-item-logol">
  35. <image class="picker-item-logo-left" src="../../static/floor.png"></image>
  36. </view>
  37. <view class="picker-item-label">楼层</view>
  38. <view class="picker-item-content" :class="value_floor!='请选择楼层'?'color':''">{{value_floor}}</view>
  39. <view class="picker-item-logor">
  40. <image class="picker-item-logo-right" src="../../static/right.png"></image>
  41. </view>
  42. </view>
  43. </picker>
  44. <!-- 选择房间区域 -->
  45. <picker class="picker-item" @click="handleRoom" @change="changeSelect_room" :range="array_room"
  46. range-key="roomName" :value="index_room" :disabled="disabled_room">
  47. <view class="select-item">
  48. <view class="picker-item-logol">
  49. <image class="picker-item-logo-left" src="../../static/room.png"></image>
  50. </view>
  51. <view class="picker-item-label">房间</view>
  52. <view class="picker-item-content" :class="value_room!='请选择房间'?'color':''">{{value_room}}</view>
  53. <view class="picker-item-logor">
  54. <image class="picker-item-logo-right" src="../../static/right.png"></image>
  55. </view>
  56. </view>
  57. </picker>
  58. <view class="submit-item">
  59. <button class="submit" type="primary" @click="handleSubmit">完成</button>
  60. </view>
  61. </view>
  62. </template>
  63. <script>
  64. export default {
  65. data() {
  66. return {
  67. // 校区筛选框绑定数组
  68. array: ["黄家湖"],
  69. // 校区筛选框数组绑定下标
  70. index: 0,
  71. // 校区筛选框选中数据
  72. value: "黄家湖",
  73. // 楼栋筛选框绑定数组
  74. array_build: ["1栋", "2栋"],
  75. // 楼栋筛选框数组绑定下标
  76. index_build: 0,
  77. // 楼栋筛选框选中数据
  78. value_build: "请选择楼栋",
  79. // 楼栋筛选框禁用
  80. disabled_build: false,
  81. // 楼层筛选框绑定数组
  82. array_floor: ["1层", "2层"],
  83. // 楼层筛选框数组绑定下标
  84. index_floor: 0,
  85. // 楼层筛选框选中数据
  86. value_floor: "请选择楼层",
  87. // 楼层筛选框禁用
  88. disabled_floor: true,
  89. // 房间筛选框绑定数组
  90. array_room: ["101", "102"],
  91. // 房间筛选框数组绑定下标
  92. index_room: 0,
  93. // 房间筛选框选中数据
  94. value_room: "请选择房间",
  95. // 房间筛选框禁用
  96. disabled_room: true,
  97. };
  98. },
  99. mounted() {
  100. // 判断是否存在card_number,不存在则重新授权
  101. this.getAuthorization();
  102. this.getBuild()
  103. },
  104. methods: {
  105. getAuthorization() {
  106. let card_number = localStorage.getItem("card_number");
  107. let studentName = localStorage.getItem("studentName");
  108. let openId = localStorage.getItem("openId");
  109. if (!card_number || !studentName || !openId) {
  110. uni.showModal({
  111. title: "提示",
  112. content: "请先领取校园卡或授权后再进行相关操作",
  113. showCancel: false,
  114. success: () => {
  115. uni.reLaunch({
  116. url: "/pages/index/index",
  117. });
  118. },
  119. });
  120. }
  121. },
  122. // 获取楼栋数据
  123. async getBuild() {
  124. let res = await this.$myRequest({
  125. url: "/room/queryAllBuild",
  126. })
  127. // console.log(res);
  128. if (res.success) {
  129. this.array_build = res.data
  130. }
  131. },
  132. // 点击楼栋区域回调
  133. handleBuild() {
  134. if (this.disabled_build) {
  135. uni.showToast({
  136. title: "请先选择校区",
  137. icon: 'none'
  138. })
  139. }
  140. },
  141. // 点击楼层区域回调
  142. handleFloor() {
  143. if (this.disabled_build) {
  144. uni.showToast({
  145. title: "请先选择校区",
  146. icon: 'none'
  147. })
  148. } else if (this.disabled_floor) {
  149. uni.showToast({
  150. title: "请先选择楼栋",
  151. icon: 'none'
  152. })
  153. }
  154. },
  155. // 点击房间区域回调
  156. handleRoom() {
  157. if (this.disabled_build) {
  158. uni.showToast({
  159. title: "请先选择校区",
  160. icon: 'none'
  161. })
  162. } else if (this.disabled_floor) {
  163. uni.showToast({
  164. title: "请先选择楼栋",
  165. icon: 'none'
  166. })
  167. } else if (this.disabled_room) {
  168. uni.showToast({
  169. title: "请先选择楼层",
  170. icon: 'none'
  171. })
  172. }
  173. },
  174. // 校区筛选框change回调
  175. changeSelect(e) {
  176. let index = e.detail.value
  177. this.value = this.array[index]
  178. },
  179. // 楼栋筛选框change回调
  180. async changeSelect_build(e) {
  181. let index = e.detail.value
  182. this.value_build = this.array_build[index].buildName
  183. this.disabled_floor = false
  184. let data = {
  185. buildId: this.array_build[index].buildId
  186. }
  187. let res = await this.$myRequest({
  188. url: "/room/queryAllFloor",
  189. data
  190. })
  191. // console.log(res);
  192. if (res.success) {
  193. this.array_floor = res.data
  194. }
  195. },
  196. // 楼层筛选框change回调
  197. async changeSelect_floor(e) {
  198. let index = e.detail.value
  199. this.value_floor = this.array_floor[index].floorName
  200. this.disabled_room = false
  201. let data = {
  202. floorId: this.array_floor[index].floorId
  203. }
  204. let res = await this.$myRequest({
  205. url: "/room/queryAllRoom",
  206. data
  207. })
  208. // console.log(res);
  209. if (res.success) {
  210. this.array_room = res.data
  211. }
  212. },
  213. // 房间筛选框change回调
  214. changeSelect_room(e) {
  215. let index = e.detail.value
  216. this.value_room = this.array_room[index].roomName
  217. },
  218. // 完成按钮点击回调
  219. handleSubmit() {
  220. if (this.value != "请选择校区" && this.value_build != "请选择楼栋" && this.value_floor != "请选择楼层" && this
  221. .value_room != "请选择房间") {
  222. let temRoom = this.value_build + this.value_floor + this.value_room
  223. localStorage.room = temRoom
  224. uni.reLaunch({
  225. url: "/pages/home/home"
  226. })
  227. } else {
  228. uni.showToast({
  229. title: "请选择完整地址",
  230. icon: 'none'
  231. })
  232. }
  233. }
  234. }
  235. }
  236. </script>
  237. <style lang="scss" scoped>
  238. .container {
  239. height: 100vh;
  240. background-image: url(../../static/bg.png);
  241. background-size: 100% 100%;
  242. .picker-item {
  243. padding: 19rpx 0 10rpx 0;
  244. .select-item {
  245. display: flex;
  246. background-color: #ffffff;
  247. height: 139rpx;
  248. .picker-item-logol {
  249. width: 88rpx;
  250. display: flex;
  251. justify-content: flex-end;
  252. .picker-item-logo-left {
  253. width: 58rpx;
  254. height: 58rpx;
  255. margin: 41rpx 0rpx 40rpx 0rpx;
  256. }
  257. }
  258. .picker-item-label {
  259. font-size: 30rpx;
  260. width: 99rpx;
  261. margin: 52rpx 0rpx 52rpx 0rpx;
  262. display: flex;
  263. justify-content: center;
  264. }
  265. .picker-item-content {
  266. display: flex;
  267. justify-content: flex-start;
  268. width: 360rpx;
  269. height: 26rpx;
  270. font-size: 32rpx;
  271. margin: 46rpx 0rpx 46rpx 120rpx;
  272. color: #999999;
  273. }
  274. .color {
  275. color: #000;
  276. }
  277. .picker-item-logor {
  278. width: 91rpx;
  279. display: flex;
  280. justify-content: center;
  281. margin: 57rpx 0rpx 51rpx 0rpx;
  282. .picker-item-logo-right {
  283. width: 20rpx;
  284. height: 31rpx;
  285. }
  286. }
  287. }
  288. }
  289. .submit-item {
  290. margin: 112rpx 30rpx;
  291. width: 690rpx;
  292. height: 96rpx;
  293. .submit {
  294. border-radius: 47.5rpx;
  295. }
  296. }
  297. }
  298. </style>