evaluate.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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" />
  12. <view class="rate_value">非常好</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 subImgList" :key="index">
  35. <img class="img2" mode="aspectFill" :src="ele" />
  36. <view class="icon" @click="handleDelete(index)">
  37. <img src="../../static/index/close2.png" />
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. <!-- 总体评价区域 -->
  43. <view class="foot">
  44. <!-- 民宿位置评价 -->
  45. <view class="foot_box">
  46. <view class="box_key">民宿位置</view>
  47. <uni-rate v-model="rateLocation" size="18" @change="onChange" />
  48. <view class="box_value">非常好</view>
  49. </view>
  50. <!-- 民宿设施评价 -->
  51. <view class="foot_box">
  52. <view class="box_key">民宿设施</view>
  53. <uni-rate v-model="rateLocation" size="18" @change="onChange" />
  54. <view class="box_value">非常好</view>
  55. </view>
  56. <!-- 民宿服务评价 -->
  57. <view class="foot_box">
  58. <view class="box_key">民宿服务</view>
  59. <uni-rate v-model="rateLocation" size="18" @change="onChange" />
  60. <view class="box_value">非常好</view>
  61. </view>
  62. <!-- 民宿卫生评价 -->
  63. <view class="foot_box">
  64. <view class="box_key">民宿卫生</view>
  65. <uni-rate v-model="rateLocation" size="18" @change="onChange" />
  66. <view class="box_value">非常好</view>
  67. </view>
  68. </view>
  69. <!-- 提交按钮区域 -->
  70. <view class="foot_btn" @click="handleSub">提交</view>
  71. <!-- 用于图片压缩的canvas画布 -->
  72. <canvas
  73. :style="{
  74. width: cw + 'px',
  75. height: cw + 'px',
  76. position: 'absolute',
  77. zIndex: -1,
  78. left: '-10000rpx',
  79. top: '-10000rpx'
  80. }"
  81. canvas-id="zipCanvas"
  82. ></canvas>
  83. <!--画布结束-->
  84. </view>
  85. </template>
  86. <script>
  87. // 图片压缩方法
  88. import getLessLimitSizeImage from '@/util/imageCompress.js'
  89. export default {
  90. data() {
  91. return {
  92. // 状态栏高度
  93. statusBarH: 0,
  94. // 胶囊按钮栏高度
  95. customBarH: 0,
  96. // 民宿评分
  97. rateValue: 2,
  98. // 评价绑定数据
  99. textareaValue: '',
  100. // 评价文字长度
  101. textareaValuelength: 0,
  102. // 显示的图片数据
  103. imgList: [],
  104. // 上传的图片数据
  105. subImgList: [],
  106. // 图片上传框的样式
  107. imageStyles: {
  108. width: '60px',
  109. height: 60,
  110. border: {
  111. // 如果为 Boolean 值,可以控制边框显示与否
  112. color: '#eee', // 边框颜色
  113. width: '1px', // 边框宽度
  114. style: 'solid', // 边框样式
  115. radius: '50%' // 边框圆角,支持百分比
  116. }
  117. },
  118. // 民宿位置评分
  119. rateLocation: 3
  120. }
  121. },
  122. created() {
  123. // 获取系统信息
  124. uni.getSystemInfo({
  125. success: (e) => {
  126. // 获取状态栏高度
  127. this.statusBarH = e.statusBarHeight + 10
  128. // // 获取菜单按钮栏高度
  129. let custom = uni.getMenuButtonBoundingClientRect()
  130. this.customBarH = custom.height + 10
  131. }
  132. })
  133. },
  134. methods: {
  135. // 点击页面标题返回箭头回调
  136. handleBack() {
  137. uni.showModal({
  138. content: '确认退出评价吗,已编辑的内容将不保存',
  139. cancelText: '退出评价',
  140. cancelColor: '#808080',
  141. confirmText: '继续写评',
  142. confirmColor: '#000000',
  143. success: (res) => {
  144. if (res.confirm) {
  145. } else if (res.cancel) {
  146. uni.navigateBack(1)
  147. }
  148. }
  149. })
  150. },
  151. // 点击提交按钮回调
  152. handleSub() {
  153. uni.navigateTo({
  154. url: `/pages/evaluateStatus/evaluateStatus?status=2`
  155. })
  156. },
  157. handleUpLoad() {
  158. uni.chooseMedia({
  159. count: 9,
  160. maxDuration: 15,
  161. success: (res) => {
  162. console.log(res)
  163. console.log(res.tempFiles)
  164. if (this.subImgList.length + res.tempFiles.length > 9) {
  165. uni.showToast({
  166. title: '最多只能上传9个图片/视频',
  167. icon: 'none'
  168. })
  169. return
  170. }
  171. uni.showLoading({
  172. title: '上传中'
  173. })
  174. // reverse()
  175. res.tempFiles.forEach((ele) => {
  176. uni.uploadFile({
  177. url: `https://chtech.ncjti.edu.cn/hotelReservation/mhotel/mhotel/uploadhimage.action`,
  178. filePath: ele.tempFilePath,
  179. name: 'myFile',
  180. success: (uploadFileRes) => {
  181. console.log(JSON.parse(uploadFileRes.data))
  182. let temRes = JSON.parse(uploadFileRes.data)
  183. if (temRes.code === 200) {
  184. this.subImgList.push(temRes.data.url)
  185. console.log(this.subImgList)
  186. uni.hideLoading()
  187. } else {
  188. uni.showToast({
  189. title: temRes.message,
  190. icon: 'none'
  191. })
  192. }
  193. },
  194. fail: () => {
  195. uni.showToast({
  196. title: '上传失败',
  197. icon: 'error'
  198. })
  199. }
  200. })
  201. })
  202. }
  203. })
  204. },
  205. // 评分改变回调
  206. onChange(e) {
  207. console.log(e.value)
  208. },
  209. // 评价输入框输入回调
  210. handleInput(e) {
  211. this.textareaValuelength = e.detail.cursor
  212. },
  213. // 选择图片回调
  214. select(e) {
  215. // console.log(e)
  216. e.tempFiles.forEach((item) => {
  217. //这里的id和页面中写的html代码的canvas的id要一致
  218. let canvasId = 'zipCanvas'
  219. //原图的路径
  220. let imagePath = item.path
  221. //大小限制1024kb
  222. let limitSize = 1024
  223. //初始绘画区域是画布自身的宽度也就是屏幕宽度
  224. let drawWidth = uni.getSystemInfoSync().windowWidth
  225. getLessLimitSizeImage(canvasId, imagePath, limitSize, drawWidth, (resPath) => {
  226. uni.showLoading({
  227. title: '上传中'
  228. })
  229. uni.uploadFile({
  230. url: `https://chtech.ncjti.edu.cn/hotelReservation/mhotel/mhotel/uploadhimage.action`,
  231. filePath: resPath,
  232. name: 'myFile',
  233. success: (uploadFileRes) => {
  234. console.log(JSON.parse(uploadFileRes.data))
  235. let temRes = JSON.parse(uploadFileRes.data)
  236. if (temRes.code === 200) {
  237. this.subImgList.push(temRes.data.url)
  238. this.imgList.push({
  239. url: item.path,
  240. name: ''
  241. })
  242. uni.hideLoading()
  243. }
  244. },
  245. fail: () => {
  246. uni.showToast({
  247. title: '上传失败',
  248. icon: 'error'
  249. })
  250. }
  251. })
  252. })
  253. })
  254. },
  255. // 删除图片回调
  256. handleDelete(index) {
  257. // console.log(e);
  258. // const num = this.imgList.findIndex((v) => v.url === e.tempFilePath)
  259. this.subImgList.splice(index, 1)
  260. // this.imgList.splice(num, 1)
  261. }
  262. }
  263. }
  264. </script>
  265. <style lang="scss" scoped>
  266. .container {
  267. min-height: 100vh;
  268. background-color: #f2f3f5;
  269. .header {
  270. display: flex;
  271. justify-content: center;
  272. position: relative;
  273. background-color: #fff;
  274. img {
  275. position: absolute;
  276. top: 0;
  277. left: 0;
  278. width: 47rpx;
  279. height: 47rpx;
  280. }
  281. .header_text {
  282. font-size: 34rpx;
  283. }
  284. }
  285. .rate {
  286. display: flex;
  287. align-items: center;
  288. margin: 20rpx 0;
  289. height: 107rpx;
  290. background-color: #fff;
  291. .rate_key {
  292. margin: 0 18rpx;
  293. font-size: 28rpx;
  294. font-weight: bold;
  295. }
  296. .rate_value {
  297. margin-left: 100rpx;
  298. color: #808080;
  299. font-size: 24rpx;
  300. }
  301. }
  302. .operation {
  303. padding: 20rpx 20rpx 33rpx;
  304. margin-bottom: 20rpx;
  305. background-color: #fff;
  306. .operation_input {
  307. box-sizing: border-box;
  308. padding: 20rpx;
  309. width: 710rpx;
  310. height: 282rpx;
  311. border-radius: 9rpx;
  312. background-color: #f2f2f2;
  313. .textarea {
  314. width: 100%;
  315. height: 203rpx;
  316. }
  317. .operation_count {
  318. height: 39rpx;
  319. text-align: end;
  320. color: #b3b3b3;
  321. font-size: 24rpx;
  322. }
  323. }
  324. .operation_uploading {
  325. display: grid;
  326. gap: 21rpx;
  327. grid-template-columns: repeat(auto-fill, 124rpx);
  328. margin-top: 20rpx;
  329. ::v-deep .uni-file-picker__item {
  330. background-color: red;
  331. }
  332. .uploading_box {
  333. position: relative;
  334. display: flex;
  335. flex-direction: column;
  336. justify-content: center;
  337. align-items: center;
  338. width: 124rpx;
  339. height: 124rpx;
  340. border-radius: 7rpx;
  341. background-color: #f2f2f2;
  342. .img {
  343. width: 40rpx;
  344. height: 40rpx;
  345. }
  346. .msg {
  347. margin-top: 5rpx;
  348. color: #a6a6a6;
  349. font-size: 20rpx;
  350. }
  351. .img2 {
  352. width: 124rpx;
  353. height: 124rpx;
  354. border-radius: 7rpx;
  355. }
  356. .icon {
  357. position: absolute;
  358. top: 0;
  359. right: 0;
  360. display: flex;
  361. justify-content: center;
  362. align-items: center;
  363. width: 30rpx;
  364. height: 30rpx;
  365. border-radius: 7rpx;
  366. background-color: rgba(000, 000, 000, 0.5);
  367. img {
  368. width: 30rpx;
  369. height: 30rpx;
  370. }
  371. }
  372. }
  373. }
  374. }
  375. .foot {
  376. display: flex;
  377. flex-direction: column;
  378. justify-content: space-between;
  379. box-sizing: border-box;
  380. padding: 30rpx 20rpx 50rpx;
  381. height: 320rpx;
  382. background-color: #fff;
  383. .foot_box {
  384. display: flex;
  385. align-items: center;
  386. .box_key {
  387. margin-right: 18rpx;
  388. font-size: 28rpx;
  389. font-weight: bold;
  390. }
  391. .box_value {
  392. margin-left: 100rpx;
  393. color: #808080;
  394. font-size: 24rpx;
  395. }
  396. }
  397. }
  398. .foot_btn {
  399. display: flex;
  400. justify-content: center;
  401. align-items: center;
  402. margin: 65rpx auto 78rpx;
  403. width: 710rpx;
  404. height: 96rpx;
  405. color: #fff;
  406. font-size: 32rpx;
  407. border-radius: 64rpx;
  408. background-color: #096562;
  409. }
  410. }
  411. </style>