questionnaireFill.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title='问卷填写' :backAlert="true"></cus-header>
  4. <div class="top adffcacjc">
  5. <p>{{title}}</p>
  6. <p class="tip">共 <span>{{list.length}}</span> 题,已作答 <span style="font-weight: bold;">{{answerNum}}</span> 题,请耐心选择!</p>
  7. </div>
  8. <div class="list" :style="{'height':(h-180-mt)+'px'}">
  9. <div class="l_item" v-for="(item,index) in list" :key="index">
  10. <div class="li_box" :class="{'active':item.warn}">
  11. <div class="lb_title adf">
  12. <span>*</span>
  13. {{index+1}}. {{item.question}}
  14. </div>
  15. <div class="lb_answers">
  16. <u-radio-group v-model="item.answer" placement="column">
  17. <div class="la_item" v-for="(pre,idx) in item.userAnswer" :key="idx">
  18. <u-radio :label="pre.questionOption" :name="pre.questionOption" activeColor="#833478" size="36rpx" iconSize="32rpx" labelSize="32rpx"></u-radio>
  19. </div>
  20. </u-radio-group>
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. <div class="bottom">
  26. <div class="zt_btn" @tap="submitWj">提交问卷</div>
  27. </div>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. data(){
  33. return {
  34. title:'',
  35. teamQuestionnaireId:'',
  36. list:[],
  37. answerNum:0,
  38. questionnaire:null
  39. }
  40. },
  41. onLoad(option) {
  42. this.title = option.title;
  43. this.teamQuestionnaireId = option.teamQuestionnaireId;
  44. this.getList();
  45. },
  46. watch:{
  47. list:{
  48. handler(newval){
  49. this.answerNum = this.list.filter(l=>l.answer!='')?.length||0;
  50. },
  51. deep:true
  52. }
  53. },
  54. methods:{
  55. getList(){
  56. if(uni.getStorageSync('questionnaire')) this.questionnaire = JSON.parse(uni.getStorageSync('questionnaire'))
  57. this.$api.get('/core/team/member/answer/listByUser/'+this.teamQuestionnaireId).then(res=>{
  58. if(res.data.code!==0) return this.$showToast(res.data.msg)
  59. this.list = res.data.data;
  60. this.list.forEach((l,i)=>{
  61. this.$set(this.list[i],'warn',false);
  62. this.$set(this.list[i],'answer','');
  63. if(this.questionnaire&&this.teamQuestionnaireId==this.questionnaire.key){
  64. let t = this.questionnaire.list.find(q=>q.id==l.id)
  65. this.$set(this.list[i],'answer',t?t.answer:'');
  66. }
  67. })
  68. })
  69. },
  70. submitWj(){
  71. this.list.forEach((l,i)=>{
  72. this.$set(this.list[i],'warn',!l.answer?true:false)
  73. })
  74. let idx = this.list.findIndex(l=>l.warn);
  75. if(idx>-1) return this.$showModal(`第${idx+1}项未选择答案,请选择。`)
  76. let newList = JSON.parse(JSON.stringify(this.list));
  77. newList.forEach(l=>{
  78. l.isAnswer = '1';
  79. let i = l.userAnswer.findIndex(a=>a.questionOption===l.answer)
  80. if(i>-1) l.userAnswer[i].userAnswer = true;
  81. delete l.answer
  82. delete l.warn
  83. })
  84. this.$api.post('/core/team/member/answer/submit',newList).then(res=>{
  85. if(res.data.code!==0) return this.$showToast(res.data.msg)
  86. uni.removeStorageSync('questionnaire')
  87. uni.navigateTo({
  88. url:'/pages/questionnaireResult'
  89. })
  90. })
  91. },
  92. setQuestionnaireCache(){
  93. if(uni.getStorageSync('questionnaire')) uni.removeStorageSync('questionnaire')
  94. let list = [];
  95. this.list.forEach(l=>{
  96. if(l.answer) list.push({id:l.id,answer:l.answer})
  97. })
  98. let qinfo = {
  99. key:this.teamQuestionnaireId,
  100. list
  101. }
  102. if(list.length===0) return
  103. uni.setStorageSync('questionnaire',JSON.stringify(qinfo));
  104. }
  105. },
  106. onUnload() {
  107. this.setQuestionnaireCache();
  108. },
  109. onBackPress() {
  110. this.setQuestionnaireCache();
  111. }
  112. }
  113. </script>
  114. <style scoped lang="less">
  115. .page{
  116. background: #F7F2F6;
  117. box-sizing: border-box;
  118. .top{
  119. p{
  120. font-family: PingFang-SC, PingFang-SC;
  121. font-weight: bold;
  122. font-size: 42rpx;
  123. color: #252525;
  124. line-height: 51rpx;
  125. text-align: center;
  126. margin-top: 48rpx;
  127. }
  128. .tip{
  129. font-family: PingFangSC, PingFang SC;
  130. font-weight: 400;
  131. font-size: 26rpx;
  132. color: #646464;
  133. line-height: 26rpx;
  134. text-align: center;
  135. margin-top: 36rpx;
  136. span{
  137. margin: 0 10rpx;
  138. }
  139. }
  140. }
  141. .list{
  142. width: 100%;
  143. overflow-y: auto;
  144. margin-top: 28rpx;
  145. .l_item{
  146. margin-top: 20rpx;
  147. width: 100%;
  148. background: #FFFFFF;
  149. padding: 6rpx;
  150. box-sizing: border-box;
  151. .li_box{
  152. width: 100%;
  153. padding: 32rpx 34rpx;
  154. box-sizing: border-box;
  155. &.active{
  156. border: 2rpx dotted #FD4F66;
  157. }
  158. .lb_title{
  159. font-family: PingFang-SC, PingFang-SC;
  160. font-weight: bold;
  161. font-size: 32rpx;
  162. color: #252525;
  163. line-height: 48rpx;
  164. span{
  165. font-family: PingFangSC, PingFang SC;
  166. font-weight: 400;
  167. font-size: 32rpx;
  168. color: #FD4F66;
  169. line-height: 51rpx;
  170. }
  171. }
  172. .lb_answers{
  173. width: calc(100% - 40rpx);
  174. margin: 30rpx 20rpx 0;
  175. box-sizing: border-box;
  176. border: 1rpx solid #E5E7EB;
  177. .la_item{
  178. padding: 34rpx 24rpx;
  179. border-bottom: 1rpx solid #E5E7EB;
  180. &:last-child{
  181. border-bottom: none;
  182. }
  183. }
  184. }
  185. .la_inp{
  186. width: 100%;
  187. height: 96rpx;
  188. border-radius: 24rpx;
  189. border: 1rpx solid #DFCDDC;
  190. padding: 24rpx 30rpx;
  191. box-sizing: border-box;
  192. margin-top: 30rpx;
  193. }
  194. .la_warn{
  195. padding: 7rpx 23rpx;
  196. margin-top: 20rpx;
  197. background: #FFECEC;
  198. .lw{
  199. width: 36rpx;
  200. height: 36rpx;
  201. border-radius: 50%;
  202. background: #FD4F66;
  203. }
  204. span{
  205. font-family: PingFangSC, PingFang SC;
  206. font-weight: 400;
  207. font-size: 24rpx;
  208. color: #FD4F66;
  209. line-height: 51rpx;
  210. margin-left: 17rpx;
  211. }
  212. }
  213. }
  214. }
  215. }
  216. .bottom{
  217. width: calc(100% - 80rpx);
  218. height: 88rpx;
  219. position: fixed;
  220. left: 40rpx;
  221. bottom: 40rpx;
  222. }
  223. }
  224. </style>