complaint.vue 10 KB

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