evaluate.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. <template>
  2. <view class="container">
  3. <!-- 页面标题区域 -->
  4. <view class="header" :style="{ height: customBarH * 2 + 'rpx', paddingTop: statusBarH * 2 + 'rpx' }">
  5. <img src="../../static/index/left2.png" :style="{ paddingTop: statusBarH * 2 + 'rpx' }" @click="handleBack" />
  6. <view class="header_text">评价</view>
  7. </view>
  8. <!-- 评分区域 -->
  9. <view class="rate">
  10. <view class="rate_key">民宿评分</view>
  11. <uni-rate v-model="rateValue" size="18" @change="onChange($event, 1)" />
  12. <view class="rate_value">{{ msg }}</view>
  13. </view>
  14. <!-- 评价上传图片视频区域 -->
  15. <view class="operation">
  16. <!-- 输入框区域 -->
  17. <view class="operation_input">
  18. <textarea
  19. maxlength="1000"
  20. class="textarea"
  21. placeholder-style="color:#B3B3B3;font-size:24rpx"
  22. placeholder="写出你的感受,可以帮助其他小伙伴哦~"
  23. v-model="textareaValue"
  24. @input="handleInput"
  25. />
  26. <view class="operation_count">({{ textareaValuelength }}/1000)</view>
  27. </view>
  28. <!-- 上传区域 -->
  29. <view class="operation_uploading">
  30. <view class="uploading_box" @click="handleUpLoad">
  31. <img class="img" src="../../static/index/photo.png" />
  32. <view class="msg">照片/视频</view>
  33. </view>
  34. <view class="uploading_box" v-for="(ele, index) in viewImgList" :key="index">
  35. <img class="img2" mode="aspectFill" v-if="ele.fileType === 'image'" :src="ele.url" @click="handleLook(ele.url, index)" />
  36. <video
  37. id="myVideo"
  38. class="video"
  39. :show-fullscreen-btn="false"
  40. :show-play-btn="false"
  41. v-if="ele.fileType === 'video'"
  42. :src="ele.url"
  43. @fullscreenchange="fullscreenchange"
  44. @click="handleClickVideo('myVideo')"
  45. ></video>
  46. <view class="icon" @click="handleDelete(index)">
  47. <img src="../../static/index/close2.png" />
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. <!-- 总体评价区域 -->
  53. <view class="foot">
  54. <!-- 民宿位置评价 -->
  55. <view class="foot_box">
  56. <view class="box_key">民宿位置</view>
  57. <uni-rate v-model="rateLocation" size="18" @change="onChange($event, 2)" />
  58. <view class="box_value">{{ msgLocation }}</view>
  59. </view>
  60. <!-- 民宿设施评价 -->
  61. <view class="foot_box">
  62. <view class="box_key">民宿设施</view>
  63. <uni-rate v-model="rateFacility" size="18" @change="onChange($event, 3)" />
  64. <view class="box_value">{{ msgFacility }}</view>
  65. </view>
  66. <!-- 民宿服务评价 -->
  67. <view class="foot_box">
  68. <view class="box_key">民宿服务</view>
  69. <uni-rate v-model="rateServe" size="18" @change="onChange($event, 4)" />
  70. <view class="box_value">{{ msgServe }}</view>
  71. </view>
  72. <!-- 民宿卫生评价 -->
  73. <view class="foot_box">
  74. <view class="box_key">民宿卫生</view>
  75. <uni-rate v-model="rateHygiene" size="18" @change="onChange($event, 5)" />
  76. <view class="box_value">{{ msgHygiene }}</view>
  77. </view>
  78. </view>
  79. <!-- 提交按钮区域 -->
  80. <view class="foot_btn" @click="handleSub">提交</view>
  81. <!-- 用于图片压缩的canvas画布 -->
  82. <canvas
  83. :style="{
  84. width: cw + 'px',
  85. height: cw + 'px',
  86. position: 'absolute',
  87. zIndex: -1,
  88. left: '-10000rpx',
  89. top: '-10000rpx'
  90. }"
  91. canvas-id="zipCanvas"
  92. ></canvas>
  93. <!--画布结束-->
  94. </view>
  95. </template>
  96. <script>
  97. // 图片压缩方法
  98. import getLessLimitSizeImage from '@/util/imageCompress.js'
  99. var dayjs = require('dayjs')
  100. export default {
  101. data() {
  102. return {
  103. // 状态栏高度
  104. statusBarH: 0,
  105. // 胶囊按钮栏高度
  106. customBarH: 0,
  107. // 民宿评分
  108. rateValue: 0,
  109. msg: '',
  110. // 评价绑定数据
  111. textareaValue: '',
  112. // 评价文字长度
  113. textareaValuelength: 0,
  114. // 上传的图片数据
  115. subImgList: [],
  116. // 显示的图片数据
  117. viewImgList: [],
  118. // 民宿位置评分
  119. rateLocation: 0,
  120. msgLocation: '',
  121. // 民宿设施评分
  122. rateFacility: 0,
  123. msgFacility: '',
  124. // 民宿服务评分
  125. rateServe: 0,
  126. msgServe: '',
  127. // 民宿卫生评分
  128. rateHygiene: 0,
  129. msgHygiene: '',
  130. // 订单id
  131. bookingId: '',
  132. // 民宿id
  133. hotelId: '',
  134. // 房间id
  135. houseId: '',
  136. //画板边长默认是屏幕宽度,正方形画布
  137. cw: uni.getSystemInfoSync().windowWidth,
  138. // video 上下文 videoContext 对象
  139. videoContext: null,
  140. // 是否是全屏状态
  141. isFullScreen: false
  142. }
  143. },
  144. created() {
  145. // 获取系统信息
  146. uni.getSystemInfo({
  147. success: (e) => {
  148. // 获取状态栏高度
  149. this.statusBarH = e.statusBarHeight + 10
  150. // // 获取菜单按钮栏高度
  151. let custom = uni.getMenuButtonBoundingClientRect()
  152. this.customBarH = custom.height + 10
  153. }
  154. })
  155. },
  156. onLoad(options) {
  157. // console.log(options)
  158. this.bookingId = options.bookingId
  159. this.hotelId = options.hotelId
  160. this.houseId = options.houseId
  161. },
  162. methods: {
  163. // 进入全屏和退出全屏时触发的回调
  164. fullscreenchange(e) {
  165. this.isFullScreen = e.detail.fullScreen
  166. },
  167. // 点击视频控件时触发的回调
  168. handleClickVideo(id) {
  169. this.videoContext = uni.createVideoContext(id)
  170. if (this.isFullScreen) {
  171. this.videoContext.stop()
  172. this.videoContext.exitFullScreen()
  173. } else {
  174. this.videoContext.requestFullScreen()
  175. this.videoContext.play()
  176. }
  177. },
  178. // 点击页面标题返回箭头回调
  179. handleBack() {
  180. uni.showModal({
  181. content: '确认退出评价吗,已编辑的内容将不保存',
  182. cancelText: '退出评价',
  183. cancelColor: '#808080',
  184. confirmText: '继续写评',
  185. confirmColor: '#000000',
  186. success: (res) => {
  187. if (res.confirm) {
  188. } else if (res.cancel) {
  189. uni.navigateBack(1)
  190. }
  191. }
  192. })
  193. },
  194. // 点击提交按钮回调
  195. async handleSub() {
  196. if (!this.rateValue || !this.rateLocation || !this.rateFacility || !this.rateHygiene || !this.rateServe) {
  197. uni.showToast({
  198. title: '请评分后再提交',
  199. icon: 'none',
  200. mask: true
  201. })
  202. return
  203. }
  204. let userInfo = uni.getStorageSync('userInfo')
  205. let time = dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss')
  206. const res = await this.$myRequest({
  207. url: '/mhotel/abcaorderRate.action',
  208. method: 'post',
  209. data: {
  210. bookingId: this.bookingId,
  211. hotelId: this.hotelId,
  212. houseId: this.houseId,
  213. content: this.textareaValue,
  214. commentStatus: 1,
  215. score: this.rateValue,
  216. scoreWs: this.rateHygiene,
  217. scoreFw: this.rateServe,
  218. scoreSs: this.rateFacility,
  219. scoreWz: this.rateLocation,
  220. createId: userInfo.id,
  221. createUsername: userInfo.user_name,
  222. createDate: time,
  223. modifyDate: time,
  224. pictureList: this.subImgList
  225. }
  226. })
  227. // console.log(res)
  228. if (res.code === 200) {
  229. uni.showToast({
  230. title: '评价成功',
  231. icon: 'success',
  232. mask: true
  233. })
  234. setTimeout(() => {
  235. uni.reLaunch({
  236. url: `/pages/evaluateStatus/evaluateStatus?status=1`
  237. })
  238. }, 1500)
  239. } else {
  240. uni.showToast({
  241. title: res.message,
  242. icon: 'none',
  243. mask: true
  244. })
  245. setTimeout(() => {
  246. uni.navigateTo({
  247. url: `/pages/evaluateStatus/evaluateStatus?status=2`
  248. })
  249. }, 1500)
  250. }
  251. },
  252. // 上传图片回调
  253. handleUpLoad() {
  254. uni.chooseMedia({
  255. count: 6,
  256. mediaType: ['mix'],
  257. success: (res) => {
  258. // console.log(res)
  259. // console.log(res.tempFiles)
  260. // 判断文件不能超过6个
  261. if (this.subImgList.length + res.tempFiles.length > 6) {
  262. uni.showToast({
  263. title: '最多只能上传6个图片/视频',
  264. icon: 'none'
  265. })
  266. return
  267. }
  268. // 判断视频文件不能超过1个
  269. let temList = [...this.viewImgList, ...res.tempFiles]
  270. let temList2 = temList.filter((ele) => ele.fileType === 'video')
  271. if (temList2.length > 1) {
  272. uni.showToast({
  273. title: '最多只能上传1个视频',
  274. icon: 'none'
  275. })
  276. return
  277. }
  278. res.tempFiles.forEach((ele) => {
  279. if (ele.fileType === 'image' && ele.size > 1024 * 1024 * 3) {
  280. //这里的id和页面中写的html代码的canvas的id要一致
  281. let canvasId = 'zipCanvas'
  282. //原图的路径
  283. let imagePath = ele.tempFilePath
  284. //大小限制1024kb
  285. let limitSize = 1024 * 3
  286. //初始绘画区域是画布自身的宽度也就是屏幕宽度
  287. let drawWidth = uni.getSystemInfoSync().windowWidth
  288. // 图片过大压缩
  289. getLessLimitSizeImage(canvasId, imagePath, limitSize, drawWidth, (resPath) => {
  290. this.handleUploadMini({ tempFilePath: resPath, fileType: ele.fileType })
  291. })
  292. } else if (ele.fileType === 'video' && ele.size > 1024 * 1024 * 5) {
  293. uni.compressVideo({
  294. src: ele.tempFilePath,
  295. quality: 'low',
  296. // bitrate: 60000,
  297. // fps: 30,
  298. // resolution: 1,
  299. success: (res) => {
  300. // console.log('压缩后', res)
  301. this.handleUploadMini({ tempFilePath: res.tempFilePath, fileType: ele.fileType })
  302. },
  303. fail: (err) => {
  304. // console.log(err)
  305. uni.showToast(
  306. {
  307. title: '视频压缩失败',
  308. icon: 'none'
  309. },
  310. 2000
  311. )
  312. }
  313. })
  314. } else {
  315. this.handleUploadMini(ele)
  316. }
  317. })
  318. }
  319. })
  320. },
  321. handleUploadMini(ele) {
  322. // console.log(ele)
  323. // 开始上传
  324. uni.showLoading({
  325. title: '上传中'
  326. })
  327. uni.uploadFile({
  328. // url: `https://chtech.ncjti.edu.cn/hotelReservation/mhotel/mhotel/uploadhimage.action`,
  329. url: `https://chtech.ncjti.edu.cn/homestay/file/cos/upload`,
  330. filePath: ele.tempFilePath,
  331. // name: 'myFile',
  332. name: 'files',
  333. success: (uploadFileRes) => {
  334. // console.log(JSON.parse(uploadFileRes.data))
  335. let temRes = JSON.parse(uploadFileRes.data)
  336. if (temRes.code === 200 || temRes.code === 1) {
  337. this.subImgList.push(temRes.data)
  338. // console.log(this.subImgList)
  339. this.viewImgList.push({
  340. url: temRes.data,
  341. fileType: ele.fileType === 'image' ? 'image' : 'video'
  342. })
  343. // console.log(this.viewImgList)
  344. } else {
  345. uni.showToast({
  346. title: temRes.message || '上传失败',
  347. icon: 'none'
  348. })
  349. }
  350. uni.hideLoading()
  351. },
  352. fail: () => {
  353. uni.showToast({
  354. title: '上传失败',
  355. icon: 'error'
  356. })
  357. }
  358. })
  359. },
  360. // 评分改变回调
  361. onChange(e, index) {
  362. // console.log(e)
  363. if (index === 1) {
  364. if (e.value === 1) {
  365. this.msg = '非常差'
  366. } else if (e.value === 2) {
  367. this.msg = '差'
  368. } else if (e.value === 3) {
  369. this.msg = '一般'
  370. } else if (e.value === 4) {
  371. this.msg = '好'
  372. } else if (e.value === 5) {
  373. this.msg = '非常好'
  374. }
  375. } else if (index === 2) {
  376. if (e.value === 1) {
  377. this.msgLocation = '非常差'
  378. } else if (e.value === 2) {
  379. this.msgLocation = '差'
  380. } else if (e.value === 3) {
  381. this.msgLocation = '一般'
  382. } else if (e.value === 4) {
  383. this.msgLocation = '好'
  384. } else if (e.value === 5) {
  385. this.msgLocation = '非常好'
  386. }
  387. } else if (index === 3) {
  388. if (e.value === 1) {
  389. this.msgFacility = '非常差'
  390. } else if (e.value === 2) {
  391. this.msgFacility = '差'
  392. } else if (e.value === 3) {
  393. this.msgFacility = '一般'
  394. } else if (e.value === 4) {
  395. this.msgFacility = '好'
  396. } else if (e.value === 5) {
  397. this.msgFacility = '非常好'
  398. }
  399. } else if (index === 4) {
  400. if (e.value === 1) {
  401. this.msgServe = '非常差'
  402. } else if (e.value === 2) {
  403. this.msgServe = '差'
  404. } else if (e.value === 3) {
  405. this.msgServe = '一般'
  406. } else if (e.value === 4) {
  407. this.msgServe = '好'
  408. } else if (e.value === 5) {
  409. this.msgServe = '非常好'
  410. }
  411. } else if (index === 5) {
  412. if (e.value === 1) {
  413. this.msgHygiene = '非常差'
  414. } else if (e.value === 2) {
  415. this.msgHygiene = '差'
  416. } else if (e.value === 3) {
  417. this.msgHygiene = '一般'
  418. } else if (e.value === 4) {
  419. this.msgHygiene = '好'
  420. } else if (e.value === 5) {
  421. this.msgHygiene = '非常好'
  422. }
  423. }
  424. },
  425. // 评价输入框输入回调
  426. handleInput(e) {
  427. this.textareaValuelength = e.detail.cursor
  428. },
  429. // 删除图片回调
  430. handleDelete(index) {
  431. this.subImgList.splice(index, 1)
  432. this.viewImgList.splice(index, 1)
  433. },
  434. handleLook(url, current) {
  435. if (this.videoContext) {
  436. this.videoContext.stop()
  437. }
  438. uni.previewImage({
  439. urls: [url],
  440. current
  441. })
  442. }
  443. }
  444. }
  445. </script>
  446. <style lang="scss" scoped>
  447. .container {
  448. min-height: 100vh;
  449. background-color: #f2f3f5;
  450. .header {
  451. display: flex;
  452. justify-content: center;
  453. position: relative;
  454. background-color: #fff;
  455. img {
  456. position: absolute;
  457. top: 0;
  458. left: 0;
  459. width: 47rpx;
  460. height: 47rpx;
  461. }
  462. .header_text {
  463. font-size: 34rpx;
  464. }
  465. }
  466. .rate {
  467. display: flex;
  468. align-items: center;
  469. margin: 20rpx 0;
  470. height: 107rpx;
  471. background-color: #fff;
  472. .rate_key {
  473. margin: 0 18rpx;
  474. font-size: 28rpx;
  475. font-weight: bold;
  476. }
  477. .rate_value {
  478. margin-left: 100rpx;
  479. color: #808080;
  480. font-size: 24rpx;
  481. }
  482. }
  483. .operation {
  484. padding: 20rpx 20rpx 33rpx;
  485. margin-bottom: 20rpx;
  486. background-color: #fff;
  487. .operation_input {
  488. box-sizing: border-box;
  489. padding: 20rpx;
  490. width: 710rpx;
  491. height: 282rpx;
  492. border-radius: 9rpx;
  493. background-color: #f2f2f2;
  494. .textarea {
  495. width: 100%;
  496. height: 203rpx;
  497. }
  498. .operation_count {
  499. height: 39rpx;
  500. text-align: end;
  501. color: #b3b3b3;
  502. font-size: 24rpx;
  503. }
  504. }
  505. .operation_uploading {
  506. display: grid;
  507. gap: 21rpx;
  508. grid-template-columns: repeat(auto-fill, 124rpx);
  509. margin-top: 20rpx;
  510. ::v-deep .uni-file-picker__item {
  511. background-color: red;
  512. }
  513. .uploading_box {
  514. position: relative;
  515. display: flex;
  516. flex-direction: column;
  517. justify-content: center;
  518. align-items: center;
  519. width: 124rpx;
  520. height: 124rpx;
  521. border-radius: 7rpx;
  522. background-color: #f2f2f2;
  523. .img {
  524. width: 40rpx;
  525. height: 40rpx;
  526. }
  527. .msg {
  528. margin-top: 5rpx;
  529. color: #a6a6a6;
  530. font-size: 20rpx;
  531. }
  532. .img2 {
  533. width: 124rpx;
  534. height: 124rpx;
  535. border-radius: 7rpx;
  536. }
  537. .video {
  538. width: 124rpx;
  539. height: 124rpx;
  540. border-radius: 7rpx;
  541. }
  542. .icon {
  543. position: absolute;
  544. top: 0;
  545. right: 0;
  546. display: flex;
  547. justify-content: center;
  548. align-items: center;
  549. width: 30rpx;
  550. height: 30rpx;
  551. border-radius: 7rpx;
  552. background-color: rgba(000, 000, 000, 0.5);
  553. img {
  554. width: 30rpx;
  555. height: 30rpx;
  556. }
  557. }
  558. }
  559. }
  560. }
  561. .foot {
  562. display: flex;
  563. flex-direction: column;
  564. justify-content: space-between;
  565. box-sizing: border-box;
  566. padding: 30rpx 20rpx 50rpx;
  567. height: 320rpx;
  568. background-color: #fff;
  569. .foot_box {
  570. display: flex;
  571. align-items: center;
  572. .box_key {
  573. margin-right: 18rpx;
  574. font-size: 28rpx;
  575. font-weight: bold;
  576. }
  577. .box_value {
  578. margin-left: 100rpx;
  579. color: #808080;
  580. font-size: 24rpx;
  581. }
  582. }
  583. }
  584. .foot_btn {
  585. display: flex;
  586. justify-content: center;
  587. align-items: center;
  588. margin: 65rpx auto 78rpx;
  589. width: 710rpx;
  590. height: 96rpx;
  591. color: #fff;
  592. font-size: 32rpx;
  593. border-radius: 64rpx;
  594. background-color: #096562;
  595. }
  596. }
  597. </style>