repairs.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  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: '今日14:00系统更新请不要进行报修!',
  159. // 报修区域
  160. repairsArea: '',
  161. // 报修地址
  162. repairsAddress: '',
  163. // 报修物品
  164. repairsGoods: '',
  165. // 故障描述
  166. repairsDescription: '',
  167. // 报修姓名
  168. repairsName: '',
  169. // 联系电话
  170. repairsPhone: '',
  171. // 紧急电话
  172. urgencyPhone: '18320846714',
  173. // 服务电话
  174. searchPhone: '18320846714',
  175. // 播放状态
  176. playStatus: false,
  177. // 定时器标识
  178. timer: null,
  179. // 录音图片地址
  180. recordingImg: '../../static/images/repairsImg/recording.jpg',
  181. // 录音文件路径
  182. recordingPath: '',
  183. // 录音时长
  184. recordingTime: 0,
  185. // 显示的图片数据
  186. imgList: [],
  187. // 上传的图片数据
  188. subImgList: [],
  189. // 图片上传框的样式
  190. imageStyles: {
  191. width: 60,
  192. height: 60,
  193. border: {
  194. color: '#ccc',
  195. width: 1,
  196. style: 'dashed',
  197. radius: '9px'
  198. }
  199. },
  200. //画板边长默认是屏幕宽度,正方形画布
  201. cw: uni.getSystemInfoSync().windowWidth
  202. }
  203. },
  204. mounted() {
  205. console.log('报修页面加载')
  206. uni.$on('addRepairsArea', this.addRepairsArea)
  207. uni.$on('addRepairsGoods', this.addRepairsGoods)
  208. //在ios下静音时播放没有声音,默认为true,改为false就好了。
  209. uni.setInnerAudioOption({
  210. obeyMuteSwitch: false
  211. })
  212. },
  213. methods: {
  214. // 确认提交按钮回调
  215. handleAffirmSub() {
  216. const flag = this.handleValidate()
  217. if (flag) {
  218. console.log(this.repairsArea)
  219. console.log(this.repairsAddress)
  220. console.log(this.repairsGoods)
  221. console.log(this.repairsDescription)
  222. console.log(this.recordingPath)
  223. console.log(this.subImgList)
  224. console.log(this.repairsName)
  225. console.log(this.repairsPhone)
  226. uni.showToast({
  227. title: '提交成功',
  228. icon: 'none'
  229. })
  230. // 不是用户报修的单,则跳转回首页
  231. const repairsUserInfo = uni.getStorageSync('repairsUserInfo')
  232. if (repairsUserInfo.routes.includes('首页')) {
  233. setTimeout(() => {
  234. uni.reLaunch({
  235. url: '/pagesRepairs/box/box'
  236. })
  237. }, 1500)
  238. }
  239. }
  240. },
  241. // 验证信息是否符合规范
  242. handleValidate() {
  243. const reName = /^[\u4e00-\u9fa5]{2,4}$/
  244. const rePhone = /^[1][3,4,5,7,8,9][0-9]{9}$/
  245. if (!this.repairsArea) {
  246. uni.showToast({
  247. title: '请选择报修区域',
  248. icon: 'none'
  249. })
  250. return
  251. }
  252. if (!this.repairsAddress) {
  253. uni.showToast({
  254. title: '请输入详细地址',
  255. icon: 'none'
  256. })
  257. return
  258. }
  259. if (!this.repairsGoods) {
  260. uni.showToast({
  261. title: '请选择报修物品',
  262. icon: 'none'
  263. })
  264. return
  265. }
  266. if (this.subImgList.length == 0) {
  267. uni.showToast({
  268. title: '请上传报修照片',
  269. icon: 'none'
  270. })
  271. return
  272. }
  273. if (!this.repairsName) {
  274. uni.showToast({
  275. title: '请输入报修姓名',
  276. icon: 'none'
  277. })
  278. return false
  279. }
  280. if (!reName.test(this.repairsName)) {
  281. uni.showToast({
  282. title: '姓名格式有误',
  283. icon: 'none'
  284. })
  285. return false
  286. }
  287. if (!this.repairsPhone) {
  288. uni.showToast({
  289. title: '请输入联系电话',
  290. icon: 'none'
  291. })
  292. return false
  293. }
  294. if (!rePhone.test(this.repairsPhone)) {
  295. uni.showToast({
  296. title: '电话号码格式有误',
  297. icon: 'none'
  298. })
  299. return false
  300. }
  301. return true
  302. },
  303. // 全局自定义事件
  304. addRepairsArea(e) {
  305. console.log(e)
  306. this.repairsArea = e.data
  307. },
  308. // 全局自定义事件
  309. addRepairsGoods(e) {
  310. console.log(e)
  311. this.repairsGoods = e.data
  312. },
  313. // 删除录音回调
  314. handleDeleteRecording() {
  315. if (this.playStatus) {
  316. uni.showToast({
  317. title: '播放中不能删除',
  318. icon: 'none',
  319. mask: true
  320. })
  321. } else {
  322. uni.showModal({
  323. title: '提示',
  324. content: '确定删除录音吗?',
  325. success: (res) => {
  326. if (res.confirm) {
  327. this.recordingPath = ''
  328. this.recordingTime = 0
  329. }
  330. }
  331. })
  332. }
  333. },
  334. // 点击录音播放回调
  335. handlePlayRecording() {
  336. innerAudioContext.src = this.recordingPath
  337. if (!this.playStatus) {
  338. this.playStatus = true
  339. innerAudioContext.play()
  340. this.timer = setInterval(() => {
  341. if (this.recordingImg == '../../static/images/repairsImg/recording.jpg') {
  342. this.recordingImg = '../../static/images/repairsImg/recording2.jpg'
  343. } else if (this.recordingImg == '../../static/images/repairsImg/recording2.jpg') {
  344. this.recordingImg = '../../static/images/repairsImg/recording3.jpg'
  345. } else if (this.recordingImg == '../../static/images/repairsImg/recording3.jpg') {
  346. this.recordingImg = '../../static/images/repairsImg/recording.jpg'
  347. }
  348. }, 300)
  349. //播放结束
  350. innerAudioContext.onEnded(() => {
  351. clearInterval(this.timer)
  352. this.timer = null
  353. this.recordingImg = '../../static/images/repairsImg/recording.jpg'
  354. this.playStatus = false
  355. })
  356. } else {
  357. clearInterval(this.timer)
  358. this.recordingImg = '../../static/images/repairsImg/recording.jpg'
  359. this.playStatus = false
  360. innerAudioContext.stop()
  361. }
  362. },
  363. // 自定义事件回调,获取录音文件路径
  364. getTempFilePath(path, time) {
  365. this.recordingPath = path
  366. this.recordingTime = time
  367. this.$refs.popup_recording.close()
  368. },
  369. // 选择图片回调
  370. select(e) {
  371. console.log(e)
  372. e.tempFiles.forEach((item) => {
  373. //这里的id和页面中写的html代码的canvas的id要一致
  374. let canvasId = 'zipCanvas'
  375. //原图的路径
  376. let imagePath = item.path
  377. //大小限制1024kb
  378. let limitSize = 1024
  379. //初始绘画区域是画布自身的宽度也就是屏幕宽度
  380. let drawWidth = uni.getSystemInfoSync().windowWidth
  381. getLessLimitSizeImage(canvasId, imagePath, limitSize, drawWidth, (resPath) => {
  382. uni.showLoading({
  383. title: '上传中'
  384. })
  385. uni.uploadFile({
  386. url: `https://jiangxih3cpartner.com/reporting/file/fileUpDown`,
  387. filePath: resPath,
  388. name: 'file',
  389. success: (uploadFileRes) => {
  390. this.subImgList.push(JSON.parse(uploadFileRes.data).data.join())
  391. this.imgList.push({
  392. url: item.path,
  393. name: ''
  394. })
  395. uni.hideLoading()
  396. },
  397. fail: () => {
  398. uni.showToast({
  399. title: '上传失败',
  400. icon: 'error'
  401. })
  402. }
  403. })
  404. })
  405. })
  406. },
  407. // 删除图片回调
  408. handleDelete(e) {
  409. // console.log(e);
  410. const num = this.imgList.findIndex((v) => v.url === e.tempFilePath)
  411. this.subImgList.splice(num, 1)
  412. this.imgList.splice(num, 1)
  413. },
  414. // 点击报修区域回调
  415. handleSelectArea() {
  416. uni.navigateTo({
  417. url: '/pagesRepairs/selectArea/selectArea'
  418. })
  419. },
  420. // 点击报修物品回调
  421. handleSelectGoods() {
  422. uni.navigateTo({
  423. url: '/pagesRepairs/selectGoods/selectGoods'
  424. })
  425. },
  426. // 点击消息通知按钮回调
  427. handleClickFixed() {
  428. uni.navigateTo({
  429. url: '/pagesRepairs/message/message'
  430. })
  431. },
  432. // 点击电话号码回调
  433. handleCallPhone(phone) {
  434. uni.makePhoneCall({
  435. phoneNumber: phone
  436. })
  437. },
  438. // 点击录音按钮回调
  439. handleRecording() {
  440. uni.getSetting({
  441. success: (res) => {
  442. if (!res.authSetting['scope.record']) {
  443. uni.authorize({
  444. scope: 'scope.record',
  445. success(res) {
  446. // 授权成功
  447. uni.showToast({
  448. title: '授权成功',
  449. icon: 'none'
  450. })
  451. },
  452. fail() {
  453. uni.showModal({
  454. content: '检测到您没打开麦克风权限,是否去设置打开?',
  455. confirmText: '确认',
  456. cancelText: '取消',
  457. success: (res) => {
  458. if (res.confirm) {
  459. uni.openSetting({
  460. success: (res) => {}
  461. })
  462. } else {
  463. uni.showToast({
  464. title: '获取麦克风权限失败',
  465. icon: 'none'
  466. })
  467. }
  468. }
  469. })
  470. }
  471. })
  472. } else {
  473. this.$refs.popup_recording.open('bottom')
  474. }
  475. },
  476. fail() {
  477. uni.showToast({
  478. title: '获取麦克风权限失败',
  479. icon: 'none'
  480. })
  481. }
  482. })
  483. }
  484. }
  485. }
  486. </script>
  487. <style lang="scss" scoped>
  488. .container {
  489. width: 100vw;
  490. height: calc(100vh - 152rpx);
  491. overflow-y: auto;
  492. .notice {
  493. height: 90rpx;
  494. }
  495. .gap {
  496. height: 12rpx;
  497. background-color: #f2f2f2;
  498. }
  499. .box_item {
  500. display: flex;
  501. align-items: center;
  502. margin: 0 30rpx;
  503. height: 105rpx;
  504. font-size: 28rpx;
  505. border-bottom: 1rpx solid #e6e6e6;
  506. .item_title {
  507. width: 190rpx;
  508. font-weight: bold;
  509. text {
  510. margin-left: 5rpx;
  511. color: #d43030;
  512. }
  513. }
  514. .item_info {
  515. flex: 1;
  516. display: flex;
  517. align-items: center;
  518. padding: 0 10rpx;
  519. height: 100%;
  520. color: #cccccc;
  521. .item_input {
  522. width: 100%;
  523. height: 105rpx;
  524. input {
  525. height: 105rpx;
  526. line-height: 105rpx;
  527. color: #000;
  528. }
  529. }
  530. .info_icon {
  531. display: flex;
  532. justify-content: center;
  533. align-items: center;
  534. width: 79rpx;
  535. height: 37rpx;
  536. border-radius: 33rpx;
  537. border: 1rpx solid #e6e6e6;
  538. img {
  539. width: 26rpx;
  540. height: 26rpx;
  541. }
  542. }
  543. .info_tips {
  544. margin-left: 33rpx;
  545. font-size: 28rpx;
  546. color: #cccccc;
  547. }
  548. }
  549. .item_color {
  550. color: #000;
  551. }
  552. .item_icon {
  553. width: 38rpx;
  554. height: 38rpx;
  555. img {
  556. width: 100%;
  557. height: 100%;
  558. }
  559. }
  560. .item_recording {
  561. display: flex;
  562. align-items: center;
  563. width: 200rpx;
  564. height: 50rpx;
  565. border-radius: 100rpx;
  566. border: 1rpx solid #cccccc;
  567. img {
  568. margin: 0 12rpx;
  569. width: 40rpx;
  570. height: 40rpx;
  571. }
  572. }
  573. .recording_icon {
  574. margin-left: auto;
  575. font-size: 40rpx;
  576. }
  577. }
  578. .box_item2 {
  579. display: flex;
  580. align-items: center;
  581. margin: 0 30rpx;
  582. height: 237rpx;
  583. font-size: 28rpx;
  584. border-bottom: 1rpx solid #e6e6e6;
  585. .item2_title {
  586. width: 190rpx;
  587. font-weight: bold;
  588. text {
  589. margin-left: 5rpx;
  590. color: #d43030;
  591. }
  592. }
  593. .item2_info {
  594. flex: 1;
  595. padding: 0 10rpx;
  596. .item2_textarea {
  597. display: flex;
  598. align-items: center;
  599. width: 100%;
  600. height: 237rpx;
  601. textarea {
  602. box-sizing: border-box;
  603. padding: 20rpx;
  604. width: 500rpx;
  605. height: 176rpx;
  606. border: 1rpx solid #e6e6e6;
  607. border-radius: 6rpx;
  608. }
  609. }
  610. }
  611. }
  612. .box_item3 {
  613. margin: 0 30rpx;
  614. height: 246rpx;
  615. border-bottom: 1rpx solid #e6e6e6;
  616. .item3_title {
  617. height: 95rpx;
  618. line-height: 95rpx;
  619. font-size: 28rpx;
  620. font-weight: bold;
  621. span {
  622. margin-left: 5rpx;
  623. color: #d43030;
  624. }
  625. text {
  626. font-size: 24rpx;
  627. color: #808080;
  628. font-weight: 400;
  629. }
  630. }
  631. }
  632. .foot {
  633. display: flex;
  634. flex-direction: column;
  635. align-items: center;
  636. margin: 0 30rpx;
  637. height: 407rpx;
  638. .foot_btn {
  639. margin-top: 167rpx;
  640. width: 100%;
  641. height: 100rpx;
  642. line-height: 100rpx;
  643. text-align: center;
  644. color: #fff;
  645. font-size: 32rpx;
  646. border-radius: 12rpx;
  647. background-color: #6fb6b8;
  648. }
  649. .foot_phone {
  650. margin-top: 30rpx;
  651. color: #b3b3b3;
  652. font-size: 24rpx;
  653. }
  654. }
  655. .fixed {
  656. z-index: 2;
  657. position: fixed;
  658. right: 0;
  659. bottom: 200rpx;
  660. display: flex;
  661. justify-content: center;
  662. align-items: center;
  663. width: 211rpx;
  664. height: 90rpx;
  665. border-radius: 150rpx 0 0 150rpx;
  666. border: 1rpx solid #d9d9d9;
  667. background-color: #fff;
  668. box-shadow: 0 0 7rpx #d9d9d9;
  669. .fixed_box {
  670. display: flex;
  671. align-items: center;
  672. font-size: 28rpx;
  673. img {
  674. margin-right: 10rpx;
  675. width: 38rpx;
  676. height: 38rpx;
  677. }
  678. }
  679. }
  680. .popup_recording {
  681. width: 100%;
  682. height: 460rpx;
  683. background-color: #fff;
  684. }
  685. }
  686. </style>