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. 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/mhotel/mhotel/uploadhimage.action`,
  197. url: `https://chtech.ncjti.edu.cn/homestay/file/cos/upload`,
  198. filePath: ele.tempFilePath,
  199. // name: 'myFile',
  200. name: 'files',
  201. success: (uploadFileRes) => {
  202. // console.log(JSON.parse(uploadFileRes.data))
  203. let temRes = JSON.parse(uploadFileRes.data)
  204. if (temRes.code === 200 || temRes.code === 1) {
  205. this.subImgList.push(temRes.data)
  206. // console.log(this.subImgList)
  207. this.viewImgList.push({
  208. url: temRes.data,
  209. fileType: ele.fileType === 'image' ? 'image' : 'video'
  210. })
  211. // console.log(this.viewImgList)
  212. } else {
  213. uni.showToast({
  214. title: temRes.message || '上传失败',
  215. icon: 'none'
  216. })
  217. }
  218. uni.hideLoading()
  219. },
  220. fail: () => {
  221. uni.showToast({
  222. title: '上传失败',
  223. icon: 'error'
  224. })
  225. }
  226. })
  227. },
  228. // 提交按钮回调
  229. async handleSub() {
  230. const reg = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>《》/?~!@#¥……&*()——|{}【】‘;:”“'。,、? ]")
  231. if (!this.inputValue) {
  232. uni.showToast({
  233. title: '请输入标题',
  234. icon: 'none',
  235. mask: true
  236. })
  237. return
  238. }
  239. if (reg.test(this.inputValue)) {
  240. uni.showToast({
  241. title: '标题不能含有特殊字符和标点符号',
  242. icon: 'none',
  243. mask: true
  244. })
  245. return
  246. }
  247. if (!this.textareaValue) {
  248. uni.showToast({
  249. title: '请输入投诉内容',
  250. icon: 'none',
  251. mask: true
  252. })
  253. return
  254. }
  255. let time = dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss')
  256. const res = await this.$myRequest({
  257. url: '/mhotel/complaintorderComplaint.action',
  258. method: 'post',
  259. data: {
  260. bookingId: this.bookingId,
  261. hotelId: this.hotelId,
  262. houseId: this.houseId,
  263. title: this.inputValue,
  264. content: this.textareaValue,
  265. createId: uni.getStorageSync('userInfo').id,
  266. createDate: time,
  267. modifyDate: time,
  268. pictureList: this.subImgList
  269. }
  270. })
  271. // console.log(res)
  272. if (res.code === 200) {
  273. uni.navigateTo({
  274. url: `/pages/complaintStatus/complaintStatus?status=1`
  275. })
  276. } else {
  277. uni.navigateTo({
  278. url: `/pages/complaintStatus/complaintStatus?status=2`
  279. })
  280. }
  281. },
  282. // 删除图片回调
  283. handleDelete(index) {
  284. this.subImgList.splice(index, 1)
  285. this.viewImgList.splice(index, 1)
  286. },
  287. handleLook(url, current) {
  288. if (this.videoContext) {
  289. this.videoContext.stop()
  290. }
  291. uni.previewImage({
  292. urls: [url],
  293. current
  294. })
  295. }
  296. }
  297. }
  298. </script>
  299. <style lang="scss" scoped>
  300. .container {
  301. display: flex;
  302. flex-direction: column;
  303. min-height: 100vh;
  304. background-color: #f2f3f5;
  305. .title {
  306. display: flex;
  307. align-items: center;
  308. margin: 20rpx 0;
  309. padding: 0 20rpx;
  310. height: 144rpx;
  311. background-color: #fff;
  312. .title_key {
  313. font-size: 28rpx;
  314. font-weight: bold;
  315. }
  316. .title_value {
  317. display: flex;
  318. align-items: center;
  319. box-sizing: border-box;
  320. padding: 0 26rpx;
  321. margin-left: 30rpx;
  322. width: 625rpx;
  323. height: 80rpx;
  324. border-radius: 11rpx;
  325. background-color: #f2f2f2;
  326. input {
  327. width: 100%;
  328. }
  329. }
  330. }
  331. .operation {
  332. padding: 20rpx 20rpx 33rpx;
  333. margin-bottom: 20rpx;
  334. background-color: #fff;
  335. .operation_input {
  336. box-sizing: border-box;
  337. padding: 20rpx;
  338. width: 710rpx;
  339. height: 282rpx;
  340. border-radius: 9rpx;
  341. background-color: #f2f2f2;
  342. .textarea {
  343. width: 100%;
  344. height: 203rpx;
  345. }
  346. .operation_count {
  347. height: 39rpx;
  348. text-align: end;
  349. color: #b3b3b3;
  350. font-size: 24rpx;
  351. }
  352. }
  353. .operation_uploading {
  354. display: grid;
  355. gap: 21rpx;
  356. grid-template-columns: repeat(auto-fill, 124rpx);
  357. margin-top: 20rpx;
  358. ::v-deep .uni-file-picker__item {
  359. background-color: red;
  360. }
  361. .uploading_box {
  362. position: relative;
  363. display: flex;
  364. flex-direction: column;
  365. justify-content: center;
  366. align-items: center;
  367. width: 124rpx;
  368. height: 124rpx;
  369. border-radius: 7rpx;
  370. background-color: #f2f2f2;
  371. .img {
  372. width: 40rpx;
  373. height: 40rpx;
  374. }
  375. .msg {
  376. margin-top: 5rpx;
  377. color: #a6a6a6;
  378. font-size: 20rpx;
  379. }
  380. .img2 {
  381. width: 124rpx;
  382. height: 124rpx;
  383. border-radius: 7rpx;
  384. }
  385. .video {
  386. width: 124rpx;
  387. height: 124rpx;
  388. border-radius: 7rpx;
  389. }
  390. .icon {
  391. position: absolute;
  392. top: 0;
  393. right: 0;
  394. display: flex;
  395. justify-content: center;
  396. align-items: center;
  397. width: 30rpx;
  398. height: 30rpx;
  399. border-radius: 7rpx;
  400. background-color: rgba(000, 000, 000, 0.5);
  401. img {
  402. width: 30rpx;
  403. height: 30rpx;
  404. }
  405. }
  406. }
  407. }
  408. }
  409. .btn {
  410. display: flex;
  411. justify-content: center;
  412. align-items: center;
  413. margin: 368rpx auto 78rpx;
  414. width: 710rpx;
  415. height: 96rpx;
  416. color: #fff;
  417. font-size: 32rpx;
  418. border-radius: 64rpx;
  419. background-color: #096562;
  420. }
  421. }
  422. </style>