repairs.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  1. <template>
  2. <view class="container">
  3. <!-- 公告区域 -->
  4. <view class="notice">
  5. <uni-notice-bar show-icon single speed="50" :scrollable="true" background-color="#fff" color="#000" :text="repairsNotice" />
  6. </view>
  7. <view class="gap"></view>
  8. <!-- 报修区域 -->
  9. <view class="box_item">
  10. <view class="item_title">
  11. 报修区域
  12. <text>*</text>
  13. </view>
  14. <view class="item_info" :class="{ item_color: repairsArea }" @click="handleSelectArea">
  15. {{ repairsArea ? repairsArea : '请选择报修区域' }}
  16. </view>
  17. <view class="item_icon" @click="handleSelectArea">
  18. <img src="../../static/images/repairsImg/right.png" />
  19. </view>
  20. </view>
  21. <!-- 详细地址区域 -->
  22. <view class="box_item">
  23. <view class="item_title">
  24. 详细地址
  25. <text>*</text>
  26. </view>
  27. <view class="item_info">
  28. <view class="item_input">
  29. <input placeholder-style="color:#CCCCCC" type="text" placeholder="请输入详细地址" v-model="repairsAddress" />
  30. </view>
  31. </view>
  32. </view>
  33. <!-- 报修物品区域 -->
  34. <view class="box_item">
  35. <view class="item_title">
  36. 报修物品
  37. <text>*</text>
  38. </view>
  39. <view class="item_info" :class="{ item_color: repairsGoods }" @click="handleSelectGoods">
  40. {{ repairsGoods ? repairsGoods : '请选择报修物品' }}
  41. </view>
  42. <view class="item_icon" @click="handleSelectGoods">
  43. <img src="../../static/images/repairsImg/right.png" />
  44. </view>
  45. </view>
  46. <!-- 故障描述 -->
  47. <view class="box_item2">
  48. <view class="item2_title">故障描述</view>
  49. <view class="item2_info">
  50. <view class="item2_textarea">
  51. <textarea placeholder-style="color:#CCCCCC" placeholder="请输入故障描述" v-model="repairsDescription"></textarea>
  52. </view>
  53. </view>
  54. </view>
  55. <!-- 报修录音区域 -->
  56. <view class="box_item">
  57. <view class="item_title">报修录音</view>
  58. <view class="item_info" v-if="!recordingPath">
  59. <view class="info_icon" @click="handleRecording">
  60. <img src="../../static/images/repairsImg/voice.png" />
  61. </view>
  62. <view class="info_tips" @click="handleRecording">点击录音</view>
  63. </view>
  64. <view class="item_recording" v-else @click="handlePlayRecording">
  65. <img :src="recordingImg" />
  66. {{ recordingTime }}″
  67. </view>
  68. <view class="recording_icon" v-if="recordingPath" @click="handleDeleteRecording">×</view>
  69. </view>
  70. <!-- 录音弹窗区域 -->
  71. <uni-popup :safe-area="true" background-color="#fff" ref="popup_recording">
  72. <view class="popup_recording">
  73. <recording @getTempFilePath="getTempFilePath" />
  74. </view>
  75. </uni-popup>
  76. <!-- 上传照片区域 -->
  77. <view class="box_item3">
  78. <view class="item3_title">
  79. 上传照片
  80. <span>*</span>
  81. <text>(可上传三张,请上传局部图和区域图)</text>
  82. </view>
  83. <uni-file-picker
  84. ref="filePicker"
  85. limit="3"
  86. v-model="imgList"
  87. fileMediatype="image"
  88. :image-styles="imageStyles"
  89. mode="grid"
  90. @select="select"
  91. @delete="handleDelete"
  92. ></uni-file-picker>
  93. </view>
  94. <!-- 报修姓名区域 -->
  95. <view class="box_item">
  96. <view class="item_title">
  97. 报修姓名
  98. <text>*</text>
  99. </view>
  100. <view class="item_info">
  101. <view class="item_input">
  102. <input placeholder-style="color:#CCCCCC" type="text" placeholder="请输入报修姓名" v-model="repairsName" />
  103. </view>
  104. </view>
  105. </view>
  106. <!-- 联系电话区域 -->
  107. <view class="box_item">
  108. <view class="item_title">
  109. 联系电话
  110. <text>*</text>
  111. </view>
  112. <view class="item_info">
  113. <view class="item_input">
  114. <input placeholder-style="color:#CCCCCC" type="number" placeholder="请输入联系电话" maxlength="11" v-model="repairsPhone" />
  115. </view>
  116. </view>
  117. </view>
  118. <!-- 底部区域 -->
  119. <view class="foot">
  120. <view class="foot_btn" @click="handleAffirmSub">确认提交</view>
  121. <view class="foot_phone" @click="handleCallPhone(urgencyPhone)">紧急电话 {{ urgencyPhone }}</view>
  122. <view class="foot_phone" @click="handleCallPhone(searchPhone)">服务监督电话 {{ searchPhone }}</view>
  123. </view>
  124. <!-- 消息通知按钮区域 -->
  125. <view class="fixed" @tap="handleClickFixed">
  126. <view class="fixed_box">
  127. <img src="../../static/images/repairsImg/message.png" />
  128. 消息通知
  129. </view>
  130. </view>
  131. <!-- 用于图片压缩的canvas画布 -->
  132. <canvas
  133. :style="{
  134. width: cw + 'px',
  135. height: cw + 'px',
  136. position: 'absolute',
  137. zIndex: -1,
  138. left: '-10000rpx',
  139. top: '-10000rpx'
  140. }"
  141. canvas-id="zipCanvas"
  142. ></canvas>
  143. <!--画布结束-->
  144. </view>
  145. </template>
  146. <script>
  147. import recording from '../components/recording.vue'
  148. // 图片压缩方法
  149. import getLessLimitSizeImage from '../util/imageCompress.js'
  150. const innerAudioContext = uni.createInnerAudioContext()
  151. export default {
  152. components: {
  153. recording
  154. },
  155. data() {
  156. return {
  157. // 报修公告
  158. repairsNotice: '',
  159. // 报修区域
  160. repairsArea: '',
  161. // 报修地址
  162. repairsAddress: '',
  163. // 报修物品
  164. repairsGoods: '',
  165. // 报修物品ID
  166. articleId: '',
  167. // 故障描述
  168. repairsDescription: '',
  169. // 报修姓名
  170. repairsName: '',
  171. // 联系电话
  172. repairsPhone: '',
  173. // 紧急电话
  174. urgencyPhone: '18320846714',
  175. // 服务电话
  176. searchPhone: '18320846714',
  177. // 播放状态
  178. playStatus: false,
  179. // 定时器标识
  180. timer: null,
  181. // 录音图片地址
  182. recordingImg: '../../static/images/repairsImg/recording.jpg',
  183. // 录音文件路径
  184. recordingPath: '',
  185. // 录音时长
  186. recordingTime: 0,
  187. // 显示的图片数据
  188. imgList: [],
  189. // 上传的图片数据
  190. subImgList: [],
  191. // 图片上传框的样式
  192. imageStyles: {
  193. width: 60,
  194. height: 60
  195. },
  196. //画板边长默认是屏幕宽度,正方形画布
  197. cw: uni.getSystemInfoSync().windowWidth,
  198. // 当前校区Id
  199. schoolId: null
  200. }
  201. },
  202. mounted() {
  203. console.log('报修页面加载')
  204. uni.$on('addRepairsArea', this.addRepairsArea)
  205. uni.$on('addRepairsGoods', this.addRepairsGoods)
  206. //在ios下静音时播放没有声音,默认为true,改为false静音时播放有声音
  207. uni.setInnerAudioOption({
  208. obeyMuteSwitch: false
  209. })
  210. this.getRepairNotice()
  211. },
  212. methods: {
  213. // 获取首页公告展示数据
  214. async getRepairNotice() {
  215. const res = await this.$myRequest_repairs({
  216. url: '/repairNoticeSetting/queryRepairNoticeSettingByTop'
  217. })
  218. // console.log(res)
  219. if (res.code === '200') {
  220. this.repairsNotice = res.data.noticeStr
  221. }
  222. },
  223. // 确认提交按钮回调
  224. handleAffirmSub() {
  225. const flag = this.handleValidate()
  226. if (flag) {
  227. uni.showModal({
  228. title: '提示',
  229. content: '确认提交吗?',
  230. success: async (res) => {
  231. if (res.confirm) {
  232. const repairsUserInfo = uni.getStorageSync('repairsUserInfo')
  233. const res = await this.$myRequest_repairs({
  234. url: '/repairRecord/insertRepairRecord',
  235. method: 'post',
  236. data: {
  237. areaId: this.repairsArea,
  238. address: this.repairsAddress,
  239. articleId: this.articleId,
  240. description: this.repairsDescription,
  241. voice: this.recordingPath,
  242. images: this.subImgList,
  243. userName: this.repairsName,
  244. userPhone: this.repairsPhone,
  245. userId: repairsUserInfo.userId
  246. }
  247. })
  248. // console.log(res)
  249. if (res.code === '200') {
  250. uni.showToast({
  251. title: res.message,
  252. icon: 'success'
  253. })
  254. // 重置数据
  255. this.repairsArea = ''
  256. this.repairsAddress = ''
  257. this.repairsGoods = ''
  258. this.articleId = ''
  259. this.repairsDescription = ''
  260. this.recordingPath = ''
  261. this.imgList = []
  262. this.subImgList = []
  263. this.repairsName = ''
  264. this.repairsPhone = ''
  265. // 不是用户报修的单,则跳转回首页
  266. if (repairsUserInfo.routes.includes('首页')) {
  267. setTimeout(() => {
  268. uni.reLaunch({
  269. url: '/pagesRepairs/box/box'
  270. })
  271. }, 1500)
  272. }
  273. }
  274. }
  275. }
  276. })
  277. }
  278. },
  279. // 验证信息是否符合规范
  280. handleValidate() {
  281. const reName = /^[\u4e00-\u9fa5]{2,4}$/
  282. const rePhone = /^[1][3,4,5,7,8,9][0-9]{9}$/
  283. if (!this.repairsArea) {
  284. uni.showToast({
  285. title: '请选择报修区域',
  286. icon: 'none'
  287. })
  288. return
  289. }
  290. if (!this.repairsAddress) {
  291. uni.showToast({
  292. title: '请输入详细地址',
  293. icon: 'none'
  294. })
  295. return
  296. }
  297. if (!this.repairsGoods) {
  298. uni.showToast({
  299. title: '请选择报修物品',
  300. icon: 'none'
  301. })
  302. return
  303. }
  304. if (this.subImgList.length == 0) {
  305. uni.showToast({
  306. title: '请上传报修照片',
  307. icon: 'none'
  308. })
  309. return
  310. }
  311. if (!this.repairsName) {
  312. uni.showToast({
  313. title: '请输入报修姓名',
  314. icon: 'none'
  315. })
  316. return false
  317. }
  318. if (!reName.test(this.repairsName)) {
  319. uni.showToast({
  320. title: '姓名格式有误',
  321. icon: 'none'
  322. })
  323. return false
  324. }
  325. if (!this.repairsPhone) {
  326. uni.showToast({
  327. title: '请输入联系电话',
  328. icon: 'none'
  329. })
  330. return false
  331. }
  332. if (!rePhone.test(this.repairsPhone)) {
  333. uni.showToast({
  334. title: '电话号码格式有误',
  335. icon: 'none'
  336. })
  337. return false
  338. }
  339. return true
  340. },
  341. // 全局自定义事件
  342. addRepairsArea(e) {
  343. console.log(e)
  344. this.repairsArea = e.data
  345. this.schoolId = e.schoolId
  346. },
  347. // 全局自定义事件
  348. addRepairsGoods(e) {
  349. console.log(e)
  350. this.repairsGoods = e.data
  351. this.articleId = e.articleId
  352. },
  353. // 删除录音回调
  354. handleDeleteRecording() {
  355. if (this.playStatus) {
  356. uni.showToast({
  357. title: '播放中不能删除',
  358. icon: 'none',
  359. mask: true
  360. })
  361. } else {
  362. uni.showModal({
  363. title: '提示',
  364. content: '确定删除录音吗?',
  365. success: (res) => {
  366. if (res.confirm) {
  367. this.recordingPath = ''
  368. this.recordingTime = 0
  369. }
  370. }
  371. })
  372. }
  373. },
  374. // 点击录音播放回调
  375. handlePlayRecording() {
  376. innerAudioContext.src = this.recordingPath
  377. if (!this.playStatus) {
  378. this.playStatus = true
  379. innerAudioContext.play()
  380. this.timer = setInterval(() => {
  381. if (this.recordingImg == '../../static/images/repairsImg/recording.jpg') {
  382. this.recordingImg = '../../static/images/repairsImg/recording2.jpg'
  383. } else if (this.recordingImg == '../../static/images/repairsImg/recording2.jpg') {
  384. this.recordingImg = '../../static/images/repairsImg/recording3.jpg'
  385. } else if (this.recordingImg == '../../static/images/repairsImg/recording3.jpg') {
  386. this.recordingImg = '../../static/images/repairsImg/recording.jpg'
  387. }
  388. }, 300)
  389. //播放结束
  390. innerAudioContext.onEnded(() => {
  391. clearInterval(this.timer)
  392. this.timer = null
  393. this.recordingImg = '../../static/images/repairsImg/recording.jpg'
  394. this.playStatus = false
  395. })
  396. } else {
  397. clearInterval(this.timer)
  398. this.recordingImg = '../../static/images/repairsImg/recording.jpg'
  399. this.playStatus = false
  400. innerAudioContext.stop()
  401. }
  402. },
  403. // 自定义事件回调,获取录音文件路径
  404. getTempFilePath(path, time) {
  405. this.recordingPath = path
  406. this.recordingTime = time
  407. this.$refs.popup_recording.close()
  408. },
  409. // 选择图片回调
  410. select(e) {
  411. // console.log(e)
  412. e.tempFiles.forEach((item) => {
  413. //这里的id和页面中写的html代码的canvas的id要一致
  414. let canvasId = 'zipCanvas'
  415. //原图的路径
  416. let imagePath = item.path
  417. //大小限制1024kb
  418. let limitSize = 1024
  419. //初始绘画区域是画布自身的宽度也就是屏幕宽度
  420. let drawWidth = uni.getSystemInfoSync().windowWidth
  421. getLessLimitSizeImage(canvasId, imagePath, limitSize, drawWidth, (resPath) => {
  422. uni.showLoading({
  423. title: '上传中'
  424. })
  425. uni.uploadFile({
  426. url: `https://chtech.ncjti.edu.cn/campusMaintenance/repair-api/repair/api/repairRecord/uploadFile`,
  427. filePath: resPath,
  428. name: 'file',
  429. header: {
  430. token: uni.getStorageSync('repairsUserInfo').token,
  431. user_head: uni.getStorageSync('repairsUserInfo').userhead
  432. },
  433. success: (uploadFileRes) => {
  434. // console.log(JSON.parse(uploadFileRes.data))
  435. this.subImgList.push(JSON.parse(uploadFileRes.data).data.resultUrl)
  436. this.imgList.push({
  437. url: item.path,
  438. name: ''
  439. })
  440. uni.hideLoading()
  441. },
  442. fail: () => {
  443. uni.showToast({
  444. title: '上传失败',
  445. icon: 'error'
  446. })
  447. }
  448. })
  449. })
  450. })
  451. },
  452. // 删除图片回调
  453. handleDelete(e) {
  454. // console.log(e);
  455. const num = this.imgList.findIndex((v) => v.url === e.tempFilePath)
  456. this.subImgList.splice(num, 1)
  457. this.imgList.splice(num, 1)
  458. },
  459. // 点击报修区域回调
  460. handleSelectArea() {
  461. uni.navigateTo({
  462. url: '/pagesRepairs/selectArea/selectArea'
  463. })
  464. },
  465. // 点击报修物品回调
  466. handleSelectGoods() {
  467. if (this.schoolId) {
  468. uni.navigateTo({
  469. url: `/pagesRepairs/selectGoods/selectGoods?schoolId=${this.schoolId}`
  470. })
  471. } else {
  472. uni.showToast({
  473. title: '请先选择报修区域',
  474. icon: 'none'
  475. })
  476. }
  477. },
  478. // 点击消息通知按钮回调
  479. handleClickFixed() {
  480. uni.navigateTo({
  481. url: '/pagesRepairs/message/message'
  482. })
  483. },
  484. // 点击电话号码回调
  485. handleCallPhone(phone) {
  486. uni.makePhoneCall({
  487. phoneNumber: phone
  488. })
  489. },
  490. // 点击录音按钮回调
  491. handleRecording() {
  492. uni.getSetting({
  493. success: (res) => {
  494. if (!res.authSetting['scope.record']) {
  495. uni.authorize({
  496. scope: 'scope.record',
  497. success(res) {
  498. // 授权成功
  499. uni.showToast({
  500. title: '授权成功',
  501. icon: 'none'
  502. })
  503. },
  504. fail() {
  505. uni.showModal({
  506. content: '检测到您没打开麦克风权限,是否去设置打开?',
  507. confirmText: '确认',
  508. cancelText: '取消',
  509. success: (res) => {
  510. if (res.confirm) {
  511. uni.openSetting({
  512. success: (res) => {}
  513. })
  514. } else {
  515. uni.showToast({
  516. title: '获取麦克风权限失败',
  517. icon: 'none'
  518. })
  519. }
  520. }
  521. })
  522. }
  523. })
  524. } else {
  525. this.$refs.popup_recording.open('bottom')
  526. }
  527. },
  528. fail() {
  529. uni.showToast({
  530. title: '获取麦克风权限失败',
  531. icon: 'none'
  532. })
  533. }
  534. })
  535. }
  536. }
  537. }
  538. </script>
  539. <style lang="scss" scoped>
  540. .container {
  541. width: 100vw;
  542. height: calc(100vh - 152rpx);
  543. overflow-y: auto;
  544. .notice {
  545. height: 90rpx;
  546. }
  547. .gap {
  548. height: 12rpx;
  549. background-color: #f2f2f2;
  550. }
  551. .box_item {
  552. display: flex;
  553. align-items: center;
  554. margin: 0 30rpx;
  555. height: 105rpx;
  556. font-size: 28rpx;
  557. border-bottom: 1rpx solid #e6e6e6;
  558. .item_title {
  559. width: 190rpx;
  560. font-weight: bold;
  561. text {
  562. margin-left: 5rpx;
  563. color: #d43030;
  564. }
  565. }
  566. .item_info {
  567. flex: 1;
  568. display: flex;
  569. align-items: center;
  570. padding: 0 10rpx;
  571. height: 100%;
  572. color: #cccccc;
  573. .item_input {
  574. width: 100%;
  575. height: 105rpx;
  576. input {
  577. height: 105rpx;
  578. line-height: 105rpx;
  579. color: #000;
  580. }
  581. }
  582. .info_icon {
  583. display: flex;
  584. justify-content: center;
  585. align-items: center;
  586. width: 79rpx;
  587. height: 37rpx;
  588. border-radius: 33rpx;
  589. border: 1rpx solid #e6e6e6;
  590. img {
  591. width: 26rpx;
  592. height: 26rpx;
  593. }
  594. }
  595. .info_tips {
  596. margin-left: 33rpx;
  597. font-size: 28rpx;
  598. color: #cccccc;
  599. }
  600. }
  601. .item_color {
  602. color: #000;
  603. }
  604. .item_icon {
  605. width: 38rpx;
  606. height: 38rpx;
  607. img {
  608. width: 100%;
  609. height: 100%;
  610. }
  611. }
  612. .item_recording {
  613. display: flex;
  614. align-items: center;
  615. width: 200rpx;
  616. height: 50rpx;
  617. border-radius: 100rpx;
  618. border: 1rpx solid #cccccc;
  619. img {
  620. margin: 0 12rpx;
  621. width: 40rpx;
  622. height: 40rpx;
  623. }
  624. }
  625. .recording_icon {
  626. margin-left: auto;
  627. font-size: 40rpx;
  628. }
  629. }
  630. .box_item2 {
  631. display: flex;
  632. align-items: center;
  633. margin: 0 30rpx;
  634. height: 237rpx;
  635. font-size: 28rpx;
  636. border-bottom: 1rpx solid #e6e6e6;
  637. .item2_title {
  638. width: 190rpx;
  639. font-weight: bold;
  640. text {
  641. margin-left: 5rpx;
  642. color: #d43030;
  643. }
  644. }
  645. .item2_info {
  646. flex: 1;
  647. padding: 0 10rpx;
  648. .item2_textarea {
  649. display: flex;
  650. align-items: center;
  651. width: 100%;
  652. height: 237rpx;
  653. textarea {
  654. box-sizing: border-box;
  655. padding: 20rpx;
  656. width: 500rpx;
  657. height: 176rpx;
  658. border: 1rpx solid #e6e6e6;
  659. border-radius: 6rpx;
  660. }
  661. }
  662. }
  663. }
  664. .box_item3 {
  665. margin: 0 30rpx;
  666. height: 246rpx;
  667. border-bottom: 1rpx solid #e6e6e6;
  668. .item3_title {
  669. height: 95rpx;
  670. line-height: 95rpx;
  671. font-size: 28rpx;
  672. font-weight: bold;
  673. span {
  674. margin-left: 5rpx;
  675. color: #d43030;
  676. }
  677. text {
  678. font-size: 24rpx;
  679. color: #808080;
  680. font-weight: 400;
  681. }
  682. }
  683. }
  684. .foot {
  685. display: flex;
  686. flex-direction: column;
  687. align-items: center;
  688. margin: 0 30rpx;
  689. height: 407rpx;
  690. .foot_btn {
  691. margin-top: 167rpx;
  692. width: 100%;
  693. height: 100rpx;
  694. line-height: 100rpx;
  695. text-align: center;
  696. color: #fff;
  697. font-size: 32rpx;
  698. border-radius: 12rpx;
  699. background-color: #6fb6b8;
  700. }
  701. .foot_phone {
  702. margin-top: 30rpx;
  703. color: #b3b3b3;
  704. font-size: 24rpx;
  705. }
  706. }
  707. .fixed {
  708. z-index: 2;
  709. position: fixed;
  710. right: 0;
  711. bottom: 200rpx;
  712. display: flex;
  713. justify-content: center;
  714. align-items: center;
  715. width: 211rpx;
  716. height: 90rpx;
  717. border-radius: 150rpx 0 0 150rpx;
  718. border: 1rpx solid #d9d9d9;
  719. background-color: #fff;
  720. box-shadow: 0 0 7rpx #d9d9d9;
  721. .fixed_box {
  722. display: flex;
  723. align-items: center;
  724. font-size: 28rpx;
  725. img {
  726. margin-right: 10rpx;
  727. width: 38rpx;
  728. height: 38rpx;
  729. }
  730. }
  731. }
  732. .popup_recording {
  733. width: 100%;
  734. height: 460rpx;
  735. background-color: #fff;
  736. }
  737. }
  738. </style>