hasQuestion.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <view class="hasquestion-wrap">
  3. <van-cell title="所属品种" :value="varietyVal||'请选择问题所属品种'" is-link @click="showFilter=true"/>
  4. <view style="padding:34rpx">
  5. <view class="title">问题描述<van-icon @click="showHint" coloe="rgba(0, 0, 0, 0.2)" name="question" />
  6. <view class="hint" v-if="hintShow">实际发布的问题会以提炼出的精简内容为准</view>
  7. </view>
  8. <textarea
  9. v-model="text"
  10. placeholder="点击输入提问"
  11. placeholder-class="textarea-placeholder"
  12. :maxlength="maxlength"
  13. @input="calcWord"
  14. />
  15. <text style="float:right;color:grey;">剩余可输入字数:<text :style="{color:(maxlength-textlength<=10)?'red':'grey'}">{{maxlength-textlength}}</text>字</text>
  16. <view class="btn-wrap">
  17. <view class="btn" :class="{'active':textlength>0}" @click="handleClick">完成</view>
  18. </view>
  19. </view>
  20. <!-- 选择品种 -->
  21. <van-popup
  22. :show="showFilter"
  23. position="bottom"
  24. closeable
  25. :close-on-click-overlay="true"
  26. @close="showFilter = false"
  27. round
  28. >
  29. <view class="fliter-wrap-list">
  30. <view class="flex top">
  31. <text style="color:#000">选择所属品种</text>
  32. </view>
  33. <van-tree-select
  34. :items="options"
  35. :main-active-index="mainActiveIndex"
  36. :active-id="activeId"
  37. @click-nav="onClickNav"
  38. @click-item="onClickItem"
  39. main-active-class="main-active-class"
  40. content-active-class="content-active-class"
  41. />
  42. </view>
  43. </van-popup>
  44. </view>
  45. </template>
  46. <script>
  47. import {apiPubAsk} from '@/api/question.js'
  48. import {apiGetTagTree} from '@/api/common'
  49. export default {
  50. data() {
  51. return {
  52. text:'',
  53. textlength:0,
  54. maxlength:40,
  55. hintShow:false,
  56. showFilter:false,
  57. options:[],
  58. mainActiveIndex:0,
  59. activeId:0,//选择的品种id
  60. variety_classify_id:0,
  61. varietyVal:'',
  62. };
  63. },
  64. onLoad(){
  65. this.getOptionsList()
  66. },
  67. methods: {
  68. async handleClick(){
  69. if(!this.textlength){
  70. uni.showToast({
  71. title: '请输入问题',
  72. icon: 'none',
  73. })
  74. return
  75. }
  76. if(!this.activeId){
  77. uni.showToast({
  78. title: '请选择问题所属品种',
  79. icon: 'none',
  80. })
  81. return
  82. }
  83. const res = await apiPubAsk({
  84. question_content:this.text,
  85. variety_classify_id:this.variety_classify_id,
  86. variety_tag_id:this.activeId
  87. })
  88. if(res.code===200){
  89. uni.showToast({
  90. title:"发布成功",
  91. icon:'success'
  92. })
  93. setTimeout(() => {
  94. uni.navigateBack({delta:1})
  95. }, 1500);
  96. }
  97. },
  98. //计算字数
  99. calcWord(e){
  100. console.log('text1',this.text)
  101. this.textlength = e.detail.value.length
  102. //真机,一次性输入字数大于maxlength时数据和显示错误
  103. if(this.textlength>=this.maxlength){
  104. this.textlength=this.maxlength
  105. this.text = this.text.slice(0,this.maxlength)
  106. }
  107. console.log('text2',this.text)
  108. },
  109. //展示提示
  110. showHint(){
  111. this.hintShow = true
  112. setTimeout(()=>{
  113. this.hintShow = false
  114. },1000)
  115. },
  116. //获取品种筛选
  117. async getOptionsList(){
  118. const res = await apiGetTagTree()
  119. if(res.code===200){
  120. const arr = res.data||[]
  121. this.options=arr.map(item=>{
  122. let obj={
  123. text:'',
  124. children:[]
  125. }
  126. obj.text=item.classify_name
  127. obj.children=item.tags.map(_item=>{
  128. return {
  129. text:_item.tag_name,
  130. id:_item.tag_id,
  131. variety_classify_id:_item.classify_id
  132. }
  133. })
  134. return obj
  135. })
  136. }
  137. },
  138. onClickNav({detail}){
  139. console.log(detail);
  140. this.mainActiveIndex=detail.index
  141. },
  142. onClickItem({detail}){
  143. console.log(detail);
  144. this.activeId=detail.id
  145. this.varietyVal=this.options[this.mainActiveIndex].text+'/'+detail.text
  146. this.variety_classify_id=detail.variety_classify_id
  147. this.showFilter=false
  148. },
  149. },
  150. };
  151. </script>
  152. <style lang="scss">
  153. .hasquestion-wrap{
  154. .title{
  155. .van-icon{
  156. color:rgba(0, 0, 0, 0.2);
  157. }
  158. }
  159. .van-cell{
  160. border-bottom: 1px solid #e5e5e5;
  161. }
  162. .fliter-wrap-list{
  163. background-color: #fff;
  164. padding-top: 28rpx;
  165. padding-bottom: 100rpx;
  166. .top{
  167. font-size: 32rpx;
  168. justify-content: center;
  169. margin-bottom: 40rpx;
  170. padding: 0 34rpx;
  171. position: relative;
  172. }
  173. .van-sidebar{
  174. flex-shrink: 0;
  175. }
  176. .van-tree-select__content{
  177. overflow-x: hidden;
  178. }
  179. .main-active-class{
  180. border-color: #E3B377;
  181. }
  182. .content-active-class{
  183. color: #E3B377;
  184. }
  185. }
  186. }
  187. </style>
  188. <style scoped lang="scss">
  189. .hasquestion-wrap{
  190. .title{
  191. margin-bottom: 20rpx;
  192. font-size: 32rpx;
  193. color: #333333;
  194. position:relative;
  195. .hint{
  196. position: absolute;
  197. padding:20rpx 30rpx;
  198. border-radius: 4rpx;
  199. font-size: 28rpx;
  200. background-color: rgba(0, 0, 0, 0.5);
  201. color:#FFFFFF;
  202. z-index: 2;
  203. left:30rpx;
  204. }
  205. }
  206. textarea{
  207. width:100%;
  208. height:294rpx;
  209. box-sizing: border-box;
  210. padding:30rpx;
  211. border:1rpx solid #BEBEBE;
  212. border-radius: 8rpx;
  213. }
  214. .btn-wrap{
  215. margin-top: 120rpx;
  216. text-align: center;
  217. .btn{
  218. display: inline-block;
  219. width:390rpx;
  220. height:80rpx;
  221. border-radius: 40rpx;
  222. font-size: 32rpx;
  223. text-align: center;
  224. line-height: 80rpx;
  225. background-color: #ADADAD99;
  226. color: #FFFFFF;
  227. &.active{
  228. background-color: #E6B77D;
  229. }
  230. }
  231. }
  232. }
  233. </style>