index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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/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.setData({
  56. score: 0,
  57. comment: ''
  58. });
  59. },
  60. methods: {
  61. handleClose() {
  62. this.$emit('close', {
  63. detail: {
  64. key: '2'
  65. }
  66. });
  67. },
  68. handleScore(e) {
  69. let { score } = e.currentTarget.dataset;
  70. if (score === this.score) {
  71. score = 0;
  72. }
  73. this.setData({
  74. score
  75. });
  76. },
  77. bindTextAreaInput(e) {
  78. this.setData({
  79. comment: e.detail.value
  80. });
  81. },
  82. sendMessage() {
  83. this.$emit('sendCustomMessage', {
  84. detail: {
  85. payload: {
  86. // data 字段作为表示,可以自定义
  87. data: 'evaluation',
  88. description: '对本次服务的评价',
  89. // 获取骰子点数
  90. extension: JSON.stringify({
  91. score: this.score,
  92. comment: this.comment
  93. })
  94. }
  95. }
  96. });
  97. this.setData({
  98. score: 0,
  99. comment: ''
  100. });
  101. this.handleClose();
  102. }
  103. }
  104. };
  105. </script>
  106. <style>
  107. @import './index.css';
  108. </style>