index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. <template>
  2. <view class="list_body">
  3. <view class="box" v-if="showPicker"></view>
  4. <mx-date-picker
  5. :show="showPicker"
  6. :type="type"
  7. :value="timeValue"
  8. :show-tips="true"
  9. :begin-text="'开始'"
  10. :end-text="'截至'"
  11. :show-seconds="true"
  12. @confirm="onSelected"
  13. @cancel="onSelected"
  14. />
  15. <view class="head">
  16. <image src="../../static/4.png" mode="aspectFit"></image>
  17. <!-- <text>报修信息表<image src="../../static/pen.svg" mode=""></image></text> -->
  18. </view>
  19. <form @submit="formSubmit" @reset="formReset">
  20. <view class="content">
  21. <!-- 宿舍楼栋 -->
  22. <view class="headline-2">
  23. <text class="uni-list-cell-left-2">宿舍楼栋:</text>
  24. <view class="uni-list-cell">
  25. <picker
  26. class="uni-input-1"
  27. mode="multiSelector"
  28. :value="roomIndex"
  29. :range="room_List"
  30. @change="bindPickerChange_room"
  31. @columnchange="handleNum"
  32. >
  33. <view class="uni-input" v-if="dormNumber">
  34. {{ dormNumber }}
  35. </view>
  36. <image src="../../static/down.svg" class="uni-list-cell_image"></image>
  37. </picker>
  38. </view>
  39. </view>
  40. <!-- <hr> -->
  41. <!-- <view class="line"></view> -->
  42. <!-- 故障分类 -->
  43. <view class="headline-2">
  44. <text class="uni-list-cell-left">故障分类:</text>
  45. <picker @change="bindPickerChange($event, List)" :value="index" :range="List" :range-key="'faultName'">
  46. <view class="uni-list-cell-os">
  47. <view class="uni-list-cell-db">
  48. <template v-if="List != null" v-model="index">
  49. <view class="uni-input-1">
  50. {{ pickerData.faultName == undefined ? '' : pickerData.faultName }}
  51. <image src="../../static/down.svg" mode=""></image>
  52. </view>
  53. </template>
  54. </view>
  55. </view>
  56. </picker>
  57. </view>
  58. <!-- 预约时间 -->
  59. <view class="headline-2">
  60. <text class="uni-list-cell-left">预约时间:</text>
  61. <view style="line-height: 35px" @click="onShowDatePicker('datetime')" class="uni-list-cell-db-2">
  62. <text style="margin-left: 254rpx">{{ timeValue }}</text>
  63. <image src="../../static/down.svg" mode="" class="timeimg"></image>
  64. </view>
  65. </view>
  66. <view class="headline-2">
  67. <text class="uni-list-cell-left">联系电话:</text>
  68. <view class="uni-list-cell-db-2">
  69. <input type="number" maxlength="11" class="uni-input-2" v-model="formData.phone" />
  70. </view>
  71. </view>
  72. <!-- 故障原因 -->
  73. <view class="os-headline-2">
  74. <text class="os-list-cell-left-2">故障原因:</text>
  75. <view class="os-list-cell-db-2">
  76. <!-- <input class="os-input-2" type="text" maxlength=50 v-model="formData.os" /> -->
  77. <textarea
  78. @input="sumfrontnum"
  79. maxlength="50"
  80. class="os-input-2"
  81. placeholder="工单描述,50字以内"
  82. placeholder-style="font-size:24rpx"
  83. ></textarea>
  84. </view>
  85. <view>
  86. <text class="num">{{ fontnum }}/50</text>
  87. </view>
  88. </view>
  89. <!-- 照片 -->
  90. <view class="photo">
  91. <view class="photo-title">上传图片(最多上传3张):</view>
  92. <view class="upload-image-view">
  93. <uni-file-picker
  94. limit="3"
  95. :value="imageValue"
  96. fileMediatype="image"
  97. :image-styles="imageStyles"
  98. mode="grid"
  99. @select="select"
  100. @delete="handleDelete"
  101. ></uni-file-picker>
  102. </view>
  103. </view>
  104. <!-- 备注 -->
  105. <button type="default" class="up" @click="getList">立即提交</button>
  106. </view>
  107. </form>
  108. </view>
  109. </template>
  110. <script>
  111. import * as TranslateImage from '../../utils/imageZip.js'
  112. import '../../static/upload-imgs.css'
  113. import MxDatePicker from '@/components/mx-datepicker'
  114. export default {
  115. components: {
  116. MxDatePicker,
  117. },
  118. data() {
  119. return {
  120. imageStyles: {
  121. width: 75,
  122. height: 75,
  123. border: {
  124. color: '#ccc',
  125. width: 1,
  126. style: 'dashed',
  127. radius: '5px',
  128. },
  129. },
  130. imageList: [], //保存图片路径集合
  131. List: [],
  132. index: '',
  133. faultName: null,
  134. pickerData: '',
  135. buildId: 1,
  136. floorId: 1,
  137. roomId: 1,
  138. formData: {
  139. phone: '',
  140. inputphone: '',
  141. os: '',
  142. },
  143. showPicker: false,
  144. datetime: '',
  145. rangetime: '',
  146. type: 'rangetime',
  147. timeValue: '',
  148. imgs: null,
  149. imageValue: [],
  150. ceshiData1: [],
  151. Timer: null,
  152. room_List: [[], [], []],
  153. roomIndex: null,
  154. IdList: [],
  155. IdList2: [],
  156. count: 0,
  157. count2: 0,
  158. dormNumber: null,
  159. fontnum: 0,
  160. }
  161. },
  162. onLoad() {
  163. this.getStudentInformation()
  164. this.getTime()
  165. this.getfault()
  166. this.init()
  167. },
  168. methods: {
  169. async init() {
  170. await this.getbuild()
  171. await this.getbuildHigh()
  172. await this.getrooms()
  173. },
  174. // 获取学生数据
  175. getStudentInformation() {
  176. let res = uni.getStorageSync('student')
  177. // console.log(res)
  178. if (res) {
  179. this.formData.phone = res.studentPhone
  180. this.formData.inputphone = res.studentOtherPhone
  181. this.dormNumber = res.dormNumber
  182. }
  183. },
  184. //统计textarea字数
  185. sumfrontnum(e) {
  186. console.log(e)
  187. this.fontnum = e.detail.value.length
  188. },
  189. // 初始化时间
  190. getTime() {
  191. let date = new Date(),
  192. year = date.getFullYear(),
  193. month = date.getMonth() + 1,
  194. day = date.getDate(),
  195. hour = date.getHours() < 10 ? '0' + date.getHours() : date.getHours(),
  196. minute = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes(),
  197. second = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
  198. month >= 1 && month <= 9 ? (month = '0' + month) : ''
  199. day >= 0 && day <= 9 ? (day = '0' + day) : ''
  200. let timer = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second
  201. this.datetime = timer
  202. },
  203. // 获取故障类型信息
  204. async getfault() {
  205. let res = await this.$myRequest({
  206. method: 'post',
  207. url: `/fault/queryAllFaultByStatus`,
  208. })
  209. // console.log(res)
  210. this.$nextTick(() => {
  211. this.List = res.data
  212. })
  213. },
  214. // 获取宿舍楼栋数据
  215. async getbuild() {
  216. let res = await this.$myRequest({
  217. method: 'post',
  218. url: `/build/queryAllBuild`,
  219. })
  220. // console.log(res)
  221. let tempList = []
  222. res.data.forEach((item) => {
  223. tempList.push(item.buildName)
  224. console.log('bulidid' + item.buildId)
  225. })
  226. this.$nextTick(() => {
  227. this.$set(this.room_List, 0, tempList)
  228. })
  229. },
  230. // 获取宿舍楼层数据
  231. async getbuildHigh() {
  232. let res = await this.$myRequest({
  233. method: 'post',
  234. url: `/build/queryAllFloorByBuildID?buildId=${this.buildId}`,
  235. })
  236. // console.log(res)
  237. this.room_List[1] = []
  238. this.room_List[2] = []
  239. this.IdList = []
  240. let tempList = []
  241. res.data.forEach((item) => {
  242. tempList.push(item.floorName)
  243. this.IdList.push(item.floorId)
  244. console.log('floorid' + item.floorId)
  245. })
  246. this.$nextTick(() => {
  247. this.$set(this.room_List, 1, tempList)
  248. this.floorId = this.IdList[this.count]
  249. })
  250. },
  251. // 获取宿舍房间数据
  252. async getrooms() {
  253. let res = await this.$myRequest({
  254. method: 'post',
  255. url: `/build/queryAllRoomByFloorID?floorId=${this.floorId}`,
  256. })
  257. // console.log(res)
  258. this.room_List[2] = []
  259. this.IdList2 = []
  260. let tempList = []
  261. res.data.forEach((item) => {
  262. tempList.push(item.roomName)
  263. this.IdList2.push(item.roomId)
  264. console.log('roomid' + item.roomId)
  265. })
  266. this.$nextTick(() => {
  267. this.$set(this.room_List, 2, tempList)
  268. this.roomId = this.IdList2[this.count2]
  269. })
  270. },
  271. // 时间选择框
  272. onShowDatePicker(type) {
  273. this.type = type
  274. this.showPicker = true
  275. this.timeValue = this[type]
  276. },
  277. // 时间选择框点击回调
  278. onSelected(e) {
  279. this.showPicker = false
  280. if (e) {
  281. this[this.type] = e.value
  282. this.timeValue = e.value
  283. }
  284. },
  285. //故障选择
  286. bindPickerChange(e, storage) {
  287. this.index = e.target.value
  288. this.pickerData = storage[this.index] // 这里就是选中的对象
  289. },
  290. // 提交订单
  291. getList() {
  292. console.log('ppppp' + this.buildId + '-' + this.floorId + '-' + this.roomId)
  293. // 处理图片参数数据
  294. this.imgs = this.ceshiData1.join(';')
  295. // 电话验证规则
  296. let phoneVer = /^[1][3,4,5,7,8,9][0-9]{9}$/
  297. // 简单校验
  298. if (this.pickerData.faultId == null) {
  299. uni.showToast({
  300. icon: 'none',
  301. title: '请选择故障类型',
  302. duration: 2000,
  303. })
  304. return
  305. }
  306. if (this.dormNumber == null) {
  307. uni.showToast({
  308. icon: 'none',
  309. title: '请选择楼栋和宿舍号',
  310. duration: 2000,
  311. })
  312. return
  313. }
  314. if (!this.timeValue) {
  315. uni.showToast({
  316. icon: 'none',
  317. title: '请选择预期时间',
  318. duration: 2000,
  319. })
  320. return
  321. }
  322. if (!this.formData.phone) {
  323. uni.showToast({
  324. title: '请输入联系电话',
  325. icon: 'none',
  326. })
  327. return
  328. } else if (!phoneVer.test(this.formData.phone)) {
  329. uni.showToast({
  330. title: '请输入正确的联系电话',
  331. icon: 'none',
  332. })
  333. return
  334. }
  335. uni.showLoading({
  336. title: '提交中',
  337. })
  338. if (this.Timer != null) {
  339. clearTimeout(this.Timer)
  340. }
  341. this.Timer = setTimeout(async () => {
  342. let res = await this.$myRequest({
  343. method: 'post',
  344. url: `/order/insertOrder`,
  345. data: {
  346. faultId: String(this.pickerData.faultId),
  347. dormNumber: this.dormNumber,
  348. orderExpectedTime: this.timeValue,
  349. studentDormitory: this.buildId + '-' + this.floorId + '-' + this.roomId,
  350. orderImages: this.imgs,
  351. orderNote: this.formData.os,
  352. studentPhone: this.formData.phone,
  353. otherPhone: this.formData.inputphone,
  354. },
  355. })
  356. // console.log(res)
  357. if (res.status == 200) {
  358. uni.showToast({
  359. title: '提交成功',
  360. })
  361. uni.reLaunch({
  362. url: '/pages/home/home',
  363. })
  364. } else {
  365. uni.showToast({
  366. title: '提交失败',
  367. icon: 'error',
  368. })
  369. }
  370. }, 1500)
  371. },
  372. // 选择图片压缩并上传
  373. select(e) {
  374. // console.log('选择文件:', e)
  375. e.tempFiles.forEach((item) => {
  376. TranslateImage.translate(item.path, (res) => {
  377. if (Number(res.size) > 1000000) {
  378. this.imageValue = []
  379. uni.showModal({
  380. content: `图片过大,请重新上传`,
  381. showCancel: false,
  382. success() {},
  383. })
  384. return
  385. }
  386. uni.showLoading({
  387. title: '上传中',
  388. })
  389. uni.uploadFile({
  390. url: `/baoxiu/repairApi/order/uploadImage`,
  391. filePath: res.url,
  392. name: 'orderImages',
  393. success: (uploadFileRes) => {
  394. this.ceshiData1.push(JSON.parse(uploadFileRes.data).data)
  395. const path = item.path
  396. this.imageValue.push({
  397. url: path,
  398. name: '',
  399. })
  400. uni.hideLoading()
  401. },
  402. fail: () => {
  403. uni.hideLoading()
  404. },
  405. })
  406. })
  407. })
  408. },
  409. // 删除图片回调
  410. handleDelete(e) {
  411. const num = this.imageValue.findIndex((v) => v.path === e.tempFilePath)
  412. this.imageValue.splice(num, 1)
  413. this.ceshiData1.splice(num, 1)
  414. },
  415. // 三级联动下拉框回调
  416. bindPickerChange_room(e) {
  417. console.log('picker发送选择改变,携带值为', e.detail.value)
  418. this.roomIndex = e.detail.value
  419. this.dormNumber =
  420. this.room_List[0][this.roomIndex[0]] +
  421. this.room_List[1][this.roomIndex[1]] +
  422. this.room_List[2][this.roomIndex[2]]
  423. console.log('mmmmmm' + this.buildId + '-' + this.floorId + '-' + this.roomId)
  424. },
  425. // 三级联动下拉框拖动回调
  426. handleNum(e) {
  427. console.log('第' + (e.detail.column + 1) + '列' + '第' + (e.detail.value + 1) + '行')
  428. if (e.detail.column == 0) {
  429. console.log('楼栋发生变化,当前为' + (e.detail.value + 1) + '栋')
  430. // if (e.detail.value < 4) {
  431. this.buildId = e.detail.value + 1
  432. // } else {
  433. // this.buildId = e.detail.value + 5
  434. // }
  435. // console.log(this.buildId + '-' + this.floorId + '-' + this.roomId)
  436. } else if (e.detail.column == 1) {
  437. // console.log("层数发生变化,当前为"+(e.detail.value+1)+"层")
  438. this.floorId = this.IdList[e.detail.value]
  439. this.count = e.detail.value
  440. // console.log(this.buildId + '-' + this.floorId + '-' + this.roomId)
  441. } else {
  442. // console.log("房间数发生变化,当前为"+(e.detail.value+1)+"号")
  443. this.roomId = this.IdList2[e.detail.value]
  444. this.count2 = e.detail.value
  445. console.log('zuizong' + this.buildId + '-' + this.floorId + '-' + this.roomId)
  446. }
  447. },
  448. },
  449. // 监听属性
  450. watch: {
  451. buildId: {
  452. handler() {
  453. this.getbuildHigh()
  454. },
  455. },
  456. floorId: {
  457. handler() {
  458. this.getrooms()
  459. },
  460. },
  461. },
  462. }
  463. </script>
  464. <style lang="scss" scoped>
  465. .list_body {
  466. height: 100%;
  467. overflow: hidden;
  468. background-color: rgba(166, 166, 166, 0.18);
  469. }
  470. .box {
  471. position: fixed;
  472. top: 0;
  473. left: 0;
  474. width: 100%;
  475. height: 100%;
  476. background: rgba(0, 0, 0, 0.3);
  477. z-index: 99;
  478. }
  479. .test {
  480. text-align: center;
  481. padding: 20rpx 0;
  482. }
  483. button {
  484. margin: 20rpx;
  485. font-size: 28rpx;
  486. }
  487. .head {
  488. height: 550rpx;
  489. margin-top: -80rpx;
  490. }
  491. .head image {
  492. width: 100%;
  493. }
  494. .headline-1 {
  495. font-size: 24rpx;
  496. }
  497. .headline-2 {
  498. font-size: 24rpx;
  499. height: 80rpx;
  500. // margin-top: 0px;
  501. border-bottom: 2rpx solid rgba(166, 166, 166, 0.18);
  502. }
  503. .content {
  504. position: relative;
  505. // width: 720rpx;
  506. height: 1260rpx;
  507. margin-top: -152rpx;
  508. // margin-left: 14rpx;
  509. // border: 2rpx solid rgba(128, 128, 128, 0.45);
  510. background-color: rgba(255, 255, 255, 1);
  511. }
  512. .uni-list-cell {
  513. float: right;
  514. width: 78%;
  515. height: 70rpx;
  516. margin-top: 8rpx;
  517. // margin-right: 10rpx;
  518. // border: 2rpx solid gray;
  519. line-height: 44rpx;
  520. // border-radius: 16px;
  521. // background-color: rgba(166, 166, 166, 0.18);
  522. }
  523. .uni-list-cell-os {
  524. float: right;
  525. width: 78%;
  526. height: 70rpx;
  527. margin-top: 2rpx;
  528. // margin-right: 10rpx;
  529. // border: 2rpx solid gray;
  530. line-height: 44rpx;
  531. // border-radius: 16px;
  532. // background-color: rgba(166, 166, 166, 0.18);
  533. }
  534. // .uni-list-cell_image {
  535. // float: right;
  536. // margin-right: 15rpx;
  537. // margin-top: -42rpx;
  538. // width: 40rpx;
  539. // height: 40rpx;
  540. // font-size: 40rpx;
  541. // }
  542. .uni-input-1 {
  543. position: relative;
  544. margin-left: 254rpx;
  545. margin-top: 14rpx;
  546. height: 50rpx;
  547. }
  548. .uni-input-1 image {
  549. position: absolute;
  550. right: 10rpx;
  551. top: 5rpx;
  552. // float: right;
  553. // margin-right: 10rpx;
  554. // // margin-top: -10rpx;
  555. width: 40rpx;
  556. height: 40rpx;
  557. font-size: 40rpx;
  558. }
  559. .uni-list-cell-left {
  560. float: left;
  561. margin-top: 26rpx;
  562. margin-left: 30rpx;
  563. text {
  564. color: red;
  565. }
  566. }
  567. .uni-list-cell-left-2 {
  568. float: left;
  569. margin-left: 30rpx;
  570. margin-top: 26rpx;
  571. text {
  572. color: red;
  573. }
  574. }
  575. .uni-list-cell-db-2 {
  576. position: relative;
  577. float: right;
  578. // margin-right: 10rpx;
  579. margin-top: 6rpx;
  580. width: 78%;
  581. height: 70rpx;
  582. // border: 2rpx solid gray;
  583. // border-radius: 16px;
  584. // background-color: rgba(166, 166, 166, 0.18);
  585. }
  586. .uni-input-2 {
  587. margin-left: 334rpx;
  588. margin-top: 16rpx;
  589. font-size: 24rpx;
  590. }
  591. .uni-input-2 image {
  592. float: right;
  593. margin-right: 10rpx;
  594. width: 40rpx;
  595. height: 40rpx;
  596. font-size: 40rpx;
  597. }
  598. .timeimg {
  599. position: absolute;
  600. right: 9rpx;
  601. top: 16rpx;
  602. width: 40rpx;
  603. height: 40rpx;
  604. font-size: 40rpx;
  605. }
  606. .photo {
  607. height: 340rpx;
  608. font-size: 24rpx;
  609. }
  610. .photo-title {
  611. float: left;
  612. margin-left: 26rpx;
  613. margin-top: 30rpx;
  614. margin-bottom: 30rpx;
  615. }
  616. .upload-image-view {
  617. /* height: 300px; */
  618. }
  619. .image {
  620. float: left;
  621. margin-left: 26rpx;
  622. margin-top: 30rpx;
  623. height: 396rpx;
  624. width: 644rpx;
  625. box-sizing: border-box;
  626. border-radius: 28rpx;
  627. background-color: rgba(166, 166, 166, 0.18);
  628. }
  629. .imageText {
  630. text-align: center;
  631. border-radius: 28rpx;
  632. width: 100%;
  633. height: 100%;
  634. background-color: rgba(166, 166, 166, 0.18);
  635. }
  636. .imgSrc image {
  637. width: 646rPX;
  638. height: 386rpx;
  639. }
  640. .os-headline-2 {
  641. position: relative;
  642. float: left;
  643. }
  644. .os-list-cell-left-2 {
  645. float: left;
  646. margin-left: 26rpx;
  647. margin-top: 25rpx;
  648. font-size: 24rpx;
  649. }
  650. .os-input-2 {
  651. margin-left: 10rpx;
  652. margin-top: 12rpx;
  653. width: 97%;
  654. font-size: 28rpx;
  655. line-height: 100%;
  656. }
  657. .os-list-cell-db-2 {
  658. float: right;
  659. width: 720rpx;
  660. height: 200rpx;
  661. margin-left: -130rpx;
  662. margin-top: 64rpx;
  663. border-radius: 16rpx;
  664. // border: 2rpx solid gray;
  665. // background-color: rgba(166, 166, 166, 0.18);
  666. }
  667. .os-headline-2 .num {
  668. position: absolute;
  669. top: 210rpx;
  670. right: 20rpx;
  671. font-size: 24rpx;
  672. }
  673. .up {
  674. position: absolute;
  675. bottom: 200rpx;
  676. left: 18%;
  677. line-height: 72rpx;
  678. width: 60%;
  679. height: 36px;
  680. background-color: rgba(42, 130, 228, 1);
  681. color: white;
  682. font-size: 14px;
  683. border-radius: 14px;
  684. }
  685. .example-body {
  686. padding: 10px;
  687. padding-top: 0;
  688. }
  689. .custom-image-box {
  690. /* #ifndef APP-NVUE */
  691. display: flex;
  692. /* #endif */
  693. flex-direction: row;
  694. justify-content: space-between;
  695. align-items: center;
  696. }
  697. .text {
  698. font-size: 14px;
  699. color: #333;
  700. }
  701. .time {
  702. margin-top: 350rpx;
  703. font-size: 24rpx;
  704. margin-left: 26rpx;
  705. }
  706. .time-input {
  707. position: relative;
  708. margin-top: -44rpx;
  709. margin-left: 135rpx;
  710. /* margin-right: 137px; */
  711. width: 300rpx;
  712. border: 2rpx solid gray;
  713. }
  714. </style>