list.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  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. this.imageValue = []
  346. uni.showModal({
  347. content: `图片过大,请重新上传`,
  348. showCancel: false,
  349. success() {}
  350. })
  351. return
  352. }
  353. uni.showLoading({
  354. title: '上传中'
  355. });
  356. uni.uploadFile({
  357. url: `/baoxiu/repairApi/order/uploadImage`,
  358. filePath: res.url,
  359. name: 'orderImages',
  360. success: (uploadFileRes) => {
  361. this.ceshiData1.push((JSON.parse(uploadFileRes.data).data))
  362. const path = item.path;
  363. this.imageValue.push({
  364. url: path,
  365. name: ""
  366. })
  367. uni.hideLoading();
  368. },
  369. fail: () => {
  370. uni.hideLoading();
  371. }
  372. });
  373. }))
  374. })
  375. },
  376. // 删除图片回调
  377. handleDelete(e) {
  378. const num = this.imageValue.findIndex(v => v.path === e.tempFilePath);
  379. this.imageValue.splice(num, 1);
  380. this.ceshiData1.splice(num, 1);
  381. },
  382. // 三级联动下拉框回调
  383. bindPickerChange_room(e) {
  384. // console.log('picker发送选择改变,携带值为', e.detail.value)
  385. this.roomIndex = e.detail.value
  386. this.dormNumber = this.room_List[0][this.roomIndex[0]] + this.room_List[1][this.roomIndex[1]] + this
  387. .room_List[2][this.roomIndex[2]]
  388. // console.log(this.buildId + '-' + this.floorId + '-' + this.roomId)
  389. },
  390. // 三级联动下拉框拖动回调
  391. handleNum(e) {
  392. // console.log("第"+(e.detail.column+1)+"列"+"第"+(e.detail.value+1)+"行" )
  393. if (e.detail.column == 0) {
  394. // console.log("楼栋发生变化,当前为"+(e.detail.value+1)+"栋")
  395. if (e.detail.value < 4) {
  396. this.buildId = e.detail.value + 1
  397. } else {
  398. this.buildId = e.detail.value + 5
  399. }
  400. // console.log(this.buildId + '-' + this.floorId + '-' + this.roomId)
  401. } else if (e.detail.column == 1) {
  402. // console.log("层数发生变化,当前为"+(e.detail.value+1)+"层")
  403. this.floorId = this.IdList[e.detail.value]
  404. this.count = e.detail.value
  405. // console.log(this.buildId + '-' + this.floorId + '-' + this.roomId)
  406. } else {
  407. // console.log("房间数发生变化,当前为"+(e.detail.value+1)+"号")
  408. this.roomId = this.IdList2[e.detail.value]
  409. this.count2 = e.detail.value
  410. // console.log(this.buildId + '-' + this.floorId + '-' + this.roomId)
  411. }
  412. }
  413. },
  414. // 监听属性
  415. watch: {
  416. buildId: {
  417. handler() {
  418. this.getbuildHigh()
  419. },
  420. },
  421. floorId: {
  422. handler() {
  423. this.getrooms()
  424. },
  425. },
  426. },
  427. }
  428. </script>
  429. <style lang="scss">
  430. .list_body {
  431. width: 100%;
  432. overflow: hidden;
  433. }
  434. .box {
  435. position: fixed;
  436. top: 0;
  437. left: 0;
  438. width: 100%;
  439. height: 100%;
  440. background: rgba(0, 0, 0, 0.3);
  441. z-index: 99;
  442. }
  443. .test {
  444. text-align: center;
  445. padding: 20rpx 0;
  446. }
  447. button {
  448. margin: 20rpx;
  449. font-size: 28rpx;
  450. }
  451. .head {
  452. height: 262rpx;
  453. font-size: 30rpx;
  454. color: white;
  455. border-radius: 0rpx 0rpx 30rpx 30rpx;
  456. background-color: rgba(42, 130, 228, 1);
  457. }
  458. .head text {
  459. float: left;
  460. margin-left: 290rpx;
  461. margin-top: 24rpx;
  462. }
  463. .head image {
  464. height: 34rpx;
  465. width: 34rpx;
  466. font-size: 34rpx;
  467. vertical-align: bottom;
  468. }
  469. .headline-1 {
  470. font-size: 24rpx;
  471. }
  472. .headline-2 {
  473. font-size: 24rpx;
  474. }
  475. .content {
  476. position: relative;
  477. width: 720rpx;
  478. height: 1260rpx;
  479. margin-top: -162rpx;
  480. margin-left: 14rpx;
  481. border: 2rpx solid rgba(128, 128, 128, 0.45);
  482. background-color: rgba(255, 255, 255, 1);
  483. }
  484. .uni-list-cell {
  485. float: right;
  486. width: 484rpx;
  487. height: 70rpx;
  488. margin-top: 36rpx;
  489. margin-right: 64rpx;
  490. border-radius: 32rpx;
  491. line-height: 44rpx;
  492. background-color: rgba(166, 166, 166, 0.18);
  493. }
  494. .uni-list-cell_image {
  495. float: right;
  496. margin-right: 10rpx;
  497. margin-top: -40rpx;
  498. width: 40rpx;
  499. height: 40rpx;
  500. font-size: 40rpx;
  501. }
  502. .uni-input-1 {
  503. margin-left: 20rpx;
  504. margin-top: 10rpx;
  505. height: 50rpx;
  506. }
  507. .uni-input-1 image {
  508. float: right;
  509. margin-right: 10rpx;
  510. width: 40rpx;
  511. height: 40rpx;
  512. font-size: 40rpx;
  513. }
  514. .uni-list-cell-left {
  515. float: left;
  516. margin-top: 48rpx;
  517. margin-left: 26rpx;
  518. text {
  519. color: red;
  520. }
  521. }
  522. .uni-list-cell-left-2 {
  523. float: left;
  524. margin-left: 30rpx;
  525. margin-top: 76rpx;
  526. text {
  527. color: red;
  528. }
  529. }
  530. .uni-list-cell-db-2 {
  531. float: right;
  532. margin-right: 64rpx;
  533. margin-top: 36rpx;
  534. width: 484rpx;
  535. height: 70rpx;
  536. border-radius: 32rpx;
  537. background-color: rgba(166, 166, 166, 0.18);
  538. }
  539. .uni-input-2 {
  540. margin-left: 20rpx;
  541. margin-top: 16rpx;
  542. font-size: 24rpx;
  543. }
  544. .uni-input-2 image {
  545. float: right;
  546. margin-right: 10rpx;
  547. width: 40rpx;
  548. height: 40rpx;
  549. font-size: 40rpx;
  550. }
  551. .timeimg {
  552. position: absolute;
  553. right: 72rpx;
  554. top: 262rpx;
  555. width: 40rpx;
  556. height: 40rpx;
  557. font-size: 40rpx;
  558. }
  559. .photo {
  560. height: 340rpx;
  561. font-size: 24rpx;
  562. }
  563. .photo-title {
  564. float: left;
  565. margin-left: 26rpx;
  566. margin-top: 30rpx;
  567. }
  568. .upload-image-view {
  569. /* height: 300px; */
  570. }
  571. .image {
  572. float: left;
  573. margin-left: 26rpx;
  574. margin-top: 30rpx;
  575. height: 396rpx;
  576. width: 644rpx;
  577. box-sizing: border-box;
  578. border-radius: 28rpx;
  579. background-color: rgba(166, 166, 166, 0.18);
  580. }
  581. .imageText {
  582. text-align: center;
  583. border-radius: 28rpx;
  584. width: 100%;
  585. height: 100%;
  586. background-color: rgba(166, 166, 166, 0.18);
  587. }
  588. .imgSrc image {
  589. width: 646rPX;
  590. height: 386rpx;
  591. }
  592. .os-headline-2 {
  593. float: left;
  594. }
  595. .os-list-cell-left-2 {
  596. float: left;
  597. margin-left: 26rpx;
  598. margin-top: 236rpx;
  599. font-size: 24rpx;
  600. }
  601. .os-input-2 {
  602. margin-left: 10rpx;
  603. margin-top: 12rpx;
  604. font-size: 24rpx;
  605. line-height: 100%;
  606. }
  607. .os-list-cell-db-2 {
  608. float: right;
  609. width: 568rpx;
  610. height: 60rpx;
  611. margin-right: 30rpx;
  612. margin-top: 224rpx;
  613. border-radius: 28rpx;
  614. background-color: rgba(166, 166, 166, 0.18);
  615. }
  616. .up {
  617. position: absolute;
  618. bottom: 212rpx;
  619. left: 20rpx;
  620. line-height: 72rpx;
  621. width: 323px;
  622. height: 36px;
  623. background-color: rgba(42, 130, 228, 1);
  624. color: white;
  625. font-size: 12px;
  626. border-radius: 14px;
  627. }
  628. .example-body {
  629. padding: 10px;
  630. padding-top: 0;
  631. }
  632. .custom-image-box {
  633. /* #ifndef APP-NVUE */
  634. display: flex;
  635. /* #endif */
  636. flex-direction: row;
  637. justify-content: space-between;
  638. align-items: center;
  639. }
  640. .text {
  641. font-size: 14px;
  642. color: #333;
  643. }
  644. </style>