detail.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. import {addDailyReportSave, editDailyReportEdit, getDailyReport, getDailyReportSearch} from "@/api/modules/daily";
  68. export default defineComponent({
  69. name: '',
  70. components: {},
  71. props: {
  72. show: {},
  73. transfer: <any>{}
  74. },
  75. setup(props, {emit}) {
  76. const store = useStore();
  77. const router = useRouter();
  78. const route = useRoute();
  79. const that = (getCurrentInstance() as ComponentInternalInstance).appContext.config.globalProperties
  80. const state = reactive({
  81. loading: false,
  82. cusDetail: <any>{},
  83. fileList: <any>[]
  84. })
  85. watch(() => props.show, (n) => {
  86. if (n) {
  87. state.loading = false
  88. state.fileList = []
  89. if (props.transfer.method !== 'add') {
  90. state.loading = true
  91. that.$api.getDailyReport(props.transfer.detail.id).then((res) => {
  92. if (res.code === 200 && res.data?.id) {
  93. setFormByInfo(res.data)
  94. } else {
  95. ElMessage.error(res.message)
  96. emit('update:show', false)
  97. }
  98. state.loading = false
  99. }).catch(() => {
  100. ElMessage.error('请求失败')
  101. })
  102. } else {
  103. state.loading = true
  104. that.$api.getDailyReportSearch().then((res) => {
  105. if (res.code === 200) {
  106. if (res.data?.id) {
  107. setFormByInfo(res.data)
  108. } else {
  109. // state.cusDetail = {
  110. // dutyTime: that.$util.YMD(new Date(store.state.app.timestamp)),
  111. // submitter: store.state.app.userInfo.displayName,
  112. // }
  113. }
  114. state.loading = false
  115. } else {
  116. ElMessage.error(res.message)
  117. emit('update:show', false)
  118. }
  119. }).catch(() => {
  120. ElMessage.error('请求失败')
  121. })
  122. }
  123. nextTick(() => {
  124. ref_form.value.reset()
  125. })
  126. }
  127. })
  128. const ref_form = ref()
  129. const isViewCpt = computed(() => {
  130. return props.transfer.method === 'view'
  131. })
  132. const setFormByInfo = (data) => {
  133. state.cusDetail = data
  134. if (state.cusDetail.fileUrl) {
  135. const urlArr = state.cusDetail.fileUrl.split(',')
  136. const nameArr = state.cusDetail.fileName.split(',')
  137. state.fileList = urlArr.map((v, i) => {
  138. return {
  139. name: nameArr?.[i] || v,
  140. url: v
  141. }
  142. })
  143. }
  144. }
  145. const onSubmit = () => {
  146. ref_form.value.submit().then(() => {
  147. ElMessageBox.confirm("是否提交?", "提示", {
  148. confirmButtonText: "确定",
  149. cancelButtonText: "取消",
  150. type: "warning",
  151. }).then(() => {
  152. state.loading = true
  153. const params: any = state.cusDetail
  154. if (state.fileList?.length > 0) {
  155. params.fileName = state.fileList.map(v => v.name).join(',')
  156. params.fileUrl = state.fileList.map(v => v.url).join(',')
  157. } else {
  158. params.fileName = ''
  159. params.fileUrl = ''
  160. }
  161. const apiHandle = params.id ? that.$api.editDailyReportEdit(params) : that.$api.addDailyReportSave(params)
  162. apiHandle.then(res => {
  163. if (res.code === 200) {
  164. ElMessage.success(res.message)
  165. emit('update:show', false)
  166. emit('refresh')
  167. } else {
  168. ElMessage.error(res.message)
  169. }
  170. state.loading = false
  171. }).catch(() => {
  172. state.loading = false
  173. })
  174. }).catch(() => {})
  175. }).catch((e) => {
  176. ElMessage({
  177. message: e[0].message,
  178. grouping: true,
  179. type: 'warning',
  180. })
  181. })
  182. }
  183. return {
  184. ...toRefs(state),
  185. onSubmit,
  186. isViewCpt,
  187. ref_form
  188. }
  189. },
  190. })
  191. </script>
  192. <style scoped lang="scss">
  193. </style>