evaluate.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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://chtech.ncjti.edu.cn/hotelReservation/mhotel/mhotel/uploadhimage.action`,
  328. url: `https://chtech.ncjti.edu.cn/homestay/file/cos/upload`,
  329. filePath: ele.tempFilePath,
  330. // name: 'myFile',
  331. name: 'files',
  332. success: (uploadFileRes) => {
  333. // console.log(JSON.parse(uploadFileRes.data))
  334. let temRes = JSON.parse(uploadFileRes.data)
  335. if (temRes.code === 200 || temRes.code === 1) {
  336. this.subImgList.push(temRes.data)
  337. // console.log(this.subImgList)
  338. this.viewImgList.push({
  339. url: temRes.data,
  340. fileType: ele.fileType === 'image' ? 'image' : 'video'
  341. })
  342. // console.log(this.viewImgList)
  343. } else {
  344. uni.showToast({
  345. title: temRes.message || '上传失败',
  346. icon: 'none'
  347. })
  348. }
  349. },
  350. fail: () => {
  351. uni.showToast({
  352. title: '上传失败',
  353. icon: 'error'
  354. })
  355. },
  356. complete: (res) => {
  357. // console.log(res);
  358. uni.hideLoading({
  359. complete: (hide) => {
  360. // console.log(hide);
  361. }
  362. })
  363. }
  364. })
  365. },
  366. // 评分改变回调
  367. onChange(e, index) {
  368. // console.log(e)
  369. if (index === 1) {
  370. if (e.value === 1) {
  371. this.msg = '非常差'
  372. } else if (e.value === 2) {
  373. this.msg = '差'
  374. } else if (e.value === 3) {
  375. this.msg = '一般'
  376. } else if (e.value === 4) {
  377. this.msg = '好'
  378. } else if (e.value === 5) {
  379. this.msg = '非常好'
  380. }
  381. } else if (index === 2) {
  382. if (e.value === 1) {
  383. this.msgLocation = '非常差'
  384. } else if (e.value === 2) {
  385. this.msgLocation = '差'
  386. } else if (e.value === 3) {
  387. this.msgLocation = '一般'
  388. } else if (e.value === 4) {
  389. this.msgLocation = '好'
  390. } else if (e.value === 5) {
  391. this.msgLocation = '非常好'
  392. }
  393. } else if (index === 3) {
  394. if (e.value === 1) {
  395. this.msgFacility = '非常差'
  396. } else if (e.value === 2) {
  397. this.msgFacility = '差'
  398. } else if (e.value === 3) {
  399. this.msgFacility = '一般'
  400. } else if (e.value === 4) {
  401. this.msgFacility = '好'
  402. } else if (e.value === 5) {
  403. this.msgFacility = '非常好'
  404. }
  405. } else if (index === 4) {
  406. if (e.value === 1) {
  407. this.msgServe = '非常差'
  408. } else if (e.value === 2) {
  409. this.msgServe = '差'
  410. } else if (e.value === 3) {
  411. this.msgServe = '一般'
  412. } else if (e.value === 4) {
  413. this.msgServe = '好'
  414. } else if (e.value === 5) {
  415. this.msgServe = '非常好'
  416. }
  417. } else if (index === 5) {
  418. if (e.value === 1) {
  419. this.msgHygiene = '非常差'
  420. } else if (e.value === 2) {
  421. this.msgHygiene = '差'
  422. } else if (e.value === 3) {
  423. this.msgHygiene = '一般'
  424. } else if (e.value === 4) {
  425. this.msgHygiene = '好'
  426. } else if (e.value === 5) {
  427. this.msgHygiene = '非常好'
  428. }
  429. }
  430. },
  431. // 评价输入框输入回调
  432. handleInput(e) {
  433. this.textareaValuelength = e.detail.cursor
  434. },
  435. // 删除图片回调
  436. handleDelete(index) {
  437. this.subImgList.splice(index, 1)
  438. this.viewImgList.splice(index, 1)
  439. },
  440. handleLook(url, current) {
  441. if (this.videoContext) {
  442. this.videoContext.stop()
  443. }
  444. uni.previewImage({
  445. urls: [url],
  446. current
  447. })
  448. }
  449. }
  450. }
  451. </script>
  452. <style lang="scss" scoped>
  453. .container {
  454. min-height: 100vh;
  455. background-color: #f2f3f5;
  456. .header {
  457. display: flex;
  458. justify-content: center;
  459. position: relative;
  460. background-color: #fff;
  461. img {
  462. position: absolute;
  463. top: 0;
  464. left: 0;
  465. width: 47rpx;
  466. height: 47rpx;
  467. }
  468. .header_text {
  469. font-size: 34rpx;
  470. }
  471. }
  472. .rate {
  473. display: flex;
  474. align-items: center;
  475. margin: 20rpx 0;
  476. height: 107rpx;
  477. background-color: #fff;
  478. .rate_key {
  479. margin: 0 18rpx;
  480. font-size: 28rpx;
  481. font-weight: bold;
  482. }
  483. .rate_value {
  484. margin-left: 100rpx;
  485. color: #808080;
  486. font-size: 24rpx;
  487. }
  488. }
  489. .operation {
  490. padding: 20rpx 20rpx 33rpx;
  491. margin-bottom: 20rpx;
  492. background-color: #fff;
  493. .operation_input {
  494. box-sizing: border-box;
  495. padding: 20rpx;
  496. width: 710rpx;
  497. height: 282rpx;
  498. border-radius: 9rpx;
  499. background-color: #f2f2f2;
  500. .textarea {
  501. width: 100%;
  502. height: 203rpx;
  503. }
  504. .operation_count {
  505. height: 39rpx;
  506. text-align: end;
  507. color: #b3b3b3;
  508. font-size: 24rpx;
  509. }
  510. }
  511. .operation_uploading {
  512. display: grid;
  513. gap: 21rpx;
  514. grid-template-columns: repeat(auto-fill, 124rpx);
  515. margin-top: 20rpx;
  516. ::v-deep .uni-file-picker__item {
  517. background-color: red;
  518. }
  519. .uploading_box {
  520. position: relative;
  521. display: flex;
  522. flex-direction: column;
  523. justify-content: center;
  524. align-items: center;
  525. width: 124rpx;
  526. height: 124rpx;
  527. border-radius: 7rpx;
  528. background-color: #f2f2f2;
  529. .img {
  530. width: 40rpx;
  531. height: 40rpx;
  532. }
  533. .msg {
  534. margin-top: 5rpx;
  535. color: #a6a6a6;
  536. font-size: 20rpx;
  537. }
  538. .img2 {
  539. width: 124rpx;
  540. height: 124rpx;
  541. border-radius: 7rpx;
  542. }
  543. .video {
  544. width: 124rpx;
  545. height: 124rpx;
  546. border-radius: 7rpx;
  547. }
  548. .icon {
  549. position: absolute;
  550. top: 0;
  551. right: 0;
  552. display: flex;
  553. justify-content: center;
  554. align-items: center;
  555. width: 30rpx;
  556. height: 30rpx;
  557. border-radius: 7rpx;
  558. background-color: rgba(000, 000, 000, 0.5);
  559. img {
  560. width: 30rpx;
  561. height: 30rpx;
  562. }
  563. }
  564. }
  565. }
  566. }
  567. .foot {
  568. display: flex;
  569. flex-direction: column;
  570. justify-content: space-between;
  571. box-sizing: border-box;
  572. padding: 30rpx 20rpx 50rpx;
  573. height: 320rpx;
  574. background-color: #fff;
  575. .foot_box {
  576. display: flex;
  577. align-items: center;
  578. .box_key {
  579. margin-right: 18rpx;
  580. font-size: 28rpx;
  581. font-weight: bold;
  582. }
  583. .box_value {
  584. margin-left: 100rpx;
  585. color: #808080;
  586. font-size: 24rpx;
  587. }
  588. }
  589. }
  590. .foot_btn {
  591. display: flex;
  592. justify-content: center;
  593. align-items: center;
  594. margin: 65rpx auto 78rpx;
  595. width: 710rpx;
  596. height: 96rpx;
  597. color: #fff;
  598. font-size: 32rpx;
  599. border-radius: 64rpx;
  600. background-color: #096562;
  601. }
  602. }
  603. </style>