complaint.vue 10 KB

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