addquestion.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <uni-section title="问题新增" type="line">
  3. <view class="example">
  4. <uni-forms ref="customForm" :rules="customRules" :modelValue="form" class="form">
  5. <uni-forms-item label="标题" required name="title">
  6. <uni-easyinput v-model="form.title" placeholder="请输入标题" maxlength="50"/>
  7. </uni-forms-item>
  8. <uni-forms-item label="正文" required name="text">
  9. <uni-easyinput type="textarea" v-model="form.text" :maxlength="1000" @blur="binddata('textDetails', $event.detail.value)" placeholder="请输入正文"></uni-easyinput>
  10. </uni-forms-item>
  11. <uni-forms-item label="提问类型" required name="typeId">
  12. <uni-data-select
  13. v-model="form.typeId"
  14. :localdata="typeList"
  15. ></uni-data-select>
  16. </uni-forms-item>
  17. <uni-forms-item label="悬赏" required name="score" >
  18. <uni-number-box v-model="form.score" :min="0" :max="99999" label="请输入悬赏积分"></uni-number-box >
  19. </uni-forms-item>
  20. <uni-forms-item label="图片" class="path" >
  21. <upload :imgArr="imageList" name="path" v-model="form.path"
  22. style="position: relative;left: -5%;top: -10%;"
  23. @updateImg="updateImg"></upload>
  24. </uni-forms-item>
  25. </uni-forms>
  26. <button type="primary" @click="submitForm('customForm')" >提交</button>
  27. </view>
  28. </uni-section>
  29. </template>
  30. <script>
  31. import upload from '@/components/upload/index.vue'
  32. import {listType,addQuestion,verifyScore,getUserInfo} from '@/api/asking/addquestion.js'
  33. export default {
  34. components: {
  35. upload
  36. },
  37. onReady() {
  38. // 设置自定义表单校验规则,必须在节点渲染完毕后执行
  39. this.$refs.customForm.setRules(this.customRules)
  40. this.getTypeList();
  41. },
  42. data() {
  43. return {
  44. disabled: false,
  45. //类型配置
  46. typeList: [],
  47. form: {},
  48. form1: {},
  49. // 表单校验
  50. customRules: {
  51. title: {
  52. rules: [{
  53. required: true,
  54. errorMessage: '标题不能为空'
  55. }]
  56. },
  57. text: {
  58. rules: [{
  59. required: true,
  60. errorMessage: '正文不能为空'
  61. }]
  62. },
  63. typeId: {
  64. rules: [{
  65. required: true,
  66. errorMessage: '提问类型不能为空'
  67. }]
  68. },
  69. },
  70. imageList: []
  71. }
  72. },
  73. methods: {
  74. //查询类型配置
  75. getTypeList() {
  76. listType(this.queryParams).then(response => {
  77. response.data.forEach(v => {
  78. this.typeList.push({
  79. text:v.type,
  80. value:v.id
  81. })
  82. })
  83. });
  84. },
  85. // 取消按钮
  86. cancel() {
  87. this.open = false;
  88. this.reset();
  89. },
  90. /** 提交按钮 */
  91. submitForm(e) {
  92. this.form.score = this.form.score==null?0:this.form.score;
  93. this.form1.scoreNum = this.form.score;
  94. this.form1.userId = getApp().globalData.userId;
  95. verifyScore(this.form1).then(res => {
  96. if(!res.data){
  97. uni.showToast({
  98. title:"您的积分不足"
  99. })
  100. }else{
  101. this.$refs[e].validate().then(res => {
  102. this.form.type = this.typeList.filter((item) => {
  103. return this.form.typeId == item.value;
  104. })[0].text;
  105. addQuestion(this.form).then(res => {
  106. uni.navigateBack();
  107. });
  108. })
  109. }
  110. });
  111. },
  112. //图片上传
  113. updateImg(imgList) {
  114. this.imageList = imgList;
  115. this.form.path = this.imageList.join(',');
  116. }
  117. }
  118. };
  119. </script>