index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <view class="tui-cards-container" v-if="display">
  3. <view class="service-evaluation">
  4. <view class="header">
  5. <label class="header-label">请对本次服务进行评价</label>
  6. <view class="btn-close" @tap="handleClose">关闭</view>
  7. </view>
  8. <view class="main">
  9. <view class="main-evaluation-score">
  10. <image
  11. v-for="(item, index) in scoreList"
  12. :key="index"
  13. class="score-star"
  14. :data-score="item"
  15. :src="'/static/images/star' + (item > score ? '-grey' : '') + '.png'"
  16. @tap="handleScore"
  17. ></image>
  18. </view>
  19. <textarea
  20. class="main-textarea"
  21. cols="30"
  22. rows="10"
  23. @input="bindTextAreaInput"
  24. placeholder="请输入评语"
  25. placeholder-style="textarea-placeholder"
  26. ></textarea>
  27. </view>
  28. <view class="footer"><view class="btn" @tap="sendMessage" :disabled="score === 0 && !comment">提交评价</view></view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. export default {
  34. data() {
  35. return {
  36. scoreList: [1, 2, 3, 4, 5],
  37. score: 5,
  38. comment: ''
  39. };
  40. },
  41. components: {},
  42. props: {
  43. display: {
  44. type: Boolean,
  45. default: ''
  46. }
  47. },
  48. watch: {
  49. display: {
  50. handler: function(newVal) {},
  51. immediate: true
  52. }
  53. },
  54. onPageShow() {
  55. this.score= 0;
  56. this.comment='';
  57. },
  58. methods: {
  59. handleClose() {
  60. this.$emit('close', {
  61. detail: {
  62. key: '2'
  63. }
  64. });
  65. },
  66. handleScore(e) {
  67. let { score } = e.currentTarget.dataset;
  68. if (score === this.score) {
  69. score = 0;
  70. }
  71. this.setData({
  72. score
  73. });
  74. },
  75. bindTextAreaInput(e) {
  76. this.setData({
  77. comment: e.detail.value
  78. });
  79. },
  80. sendMessage() {
  81. this.$emit('sendCustomMessage', {
  82. detail: {
  83. payload: {
  84. // data 字段作为表示,可以自定义
  85. data: 'evaluation',
  86. description: '对本次服务的评价',
  87. // 获取骰子点数
  88. extension: JSON.stringify({
  89. score: this.score,
  90. comment: this.comment
  91. })
  92. }
  93. }
  94. });
  95. this.setData({
  96. score: 0,
  97. comment: ''
  98. });
  99. this.handleClose();
  100. }
  101. }
  102. };
  103. </script>
  104. <style>
  105. @import './index.css';
  106. </style>