complaint.vue 10 KB

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