complaint.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. <template>
  2. <view class="container">
  3. <!-- 标题区域 -->
  4. <view class="title">
  5. <view class="title_key">标题</view>
  6. <view class="title_value">
  7. <input maxlength="10" type="text" placeholder="请输入标题,不要超过10个字哦~" placeholder-style="color:#B3B3B3;fontSize:28rpx;" v-model="inputValue" />
  8. </view>
  9. </view>
  10. <!-- 评价上传图片视频区域 -->
  11. <view class="operation">
  12. <!-- 输入框区域 -->
  13. <view class="operation_input">
  14. <textarea
  15. maxlength="1000"
  16. class="textarea"
  17. placeholder-style="color:#B3B3B3;font-size:24rpx"
  18. placeholder="写出你的相关问题"
  19. v-model="textareaValue"
  20. @input="handleInput"
  21. />
  22. <view class="operation_count">({{ textareaValuelength }}/1000)</view>
  23. </view>
  24. <!-- 上传区域 -->
  25. <view class="operation_uploading">
  26. <view class="uploading_box" @click="handleUpLoad">
  27. <img class="img" src="../../static/index/photo.png" />
  28. <view class="msg">照片/视频</view>
  29. </view>
  30. <view class="uploading_box" v-for="(ele, index) in viewImgList" :key="index">
  31. <img class="img2" mode="aspectFill" v-if="ele.fileType === 'image'" :src="ele.url" @click="handleLook(ele.url, index)" />
  32. <video
  33. id="myVideo"
  34. class="video"
  35. :show-fullscreen-btn="false"
  36. :show-play-btn="false"
  37. v-if="ele.fileType === 'video'"
  38. :src="ele.url"
  39. @fullscreenchange="fullscreenchange"
  40. @click="handleClickVideo('myVideo')"
  41. ></video>
  42. <view class="icon" @click="handleDelete(index)">
  43. <img src="../../static/index/close2.png" />
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. <!-- 提交按钮区域 -->
  49. <view class="btn" @click="handleSub">提交</view>
  50. <!-- 用于图片压缩的canvas画布 -->
  51. <canvas
  52. :style="{
  53. width: cw + 'px',
  54. height: cw + 'px',
  55. position: 'absolute',
  56. zIndex: -1,
  57. left: '-10000rpx',
  58. top: '-10000rpx'
  59. }"
  60. canvas-id="zipCanvas"
  61. ></canvas>
  62. <!--画布结束-->
  63. </view>
  64. </template>
  65. <script>
  66. import getLessLimitSizeImage from '../../util/imageCompress.js'
  67. var dayjs = require('dayjs')
  68. import { cos } from '@/util/cos.js'
  69. export default {
  70. data() {
  71. return {
  72. // 标题输入框绑定数据
  73. inputValue: '',
  74. // 评价绑定数据
  75. textareaValue: '',
  76. // 评价文字长度
  77. textareaValuelength: 0,
  78. // 上传的图片数据
  79. subImgList: [],
  80. // 显示的图片数据
  81. viewImgList: [],
  82. // 订单id
  83. bookingId: '',
  84. // 民宿id
  85. hotelId: '',
  86. // 房间id
  87. houseId: '',
  88. //画板边长默认是屏幕宽度,正方形画布
  89. cw: uni.getSystemInfoSync().windowWidth,
  90. // video 上下文 videoContext 对象
  91. videoContext: null,
  92. // 是否是全屏状态
  93. isFullScreen: false
  94. }
  95. },
  96. onLoad(options) {
  97. this.bookingId = options.bookingId
  98. this.hotelId = options.hotelId
  99. this.houseId = options.houseId
  100. },
  101. methods: {
  102. // 进入全屏和退出全屏时触发的回调
  103. fullscreenchange(e) {
  104. this.isFullScreen = e.detail.fullScreen
  105. },
  106. // 点击视频控件时触发的回调
  107. handleClickVideo(id) {
  108. this.videoContext = uni.createVideoContext(id)
  109. if (this.isFullScreen) {
  110. this.videoContext.stop()
  111. this.videoContext.exitFullScreen()
  112. } else {
  113. this.videoContext.requestFullScreen()
  114. this.videoContext.play()
  115. }
  116. },
  117. // 评价输入框输入回调
  118. handleInput(e) {
  119. this.textareaValuelength = e.detail.cursor
  120. },
  121. // 上传图片回调
  122. handleUpLoad() {
  123. uni.chooseMedia({
  124. count: 6 - this.subImgList.length,
  125. mediaType: ['mix'],
  126. maxDuration: 10,
  127. success: (res) => {
  128. // 判断视频文件不能超过1个
  129. let temList = [...this.viewImgList, ...res.tempFiles]
  130. let temList2 = temList.filter((ele) => ele.fileType === 'video')
  131. if (temList2.length > 1) {
  132. uni.showToast({
  133. title: '最多只能上传1个视频',
  134. icon: 'none'
  135. })
  136. return
  137. }
  138. res.tempFiles.forEach((ele) => {
  139. if (ele.fileType === 'image' && ele.size > 1024 * 1024 * 3) {
  140. //这里的id和页面中写的html代码的canvas的id要一致
  141. let canvasId = 'zipCanvas'
  142. //原图的路径
  143. let imagePath = ele.tempFilePath
  144. //大小限制1024kb
  145. let limitSize = 1024 * 3
  146. //初始绘画区域是画布自身的宽度也就是屏幕宽度
  147. let drawWidth = uni.getSystemInfoSync().windowWidth
  148. // 图片过大压缩
  149. getLessLimitSizeImage(canvasId, imagePath, limitSize, drawWidth, (resPath) => {
  150. this.handleUploadMini({ tempFilePath: resPath, fileType: ele.fileType })
  151. })
  152. } else if (ele.fileType === 'video' && ele.size > 1024 * 1024 * 5) {
  153. // 视频过大压缩
  154. uni.compressVideo({
  155. src: ele.tempFilePath,
  156. quality: 'low',
  157. // bitrate: 60000,
  158. // fps: 30,
  159. // resolution: 1,
  160. success: (res) => {
  161. // console.log('压缩后', res)
  162. this.handleUploadMini({ tempFilePath: res.tempFilePath, fileType: ele.fileType })
  163. },
  164. fail: (err) => {
  165. // console.log(err)
  166. uni.showToast(
  167. {
  168. title: '视频压缩失败',
  169. icon: 'none'
  170. },
  171. 2000
  172. )
  173. }
  174. })
  175. } else {
  176. this.handleUploadMini(ele)
  177. }
  178. })
  179. },
  180. fail: (err) => {
  181. console.log(err)
  182. uni.showToast({
  183. title: '选择文件失败',
  184. icon: 'none',
  185. mask: true
  186. })
  187. }
  188. })
  189. },
  190. handleUploadMini(ele) {
  191. // console.log(ele)
  192. // 开始上传
  193. uni.showLoading({
  194. title: '上传中'
  195. })
  196. let filePath = ele.tempFilePath
  197. let Key = filePath.substr(filePath.lastIndexOf('/') + 1)
  198. cos.postObject(
  199. {
  200. Bucket: 'jinganminsu-1320402385',
  201. Region: 'ap-nanjing',
  202. Key: Key,
  203. FilePath: filePath,
  204. onProgress: (info) => {
  205. // console.log(info)
  206. }
  207. },
  208. (err, data) => {
  209. if (err) {
  210. console.log('上传失败', err)
  211. } else {
  212. // console.log('上传成功', data)
  213. uni.hideLoading()
  214. let imgUrl = 'https://' + data.Location
  215. this.subImgList.push(imgUrl)
  216. this.viewImgList.push({
  217. url: imgUrl,
  218. fileType: ele.fileType === 'image' ? 'image' : 'video'
  219. })
  220. }
  221. }
  222. )
  223. },
  224. // 提交按钮回调
  225. async handleSub() {
  226. const reg = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>《》/?~!@#¥……&*()——|{}【】‘;:”“'。,、? ]")
  227. if (!this.inputValue) {
  228. uni.showToast({
  229. title: '请输入标题',
  230. icon: 'none',
  231. mask: true
  232. })
  233. return
  234. }
  235. if (reg.test(this.inputValue)) {
  236. uni.showToast({
  237. title: '标题不能含有特殊字符和标点符号',
  238. icon: 'none',
  239. mask: true
  240. })
  241. return
  242. }
  243. if (!this.textareaValue) {
  244. uni.showToast({
  245. title: '请输入投诉内容',
  246. icon: 'none',
  247. mask: true
  248. })
  249. return
  250. }
  251. let time = dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss')
  252. const res = await this.$myRequest({
  253. url: '/mhotel/complaintorderComplaint.action',
  254. method: 'post',
  255. data: {
  256. bookingId: this.bookingId,
  257. hotelId: this.hotelId,
  258. houseId: this.houseId,
  259. title: this.inputValue,
  260. content: this.textareaValue,
  261. createId: uni.getStorageSync('userInfo').id,
  262. createDate: time,
  263. modifyDate: time,
  264. pictureList: this.subImgList
  265. }
  266. })
  267. // console.log(res)
  268. if (res.code === 200) {
  269. uni.navigateTo({
  270. url: `/pages/complaintStatus/complaintStatus?status=1`
  271. })
  272. } else {
  273. uni.navigateTo({
  274. url: `/pages/complaintStatus/complaintStatus?status=2`
  275. })
  276. }
  277. },
  278. // 删除图片回调
  279. handleDelete(index) {
  280. this.subImgList.splice(index, 1)
  281. this.viewImgList.splice(index, 1)
  282. },
  283. handleLook(url, current) {
  284. if (this.videoContext) {
  285. this.videoContext.stop()
  286. }
  287. uni.previewImage({
  288. urls: [url],
  289. current
  290. })
  291. }
  292. }
  293. }
  294. </script>
  295. <style lang="scss" scoped>
  296. .container {
  297. display: flex;
  298. flex-direction: column;
  299. min-height: 100vh;
  300. background-color: #f2f3f5;
  301. .title {
  302. display: flex;
  303. align-items: center;
  304. margin: 20rpx 0;
  305. padding: 0 20rpx;
  306. height: 144rpx;
  307. background-color: #fff;
  308. .title_key {
  309. font-size: 28rpx;
  310. font-weight: bold;
  311. }
  312. .title_value {
  313. display: flex;
  314. align-items: center;
  315. box-sizing: border-box;
  316. padding: 0 26rpx;
  317. margin-left: 30rpx;
  318. width: 625rpx;
  319. height: 80rpx;
  320. border-radius: 11rpx;
  321. background-color: #f2f2f2;
  322. input {
  323. width: 100%;
  324. }
  325. }
  326. }
  327. .operation {
  328. padding: 20rpx 20rpx 33rpx;
  329. margin-bottom: 20rpx;
  330. background-color: #fff;
  331. .operation_input {
  332. box-sizing: border-box;
  333. padding: 20rpx;
  334. width: 710rpx;
  335. height: 282rpx;
  336. border-radius: 9rpx;
  337. background-color: #f2f2f2;
  338. .textarea {
  339. width: 100%;
  340. height: 203rpx;
  341. }
  342. .operation_count {
  343. height: 39rpx;
  344. text-align: end;
  345. color: #b3b3b3;
  346. font-size: 24rpx;
  347. }
  348. }
  349. .operation_uploading {
  350. display: grid;
  351. gap: 21rpx;
  352. grid-template-columns: repeat(auto-fill, 124rpx);
  353. margin-top: 20rpx;
  354. ::v-deep .uni-file-picker__item {
  355. background-color: red;
  356. }
  357. .uploading_box {
  358. position: relative;
  359. display: flex;
  360. flex-direction: column;
  361. justify-content: center;
  362. align-items: center;
  363. width: 124rpx;
  364. height: 124rpx;
  365. border-radius: 7rpx;
  366. background-color: #f2f2f2;
  367. .img {
  368. width: 40rpx;
  369. height: 40rpx;
  370. }
  371. .msg {
  372. margin-top: 5rpx;
  373. color: #a6a6a6;
  374. font-size: 20rpx;
  375. }
  376. .img2 {
  377. width: 124rpx;
  378. height: 124rpx;
  379. border-radius: 7rpx;
  380. }
  381. .video {
  382. width: 124rpx;
  383. height: 124rpx;
  384. border-radius: 7rpx;
  385. }
  386. .icon {
  387. position: absolute;
  388. top: 0;
  389. right: 0;
  390. display: flex;
  391. justify-content: center;
  392. align-items: center;
  393. width: 30rpx;
  394. height: 30rpx;
  395. border-radius: 7rpx;
  396. background-color: rgba(000, 000, 000, 0.5);
  397. img {
  398. width: 30rpx;
  399. height: 30rpx;
  400. }
  401. }
  402. }
  403. }
  404. }
  405. .btn {
  406. display: flex;
  407. justify-content: center;
  408. align-items: center;
  409. margin: 368rpx auto 78rpx;
  410. width: 710rpx;
  411. height: 96rpx;
  412. color: #fff;
  413. font-size: 32rpx;
  414. border-radius: 64rpx;
  415. background-color: #096562;
  416. }
  417. }
  418. </style>