wenjuan.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <view class="wenjuan">
  3. <view class="title_wrap">
  4. <view class="title">
  5. {{title}}
  6. </view>
  7. <view class="notice">
  8. <text>注意事项:</text>
  9. <view class="item" v-for="(item,index) in notice" :key="index">
  10. {{item}}
  11. </view>
  12. </view>
  13. </view>
  14. <view class="wrap">
  15. <view class="item" v-for="(item,index) in list" :key="index">
  16. <view class="item_title">
  17. <text class="star" v-if="item.is_must == 1">*</text>
  18. <text>{{index+1}}、{{item.title}}</text>
  19. </view>
  20. <u-input :disabled="!status" border min="0" max="25" type="number" placeholder="请输入分值" value=""
  21. v-model="form[index]" @blur="change(item,index)" />
  22. </view>
  23. </view>
  24. <view class="btn" v-if="status" @click="confirm">
  25. 提交
  26. </view>
  27. <view class="wraning" v-else>
  28. 您已完成评价,不可再次评价!
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. export default {
  34. data() {
  35. return {
  36. list: [],
  37. form: {},
  38. title: '',
  39. warn: false,
  40. id: '',
  41. notice: '',
  42. status: true,
  43. mine_id: ''
  44. }
  45. },
  46. async onLoad(options) {
  47. this.mine_id = options.id
  48. await this.getList()
  49. // this.getStatus()
  50. console.log(this.$store.state.vuex_user, 'this.$store.state.vuex_user')
  51. },
  52. methods: {
  53. getList() {
  54. this.$u.get('/answer/question', {
  55. type: 1
  56. }).then(res => {
  57. this.list = res.data.list
  58. this.title = res.data.title
  59. this.id = res.data.id
  60. this.notice = res.data.announcements
  61. console.log(res, 'res')
  62. this.getStatus()
  63. })
  64. },
  65. getStatus() {
  66. this.$u.get('/answer/is-answer-status', {
  67. question_id: this.id,
  68. teacher_id: this.mine_id
  69. }).then(res => {
  70. if (res.data.msg) {
  71. uni.showToast({
  72. title: res.data.msg,
  73. icon: 'none'
  74. })
  75. }
  76. this.status = res.data.status
  77. console.log(res, 'res')
  78. })
  79. },
  80. //input框失去焦点
  81. change(item, index) {
  82. console.log(this.form[index],'fushu')
  83. if (item.is_must == 1) {
  84. if (Number(this.form[index])!=0 && !this.form[index]) {
  85. this.warn = true
  86. let message = '请完成第' + (index + 1) + '条的填写'
  87. uni.showToast({
  88. title: message,
  89. icon: 'none'
  90. })
  91. }
  92. }
  93. if (Number(this.form[index]) > item.max_point || Number(this.form[index]) < item.min_point) {
  94. console.log(this.form[index],'fushu')
  95. this.form[index] = ''
  96. uni.showToast({
  97. title: '输入分值超出范围,请重新输入',
  98. icon: 'none'
  99. })
  100. console.log(this.form[index])
  101. }
  102. this.form[index] = parseInt(this.form[index])
  103. },
  104. confirm() {
  105. let that = this
  106. console.log(this.form, 'form')
  107. try {
  108. this.list.forEach((item, index) => {
  109. if (item.is_must == 1 && (Number(this.form[index])!=0 && !this.form[index])) {
  110. let message = '请完成第' + (index + 1) + '条的填写'
  111. uni.showToast({
  112. title: message,
  113. icon: 'none'
  114. })
  115. throw new Error('ending')
  116. } else {
  117. }
  118. })
  119. uni.showModal({
  120. title: '提交确认',
  121. content: '确认提交问卷?',
  122. showCancel: true, //是否显示取消按钮
  123. cancelText: "否", //默认是“取消”
  124. // cancelColor: 'skyblue', //取消文字的颜色
  125. confirmText: "是", //默认是“确定”
  126. // confirmColor: 'skyblue', //确定文字的颜色
  127. success: function(res) {
  128. if (res.cancel) {
  129. //点击取消,默认隐藏弹框
  130. } else {
  131. //点击确定
  132. let params = {
  133. question_id: that.id,
  134. data: [],
  135. teacher_id: that.mine_id
  136. }
  137. for (let i in that.form) {
  138. params.data.push(that.form[i])
  139. }
  140. console.log(params, 'params')
  141. that.$u.post('/answer/answer', params).then(res => {
  142. uni.showToast({
  143. title: res.message,
  144. icon: 'none'
  145. })
  146. // that.getStatus()
  147. setTimeout(() => {
  148. uni.navigateBack()
  149. }, 1000)
  150. })
  151. }
  152. },
  153. })
  154. } catch (e) {
  155. if (e.message == "ending") {
  156. console.log("结束了");
  157. } else {
  158. console.log(e.message);
  159. }
  160. }
  161. }
  162. }
  163. }
  164. </script>
  165. <style scoped lang="scss">
  166. .wenjuan {
  167. padding: 0 15px 20px;
  168. .title_wrap {
  169. border-bottom: 1px dashed #999999;
  170. // padding-bottom: 20px;
  171. .title {
  172. text-align: center;
  173. font-size: 18px;
  174. font-weight: 600;
  175. padding-bottom: 10px;
  176. }
  177. .notice {
  178. // color: #999999;
  179. background-color: #f0f0f0;
  180. padding: 5px;
  181. border-radius: 6px;
  182. margin-bottom: 10px;
  183. font-size: 12px;
  184. line-height: 22px;
  185. text {
  186. font-size: 14px;
  187. font-weight: 550;
  188. }
  189. }
  190. }
  191. .wrap {
  192. margin-top: 15px;
  193. margin-bottom: 30px;
  194. .item {
  195. margin-bottom: 30px;
  196. .item_title {
  197. .star {
  198. color: red;
  199. margin-right: 2px;
  200. }
  201. margin-bottom: 10px;
  202. }
  203. u-input {
  204. margin-top: 10px;
  205. border: 1px solid;
  206. // width: 100px;
  207. width: 50%;
  208. padding: 5px 8px;
  209. height: 30px;
  210. box-sizing: border-box;
  211. }
  212. }
  213. }
  214. .btn {
  215. height: 40px;
  216. background-color: #D12727;
  217. color: #fff;
  218. font-size: 16px;
  219. line-height: 40px;
  220. text-align: center;
  221. border-radius: 20px;
  222. }
  223. .wraning {
  224. color: #CE3C39;
  225. font-size: 14px;
  226. text-align: center;
  227. }
  228. }
  229. </style>