repairs.vue 16 KB

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