| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652 |
- <template>
- <scroll-view class="container" :scroll-y="isScroll">
- <view class="title">维修日期</view>
- <uni-datetime-picker disabled placeholder="请选择日期" type="date" v-model="repairDate" />
- <view class="title">维修内容</view>
- <view class="textarea">
- <textarea placeholder-style="color:#CCCCCC" placeholder="请输入维修内容" v-model="repairContent"></textarea>
- </view>
- <view class="title">维修结果</view>
- <!-- 录音区域 -->
- <view class="voice">
- <view class="voice_box" v-if="!recordingPath" @click="handleRecording">
- <img src="../../static/images/repairsImg/voice.png" />
- </view>
- <view v-if="!recordingPath" @click="handleRecording">点击录音</view>
- <view class="item_recording" v-if="recordingPath" @click="handlePlayRecording">
- <img :src="recordingImg" />
- {{ recordingTime }}″
- </view>
- <view class="recording_icon" v-if="recordingPath" @click="handleDeleteRecording">×</view>
- </view>
- <!-- 录音弹窗区域 -->
- <uni-popup :safe-area="true" background-color="#fff" ref="popup_recording">
- <view class="popup_recording">
- <recording @getTempFilePath="getTempFilePath" />
- </view>
- </uni-popup>
- <view class="title">关联耗材</view>
- <!-- 每一个耗材盒子区域 -->
- <view class="detail_box" v-for="(item, index) in goodList" :key="index">
- <view class="detail_box_item">
- <view class="item_key">耗材名称</view>
- <view class="item_value">{{ item.consumeName }}</view>
- </view>
- <view class="detail_box_item">
- <view class="item_key">耗材数量</view>
- <view class="item_value">
- <uni-number-box v-model="item.number" :min="0" @change="bindChange($event, index)"></uni-number-box>
- </view>
- </view>
- <view class="detail_box_item">
- <view class="item_key">耗材单价</view>
- <view class="item_value">
- <uni-easyinput
- type="number"
- :clearable="false"
- v-model="item.price"
- placeholder="请输入耗材单价"
- placeholderStyle="font-size:16px"
- @focus="handleFocus"
- @blur="handleChangePrice($event, item)"
- ></uni-easyinput>
- </view>
- </view>
- </view>
- <!-- 添加耗材区域 -->
- <view class="add" @click="handleAdd">
- <text>+</text>
- 添加耗材
- </view>
- <!-- 合计费用区域 -->
- <view class="total">
- <view>合计费用</view>
- <view>{{ countMoney }}元</view>
- </view>
- <view class="title">维修师傅</view>
- <view class="box">
- <img src="../../static/images/repairsImg/people.png" />
- {{ info.maintenancerName }}
- </view>
- <view class="title">手机</view>
- <view class="box">
- <img src="../../static/images/repairsImg/phone2.png" />
- {{ info.maintenancerPhone }}
- </view>
- <view class="title">现场拍照</view>
- <uni-file-picker
- ref="filePicker"
- limit="3"
- v-model="imgList"
- fileMediatype="image"
- :image-styles="imageStyles"
- mode="grid"
- @select="select"
- @delete="handleDelete"
- ></uni-file-picker>
- <view class="btn" @click="handleSub">确认提交</view>
- <!-- 用于图片压缩的canvas画布 -->
- <canvas
- :style="{
- width: cw + 'px',
- height: cw + 'px',
- position: 'absolute',
- zIndex: -1,
- left: '-10000rpx',
- top: '-10000rpx'
- }"
- canvas-id="zipCanvas"
- ></canvas>
- <!--画布结束-->
- </scroll-view>
- </template>
- <script>
- import recording from '../components/recording.vue'
- // 图片压缩方法
- import getLessLimitSizeImage from '../util/imageCompress.js'
- const innerAudioContext = uni.createInnerAudioContext()
- export default {
- components: {
- recording
- },
- data() {
- return {
- // 维修日期
- repairDate: '',
- // 维修内容
- repairContent: '',
- // 耗材列表
- goodList: [],
- // 显示的图片数据
- imgList: [],
- // 上传的图片数据
- subImgList: [],
- // 图片上传框的样式
- imageStyles: {
- width: 60,
- height: 60,
- border: {
- color: '#ccc',
- width: 1,
- style: 'dashed',
- radius: '9px'
- }
- },
- //画板边长默认是屏幕宽度,正方形画布
- cw: uni.getSystemInfoSync().windowWidth,
- // 录音文件路径
- recordingPath: '',
- // 录音图片地址
- recordingImg: '../../static/images/repairsImg/recording.jpg',
- // 录音时长
- recordingTime: 0,
- // 播放状态
- playStatus: false,
- // 定时器标识
- timer: null,
- // 订单详情信息
- info: {},
- // 是否允许页面滚动
- isScroll: true
- }
- },
- computed: {
- // 合计费用
- countMoney() {
- let countMoney = 0
- this.goodList.forEach((ele) => {
- countMoney += Number(ele.number) * Number(ele.price)
- })
- if (countMoney) {
- return countMoney
- } else {
- return 0
- }
- }
- },
- onLoad(options) {
- this.info = JSON.parse(options.info)
- this.getTodayTime()
- },
- mounted() {
- //在ios下静音时播放没有声音,默认为true,改为false就好了。
- uni.setInnerAudioOption({
- obeyMuteSwitch: false
- })
- uni.$on('addConsumable', this.addConsumable)
- },
- methods: {
- // 获取今天日期 YY-MM-DD
- getTodayTime() {
- let today = new Date()
- this.repairDate = `${today.getFullYear()}-${(today.getMonth() + 1).toString().padStart(2, 0)}-${today.getDate().toString().padStart(2, 0)}`
- },
- // 单价输入框输入回调 (失去焦点)
- handleChangePrice(e, item) {
- this.isScroll = true
- // 验证输入单价格式 只能是数字,小数点最多两位
- const reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/
- if (!reg.test(e.detail.value)) {
- uni.showToast({
- title: '请确定单价为数字,并且只能保留两位小数点',
- icon: 'none'
- })
- item.price = 0
- }
- },
- // 价格输入框聚焦回调
- handleFocus() {
- this.isScroll = false
- },
- // 全局自定义事件
- addConsumable(e) {
- // console.log(e)
- // 判断是否存在相同的耗材
- let flag = this.goodList.some((ele) => {
- return ele.consumeName === e.data.name
- })
- if (!flag) {
- this.$set(e.data, 'number', 1)
- this.$set(e.data, 'consumeName', e.data.name)
- this.$set(e.data, 'consumeId', e.data.id)
- this.$set(e.data, 'articleId', e.articleId)
- // this.$delete(e.data, 'name')
- // this.$delete(e.data, 'id')
- this.goodList.push(e.data)
- }
- },
- // 确认提交按钮回调
- handleSub() {
- // if (!this.goodList.length) {
- // uni.showToast({
- // title: '请添加耗材',
- // icon: 'none'
- // })
- // return
- // }
- // if (this.countMoney <= 0) {
- // uni.showToast({
- // title: '合计费用不能小于0元',
- // icon: 'none'
- // })
- // return
- // }
- if (this.subImgList.length === 0) {
- uni.showToast({
- title: '请上传现场照片',
- icon: 'none'
- })
- return
- }
- uni.showModal({
- title: '提示',
- content: '确认提交吗?',
- success: async (res) => {
- if (res.confirm) {
- // 维修内容
- console.log(this.repairContent)
- // 录音文件路径
- console.log(this.recordingPath)
- // 录音时长
- console.log(this.recordingTime)
- // 耗材集合
- console.log(this.goodList)
- // 总费用
- console.log(this.countMoney)
- // 现场拍照集合
- console.log(this.subImgList)
- const res = await this.$myRequest_repairs({
- url: '/repairRecord/finishOrder',
- method: 'post',
- data: {
- recordId: this.info.id,
- images: this.subImgList,
- content: this.repairContent,
- voice: this.recordingPath,
- voiceLength: this.recordingTime,
- consumes: this.goodList
- }
- })
- // console.log(res)
- if (res.code === '200') {
- uni.showToast({
- title: '提交成功',
- icon: 'success'
- })
- setTimeout(() => {
- uni.reLaunch({
- url: '/pagesRepairs/box/box'
- })
- }, 1500)
- }
- }
- }
- })
- },
- // 耗材数量计数器改变回调
- bindChange(e, index) {
- // console.log(e)
- // console.log(index)
- if (e === 0) {
- this.goodList.splice(index, 1)
- }
- },
- // 添加耗材按钮回调
- handleAdd() {
- let temList = JSON.stringify(this.goodList.map((ele) => ele.consumeId))
- uni.navigateTo({
- url: `/pagesRepairs/addGoods/addGoods?activeList=${temList}`
- })
- },
- // 选择图片回调
- select(e) {
- // console.log(e)
- e.tempFiles.forEach((item) => {
- //这里的id和页面中写的html代码的canvas的id要一致
- let canvasId = 'zipCanvas'
- //原图的路径
- let imagePath = item.path
- //大小限制1024kb
- let limitSize = 1024
- //初始绘画区域是画布自身的宽度也就是屏幕宽度
- let drawWidth = uni.getSystemInfoSync().windowWidth
- getLessLimitSizeImage(canvasId, imagePath, limitSize, drawWidth, (resPath) => {
- uni.showLoading({
- title: '上传中'
- })
- uni.uploadFile({
- url: `https://chtech.ncjti.edu.cn/campusMaintenance/repair-api/repair/api/repairRecord/uploadFile`,
- filePath: resPath,
- name: 'file',
- header: {
- token: uni.getStorageSync('repairsUserInfo').token,
- user_head: uni.getStorageSync('repairsUserInfo').userhead
- },
- success: (uploadFileRes) => {
- // console.log(JSON.parse(uploadFileRes.data))
- this.subImgList.push(JSON.parse(uploadFileRes.data).data.resultUrl)
- this.imgList.push({
- url: item.path,
- name: ''
- })
- uni.hideLoading()
- },
- fail: () => {
- uni.showToast({
- title: '上传失败',
- icon: 'error'
- })
- }
- })
- })
- })
- },
- // 删除图片回调
- handleDelete(e) {
- // console.log(e);
- const num = this.imgList.findIndex((v) => v.url === e.tempFilePath)
- this.subImgList.splice(num, 1)
- this.imgList.splice(num, 1)
- },
- // 点击录音按钮回调
- handleRecording() {
- uni.getSetting({
- success: (res) => {
- if (!res.authSetting['scope.record']) {
- uni.authorize({
- scope: 'scope.record',
- success(res) {
- // 授权成功
- uni.showToast({
- title: '授权成功',
- icon: 'none'
- })
- },
- fail() {
- uni.showModal({
- content: '检测到您没打开麦克风权限,是否去设置打开?',
- confirmText: '确认',
- cancelText: '取消',
- success: (res) => {
- if (res.confirm) {
- uni.openSetting({
- success: (res) => {}
- })
- } else {
- uni.showToast({
- title: '获取麦克风权限失败',
- icon: 'none'
- })
- }
- }
- })
- }
- })
- } else {
- this.$refs.popup_recording.open('bottom')
- }
- },
- fail() {
- uni.showToast({
- title: '获取麦克风权限失败',
- icon: 'none'
- })
- }
- })
- },
- // 点击录音播放回调
- handlePlayRecording() {
- innerAudioContext.src = this.recordingPath
- if (!this.playStatus) {
- this.playStatus = true
- innerAudioContext.play()
- this.timer = setInterval(() => {
- if (this.recordingImg == '../../static/images/repairsImg/recording.jpg') {
- this.recordingImg = '../../static/images/repairsImg/recording2.jpg'
- } else if (this.recordingImg == '../../static/images/repairsImg/recording2.jpg') {
- this.recordingImg = '../../static/images/repairsImg/recording3.jpg'
- } else if (this.recordingImg == '../../static/images/repairsImg/recording3.jpg') {
- this.recordingImg = '../../static/images/repairsImg/recording.jpg'
- }
- }, 300)
- //播放结束
- innerAudioContext.onEnded(() => {
- clearInterval(this.timer)
- this.timer = null
- this.recordingImg = '../../static/images/repairsImg/recording.jpg'
- this.playStatus = false
- })
- } else {
- clearInterval(this.timer)
- this.recordingImg = '../../static/images/repairsImg/recording.jpg'
- this.playStatus = false
- innerAudioContext.stop()
- }
- },
- // 删除录音回调
- handleDeleteRecording() {
- if (this.playStatus) {
- uni.showToast({
- title: '播放中不能删除',
- icon: 'none',
- mask: true
- })
- } else {
- uni.showModal({
- title: '提示',
- content: '确定删除录音吗?',
- success: (res) => {
- if (res.confirm) {
- this.recordingPath = ''
- this.recordingTime = 0
- }
- }
- })
- }
- },
- // 自定义事件回调,获取录音文件路径
- getTempFilePath(path, time) {
- this.recordingPath = path
- this.recordingTime = time
- this.$refs.popup_recording.close()
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .container {
- box-sizing: border-box;
- padding: 0 30rpx;
- width: 100%;
- .title {
- display: flex;
- align-items: center;
- height: 107rpx;
- font-size: 36rpx;
- font-weight: bold;
- }
- .textarea {
- height: 310rpx;
- border-radius: 10rpx;
- border: 1rpx solid #cccccc;
- textarea {
- box-sizing: border-box;
- padding: 25rpx 35rpx;
- width: 100%;
- font-size: 32rpx;
- }
- }
- .voice {
- display: flex;
- align-items: center;
- height: 94rpx;
- font-size: 32rpx;
- color: #cccccc;
- border-radius: 10rpx;
- border: 1rpx solid #cccccc;
- .voice_box {
- display: flex;
- justify-content: center;
- align-items: center;
- margin: 0 38rpx 0 33rpx;
- width: 101rpx;
- height: 47rpx;
- border-radius: 33rpx;
- box-shadow: 0px 0px 4rpx rgba(0, 0, 0, 0.25);
- img {
- width: 33rpx;
- height: 33rpx;
- }
- }
- .item_recording {
- margin-left: 35rpx;
- display: flex;
- align-items: center;
- width: 230rpx;
- height: 65rpx;
- color: #000;
- border-radius: 100rpx;
- border: 1rpx solid #cccccc;
- img {
- margin: 0 12rpx;
- width: 40rpx;
- height: 40rpx;
- }
- }
- .recording_icon {
- margin-left: auto;
- margin-right: 35rpx;
- font-size: 40rpx;
- }
- }
- .popup_recording {
- width: 100%;
- height: 460rpx;
- background-color: #fff;
- }
- .detail_box {
- box-sizing: border-box;
- margin-bottom: 46rpx;
- padding: 5rpx 30rpx 0;
- width: 690rpx;
- height: 284rpx;
- border-radius: 9rpx;
- box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.25);
- .detail_box_item {
- display: flex;
- justify-content: space-between;
- align-items: center;
- height: 92rpx;
- font-size: 32rpx;
- border-bottom: 1rpx solid #e5e5e5;
- .item_key {
- width: 150rpx;
- color: #808080;
- }
- .item_value {
- font-weight: bold;
- ::v-deep .is-input-border {
- text-align: right;
- border: none;
- }
- ::v-deep .uni-easyinput__content-input {
- font-size: 32rpx;
- }
- }
- }
- }
- .add {
- display: flex;
- justify-content: center;
- align-items: center;
- width: 690rpx;
- height: 90rpx;
- color: #6fb6b8;
- font-size: 32rpx;
- border-radius: 9rpx;
- background-color: #ebf2f2;
- text {
- margin-right: 10rpx;
- font-size: 48rpx;
- }
- }
- .total {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin: auto;
- width: 622rpx;
- height: 100rpx;
- font-size: 32rpx;
- font-weight: bold;
- border-bottom: 1rpx solid #e5e5e5;
- }
- .box {
- display: flex;
- align-items: center;
- height: 94rpx;
- font-size: 32rpx;
- border-radius: 10rpx;
- border: 1rpx solid #cccccc;
- img {
- margin: 0 14rpx 0 30rpx;
- width: 40rpx;
- height: 40rpx;
- }
- }
- .btn {
- display: flex;
- justify-content: center;
- align-items: center;
- margin: 65rpx 0 60rpx;
- height: 100rpx;
- color: #fff;
- font-size: 32rpx;
- border-radius: 12rpx;
- background-color: #6fb6b8;
- }
- }
- </style>
|