list.vue 16 KB

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