hasQuestion.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <view class="hasquestion-wrap">
  3. <view class="title">问题描述<van-icon @click="showHint" coloe="rgba(0, 0, 0, 0.2)" name="question" />
  4. <view class="hint" v-if="hintShow">实际发布的问题会以提炼出的精简内容为准</view>
  5. </view>
  6. <textarea
  7. v-model="text"
  8. placeholder="点击输入提问"
  9. placeholder-class="textarea-placeholder"
  10. :maxlength="maxlength"
  11. @input="calcWord"
  12. />
  13. <text style="float:right;color:grey;">剩余可输入字数:<text :style="{color:(maxlength-textlength<=10)?'red':'grey'}">{{maxlength-textlength}}</text>字</text>
  14. <view class="btn-wrap">
  15. <view class="btn" :class="{'active':textlength>0}" @click="handleClick">完成</view>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. import {apiPubAsk} from '@/api/question.js'
  21. export default {
  22. data() {
  23. return {
  24. text:'',
  25. textlength:0,
  26. maxlength:50,
  27. hintShow:false
  28. };
  29. },
  30. methods: {
  31. async handleClick(){
  32. if(!this.textlength){
  33. uni.showToast({
  34. title: '请输入问题',
  35. icon: 'none',
  36. })
  37. return
  38. }
  39. const res = await apiPubAsk({
  40. question_content:this.text
  41. })
  42. if(res.code===200){
  43. uni.navigateBack({delta:1})
  44. }
  45. },
  46. //计算字数
  47. calcWord(e){
  48. console.log('text1',this.text)
  49. this.textlength = e.detail.value.length
  50. //真机,一次性输入字数大于maxlength时数据和显示错误
  51. if(this.textlength>=this.maxlength){
  52. this.textlength=this.maxlength
  53. this.text = this.text.slice(0,this.maxlength)
  54. }
  55. console.log('text2',this.text)
  56. },
  57. //展示提示
  58. showHint(){
  59. this.hintShow = true
  60. setTimeout(()=>{
  61. this.hintShow = false
  62. },1000)
  63. }
  64. },
  65. };
  66. </script>
  67. <style lang="scss">
  68. .hasquestion-wrap{
  69. .title{
  70. .van-icon{
  71. color:rgba(0, 0, 0, 0.2);
  72. }
  73. }
  74. }
  75. </style>
  76. <style scoped lang="scss">
  77. .hasquestion-wrap{
  78. padding:40rpx 34rpx;
  79. .title{
  80. margin-bottom: 20rpx;
  81. font-size: 32rpx;
  82. color: #333333;
  83. position:relative;
  84. .hint{
  85. position: absolute;
  86. padding:20rpx 30rpx;
  87. border-radius: 4rpx;
  88. font-size: 28rpx;
  89. background-color: rgba(0, 0, 0, 0.5);
  90. color:#FFFFFF;
  91. z-index: 2;
  92. left:30rpx;
  93. }
  94. }
  95. textarea{
  96. width:100%;
  97. height:294rpx;
  98. box-sizing: border-box;
  99. padding:30rpx;
  100. border:1rpx solid #BEBEBE;
  101. border-radius: 8rpx;
  102. }
  103. .btn-wrap{
  104. margin-top: 120rpx;
  105. text-align: center;
  106. .btn{
  107. display: inline-block;
  108. width:390rpx;
  109. height:80rpx;
  110. border-radius: 40rpx;
  111. font-size: 32rpx;
  112. text-align: center;
  113. line-height: 80rpx;
  114. background-color: #ADADAD99;
  115. color: #FFFFFF;
  116. &.active{
  117. background-color: #E6B77D;
  118. }
  119. }
  120. }
  121. }
  122. </style>