submit-task.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <view>
  3. <nav-bar title="任务提交" goBack />
  4. <view class="pages-content">
  5. <template v-if="TaskInfo">
  6. <view class="task-title">
  7. {{TaskInfo.childTaskTitle}}
  8. </view>
  9. <view class="task-explain">
  10. {{TaskInfo.childTaskRemark}}
  11. </view>
  12. <view class="task-form-box" v-if="TaskRule && TaskRule.length > 0">
  13. <block v-for="(Rule,RuleIndex) in TaskRule">
  14. <!-- ( code: 0, msg:"定位地址")
  15. ( code: 1,msg:"照片")
  16. ( code: 2, msg:"视频")
  17. ( code: 3,msg:“录音")
  18. ( code: 4,msg:“提交内容”) -->
  19. <submitlLocation v-if="Rule.taskRuleType === 0 && Rule.need" :rule="Rule" :checkPage="checkPage"
  20. v-model="formData.lbsPosition" />
  21. <!-- 照片 -->
  22. <submitImg v-if="Rule.taskRuleType === 1&& Rule.need" :rule="Rule" v-model="formData.photos"
  23. :checkPage="checkPage" />
  24. <!-- 视频 -->
  25. <submitVideo v-if="Rule.taskRuleType === 2&& Rule.need" :rule="Rule"
  26. v-model="formData.videos" />
  27. <!-- 音频 -->
  28. <submitAudio v-if="Rule.taskRuleType === 3&& Rule.need" :rule="Rule"
  29. v-model="formData.soundRecording" :checkPage="checkPage" />
  30. <!-- 内容 -->
  31. <submintContent v-if="Rule.taskRuleType === 4&& Rule.need" :rule="Rule"
  32. v-model="formData.submitContent" :checkPage="checkPage" />
  33. </block>
  34. </view>
  35. </template>
  36. <view class="submitTime" v-if="checkPage && TaskInfo">
  37. 提交时间:<text class="submitTime-t">{{TaskInfo.submitTime}}</text>
  38. </view>
  39. <!-- 必须要有规则才能显示提交按钮 -->
  40. <task-bottom-btn v-if="TaskRule && TaskRule.length > 0 && !checkPage" btnName="提交" @onClick="onSubmit" />
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import taskBottomBtn from "./components/task-bottom-btn.vue";
  46. import submintContent from "./components/submintContent.vue";
  47. import submitImg from "./components/submitImg.vue";
  48. // import submitVideo from "./components/submitVideo.vue";
  49. // import submitVideo_app from "./components/submitVideo_app.vue";
  50. import submitVideo from "./components/submitVideo.vue";
  51. import submitAudio from "./components/submitAudio.vue";
  52. import submitlLocation from "./components/submitlLocation.vue";
  53. import {
  54. getTaskInfo_Api,
  55. getrReceiveTask_Api,
  56. getMyTaskInfo_Api,
  57. getMyMoreTaskInfo_Api,
  58. onSubmitCheck_Api,
  59. submitTask_Api
  60. } from "@/api/task.js"
  61. export default {
  62. components: {
  63. taskBottomBtn,
  64. submintContent,
  65. submitImg,
  66. submitAudio,
  67. submitlLocation,
  68. submitVideo
  69. },
  70. data() {
  71. return {
  72. checkPage: false,
  73. // 单任务领取ID
  74. receiveTaskId: null,
  75. //多任务子ID
  76. receiveChildTaskId: null,
  77. // 任务信息
  78. TaskInfo: null,
  79. // 任务规则
  80. TaskRule: null,
  81. formData: {
  82. submitContent: '',
  83. photos: [],
  84. lbsPosition: '',
  85. soundRecording: [],
  86. videos: []
  87. }
  88. }
  89. },
  90. onLoad(opt) {
  91. this.receiveTaskId = opt.receiveTaskId;
  92. this.receiveChildTaskId = opt.receiveChildTaskId;
  93. this.checkPage = opt.checkPage === 'true' ? true : false;
  94. if (this.receiveTaskId) {
  95. // 查询单任务详情
  96. this.getMyTaskInfo()
  97. }
  98. if (this.receiveChildTaskId) {
  99. // 查询单任务详情
  100. this.getMyMoreTaskInfo()
  101. }
  102. },
  103. methods: {
  104. initFormData(val) {
  105. this.formData = {
  106. submitContent: val.submitContent || '',
  107. photos: val.photos || [],
  108. lbsPosition: val.lbsPosition || '',
  109. soundRecording: val.soundRecording || [],
  110. videos: val.videos || [],
  111. }
  112. },
  113. // 查询单任务详情
  114. getMyTaskInfo() {
  115. getMyTaskInfo_Api(this.receiveTaskId).then(res => {
  116. const childTask = res.data ? res.data.childTaskVoList[0] : null
  117. if (childTask) {
  118. this.TaskInfo = childTask
  119. this.TaskRule = childTask.childTaskRule || null
  120. this.initFormData(childTask);
  121. };
  122. })
  123. },
  124. getMyMoreTaskInfo() {
  125. getMyMoreTaskInfo_Api(this.receiveChildTaskId).then(res => {
  126. const childTask = res.data || null
  127. this.TaskInfo = childTask
  128. this.TaskRule = childTask?.childTaskRule || null;
  129. this.initFormData(childTask)
  130. })
  131. },
  132. onSubmit() {
  133. if (!this.TaskRule || this.TaskRule.length === 0) return
  134. const obj = {};
  135. try {
  136. this.TaskRule.forEach(el => {
  137. switch (el.taskRuleType) {
  138. case 0:
  139. if (el.need) {
  140. const num = this.formData.lbsPosition;
  141. if (el.required && !num) throw new Error('请先定位');
  142. obj.lbsPosition = this.formData.lbsPosition
  143. }
  144. break;
  145. case 1:
  146. if (el.need) {
  147. const num = this.formData.photos.length;
  148. if (el.required && !num) throw new Error('请先上传照片');
  149. obj.photos = this.formData.photos
  150. }
  151. break;
  152. case 2:
  153. if (el.need) {
  154. const num = this.formData.videos;
  155. if (el.required && !num) throw new Error('请先上传视频');
  156. obj.videos = this.formData.videos
  157. }
  158. break;
  159. case 3:
  160. if (el.need) {
  161. const num = this.formData.soundRecording.length;
  162. if (el.required && !num) throw new Error('请先上传录音');
  163. obj.soundRecording = this.formData.soundRecording
  164. }
  165. break;
  166. case 4:
  167. if (el.need) {
  168. const num = this.formData.submitContent;
  169. if (el.required && !num) throw new Error('请输入内容');
  170. obj.submitContent = this.formData.submitContent
  171. }
  172. break;
  173. }
  174. })
  175. } catch (e) {
  176. //TODO handle the exception
  177. uni.showToast({
  178. title: e.message,
  179. icon: 'none'
  180. })
  181. return false
  182. }
  183. submitTask_Api({
  184. ...obj,
  185. receiveChildTaskId: this.TaskInfo.receiveChildTaskId
  186. }).then(res => {
  187. uni.showToast({
  188. title: '提交成功',
  189. icon: 'none'
  190. })
  191. uni.redirectTo({
  192. url: '/pages/task/submit-success'
  193. })
  194. })
  195. }
  196. }
  197. }
  198. </script>
  199. <style lang="scss" scoped>
  200. @import "./common.scss";
  201. .pages-content {
  202. width: 100%;
  203. padding: 0 30rpx;
  204. .task-form-box {
  205. padding-bottom: 72rpx;
  206. }
  207. }
  208. .form-placeholder {
  209. font-size: 24rpx;
  210. font-weight: Light;
  211. color: #b3b3b3;
  212. // line-height: 50rpx;
  213. }
  214. .submitTime {
  215. font-size: 28rpx;
  216. font-weight: 600;
  217. text-align: left;
  218. color: #1A1A1A;
  219. line-height: 40px;
  220. .submitTime-t {
  221. font-weight: 400;
  222. color: #808080;
  223. }
  224. }
  225. </style>