evaluate.vue 15 KB

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