detail.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <CusDialog
  3. title="日志"
  4. :show="show"
  5. @close="$emit('update:show', false)"
  6. @submit="onSubmit"
  7. height="560px"
  8. :closeConfirm="!isViewCpt"
  9. :loading="loading"
  10. :showSubmit="!isViewCpt"
  11. >
  12. <div class="__normal-form">
  13. <CusForm labelWidth="100px" ref="ref_form" :formView="isViewCpt">
  14. <CusFormColumn
  15. :span="24"
  16. required
  17. label="日志标题:"
  18. v-model:param="cusDetail.title"/>
  19. <CusFormColumn
  20. :span="24"
  21. required
  22. label="日志日期:"
  23. link="date"
  24. :disabled="true"
  25. v-model:param="cusDetail.dutyTime"/>
  26. <CusFormColumn
  27. :span="24"
  28. required
  29. label="提交人员:"
  30. :disabled="true"
  31. v-model:param="cusDetail.submitter"/>
  32. <CusFormColumn
  33. :span="24"
  34. required
  35. label="日志记录:"
  36. type="textarea"
  37. :rows="4"
  38. show-word-limit
  39. :maxlength="100"
  40. v-model:param="cusDetail.dutyRecord"/>
  41. <CusFormColumn
  42. :span="24"
  43. label="上传文件:"
  44. link="upload"
  45. v-model:param="fileList"
  46. :delRule="(file) => true"/>
  47. </CusForm>
  48. </div>
  49. </CusDialog>
  50. </template>
  51. <script lang="ts">
  52. import {
  53. defineComponent,
  54. computed,
  55. onMounted,
  56. ref,
  57. reactive,
  58. watch,
  59. getCurrentInstance,
  60. ComponentInternalInstance,
  61. toRefs,
  62. nextTick
  63. } from 'vue'
  64. import {useStore} from 'vuex'
  65. import {useRouter, useRoute} from 'vue-router'
  66. import {ElMessage, ElMessageBox} from "element-plus";
  67. export default defineComponent({
  68. name: '',
  69. components: {},
  70. props: {
  71. show: {},
  72. transfer: <any>{}
  73. },
  74. setup(props, {emit}) {
  75. const store = useStore();
  76. const router = useRouter();
  77. const route = useRoute();
  78. const that = (getCurrentInstance() as ComponentInternalInstance).appContext.config.globalProperties
  79. const state = reactive({
  80. loading: false,
  81. cusDetail: <any>{},
  82. fileList: <any>[]
  83. })
  84. watch(() => props.show, (n) => {
  85. if (n) {
  86. state.loading = false
  87. state.fileList = []
  88. if (props.transfer.method !== 'add') {
  89. state.loading = true
  90. that.$api.getDailyReport(props.transfer.detail.id).then((res) => {
  91. if (res.code === 200 && res.data?.id) {
  92. setFormByInfo(res.data)
  93. } else {
  94. ElMessage.error(res.message)
  95. emit('update:show', false)
  96. }
  97. state.loading = false
  98. }).catch(() => {
  99. ElMessage.error('请求失败')
  100. })
  101. } else {
  102. state.loading = true
  103. that.$api.getDailyReportSearch().then((res) => {
  104. if (res.code === 200) {
  105. if (res.data?.id) {
  106. setFormByInfo(res.data)
  107. } else {
  108. const submitT = new Date(`${that.$util.YMD(store.state.app.timestamp)} ${store.state.app.publicConfig['log.submit.time']}`).getTime()
  109. const diff = new Date(store.state.app.timestamp).getTime() < submitT ? (1000 * 60 * 60 * 24) : 0
  110. state.cusDetail = {
  111. dutyTime: that.$util.YMD(new Date(store.state.app.timestamp).getTime() - diff),
  112. submitter: store.state.app.userInfo.displayName,
  113. }
  114. }
  115. state.loading = false
  116. } else {
  117. ElMessage.error(res.message)
  118. emit('update:show', false)
  119. }
  120. }).catch(() => {
  121. ElMessage.error('请求失败')
  122. })
  123. }
  124. nextTick(() => {
  125. ref_form.value.reset()
  126. })
  127. }
  128. })
  129. const ref_form = ref()
  130. const isViewCpt = computed(() => {
  131. return props.transfer.method === 'view'
  132. })
  133. const setFormByInfo = (data) => {
  134. state.cusDetail = data
  135. if (state.cusDetail.fileUrl) {
  136. const urlArr = state.cusDetail.fileUrl.split(',')
  137. const nameArr = state.cusDetail.fileName.split(',')
  138. state.fileList = urlArr.map((v, i) => {
  139. return {
  140. name: nameArr?.[i] || v,
  141. url: v
  142. }
  143. })
  144. }
  145. }
  146. const onSubmit = () => {
  147. ref_form.value.submit().then(() => {
  148. ElMessageBox.confirm("是否提交?", "提示", {
  149. confirmButtonText: "确定",
  150. cancelButtonText: "取消",
  151. type: "warning",
  152. }).then(() => {
  153. state.loading = true
  154. const params: any = state.cusDetail
  155. if (state.fileList?.length > 0) {
  156. params.fileName = state.fileList.map(v => v.name).join(',')
  157. params.fileUrl = state.fileList.map(v => v.url).join(',')
  158. } else {
  159. params.fileName = ''
  160. params.fileUrl = ''
  161. }
  162. const apiHandle = params.id ? that.$api.editDailyReportEdit(params) : that.$api.addDailyReportSave(params)
  163. apiHandle.then(res => {
  164. if (res.code === 200) {
  165. ElMessage.success(res.message)
  166. emit('update:show', false)
  167. emit('refresh')
  168. } else {
  169. ElMessage.error(res.message)
  170. }
  171. state.loading = false
  172. }).catch(() => {
  173. state.loading = false
  174. })
  175. }).catch(() => {})
  176. }).catch((e) => {
  177. ElMessage({
  178. message: e[0].message,
  179. grouping: true,
  180. type: 'warning',
  181. })
  182. })
  183. }
  184. return {
  185. ...toRefs(state),
  186. onSubmit,
  187. isViewCpt,
  188. ref_form
  189. }
  190. },
  191. })
  192. </script>
  193. <style scoped lang="scss">
  194. </style>