index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <template>
  2. <view class="content" v-if="formData.itemName!=null">
  3. <view class="">
  4. <image class="logo" src="../../static/logo.png"></image>
  5. <view class="uni-box-head">
  6. <uni-title type="h2" align="center" :title="formData.itemName + formData.cycleName"></uni-title>
  7. </view>
  8. <uni-notice-bar show-icon text="以下各评分项之和需等于100" />
  9. <uni-title type="h5" align="center" :title="questions[0].parentLabel" color=rgb(191,44,35)></uni-title>
  10. </view>
  11. <view class="formData">
  12. <uni-forms :modelValue="formData" ref="form">
  13. <view class="uni-box-head">
  14. <uni-forms-item name="professorNo">
  15. <uni-easyinput prefixIcon="person" v-model="formData.professorNo" placeholder="请输入专家编号(必填)"
  16. maxlength="8" trim="all" />
  17. </uni-forms-item>
  18. </view>
  19. <uni-forms-item v-for="(item,index) in questions" :key="index">
  20. <uni-card :is-shadow="true" margin="5px">
  21. <uni-icons type="help-filled" size="20" color="green"></uni-icons>
  22. <text class="uni-body"
  23. style="color: black; font-size:medium; letter-spacing: 1px; margin-left: 20rpx; border-bottom: 1rpx solid gray;">{{(index+1) +"."+item.label}}</text>
  24. <text style="font-size: smaller; color:darkgrey;float:right">
  25. {{(item.minScore==null ||item.maxScore==null )?"":item.minScore+'-'+item.maxScore}}
  26. </text>
  27. <view slot="actions">
  28. <view class="uni-mt-5">
  29. <uni-forms-item name="score">
  30. <uni-easyinput suffixIcon="star-filled" type="number" v-model="item.score"
  31. trim="all" placeholder="请输入该项分数" />
  32. </uni-forms-item>
  33. </view>
  34. </view>
  35. </uni-card>
  36. </uni-forms-item>
  37. </uni-forms>
  38. <button type="primary" @click="submit">下一步</button>
  39. </view>
  40. <view>
  41. <!-- 提示窗示例 -->
  42. <uni-popup ref="alertDialog" type="dialog">
  43. <uni-popup-dialog :type="msgType" cancelText="关闭" title="提示" :content="content"
  44. @close="dialogClose"></uni-popup-dialog>
  45. </uni-popup>
  46. </view>
  47. </view>
  48. <view v-else class="noDucument">
  49. <image class="logo" src="../../static/logo.png"></image>
  50. 暂无问卷
  51. </view>
  52. </template>
  53. <script>
  54. export default {
  55. data() {
  56. return {
  57. formData: {
  58. id: null,
  59. documentId: null,
  60. cycleName: "",
  61. itemName: "",
  62. questions: [
  63. {
  64. parentLabel:""
  65. }
  66. ]
  67. },
  68. msgType: 'error',
  69. content: null,
  70. socket: null,
  71. questions: [
  72. {
  73. parentLabel:""
  74. }
  75. ],
  76. commitQuestions: [],
  77. index: 1
  78. }
  79. },
  80. onLoad() {
  81. this.initWS();
  82. this.getDocument();
  83. },
  84. methods: {
  85. initWS() {
  86. let socket = uni.connectSocket({
  87. url: 'wss://kps.scdayou.com/ws/apo/ws',
  88. //url: 'ws://127.0.0.1:8090/apo/ws',
  89. method: 'GET',
  90. success: () => {
  91. console.log("socket success")
  92. }
  93. });
  94. this.socket = socket;
  95. },
  96. dialogToggle(val) {
  97. this.content = val;
  98. this.$refs.alertDialog.open()
  99. },
  100. getDocument() {
  101. var that = this;
  102. uni.request({
  103. //url: "http://127.0.0.1:8090/apo/document/current",
  104. url: "https://kps.scdayou.com/apo/document/current",
  105. data: null,
  106. method: "get",
  107. success: function(res) {
  108. that.formData = res.data.data;
  109. that.questions = that.formData.questions[0];
  110. },
  111. })
  112. },
  113. submit() {
  114. //uni.showLoading()
  115. var that = this;
  116. const data = that.formData;
  117. let xQuestions = that.questions;
  118. if (!data.professorNo) {
  119. that.dialogToggle("请输入专家编号")
  120. //uni.hideLoading()
  121. return
  122. }
  123. let totalScore = 0;
  124. for (let i in xQuestions) {
  125. if (xQuestions[i].score == null || xQuestions[i].score == "") {
  126. that.dialogToggle("还存在未评分的题目,请完成后提交。")
  127. return
  128. }
  129. totalScore += parseFloat(xQuestions[i].score);
  130. }
  131. if (totalScore != 100) {
  132. that.dialogToggle("评分之和必须等于100,请检查后再提交。")
  133. return
  134. }
  135. for (let i in that.questions) {
  136. that.commitQuestions.push(that.questions[i]);
  137. }
  138. console.log("当前的", xQuestions)
  139. that.questions = [];
  140. for (let i=this.index; i<that.formData.questions.length;i++){
  141. console.log("i",i)
  142. if (that.formData.questions[i].length>0){
  143. this.questions = that.formData.questions[i];
  144. this.index = i+1;
  145. return
  146. }
  147. }
  148. console.log("that.commotData", that.commitQuestions)
  149. that.formData.result = that.commitQuestions;
  150. that.formData.questions = [];
  151. uni.request({
  152. //url: "http://127.0.0.1:8090/apo/document/commit",
  153. url: "https://kps.scdayou.com/apo/document/commit",
  154. data: that.formData,
  155. method: "post",
  156. success: function(res) {
  157. that.formData = {
  158. professorNo: null,
  159. questions: []
  160. };
  161. that.commitQuestions = [];
  162. that.questions = [];
  163. uni.closeSocket(that.socket);
  164. uni.navigateTo({
  165. url: 'ok'
  166. });
  167. },
  168. })
  169. },
  170. findChildren(item,callback){
  171. if (item.children.length>0){
  172. callback(item.children);
  173. }
  174. }
  175. },
  176. destoryed() {
  177. // 在组件销毁前断开 WebSocket 连接
  178. uni.onSocketClose(function(res) {
  179. console.log('WebSocket 已关闭!');
  180. });
  181. },
  182. beforeDestory() {
  183. uni.onSocketClose(function(res) {
  184. console.log('WebSocket 已关闭!');
  185. });
  186. }
  187. }
  188. </script>
  189. <style>
  190. .content {
  191. align-items: center;
  192. justify-content: center;
  193. }
  194. .logo {
  195. height: 170rpx;
  196. width: 700rpx;
  197. margin-top: 10rpx;
  198. margin-left: 10rpx;
  199. margin-bottom: 50rpx;
  200. margin-right: 10rpx;
  201. }
  202. .uni-box-head {
  203. margin-right: 10rpx;
  204. margin-left: 10rpx;
  205. margin-bottom: 20rpx;
  206. }
  207. .uni-mt-5 {
  208. margin-left: 1.5%;
  209. margin-bottom: 40rpx
  210. }
  211. .options {
  212. display: flex;
  213. margin-bottom: 20rpx
  214. }
  215. .text {
  216. font-size: larger !important;
  217. margin-top: 5rpx;
  218. letter-spacing: 0.5px;
  219. }
  220. .noDucument {
  221. text-align: center;
  222. font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
  223. font-size: 20px;
  224. font-weight: bold;
  225. color: red;
  226. margin-top: 40%;
  227. }
  228. .button-text {
  229. color: #fff;
  230. font-size: 12px;
  231. }
  232. .error-text {
  233. color: #f56c6c;
  234. }
  235. </style>