fillTeamInfo.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <view class="default_page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title='填写所在团队信息'></cus-header>
  4. <cus-team-info-fill ref="teamRef" :submitting="creationState.submitting || creationState.completed" @handleConfirm="handleConfirm" :confirmText="confirmText" :qtype="qtype"></cus-team-info-fill>
  5. </view>
  6. </template>
  7. <script>
  8. import CusTeamInfoFill from '@/components/CusTeamInfoFill/index.vue'
  9. import teamBackgroundRules from '@/utils/teamBackgroundFile.js'
  10. const {
  11. beginTeamSubmission,
  12. createTeamCreationState,
  13. finishTeamSubmission,
  14. rememberCreatedTeam,
  15. setTeamSubmissionStage
  16. } = teamBackgroundRules
  17. export default {
  18. components:{ CusTeamInfoFill },
  19. data(){
  20. return {
  21. title:'',
  22. type:'',
  23. next:'',
  24. questionnaireId:'',
  25. confirmText:'下一步',
  26. qtype:'',
  27. creationState:createTeamCreationState()
  28. }
  29. },
  30. onLoad(options) {
  31. this.title = options.title||'';
  32. this.type = options.type;
  33. this.qtype = options.qtype||'';
  34. this.questionnaireId = options.questionnaireId||'';
  35. this.confirmText = options.type?'确定':'下一步';
  36. this.next = options.next;
  37. if(this.next) this.confirmText = '下一步';
  38. },
  39. methods:{
  40. async handleConfirm(team){
  41. if(!beginTeamSubmission(this.creationState)) return
  42. team.questionnaireId = this.questionnaireId;
  43. try {
  44. let teamId = this.creationState.createdTeamId
  45. if(!teamId){
  46. setTeamSubmissionStage(this.creationState, 'save')
  47. const { data:res } = await this.$api.post('/core/user/team',team)
  48. if(res.code!==0){
  49. this.$showToast(res.msg || '团队保存失败,请重试')
  50. return
  51. }
  52. teamId = res.data && res.data.teamId
  53. if(!teamId){
  54. this.$showToast('团队保存未返回团队ID,请重试')
  55. return
  56. }
  57. rememberCreatedTeam(this.creationState, teamId)
  58. }
  59. setTeamSubmissionStage(this.creationState, 'upload')
  60. const uploadResult = await this.$refs.teamRef.flushBackgroundFiles(teamId)
  61. if(uploadResult.failed > 0 || this.$refs.teamRef.hasUnresolvedBackgroundFiles()){
  62. await this.$showModal('仍有背景资料未上传成功,请重试后继续;团队已保存,无需再次创建')
  63. return
  64. }
  65. if(this.$refs.teamRef.hasDeferredPcUpload()){
  66. setTeamSubmissionStage(this.creationState, 'pcSession')
  67. await this.$refs.teamRef.waitForDeferredPcUpload(teamId)
  68. }
  69. setTeamSubmissionStage(this.creationState, this.next ? 'publish' : 'navigate')
  70. await this.continueAfterTeamCreated(teamId)
  71. finishTeamSubmission(this.creationState, true)
  72. } catch(error) {
  73. this.showStageError(error)
  74. } finally {
  75. finishTeamSubmission(this.creationState)
  76. }
  77. },
  78. showStageError(error) {
  79. const prefix = {
  80. save:'团队保存失败',
  81. upload:'背景资料处理失败',
  82. pcSession:'电脑上传流程失败',
  83. publish:'问卷发布失败',
  84. navigate:'后续操作失败'
  85. }[this.creationState.stage] || '操作失败'
  86. const message = error && (error.message || error.msg)
  87. this.$showToast(message ? `${prefix}:${message}` : `${prefix},请重试`)
  88. },
  89. async continueAfterTeamCreated(teamId) {
  90. if(this.next){
  91. const response = await this.$api.post('/core/team/questionnaire/publish',{
  92. answerSetting:1,
  93. coachId:JSON.parse(uni.getStorageSync('userInfo')).id,
  94. startTime:new Date().Format('yyyy-MM-dd hh:mm:ss'),
  95. endTime:new Date(new Date().setDate(new Date().getDate()+30)).Format('yyyy-MM-dd hh:mm:ss'),
  96. questionnaireId:this.questionnaireId,
  97. teamId,
  98. type:1
  99. })
  100. const result = response.data
  101. if(result.code!==0) throw new Error(result.msg || '发布请求失败')
  102. this.$showToast('保存成功,即将填写问卷')
  103. setTimeout(()=>{
  104. uni.removeStorageSync('newUser')
  105. uni.navigateTo({
  106. url:`/pagesPublish/questionnaireFill?teamQuestionnaireId=${result.data}&teamId=${teamId}&type=${this.type}&title=${this.title}`
  107. })
  108. },1500)
  109. return
  110. }
  111. this.$showToast('团队新增成功')
  112. setTimeout(()=>{
  113. this.getOpenerEventChannel().emit('saveTeamInfo')
  114. uni.navigateBack()
  115. },1500)
  116. }
  117. }
  118. }
  119. </script>
  120. <style scoped lang="scss">
  121. .default_page{
  122. box-sizing: border-box;
  123. }
  124. </style>