submit-task.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <view>
  3. <navbar :config="config" backColor="#999999"></navbar>
  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. config: {
  74. back: true,
  75. title: '任务提交',
  76. color: 'black',
  77. backgroundColor: [1, '#fff'],
  78. statusBarFontColor: 'black'
  79. },
  80. // 单任务领取ID
  81. receiveTaskId: null,
  82. //多任务子ID
  83. receiveChildTaskId: null,
  84. // 任务信息
  85. TaskInfo: null,
  86. // 任务规则
  87. TaskRule: null,
  88. formData: {
  89. submitContent: '',
  90. photos: [],
  91. lbsPosition: '',
  92. soundRecording: [],
  93. videos: []
  94. }
  95. }
  96. },
  97. onLoad(opt) {
  98. this.receiveTaskId = opt.receiveTaskId;
  99. this.receiveChildTaskId = opt.receiveChildTaskId;
  100. this.checkPage = opt.checkPage === 'true' ? true : false;
  101. if (this.receiveTaskId) {
  102. // 查询单任务详情
  103. this.getMyTaskInfo()
  104. }
  105. if (this.receiveChildTaskId) {
  106. // 查询单任务详情
  107. this.getMyMoreTaskInfo()
  108. }
  109. },
  110. methods: {
  111. initFormData(val) {
  112. this.formData = {
  113. submitContent: val.submitContent || '',
  114. photos: val.photos || [],
  115. lbsPosition: val.lbsPosition || '',
  116. soundRecording: val.soundRecording || [],
  117. videos: val.videos || [],
  118. }
  119. },
  120. // 查询单任务详情
  121. getMyTaskInfo() {
  122. getMyTaskInfo_Api(this.receiveTaskId).then(res => {
  123. const childTask = res.data ? res.data.childTaskVoList[0] : null
  124. if (childTask) {
  125. this.TaskInfo = childTask
  126. this.TaskRule = childTask.childTaskRule || null
  127. this.initFormData(childTask);
  128. };
  129. })
  130. },
  131. getMyMoreTaskInfo() {
  132. getMyMoreTaskInfo_Api(this.receiveChildTaskId).then(res => {
  133. const childTask = res.data || null
  134. this.TaskInfo = childTask
  135. this.TaskRule = childTask?.childTaskRule || null;
  136. this.initFormData(childTask)
  137. })
  138. },
  139. onSubmit() {
  140. if (!this.TaskRule || this.TaskRule.length === 0) return
  141. const obj = {};
  142. try {
  143. this.TaskRule.forEach(el => {
  144. switch (el.taskRuleType) {
  145. case 0:
  146. if (el.need) {
  147. const num = this.formData.lbsPosition;
  148. if (el.required && !num) throw new Error('请先定位');
  149. obj.lbsPosition = this.formData.lbsPosition
  150. }
  151. break;
  152. case 1:
  153. if (el.need) {
  154. const num = this.formData.photos.length;
  155. if (el.required && !num) throw new Error('请先上传照片');
  156. obj.photos = this.formData.photos
  157. }
  158. break;
  159. case 2:
  160. if (el.need) {
  161. const num = this.formData.videos;
  162. if (el.required && !num) throw new Error('请先上传视频');
  163. obj.videos = this.formData.videos
  164. }
  165. break;
  166. case 3:
  167. if (el.need) {
  168. const num = this.formData.soundRecording.length;
  169. if (el.required && !num) throw new Error('请先上传录音');
  170. obj.soundRecording = this.formData.soundRecording
  171. }
  172. break;
  173. case 4:
  174. if (el.need) {
  175. const num = this.formData.submitContent;
  176. if (el.required && !num) throw new Error('请输入内容');
  177. obj.submitContent = this.formData.submitContent
  178. }
  179. break;
  180. }
  181. })
  182. } catch (e) {
  183. //TODO handle the exception
  184. uni.showToast({
  185. title: e.message,
  186. icon: 'none'
  187. })
  188. return false
  189. }
  190. submitTask_Api({
  191. ...obj,
  192. receiveChildTaskId: this.TaskInfo.receiveChildTaskId
  193. }).then(res => {
  194. uni.showToast({
  195. title: '提交成功',
  196. icon: 'none'
  197. })
  198. uni.redirectTo({
  199. url: '/pages/task/submit-success'
  200. })
  201. })
  202. }
  203. }
  204. }
  205. </script>
  206. <style lang="scss" scoped>
  207. @import "./common.scss";
  208. .pages-content {
  209. width: 100%;
  210. padding: 0 30rpx;
  211. .task-form-box {
  212. padding-bottom: 72rpx;
  213. }
  214. }
  215. .form-placeholder {
  216. font-size: 24rpx;
  217. font-weight: Light;
  218. color: #b3b3b3;
  219. // line-height: 50rpx;
  220. }
  221. .submitTime {
  222. font-size: 28rpx;
  223. font-weight: 600;
  224. text-align: left;
  225. color: #1A1A1A;
  226. line-height: 40px;
  227. .submitTime-t {
  228. font-weight: 400;
  229. color: #808080;
  230. }
  231. }
  232. </style>