index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. watch:{
  85. questions:{
  86. handler(newValue,oldValue){
  87. let lastItemIndex = this.questions.length-1;
  88. let preouisLastItemIndex = this.questions.length-2;
  89. let lastScore =100;
  90. for (let i in newValue){
  91. if (newValue[i].score != null && newValue[i].score != "") {
  92. lastScore = lastScore - (parseFloat(newValue[i].score));
  93. if (i == preouisLastItemIndex && lastScore>=0){
  94. this.questions[lastItemIndex].score = lastScore
  95. }
  96. }
  97. }
  98. },
  99. deep:true
  100. }
  101. },
  102. methods: {
  103. initWS() {
  104. let socket = uni.connectSocket({
  105. url: 'wss://kps.scdayou.com/ws/apo/ws',
  106. //url: 'ws://127.0.0.1:8090/apo/ws',
  107. method: 'GET',
  108. success: () => {
  109. console.log("socket success")
  110. }
  111. });
  112. this.socket = socket;
  113. },
  114. dialogToggle(val) {
  115. this.content = val;
  116. this.$refs.alertDialog.open()
  117. },
  118. getDocument() {
  119. var that = this;
  120. uni.request({
  121. //url: "http://127.0.0.1:8090/apo/document/current",
  122. url: "https://kps.scdayou.com/apo/document/current",
  123. data: null,
  124. method: "get",
  125. success: function(res) {
  126. that.formData = res.data.data;
  127. if (that.formData.questions!=null){
  128. that.questions = that.formData.questions[0];
  129. }
  130. },
  131. })
  132. },
  133. submit() {
  134. //uni.showLoading()
  135. var that = this;
  136. const data = that.formData;
  137. let xQuestions = that.questions;
  138. if (!data.professorNo) {
  139. that.dialogToggle("请输入专家编号")
  140. //uni.hideLoading()
  141. return
  142. }
  143. let totalScore = 0;
  144. for (let i in xQuestions) {
  145. if (xQuestions[i].score == null || xQuestions[i].score == "") {
  146. that.dialogToggle("还存在未评分的题目,请完成后提交。")
  147. return
  148. }
  149. totalScore += parseFloat(xQuestions[i].score);
  150. }
  151. if (totalScore != 100) {
  152. that.dialogToggle("评分之和必须等于100,请检查后再提交。")
  153. return
  154. }
  155. for (let i in that.questions) {
  156. that.commitQuestions.push(that.questions[i]);
  157. }
  158. that.questions = [];
  159. for (let i=this.index; i<that.formData.questions.length;i++){
  160. if (that.formData.questions[i].length>0){
  161. this.questions = that.formData.questions[i];
  162. this.index = i+1;
  163. return
  164. }
  165. }
  166. that.formData.result = that.commitQuestions;
  167. that.formData.questions = [];
  168. uni.request({
  169. //url: "http://127.0.0.1:8090/apo/document/commit",
  170. url: "https://kps.scdayou.com/apo/document/commit",
  171. data: that.formData,
  172. method: "post",
  173. success: function(res) {
  174. that.formData = {
  175. professorNo: null,
  176. questions: []
  177. };
  178. that.commitQuestions = [];
  179. that.questions = [];
  180. uni.closeSocket(that.socket);
  181. uni.navigateTo({
  182. url: 'ok'
  183. });
  184. },
  185. })
  186. },
  187. findChildren(item,callback){
  188. if (item.children.length>0){
  189. callback(item.children);
  190. }
  191. }
  192. },
  193. destoryed() {
  194. // 在组件销毁前断开 WebSocket 连接
  195. uni.onSocketClose(function(res) {
  196. console.log('WebSocket 已关闭!');
  197. });
  198. },
  199. beforeDestory() {
  200. uni.onSocketClose(function(res) {
  201. console.log('WebSocket 已关闭!');
  202. });
  203. }
  204. }
  205. </script>
  206. <style>
  207. .content {
  208. align-items: center;
  209. justify-content: center;
  210. }
  211. .logo {
  212. height: 170rpx;
  213. width: 700rpx;
  214. margin-top: 10rpx;
  215. margin-left: 10rpx;
  216. margin-bottom: 50rpx;
  217. margin-right: 10rpx;
  218. }
  219. .uni-box-head {
  220. margin-right: 10rpx;
  221. margin-left: 10rpx;
  222. margin-bottom: 20rpx;
  223. }
  224. .uni-mt-5 {
  225. margin-left: 1.5%;
  226. margin-bottom: 40rpx
  227. }
  228. .options {
  229. display: flex;
  230. margin-bottom: 20rpx
  231. }
  232. .text {
  233. font-size: larger !important;
  234. margin-top: 5rpx;
  235. letter-spacing: 0.5px;
  236. }
  237. .noDucument {
  238. text-align: center;
  239. font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
  240. font-size: 20px;
  241. font-weight: bold;
  242. color: red;
  243. margin-top: 40%;
  244. }
  245. .button-text {
  246. color: #fff;
  247. font-size: 12px;
  248. }
  249. .error-text {
  250. color: #f56c6c;
  251. }
  252. </style>