index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <view class="bodyContent">
  3. <form bindsubmit="handleSubmit">
  4. <view class="uni-list">
  5. <view class="uni-list-cell">
  6. <view class="uni-list-cell-left">
  7. <text>*</text>
  8. 姓名
  9. </view>
  10. <view class="uni-list-cell-db">
  11. <u--input class="uni-input" v-model="name" placeholder="请输入姓名"></u--input>
  12. </view>
  13. </view>
  14. </view>
  15. <view class="uni-list">
  16. <view class="uni-list-cell">
  17. <view class="uni-list-cell-left">
  18. <text>*</text>
  19. 性别
  20. </view>
  21. <view class="uni-list-cell-db">
  22. <view class="radio">
  23. <radio-group @change="radioChange">
  24. <label style="margin-right: 30px">
  25. <radio value="0" :checked="men" />
  26. </label>
  27. <label>
  28. <radio value="1" :checked="women" />
  29. </label>
  30. </radio-group>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. <view class="uni-list">
  36. <view class="uni-list-cell">
  37. <view class="uni-list-cell-left">
  38. <text>*</text>
  39. 班级
  40. </view>
  41. <view class="uni-list-cell-db">
  42. <u--input class="uni-input" v-model="studentClazz" placeholder="请输入班级"></u--input>
  43. </view>
  44. </view>
  45. </view>
  46. <view class="uni-list">
  47. <view class="uni-list-cell">
  48. <view class="uni-list-cell-left">
  49. <text>*</text>
  50. 手机号
  51. </view>
  52. <view class="uni-list-cell-db">
  53. <u--input class="uni-input" maxlength="11" v-model="studentPhone" placeholder="请输入手机号"></u--input>
  54. </view>
  55. </view>
  56. </view>
  57. <view class="uni-list">
  58. <view class="uni-list-cell">
  59. <view class="uni-list-cell-left">
  60. <text>*</text>
  61. 备选手机号
  62. </view>
  63. <view class="uni-list-cell-db">
  64. <u--input
  65. class="uni-input"
  66. maxlength="11"
  67. v-model="studentOtherPhone"
  68. placeholder="请输入备选手机号"
  69. ></u--input>
  70. </view>
  71. </view>
  72. </view>
  73. <view class="uni-list">
  74. <view class="cuni-list-cell">
  75. <view class="uni-list-cell-left">
  76. <text>*</text>
  77. 学生宿舍
  78. </view>
  79. <view class="uni-list-cell-db">
  80. <picker
  81. class="uni-input-1"
  82. mode="multiSelector"
  83. :value="roomIndex"
  84. :range="room_List"
  85. @change="bindPickerChange_room"
  86. @columnchange="handleNum"
  87. >
  88. <view class="uni-input2" v-if="dormNumber">
  89. {{ dormNumber }}
  90. </view>
  91. <view class="uni-input2" style="color: #c0c4cc" v-else>请选择学生宿舍</view>
  92. </picker>
  93. </view>
  94. </view>
  95. </view>
  96. <view class="uni-list">
  97. <view class="uni-list-cell">
  98. <view class="uni-list-cell-left">
  99. <text>*</text>
  100. 学生校区
  101. </view>
  102. <view class="uni-list-cell-db">
  103. <picker @change="bindPickerChange" :value="studentCampus" :range="array">
  104. <view class="uni-input2" v-if="studentCampus !== null">{{ array[studentCampus] }}</view>
  105. <view class="uni-input2" style="color: #c0c4cc" v-else>请选择学生校区</view>
  106. </picker>
  107. </view>
  108. </view>
  109. </view>
  110. <button
  111. @click="modifyInformation"
  112. form-type="submit"
  113. style="color: white; background-color: rgba(42, 130, 228, 1)"
  114. >
  115. 确认
  116. </button>
  117. </form>
  118. </view>
  119. </template>
  120. <script>
  121. export default {
  122. data() {
  123. return {
  124. name: '', //姓名
  125. studentSex: 0, //性别
  126. studentClazz: '', //班级
  127. studentPhone: '', //手机号
  128. studentOtherPhone: '', //备用手机号
  129. dormNumber: null, //学生宿舍
  130. studentCampus: null, //学生校区
  131. studentDormitory: '',
  132. array: ['黄家湖校区', '墨轩湖校区'],
  133. men: true,
  134. women: false,
  135. room_List: [[], [], []],
  136. roomIndex: null,
  137. buildId: 1,
  138. floorId: 1,
  139. roomId: 1,
  140. IdList: [],
  141. IdList2: [],
  142. count: 0,
  143. count2: 0,
  144. }
  145. },
  146. onLoad() {
  147. this.getStudentInformation()
  148. // this.getbuild()
  149. // this.getbuildHigh()
  150. // this.getrooms()
  151. this.init()
  152. },
  153. methods: {
  154. async init() {
  155. await this.getbuild()
  156. await this.getbuildHigh()
  157. await this.getrooms()
  158. },
  159. // 获取学生数据
  160. getStudentInformation() {
  161. let res = uni.getStorageSync('student')
  162. // console.log('这是获取key中的内容', res)
  163. if (res) {
  164. this.name = res.studentName
  165. this.studentSex = res.studentSex
  166. if (this.studentSex == 0) {
  167. this.men = true
  168. this.women = false
  169. } else {
  170. this.men = false
  171. this.women = true
  172. }
  173. this.studentCampus = res.studentCampus
  174. this.studentPhone = res.studentPhone
  175. this.studentOtherPhone = res.studentOtherPhone
  176. this.studentDormitory = res.studentDormitory
  177. this.dormNumber = res.dormNumber
  178. this.studentClazz = res.studentClazz
  179. }
  180. },
  181. // 获取宿舍楼栋数据
  182. async getbuild() {
  183. let res = await this.$myRequest({
  184. method: 'post',
  185. url: `/build/queryAllBuild`,
  186. })
  187. // console.log(res)
  188. let tempList = []
  189. res.data.forEach((item) => {
  190. tempList.push(item.buildName)
  191. })
  192. this.$nextTick(() => {
  193. this.$set(this.room_List, 0, tempList)
  194. })
  195. },
  196. // 获取宿舍楼层数据
  197. async getbuildHigh() {
  198. let res = await this.$myRequest({
  199. method: 'post',
  200. url: `/build/queryAllFloorByBuildID?buildId=${this.buildId}`,
  201. })
  202. // console.log(res)
  203. this.room_List[1] = []
  204. this.room_List[2] = []
  205. this.IdList = []
  206. let tempList = []
  207. res.data.forEach((item) => {
  208. tempList.push(item.floorName)
  209. this.IdList.push(item.floorId)
  210. })
  211. this.$nextTick(() => {
  212. this.$set(this.room_List, 1, tempList)
  213. this.floorId = this.IdList[this.count]
  214. })
  215. },
  216. // 获取宿舍房间数据
  217. async getrooms() {
  218. let res = await this.$myRequest({
  219. method: 'post',
  220. url: `/build/queryAllRoomByFloorID?floorId=${this.floorId}`,
  221. })
  222. // console.log(res)
  223. this.room_List[2] = []
  224. this.IdList2 = []
  225. let tempList2 = []
  226. res.data.forEach((item) => {
  227. tempList2.push(item.roomName)
  228. this.IdList2.push(item.roomId)
  229. })
  230. this.$nextTick(() => {
  231. this.$set(this.room_List, 2, tempList2)
  232. this.roomId = this.IdList2[this.count2]
  233. })
  234. },
  235. // 编辑信息
  236. async modifyInformation() {
  237. let phoneVer = /^[1][3,4,5,7,8,9][0-9]{9}$/ //验证规则
  238. if (!this.name || !this.studentPhone || !this.studentOtherPhone) {
  239. uni.showToast({
  240. title: '请输入具体信息',
  241. icon: 'none',
  242. })
  243. } else if (!phoneVer.test(this.studentPhone) || !phoneVer.test(this.studentOtherPhone)) {
  244. uni.showToast({
  245. title: '请输入正确的联系电话',
  246. icon: 'none',
  247. })
  248. } else {
  249. let res = await this.$myRequest({
  250. method: 'post',
  251. url: `/student/updateStudent?studentOtherPhone=${this.studentOtherPhone}&studentName=${this.name}&studentDormitory=${this.studentDormitory}&studentSex=${this.studentSex}&studentPhone=${this.studentPhone}&studentCampus=${this.studentCampus}&dormNumber=${this.dormNumber}&studentClazz=${this.studentClazz}`,
  252. })
  253. // console.log(res)
  254. if (res.status == 200) {
  255. uni.showToast({
  256. title: '编辑成功',
  257. icon: 'success',
  258. })
  259. uni.setStorageSync('updataMsg', true)
  260. uni.setStorageSync('student', res.data)
  261. setTimeout(() => {
  262. uni.redirectTo({
  263. url: '../home/home',
  264. })
  265. }, 1000)
  266. } else {
  267. uni.showToast({
  268. title: '编辑失败',
  269. icon: 'error',
  270. })
  271. }
  272. }
  273. },
  274. // 学生校区选择框
  275. bindPickerChange(e) {
  276. // console.log(e)
  277. this.studentCampus = e.detail.value
  278. },
  279. // 性别选择框
  280. radioChange(e) {
  281. // console.log(e.detail.value)
  282. this.studentSex = e.detail.value
  283. },
  284. // 三级联动下拉框回调
  285. bindPickerChange_room(e) {
  286. // console.log('picker发送选择改变,携带值为', e.detail.value)
  287. this.roomIndex = e.detail.value
  288. this.dormNumber =
  289. this.room_List[0][this.roomIndex[0]] +
  290. this.room_List[1][this.roomIndex[1]] +
  291. this.room_List[2][this.roomIndex[2]]
  292. // console.log(this.buildId + '-' + this.floorId + '-' + this.roomId)
  293. },
  294. // 三级联动下拉框拖动回调
  295. handleNum(e) {
  296. // console.log("第"+(e.detail.column+1)+"列"+"第"+(e.detail.value+1)+"行" )
  297. if (e.detail.column == 0) {
  298. // console.log("楼栋发生变化,当前为"+(e.detail.value+1)+"栋")
  299. if (e.detail.value < 4) {
  300. this.buildId = e.detail.value + 1
  301. } else {
  302. this.buildId = e.detail.value + 5
  303. }
  304. } else if (e.detail.column == 1) {
  305. // console.log("层数发生变化,当前为"+(e.detail.value+1)+"层")
  306. this.floorId = this.IdList[e.detail.value]
  307. this.count = e.detail.value
  308. } else {
  309. // console.log("房间数发生变化,当前为"+(e.detail.value+1)+"号")
  310. this.roomId = this.IdList2[e.detail.value]
  311. this.count2 = e.detail.value
  312. }
  313. // console.log(this.buildId + '-' + this.floorId + '-' + this.roomId)
  314. },
  315. },
  316. // 监听属性
  317. watch: {
  318. buildId: {
  319. handler() {
  320. this.getbuildHigh()
  321. },
  322. immediate: true,
  323. },
  324. floorId: {
  325. handler() {
  326. this.getrooms()
  327. },
  328. immediate: true,
  329. },
  330. },
  331. }
  332. </script>
  333. <style>
  334. .bodyContent {
  335. position: fixed;
  336. width: 100%;
  337. }
  338. .uni-list-cell-left {
  339. float: left;
  340. width: 22%;
  341. height: 94rpx;
  342. text-align: center;
  343. font-size: 28rpx;
  344. border-bottom: 1px solid rgba(200, 200, 205, 1);
  345. line-height: 94rpx;
  346. }
  347. .uni-list-cell-left text {
  348. color: red;
  349. }
  350. .uni-list-cell-db {
  351. float: right;
  352. width: 78%;
  353. height: 94rpx;
  354. border-bottom: 1px solid rgba(200, 200, 205, 1);
  355. }
  356. /* .uni-list-cell-db .name {
  357. float: right;
  358. } */
  359. .uni-list {
  360. position: relative;
  361. font-size: 28rpx;
  362. }
  363. .uni-list-cell-db input {
  364. height: 94rpx;
  365. width: 78%;
  366. float: right;
  367. text-align: center;
  368. line-height: 94rpx;
  369. font-size: 28rpx;
  370. border: none;
  371. }
  372. .uni-list-cell-db .u-border {
  373. border: none;
  374. float: right;
  375. margin-top: 16rpx;
  376. width: 196rpx;
  377. }
  378. .uni-list-cell-db .uni-input {
  379. float: right;
  380. margin-right: 44rpx;
  381. width: 240rpx;
  382. line-height: 94rpx;
  383. }
  384. .uni-list-cell-db .uni-input2 {
  385. float: right;
  386. margin-right: 64rpx;
  387. width: 240rpx;
  388. height: 96rpx;
  389. line-height: 94rpx;
  390. font-size: 30rpx;
  391. }
  392. .uni-list-cell-db uni-image {
  393. position: absolute;
  394. width: 52rpx;
  395. height: 52rpx;
  396. right: 6rpx;
  397. top: 22rpx;
  398. }
  399. button {
  400. position: absolute;
  401. top: 690rpx;
  402. left: 48rpx;
  403. width: 656rpx;
  404. height: 94rpx;
  405. color: white;
  406. }
  407. .radio {
  408. float: right;
  409. margin: 24rpx 72rpx 0 0;
  410. /* color: #C0C4CC; */
  411. }
  412. .uni-input-1 {
  413. height: 50rpx;
  414. }
  415. </style>