evaluate.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  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="zipCanvas2"
  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&hotelId=${this.hotelId}`
  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&hotelId=${this.hotelId}`
  248. })
  249. }, 1500)
  250. }
  251. },
  252. // 上传图片回调
  253. handleUpLoad() {
  254. uni.chooseMedia({
  255. count: 6 - this.subImgList.length,
  256. mediaType: ['mix'],
  257. maxDuration: 10,
  258. success: (res) => {
  259. // 判断视频文件不能超过1个
  260. let temList = [...this.viewImgList, ...res.tempFiles]
  261. let temList2 = temList.filter((ele) => ele.fileType === 'video')
  262. if (temList2.length > 1) {
  263. uni.showToast({
  264. title: '最多只能上传1个视频',
  265. icon: 'none'
  266. })
  267. return
  268. }
  269. res.tempFiles.forEach((ele) => {
  270. if (ele.fileType === 'image' && ele.size > 1024 * 1024 * 3) {
  271. //这里的id和页面中写的html代码的canvas的id要一致
  272. let canvasId = 'zipCanvas2'
  273. //原图的路径
  274. let imagePath = ele.tempFilePath
  275. //大小限制1024kb
  276. let limitSize = 1024 * 3
  277. //初始绘画区域是画布自身的宽度也就是屏幕宽度
  278. let drawWidth = uni.getSystemInfoSync().windowWidth
  279. // 图片过大压缩
  280. getLessLimitSizeImage(canvasId, imagePath, limitSize, drawWidth, (resPath) => {
  281. this.handleUploadMini({ tempFilePath: resPath, fileType: ele.fileType })
  282. })
  283. } else if (ele.fileType === 'video' && ele.size > 1024 * 1024 * 5) {
  284. uni.compressVideo({
  285. src: ele.tempFilePath,
  286. quality: 'low',
  287. // bitrate: 60000,
  288. // fps: 30,
  289. // resolution: 1,
  290. success: (res) => {
  291. // console.log('压缩后', res)
  292. this.handleUploadMini({ tempFilePath: res.tempFilePath, fileType: ele.fileType })
  293. },
  294. fail: (err) => {
  295. // console.log(err)
  296. uni.showToast(
  297. {
  298. title: '视频压缩失败',
  299. icon: 'none'
  300. },
  301. 2000
  302. )
  303. }
  304. })
  305. } else {
  306. this.handleUploadMini(ele)
  307. }
  308. })
  309. },
  310. fail: (err) => {
  311. console.log(err)
  312. uni.showToast({
  313. title: '选择文件失败',
  314. icon: 'none',
  315. mask: true
  316. })
  317. }
  318. })
  319. },
  320. handleUploadMini(ele) {
  321. // console.log(ele)
  322. // 开始上传
  323. uni.showLoading({
  324. title: '上传中'
  325. })
  326. uni.uploadFile({
  327. url: `https://www.jinganrenjiams.com/hotelReservation/file/cos/upload`,
  328. filePath: ele.tempFilePath,
  329. // name: 'myFile',
  330. name: 'files',
  331. success: (uploadFileRes) => {
  332. // console.log(JSON.parse(uploadFileRes.data))
  333. let temRes = JSON.parse(uploadFileRes.data)
  334. if (temRes.code === 200 || temRes.code === 1) {
  335. this.subImgList.push(temRes.data)
  336. // console.log(this.subImgList)
  337. this.viewImgList.push({
  338. url: temRes.data,
  339. fileType: ele.fileType === 'image' ? 'image' : 'video'
  340. })
  341. // console.log(this.viewImgList)
  342. } else {
  343. uni.showToast({
  344. title: temRes.message || '上传失败',
  345. icon: 'none'
  346. })
  347. }
  348. },
  349. fail: () => {
  350. uni.showToast({
  351. title: '上传失败',
  352. icon: 'error'
  353. })
  354. },
  355. complete: (res) => {
  356. // console.log(res);
  357. uni.hideLoading({
  358. complete: (hide) => {
  359. // console.log(hide);
  360. }
  361. })
  362. }
  363. })
  364. },
  365. // 评分改变回调
  366. onChange(e, index) {
  367. // console.log(e)
  368. if (index === 1) {
  369. if (e.value === 1) {
  370. this.msg = '非常差'
  371. } else if (e.value === 2) {
  372. this.msg = '差'
  373. } else if (e.value === 3) {
  374. this.msg = '一般'
  375. } else if (e.value === 4) {
  376. this.msg = '好'
  377. } else if (e.value === 5) {
  378. this.msg = '非常好'
  379. }
  380. } else if (index === 2) {
  381. if (e.value === 1) {
  382. this.msgLocation = '非常差'
  383. } else if (e.value === 2) {
  384. this.msgLocation = '差'
  385. } else if (e.value === 3) {
  386. this.msgLocation = '一般'
  387. } else if (e.value === 4) {
  388. this.msgLocation = '好'
  389. } else if (e.value === 5) {
  390. this.msgLocation = '非常好'
  391. }
  392. } else if (index === 3) {
  393. if (e.value === 1) {
  394. this.msgFacility = '非常差'
  395. } else if (e.value === 2) {
  396. this.msgFacility = '差'
  397. } else if (e.value === 3) {
  398. this.msgFacility = '一般'
  399. } else if (e.value === 4) {
  400. this.msgFacility = '好'
  401. } else if (e.value === 5) {
  402. this.msgFacility = '非常好'
  403. }
  404. } else if (index === 4) {
  405. if (e.value === 1) {
  406. this.msgServe = '非常差'
  407. } else if (e.value === 2) {
  408. this.msgServe = '差'
  409. } else if (e.value === 3) {
  410. this.msgServe = '一般'
  411. } else if (e.value === 4) {
  412. this.msgServe = '好'
  413. } else if (e.value === 5) {
  414. this.msgServe = '非常好'
  415. }
  416. } else if (index === 5) {
  417. if (e.value === 1) {
  418. this.msgHygiene = '非常差'
  419. } else if (e.value === 2) {
  420. this.msgHygiene = '差'
  421. } else if (e.value === 3) {
  422. this.msgHygiene = '一般'
  423. } else if (e.value === 4) {
  424. this.msgHygiene = '好'
  425. } else if (e.value === 5) {
  426. this.msgHygiene = '非常好'
  427. }
  428. }
  429. },
  430. // 评价输入框输入回调
  431. handleInput(e) {
  432. this.textareaValuelength = e.detail.cursor
  433. },
  434. // 删除图片回调
  435. handleDelete(index) {
  436. this.subImgList.splice(index, 1)
  437. this.viewImgList.splice(index, 1)
  438. },
  439. handleLook(url, current) {
  440. if (this.videoContext) {
  441. this.videoContext.stop()
  442. }
  443. uni.previewImage({
  444. urls: [url],
  445. current
  446. })
  447. }
  448. }
  449. }
  450. </script>
  451. <style lang="scss" scoped>
  452. .container {
  453. min-height: 100vh;
  454. background-color: #f2f3f5;
  455. .header {
  456. display: flex;
  457. justify-content: center;
  458. position: relative;
  459. background-color: #fff;
  460. img {
  461. position: absolute;
  462. top: 0;
  463. left: 0;
  464. width: 47rpx;
  465. height: 47rpx;
  466. }
  467. .header_text {
  468. font-size: 34rpx;
  469. }
  470. }
  471. .rate {
  472. display: flex;
  473. align-items: center;
  474. margin: 20rpx 0;
  475. height: 107rpx;
  476. background-color: #fff;
  477. .rate_key {
  478. margin: 0 18rpx;
  479. font-size: 28rpx;
  480. font-weight: bold;
  481. }
  482. .rate_value {
  483. margin-left: 100rpx;
  484. color: #808080;
  485. font-size: 24rpx;
  486. }
  487. }
  488. .operation {
  489. padding: 20rpx 20rpx 33rpx;
  490. margin-bottom: 20rpx;
  491. background-color: #fff;
  492. .operation_input {
  493. box-sizing: border-box;
  494. padding: 20rpx;
  495. width: 710rpx;
  496. height: 282rpx;
  497. border-radius: 9rpx;
  498. background-color: #f2f2f2;
  499. .textarea {
  500. width: 100%;
  501. height: 203rpx;
  502. }
  503. .operation_count {
  504. height: 39rpx;
  505. text-align: end;
  506. color: #b3b3b3;
  507. font-size: 24rpx;
  508. }
  509. }
  510. .operation_uploading {
  511. display: grid;
  512. gap: 21rpx;
  513. grid-template-columns: repeat(auto-fill, 124rpx);
  514. margin-top: 20rpx;
  515. ::v-deep .uni-file-picker__item {
  516. background-color: red;
  517. }
  518. .uploading_box {
  519. position: relative;
  520. display: flex;
  521. flex-direction: column;
  522. justify-content: center;
  523. align-items: center;
  524. width: 124rpx;
  525. height: 124rpx;
  526. border-radius: 7rpx;
  527. background-color: #f2f2f2;
  528. .img {
  529. width: 40rpx;
  530. height: 40rpx;
  531. }
  532. .msg {
  533. margin-top: 5rpx;
  534. color: #a6a6a6;
  535. font-size: 20rpx;
  536. }
  537. .img2 {
  538. width: 124rpx;
  539. height: 124rpx;
  540. border-radius: 7rpx;
  541. }
  542. .video {
  543. width: 124rpx;
  544. height: 124rpx;
  545. border-radius: 7rpx;
  546. }
  547. .icon {
  548. position: absolute;
  549. top: 0;
  550. right: 0;
  551. display: flex;
  552. justify-content: center;
  553. align-items: center;
  554. width: 30rpx;
  555. height: 30rpx;
  556. border-radius: 7rpx;
  557. background-color: rgba(000, 000, 000, 0.5);
  558. img {
  559. width: 30rpx;
  560. height: 30rpx;
  561. }
  562. }
  563. }
  564. }
  565. }
  566. .foot {
  567. display: flex;
  568. flex-direction: column;
  569. justify-content: space-between;
  570. box-sizing: border-box;
  571. padding: 30rpx 20rpx 50rpx;
  572. height: 320rpx;
  573. background-color: #fff;
  574. .foot_box {
  575. display: flex;
  576. align-items: center;
  577. .box_key {
  578. margin-right: 18rpx;
  579. font-size: 28rpx;
  580. font-weight: bold;
  581. }
  582. .box_value {
  583. margin-left: 100rpx;
  584. color: #808080;
  585. font-size: 24rpx;
  586. }
  587. }
  588. }
  589. .foot_btn {
  590. display: flex;
  591. justify-content: center;
  592. align-items: center;
  593. margin: 65rpx auto 78rpx;
  594. width: 710rpx;
  595. height: 96rpx;
  596. color: #fff;
  597. font-size: 32rpx;
  598. border-radius: 64rpx;
  599. background-color: #096562;
  600. }
  601. }
  602. </style>