taskEdit.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <template>
  2. <view class="task-details">
  3. <view class="task-details__header">
  4. <task-card type="show" :dataSource="taskDetail"></task-card>
  5. </view>
  6. <view class="panel">
  7. <view class="panel__header">
  8. <view class="panel__title">任务汇报</view>
  9. </view>
  10. <view class="panel__content">
  11. <view class="task-details__area">
  12. <view class="task-details__edit-icon" v-if="!isMessageEdit" @click="isMessageEdit=!isMessageEdit">
  13. <uni-icons type="compose" color="#1B76FF"></uni-icons>
  14. </view>
  15. <u--textarea :focus="true" v-else v-model="report_msg" placeholder="" :maxlength="200" autoHeight
  16. border="none">
  17. </u--textarea>
  18. </view>
  19. </view>
  20. </view>
  21. <view class="task-details__body" v-if="task_type">
  22. <!-- <u-sticky>
  23. <task-tabs @tabClick="handleTabClick" :tabList="tabList"></task-tabs>
  24. </u-sticky> -->
  25. <view class="task-details__content">
  26. <!-- <transition name="slide-fade" mode="out-in" appear>
  27. <component :is="currentComponent" :dataSource="taskDetail" :isEdit="isEdit"></component>
  28. </transition> -->
  29. <EntrapmentComponent :dataSource="taskDetail" :isEdit="true" :isShowHeader="true"></EntrapmentComponent>
  30. </view>
  31. </view>
  32. <view class="task-details__footer">
  33. <u-button text="提交" type="primary" size="small" @click="taskfillingcom"></u-button>
  34. </view>
  35. <u-loading-page loading-text="加载中..." :loading="loading" font-size="16"></u-loading-page>
  36. </view>
  37. </template>
  38. <script>
  39. import {
  40. mapState
  41. } from 'vuex';
  42. import ClockInRecordComponent from './components/ClockInRecord.vue';
  43. import EntrapmentComponent from './components/Entrapment.vue';
  44. import GisComponent from './components/Gis.vue';
  45. import * as taskService from '@/service/task.js';
  46. import HeartBeat from '@/util/HeartBeat.js'
  47. export default {
  48. components: {
  49. ClockInRecordComponent,
  50. EntrapmentComponent,
  51. GisComponent
  52. },
  53. computed: {
  54. ...mapState({
  55. wornlist: state => state.wornlist
  56. }),
  57. tabList() {
  58. if (this.task_type) {
  59. return [{
  60. id: 1,
  61. name: '签到记录',
  62. }, {
  63. id: 2,
  64. name: '诱捕器',
  65. }, {
  66. id: 3,
  67. name: '行驶轨迹'
  68. }]
  69. } else {
  70. return [{
  71. id: 1,
  72. name: '签到记录',
  73. }, {
  74. id: 3,
  75. name: '行驶轨迹'
  76. }]
  77. }
  78. }
  79. },
  80. data() {
  81. return {
  82. currentComponent: ClockInRecordComponent,
  83. taskID: '',
  84. loading: false,
  85. taskDetail: {},
  86. draft: [],
  87. taskinfo: {},
  88. report_msg: '',
  89. task_type: false,
  90. isEdit: false,
  91. isMessageEdit: false,
  92. istask: 1 // 任务模块
  93. }
  94. },
  95. onShow() {
  96. this.report_msg = ''
  97. },
  98. onLoad(options) {
  99. console.warn(options, '------------- on load --------------')
  100. this.taskID = options.taskID;
  101. this.getTaskDetail()
  102. },
  103. watch: {
  104. wornlist(news, old) {
  105. // console.log(this.taskinfo.trap_record_list)
  106. console.warn(news, ' task edit watch')
  107. this.draft = []
  108. this.draft.push(news)
  109. for (var i = 0; i < this.taskinfo.trap_record_list.length; i++) {
  110. for (var j = 0; j < news; j++) {
  111. if (this.taskinfo.trap_record_list[i].id == news.record_id) {
  112. this.taskinfo.trap_record_list[i].report_status = news.report_status
  113. } else {
  114. this.taskinfo.trap_record_list[i].report_status = ""
  115. }
  116. }
  117. }
  118. this.taskfillingdraft()
  119. },
  120. // kpsurlL(news, old) {
  121. // if (this.istask == 1) {
  122. // if (news != "") {
  123. // let pages = getCurrentPages();
  124. // var page = pages[pages.length - 1];
  125. // var currentWebview = page.$getAppWebview();
  126. // currentWebview.setTitleNViewButtonStyle(0, {
  127. // text: " ",
  128. // });
  129. // this.$store.state.kpsurlL = 1
  130. // } else {
  131. // let pages = getCurrentPages();
  132. // var page = pages[pages.length - 1];
  133. // var currentWebview = page.$getAppWebview();
  134. // currentWebview.setTitleNViewButtonStyle(0, {
  135. // text: "提交",
  136. // });
  137. // this.$store.state.kpsurlL = 0
  138. // }
  139. // }
  140. // }
  141. },
  142. methods: {
  143. getTaskDetail() {
  144. console.warn('get task detail start')
  145. if (!this.taskID) {
  146. return
  147. }
  148. console.warn('get task detail fetch')
  149. this.loading = true;
  150. taskService.getTaskDetailByTaskID(this.taskID).then(res => {
  151. console.warn(res, 'get task detail')
  152. this.taskDetail = this.taskinfo = res;
  153. this.isEdit = res.task_status === '处理中';
  154. this.task_id = res.task_id;
  155. console.log(this.taskinfo, '------------------------------- task info', this.taskDetail)
  156. // if (this.taskinfo.img_list == "" || this.taskinfo.img_list.length == 0) {
  157. // this.taskinfo.img_list = []
  158. // } else {
  159. // this.taskinfo.img_list = JSON.parse(this.taskinfo.img_list)
  160. // }
  161. console.warn(this.taskinfo.task_type, 'get task detail --1213144')
  162. if (res.task_type == "有害生物监测") {
  163. this.task_type = true
  164. } else {
  165. this.task_type = false
  166. }
  167. this.$store.state.worndatabase = JSON.parse(JSON.stringify(this.taskinfo.trap_record_list))
  168. }).finally(() => {
  169. this.loading = false;
  170. })
  171. },
  172. handleTabClick(id) {
  173. switch (id) {
  174. case 1:
  175. this.currentComponent = ClockInRecordComponent;
  176. break;
  177. case 2:
  178. this.currentComponent = EntrapmentComponent;
  179. break;
  180. case 3:
  181. this.currentComponent = GisComponent;
  182. break;
  183. }
  184. },
  185. async taskfillingdraft() { //任务填报接口
  186. // this.gettaskinfo()
  187. var arr = JSON.parse(JSON.stringify(this.$store.state.worndatabase))
  188. console.warn(this.draft, 'draft')
  189. console.log(arr, 'arr draft')
  190. for (var i = 0; i < arr.length; i++) {
  191. for (var j = 0; j < this.draft.length; j++) {
  192. if (arr[i].id == this.draft[j].record_id || arr[i].record_id == this.draft[j].record_id) {
  193. arr.splice(i, 1)
  194. i--;
  195. }
  196. }
  197. }
  198. for (var i = 0; i < this.taskinfo.trap_record_list.length; i++) {
  199. for (var j = 0; j < this.draft.length; j++) {
  200. if (this.taskinfo.trap_record_list[i].id == this.draft[j].record_id) {
  201. // console.log(this.taskinfo.trap_record_list[i])
  202. this.taskinfo.trap_record_list[i].report_status = this.draft[j].report_status
  203. }
  204. }
  205. }
  206. this.draft = this.draft.concat(arr)
  207. this.$store.state.worndatabase = JSON.parse(JSON.stringify(this.draft))
  208. // console.log(arr)
  209. for (var i = 0; i < this.draft.length; i++) {
  210. if (this.draft[i].id) {
  211. this.draft[i]["record_id"] = this.draft[i].id
  212. }
  213. }
  214. console.warn(this.draft, "0000 草稿提交")
  215. var data = {}
  216. if (this.task_type) {
  217. data = {
  218. task_id: this.task_id, // 是 任务id
  219. // report_msg: this.textareavalue, // 是 任务汇报内容
  220. // img_list: JSON.stringify(this.urllist), // 是 图片列表 ['http://www.c.com']
  221. trap_record_list: JSON.stringify(this.draft),
  222. }
  223. console.log("有数据", data)
  224. } else {
  225. data = {
  226. task_id: this.task_id, // 是 任务id
  227. report_msg: this.textareavalue, // 是 任务汇报内容
  228. img_list: JSON.stringify(this.urllist), // 是 图片列表 ['http://www.c.com']
  229. }
  230. console.log("无数据", data)
  231. }
  232. console.log(data, 555)
  233. const res = await this.$myRequest({
  234. url: '/api/api_gateway?method=app.task.task_filling_draft',
  235. data: data,
  236. })
  237. // console.log(res)
  238. },
  239. taskfillingcom() {
  240. console.log(this.taskinfo.trap_record_list)
  241. var tf = this.taskinfo.trap_record_list.every((item) => {
  242. console.log(item.report_status)
  243. return item.report_status != ""
  244. })
  245. if (!this.report_msg) {
  246. uni.$u.toast('请填写任务汇报')
  247. } else if (!tf) {
  248. if (this.task_type) {
  249. uni.$u.toast('请将所有设备全部登记后提交!')
  250. } else {
  251. // this.taskfillingdraft()+
  252. this.taskfilling()
  253. }
  254. } else {
  255. // this.taskfillingdraft()
  256. this.taskfilling()
  257. }
  258. },
  259. async taskfilling() { //任务填报接口
  260. this.loading = true;
  261. const res = await this.$myRequest({
  262. url: '/api/api_gateway?method=app.task.task_filling',
  263. data: {
  264. // task_id:id,
  265. task_id: this.task_id, // 是 任务id
  266. report_msg: this.report_msg, // 是 任务汇报内容
  267. // img_list: JSON.stringify(this.urllist), // 是 图片列表
  268. }
  269. })
  270. console.log(res)
  271. uni.$u.toast('提交成功')
  272. HeartBeat.getInstance().clearByType('record_' + this.task_id);
  273. taskService.updateTaskWalkStatus({
  274. task_id: this.task_id,
  275. action: 'stop'
  276. })
  277. setTimeout(() => {
  278. this.loading = false;
  279. uni.switchTab({
  280. url: '/pages/index/index'
  281. })
  282. })
  283. },
  284. }
  285. }
  286. </script>
  287. <style lang="scss" scoped>
  288. .task-details {
  289. padding: 24rpx 24rpx 100rpx;
  290. &__header {
  291. margin-bottom: 24rpx;
  292. }
  293. &__body {
  294. display: flex;
  295. flex-direction: column;
  296. box-sizing: border-box;
  297. // padding: 32rpx 0;
  298. background-color: #fff;
  299. border-radius: 8rpx;
  300. }
  301. &__content {
  302. flex: 1 1 auto;
  303. display: flex;
  304. flex-direction: column;
  305. align-items: center;
  306. // padding: 10rpx 0;
  307. }
  308. &__area {
  309. font-size: 12px;
  310. line-height: 18px;
  311. color: #656565;
  312. font-weight: 400;
  313. }
  314. &__edit-icon {
  315. padding: 24rpx 0;
  316. }
  317. &__footer {
  318. position: fixed;
  319. bottom: 0rpx;
  320. left: 0;
  321. right: 0;
  322. background-color: #fff;
  323. padding: 40rpx;
  324. }
  325. }
  326. .panel {
  327. background-color: #fff;
  328. border-radius: 16rpx;
  329. padding: 16rpx;
  330. margin-bottom: 24rpx;
  331. &__header {
  332. display: flex;
  333. align-items: center;
  334. justify-content: space-between;
  335. }
  336. &__title {
  337. flex: 1 1 auto;
  338. font-size: 14px;
  339. color: #333;
  340. line-height: 40rpx;
  341. margin-right: 100rpx;
  342. padding-bottom: 10rpx;
  343. @include hairline-bottom(rgba(151, 151, 151, 0.09));
  344. }
  345. &__content {
  346. padding: 10rpx 0;
  347. }
  348. }
  349. </style>
  350. <style>
  351. page {
  352. background-color: #F7F8FB;
  353. }
  354. /* 可以设置不同的进入和离开动画 */
  355. /* 设置持续时间和动画函数 */
  356. .slide-fade-enter-active {
  357. transition: all .3s ease;
  358. }
  359. .slide-fade-leave-active {
  360. transition: all .8s cubic-bezier(1.0, 0.5, 0.8, 1.0);
  361. }
  362. .slide-fade-enter,
  363. .slide-fade-leave-to
  364. /* .slide-fade-leave-active for below version 2.1.8 */
  365. {
  366. transform: translateX(10px);
  367. opacity: 0;
  368. }
  369. </style>