add.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <view class="uni-app">
  3. <view class="status-bar" />
  4. <view class="main-container">
  5. <wk-nav-bar :title="navTitle">
  6. <!-- #ifndef MP-WEIXIN -->
  7. <button
  8. class="button white-btn"
  9. @click="handleSave">
  10. 保存
  11. </button>
  12. <!-- #endif -->
  13. </wk-nav-bar>
  14. <view class="container">
  15. <wk-form ref="form" :fields="fieldArr" />
  16. </view>
  17. <!-- #ifdef MP-WEIXIN -->
  18. <view class="footer-btn-group">
  19. <button class="button" @click="handleSave">
  20. 保存
  21. </button>
  22. </view>
  23. <!-- #endif -->
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import {
  29. SaveWorkTask,
  30. UpdateWorkChildTask,
  31. AddWorkChildTask
  32. } from 'API/oa/task'
  33. import Fields from '@/utils/fields.js'
  34. import { guid } from '@/utils/lib.js'
  35. import { mapGetters } from 'vuex'
  36. import moment from 'moment'
  37. export default {
  38. name: 'AddTask',
  39. data() {
  40. return {
  41. id: null,
  42. pid: null,
  43. fieldArr: [],
  44. loading: false
  45. }
  46. },
  47. computed: {
  48. ...mapGetters({
  49. userInfo: 'user/userInfo'
  50. }),
  51. navTitle() {
  52. if (!this.pid) return '新建任务'
  53. return this.id ? '编辑子任务' : '添加子任务'
  54. }
  55. },
  56. onLoad(options) {
  57. this.id = options.id || null
  58. this.pid = options.pid || null
  59. this.initForm()
  60. },
  61. onUnload() {
  62. getApp().globalData.formBridge = {}
  63. },
  64. methods: {
  65. initForm() {
  66. this.fieldArr = [
  67. new Fields({
  68. name: '任务名称',
  69. fieldName: 'name',
  70. formType: 'text',
  71. isNull: 1
  72. }),
  73. new Fields({
  74. name: '负责人',
  75. fieldName: 'mainUserId',
  76. formType: 'single_user',
  77. isNull: 1,
  78. value: [this.userInfo]
  79. }),
  80. new Fields({
  81. name: '结束时间',
  82. fieldName: 'stopTime',
  83. formType: 'date'
  84. })
  85. ]
  86. if (this.pid) {
  87. const bridge = getApp().globalData.formBridge
  88. if (!bridge.default) return
  89. this.$nextTick(() => {
  90. this.$refs.form.setForm(bridge.default || {})
  91. })
  92. }
  93. },
  94. handleSave() {
  95. if (this.loading) return
  96. this.loading = true
  97. this.$refs.form.getForm().then(form => {
  98. form = form.entity
  99. // if (form.stopTime && moment().isAfter(form.stopTime)) {
  100. // this.$toast('结束时间必须大于当前时间')
  101. // this.loading = false
  102. // return
  103. // }
  104. if (this.id) form.taskId = this.id
  105. if (this.pid) form.pid = this.pid
  106. let request = null
  107. if (this.pid) {
  108. request = this.id ? UpdateWorkChildTask : AddWorkChildTask
  109. } else {
  110. request = SaveWorkTask
  111. }
  112. console.log('save: ', form)
  113. request(form).then(() => {
  114. this.$toast(this.id ? '编辑成功' : '添加成功')
  115. this.loading = false
  116. this.$refreshAndToPrev(this)
  117. }).catch()
  118. }).catch(() => {
  119. this.loading = false
  120. })
  121. }
  122. }
  123. }
  124. </script>
  125. <style scoped lang="scss">
  126. .main-container {
  127. background-color: white;
  128. .container {
  129. flex: 1;
  130. }
  131. }
  132. </style>