repairRecord.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. <template>
  2. <scroll-view class="container" :scroll-y="isScroll">
  3. <view class="title">维修日期</view>
  4. <uni-datetime-picker disabled placeholder="请选择日期" type="date" v-model="repairDate" />
  5. <view class="title">维修内容</view>
  6. <view class="textarea">
  7. <textarea placeholder-style="color:#CCCCCC" placeholder="请输入维修内容" v-model="repairContent"></textarea>
  8. </view>
  9. <view class="title">维修结果</view>
  10. <!-- 录音区域 -->
  11. <view class="voice">
  12. <view class="voice_box" v-if="!recordingPath" @click="handleRecording">
  13. <img src="../../static/images/repairsImg/voice.png" />
  14. </view>
  15. <view v-if="!recordingPath" @click="handleRecording">点击录音</view>
  16. <view class="item_recording" v-if="recordingPath" @click="handlePlayRecording">
  17. <img :src="recordingImg" />
  18. {{ recordingTime }}″
  19. </view>
  20. <view class="recording_icon" v-if="recordingPath" @click="handleDeleteRecording">×</view>
  21. </view>
  22. <!-- 录音弹窗区域 -->
  23. <uni-popup :safe-area="true" background-color="#fff" ref="popup_recording">
  24. <view class="popup_recording">
  25. <recording @getTempFilePath="getTempFilePath" />
  26. </view>
  27. </uni-popup>
  28. <view class="title">关联耗材</view>
  29. <!-- 每一个耗材盒子区域 -->
  30. <view class="detail_box" v-for="(item, index) in goodList" :key="index">
  31. <view class="detail_box_item">
  32. <view class="item_key">耗材名称</view>
  33. <view class="item_value">{{ item.consumeName }}</view>
  34. </view>
  35. <view class="detail_box_item">
  36. <view class="item_key">耗材数量</view>
  37. <view class="item_value">
  38. <uni-number-box v-model="item.number" :min="0" @change="bindChange($event, index)"></uni-number-box>
  39. </view>
  40. </view>
  41. <view class="detail_box_item">
  42. <view class="item_key">耗材单价</view>
  43. <view class="item_value">
  44. <uni-easyinput
  45. type="number"
  46. :clearable="false"
  47. v-model="item.price"
  48. placeholder="请输入耗材单价"
  49. placeholderStyle="font-size:16px"
  50. @focus="handleFocus"
  51. @blur="handleChangePrice($event, item)"
  52. ></uni-easyinput>
  53. </view>
  54. </view>
  55. </view>
  56. <!-- 添加耗材区域 -->
  57. <view class="add" @click="handleAdd">
  58. <text>+</text>
  59. 添加耗材
  60. </view>
  61. <!-- 合计费用区域 -->
  62. <view class="total">
  63. <view>合计费用</view>
  64. <view>{{ countMoney }}元</view>
  65. </view>
  66. <view class="title">维修师傅</view>
  67. <view class="box">
  68. <img src="../../static/images/repairsImg/people.png" />
  69. {{ info.maintenancerName }}
  70. </view>
  71. <view class="title">手机</view>
  72. <view class="box">
  73. <img src="../../static/images/repairsImg/phone2.png" />
  74. {{ info.maintenancerPhone }}
  75. </view>
  76. <view class="title">现场拍照</view>
  77. <uni-file-picker
  78. ref="filePicker"
  79. limit="3"
  80. v-model="imgList"
  81. fileMediatype="image"
  82. :image-styles="imageStyles"
  83. mode="grid"
  84. @select="select"
  85. @delete="handleDelete"
  86. ></uni-file-picker>
  87. <view class="btn" @click="handleSub">确认提交</view>
  88. <!-- 用于图片压缩的canvas画布 -->
  89. <canvas
  90. :style="{
  91. width: cw + 'px',
  92. height: cw + 'px',
  93. position: 'absolute',
  94. zIndex: -1,
  95. left: '-10000rpx',
  96. top: '-10000rpx'
  97. }"
  98. canvas-id="zipCanvas"
  99. ></canvas>
  100. <!--画布结束-->
  101. </scroll-view>
  102. </template>
  103. <script>
  104. import recording from '../components/recording.vue'
  105. // 图片压缩方法
  106. import getLessLimitSizeImage from '../util/imageCompress.js'
  107. const innerAudioContext = uni.createInnerAudioContext()
  108. export default {
  109. components: {
  110. recording
  111. },
  112. data() {
  113. return {
  114. // 维修日期
  115. repairDate: '',
  116. // 维修内容
  117. repairContent: '',
  118. // 耗材列表
  119. goodList: [],
  120. // 显示的图片数据
  121. imgList: [],
  122. // 上传的图片数据
  123. subImgList: [],
  124. // 图片上传框的样式
  125. imageStyles: {
  126. width: 60,
  127. height: 60,
  128. border: {
  129. color: '#ccc',
  130. width: 1,
  131. style: 'dashed',
  132. radius: '9px'
  133. }
  134. },
  135. //画板边长默认是屏幕宽度,正方形画布
  136. cw: uni.getSystemInfoSync().windowWidth,
  137. // 录音文件路径
  138. recordingPath: '',
  139. // 录音图片地址
  140. recordingImg: '../../static/images/repairsImg/recording.jpg',
  141. // 录音时长
  142. recordingTime: 0,
  143. // 播放状态
  144. playStatus: false,
  145. // 定时器标识
  146. timer: null,
  147. // 订单详情信息
  148. info: {},
  149. // 是否允许页面滚动
  150. isScroll: true
  151. }
  152. },
  153. computed: {
  154. // 合计费用
  155. countMoney() {
  156. let countMoney = 0
  157. this.goodList.forEach((ele) => {
  158. countMoney += Number(ele.number) * Number(ele.price)
  159. })
  160. if (countMoney) {
  161. return countMoney
  162. } else {
  163. return 0
  164. }
  165. }
  166. },
  167. onLoad(options) {
  168. this.info = JSON.parse(options.info)
  169. this.getTodayTime()
  170. },
  171. mounted() {
  172. //在ios下静音时播放没有声音,默认为true,改为false就好了。
  173. uni.setInnerAudioOption({
  174. obeyMuteSwitch: false
  175. })
  176. uni.$on('addConsumable', this.addConsumable)
  177. },
  178. methods: {
  179. // 获取今天日期 YY-MM-DD
  180. getTodayTime() {
  181. let today = new Date()
  182. this.repairDate = `${today.getFullYear()}-${(today.getMonth() + 1).toString().padStart(2, 0)}-${today.getDate().toString().padStart(2, 0)}`
  183. },
  184. // 单价输入框输入回调 (失去焦点)
  185. handleChangePrice(e, item) {
  186. this.isScroll = true
  187. // 验证输入单价格式 只能是数字,小数点最多两位
  188. const reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/
  189. if (!reg.test(e.detail.value)) {
  190. uni.showToast({
  191. title: '请确定单价为数字,并且只能保留两位小数点',
  192. icon: 'none'
  193. })
  194. item.price = 0
  195. }
  196. },
  197. // 价格输入框聚焦回调
  198. handleFocus() {
  199. this.isScroll = false
  200. },
  201. // 全局自定义事件
  202. addConsumable(e) {
  203. // console.log(e)
  204. // 判断是否存在相同的耗材
  205. let flag = this.goodList.some((ele) => {
  206. return ele.consumeName === e.data.name
  207. })
  208. if (!flag) {
  209. this.$set(e.data, 'number', 1)
  210. this.$set(e.data, 'consumeName', e.data.name)
  211. this.$set(e.data, 'consumeId', e.data.id)
  212. this.$set(e.data, 'articleId', e.articleId)
  213. // this.$delete(e.data, 'name')
  214. // this.$delete(e.data, 'id')
  215. this.goodList.push(e.data)
  216. }
  217. },
  218. // 确认提交按钮回调
  219. handleSub() {
  220. // if (!this.goodList.length) {
  221. // uni.showToast({
  222. // title: '请添加耗材',
  223. // icon: 'none'
  224. // })
  225. // return
  226. // }
  227. // if (this.countMoney <= 0) {
  228. // uni.showToast({
  229. // title: '合计费用不能小于0元',
  230. // icon: 'none'
  231. // })
  232. // return
  233. // }
  234. if (this.subImgList.length === 0) {
  235. uni.showToast({
  236. title: '请上传现场照片',
  237. icon: 'none'
  238. })
  239. return
  240. }
  241. uni.showModal({
  242. title: '提示',
  243. content: '确认提交吗?',
  244. success: async (res) => {
  245. if (res.confirm) {
  246. // 维修内容
  247. console.log(this.repairContent)
  248. // 录音文件路径
  249. console.log(this.recordingPath)
  250. // 录音时长
  251. console.log(this.recordingTime)
  252. // 耗材集合
  253. console.log(this.goodList)
  254. // 总费用
  255. console.log(this.countMoney)
  256. // 现场拍照集合
  257. console.log(this.subImgList)
  258. const res = await this.$myRequest_repairs({
  259. url: '/repairRecord/finishOrder',
  260. method: 'post',
  261. data: {
  262. recordId: this.info.id,
  263. images: this.subImgList,
  264. content: this.repairContent,
  265. voice: this.recordingPath,
  266. voiceLength: this.recordingTime,
  267. consumes: this.goodList
  268. }
  269. })
  270. // console.log(res)
  271. if (res.code === '200') {
  272. uni.showToast({
  273. title: '提交成功',
  274. icon: 'success'
  275. })
  276. setTimeout(() => {
  277. uni.reLaunch({
  278. url: '/pagesRepairs/box/box'
  279. })
  280. }, 1500)
  281. }
  282. }
  283. }
  284. })
  285. },
  286. // 耗材数量计数器改变回调
  287. bindChange(e, index) {
  288. // console.log(e)
  289. // console.log(index)
  290. if (e === 0) {
  291. this.goodList.splice(index, 1)
  292. }
  293. },
  294. // 添加耗材按钮回调
  295. handleAdd() {
  296. let temList = JSON.stringify(this.goodList.map((ele) => ele.consumeId))
  297. uni.navigateTo({
  298. url: `/pagesRepairs/addGoods/addGoods?activeList=${temList}`
  299. })
  300. },
  301. // 选择图片回调
  302. select(e) {
  303. // console.log(e)
  304. e.tempFiles.forEach((item) => {
  305. //这里的id和页面中写的html代码的canvas的id要一致
  306. let canvasId = 'zipCanvas'
  307. //原图的路径
  308. let imagePath = item.path
  309. //大小限制1024kb
  310. let limitSize = 1024
  311. //初始绘画区域是画布自身的宽度也就是屏幕宽度
  312. let drawWidth = uni.getSystemInfoSync().windowWidth
  313. getLessLimitSizeImage(canvasId, imagePath, limitSize, drawWidth, (resPath) => {
  314. uni.showLoading({
  315. title: '上传中'
  316. })
  317. uni.uploadFile({
  318. url: `https://chtech.ncjti.edu.cn/campusMaintenance/repair-api/repair/api/repairRecord/uploadFile`,
  319. filePath: resPath,
  320. name: 'file',
  321. header: {
  322. token: uni.getStorageSync('repairsUserInfo').token,
  323. user_head: uni.getStorageSync('repairsUserInfo').userhead
  324. },
  325. success: (uploadFileRes) => {
  326. // console.log(JSON.parse(uploadFileRes.data))
  327. this.subImgList.push(JSON.parse(uploadFileRes.data).data.resultUrl)
  328. this.imgList.push({
  329. url: item.path,
  330. name: ''
  331. })
  332. uni.hideLoading()
  333. },
  334. fail: () => {
  335. uni.showToast({
  336. title: '上传失败',
  337. icon: 'error'
  338. })
  339. }
  340. })
  341. })
  342. })
  343. },
  344. // 删除图片回调
  345. handleDelete(e) {
  346. // console.log(e);
  347. const num = this.imgList.findIndex((v) => v.url === e.tempFilePath)
  348. this.subImgList.splice(num, 1)
  349. this.imgList.splice(num, 1)
  350. },
  351. // 点击录音按钮回调
  352. handleRecording() {
  353. uni.getSetting({
  354. success: (res) => {
  355. if (!res.authSetting['scope.record']) {
  356. uni.authorize({
  357. scope: 'scope.record',
  358. success(res) {
  359. // 授权成功
  360. uni.showToast({
  361. title: '授权成功',
  362. icon: 'none'
  363. })
  364. },
  365. fail() {
  366. uni.showModal({
  367. content: '检测到您没打开麦克风权限,是否去设置打开?',
  368. confirmText: '确认',
  369. cancelText: '取消',
  370. success: (res) => {
  371. if (res.confirm) {
  372. uni.openSetting({
  373. success: (res) => {}
  374. })
  375. } else {
  376. uni.showToast({
  377. title: '获取麦克风权限失败',
  378. icon: 'none'
  379. })
  380. }
  381. }
  382. })
  383. }
  384. })
  385. } else {
  386. this.$refs.popup_recording.open('bottom')
  387. }
  388. },
  389. fail() {
  390. uni.showToast({
  391. title: '获取麦克风权限失败',
  392. icon: 'none'
  393. })
  394. }
  395. })
  396. },
  397. // 点击录音播放回调
  398. handlePlayRecording() {
  399. innerAudioContext.src = this.recordingPath
  400. if (!this.playStatus) {
  401. this.playStatus = true
  402. innerAudioContext.play()
  403. this.timer = setInterval(() => {
  404. if (this.recordingImg == '../../static/images/repairsImg/recording.jpg') {
  405. this.recordingImg = '../../static/images/repairsImg/recording2.jpg'
  406. } else if (this.recordingImg == '../../static/images/repairsImg/recording2.jpg') {
  407. this.recordingImg = '../../static/images/repairsImg/recording3.jpg'
  408. } else if (this.recordingImg == '../../static/images/repairsImg/recording3.jpg') {
  409. this.recordingImg = '../../static/images/repairsImg/recording.jpg'
  410. }
  411. }, 300)
  412. //播放结束
  413. innerAudioContext.onEnded(() => {
  414. clearInterval(this.timer)
  415. this.timer = null
  416. this.recordingImg = '../../static/images/repairsImg/recording.jpg'
  417. this.playStatus = false
  418. })
  419. } else {
  420. clearInterval(this.timer)
  421. this.recordingImg = '../../static/images/repairsImg/recording.jpg'
  422. this.playStatus = false
  423. innerAudioContext.stop()
  424. }
  425. },
  426. // 删除录音回调
  427. handleDeleteRecording() {
  428. if (this.playStatus) {
  429. uni.showToast({
  430. title: '播放中不能删除',
  431. icon: 'none',
  432. mask: true
  433. })
  434. } else {
  435. uni.showModal({
  436. title: '提示',
  437. content: '确定删除录音吗?',
  438. success: (res) => {
  439. if (res.confirm) {
  440. this.recordingPath = ''
  441. this.recordingTime = 0
  442. }
  443. }
  444. })
  445. }
  446. },
  447. // 自定义事件回调,获取录音文件路径
  448. getTempFilePath(path, time) {
  449. this.recordingPath = path
  450. this.recordingTime = time
  451. this.$refs.popup_recording.close()
  452. }
  453. }
  454. }
  455. </script>
  456. <style lang="scss" scoped>
  457. .container {
  458. box-sizing: border-box;
  459. padding: 0 30rpx;
  460. width: 100%;
  461. .title {
  462. display: flex;
  463. align-items: center;
  464. height: 107rpx;
  465. font-size: 36rpx;
  466. font-weight: bold;
  467. }
  468. .textarea {
  469. height: 310rpx;
  470. border-radius: 10rpx;
  471. border: 1rpx solid #cccccc;
  472. textarea {
  473. box-sizing: border-box;
  474. padding: 25rpx 35rpx;
  475. width: 100%;
  476. font-size: 32rpx;
  477. }
  478. }
  479. .voice {
  480. display: flex;
  481. align-items: center;
  482. height: 94rpx;
  483. font-size: 32rpx;
  484. color: #cccccc;
  485. border-radius: 10rpx;
  486. border: 1rpx solid #cccccc;
  487. .voice_box {
  488. display: flex;
  489. justify-content: center;
  490. align-items: center;
  491. margin: 0 38rpx 0 33rpx;
  492. width: 101rpx;
  493. height: 47rpx;
  494. border-radius: 33rpx;
  495. box-shadow: 0px 0px 4rpx rgba(0, 0, 0, 0.25);
  496. img {
  497. width: 33rpx;
  498. height: 33rpx;
  499. }
  500. }
  501. .item_recording {
  502. margin-left: 35rpx;
  503. display: flex;
  504. align-items: center;
  505. width: 230rpx;
  506. height: 65rpx;
  507. color: #000;
  508. border-radius: 100rpx;
  509. border: 1rpx solid #cccccc;
  510. img {
  511. margin: 0 12rpx;
  512. width: 40rpx;
  513. height: 40rpx;
  514. }
  515. }
  516. .recording_icon {
  517. margin-left: auto;
  518. margin-right: 35rpx;
  519. font-size: 40rpx;
  520. }
  521. }
  522. .popup_recording {
  523. width: 100%;
  524. height: 460rpx;
  525. background-color: #fff;
  526. }
  527. .detail_box {
  528. box-sizing: border-box;
  529. margin-bottom: 46rpx;
  530. padding: 5rpx 30rpx 0;
  531. width: 690rpx;
  532. height: 284rpx;
  533. border-radius: 9rpx;
  534. box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.25);
  535. .detail_box_item {
  536. display: flex;
  537. justify-content: space-between;
  538. align-items: center;
  539. height: 92rpx;
  540. font-size: 32rpx;
  541. border-bottom: 1rpx solid #e5e5e5;
  542. .item_key {
  543. width: 150rpx;
  544. color: #808080;
  545. }
  546. .item_value {
  547. font-weight: bold;
  548. ::v-deep .is-input-border {
  549. text-align: right;
  550. border: none;
  551. }
  552. ::v-deep .uni-easyinput__content-input {
  553. font-size: 32rpx;
  554. }
  555. }
  556. }
  557. }
  558. .add {
  559. display: flex;
  560. justify-content: center;
  561. align-items: center;
  562. width: 690rpx;
  563. height: 90rpx;
  564. color: #6fb6b8;
  565. font-size: 32rpx;
  566. border-radius: 9rpx;
  567. background-color: #ebf2f2;
  568. text {
  569. margin-right: 10rpx;
  570. font-size: 48rpx;
  571. }
  572. }
  573. .total {
  574. display: flex;
  575. justify-content: space-between;
  576. align-items: center;
  577. margin: auto;
  578. width: 622rpx;
  579. height: 100rpx;
  580. font-size: 32rpx;
  581. font-weight: bold;
  582. border-bottom: 1rpx solid #e5e5e5;
  583. }
  584. .box {
  585. display: flex;
  586. align-items: center;
  587. height: 94rpx;
  588. font-size: 32rpx;
  589. border-radius: 10rpx;
  590. border: 1rpx solid #cccccc;
  591. img {
  592. margin: 0 14rpx 0 30rpx;
  593. width: 40rpx;
  594. height: 40rpx;
  595. }
  596. }
  597. .btn {
  598. display: flex;
  599. justify-content: center;
  600. align-items: center;
  601. margin: 65rpx 0 60rpx;
  602. height: 100rpx;
  603. color: #fff;
  604. font-size: 32rpx;
  605. border-radius: 12rpx;
  606. background-color: #6fb6b8;
  607. }
  608. }
  609. </style>