appraise.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <mobile-frame>
  3. <view class="info">
  4. <view class="one">
  5. <uni-forms ref="form" :modelValue="form" :rules="rules" label-width="auto">
  6. <uni-forms-item label="评论内容" name="content">
  7. <uni-easyinput type="textarea" v-model="form.content" placeholder="请输入评论内容" />
  8. </uni-forms-item>
  9. <uni-forms-item label="上传评论图片" name="file">
  10. <upload :list="file" name="file" :count="6" @uplSuc="uplSuc" @uplDel="uplDel"></upload>
  11. </uni-forms-item>
  12. <uni-forms-item label="等级" name="grade">
  13. <uni-rate size="18" v-model="form.grade" @change="onChange" />
  14. </uni-forms-item>
  15. </uni-forms>
  16. <view class="btn">
  17. <button type="primary" @click="onSubmit('form')" size="small">提交</button>
  18. </view>
  19. </view>
  20. </view>
  21. </mobile-frame>
  22. </template>
  23. <script>
  24. import upload from '@/components/upload/index.vue';
  25. export default {
  26. components: {
  27. upload
  28. },
  29. data() {
  30. return {
  31. id: '',
  32. user: {},
  33. form: {},
  34. file: [],
  35. rules: {
  36. content: {
  37. rules: [{
  38. required: true,
  39. errorMessage: '请输入评论内容',
  40. }]
  41. },
  42. grade: {
  43. rules: [{
  44. required: true,
  45. errorMessage: '请输入评论等级',
  46. }]
  47. }
  48. },
  49. };
  50. },
  51. onLoad: function(e) {
  52. const that = this;
  53. that.$set(that, `id`, e.id || '');
  54. // 监听用户是否登录
  55. that.watchLogin();
  56. },
  57. methods: {
  58. // 图片上传
  59. uplSuc(e) {
  60. const that = this;
  61. that.$set(that, `${e.name}`, [...that[e.name], e.data]);
  62. },
  63. // 图片删除
  64. uplDel(e) {
  65. const that = this;
  66. let data = that[e.name];
  67. let arr = data.filter((i, index) => index != e.data.index);
  68. that.$set(that, `${e.name}`, arr)
  69. },
  70. // 等级改变
  71. onChange(e) {
  72. console.log(this.form.num);
  73. },
  74. // 提交保存
  75. async onSubmit(ref) {
  76. const that = this;
  77. that.$refs[ref].validate().then(async params => {
  78. console.log(params);
  79. })
  80. },
  81. // 监听用户是否登录
  82. watchLogin() {
  83. const that = this;
  84. uni.getStorage({
  85. key: 'token',
  86. success: function(res) {
  87. let user = that.$jwt(res.data);
  88. if (user) that.$set(that, `user`, user);
  89. // that.search();
  90. },
  91. fail: function(err) {
  92. uni.navigateTo({
  93. url: `/pages/login/index`
  94. })
  95. }
  96. });
  97. },
  98. }
  99. }
  100. </script>
  101. <style lang="scss">
  102. .info {
  103. display: flex;
  104. flex-direction: column;
  105. width: 100vw;
  106. height: 100vh;
  107. .one {
  108. padding: 2vw;
  109. .uni-input {
  110. border: #f1f1ff 1px solid;
  111. padding: 2vw 2vw;
  112. border-radius: 1vw;
  113. }
  114. .btn {
  115. text-align: center;
  116. button {
  117. margin: 0 2vw 2vw 2vw;
  118. background-color: var(--ff0Color);
  119. color: var(--fffColor);
  120. }
  121. .name {
  122. color: var(--f85Color);
  123. font-size: var(--font14Size);
  124. }
  125. }
  126. }
  127. }
  128. .uni-forms-item {
  129. margin-bottom: 6vw !important;
  130. display: flex;
  131. flex-direction: row;
  132. }
  133. .uni-forms-item__content {
  134. display: flex;
  135. align-items: center;
  136. }
  137. </style>