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