repairRecord.vue 15 KB

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