material-form.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <div v-loading="isLoading" class="hc-task-form white relative">
  3. <!-- 基础表单 -->
  4. <hc-card-item>
  5. <hc-info-table>
  6. <tr>
  7. <hc-info-table-td center is-title>合同材料:</hc-info-table-td>
  8. <hc-info-table-td width="120px">{{ baseForm?.contractMaterialName }}</hc-info-table-td>
  9. <hc-info-table-td center is-title>材料到场编号:</hc-info-table-td>
  10. <hc-info-table-td width="120px">{{ baseForm?.materialArriveNumber }}</hc-info-table-td>
  11. </tr>
  12. <tr>
  13. <hc-info-table-td center is-title>计量期:</hc-info-table-td>
  14. <hc-info-table-td width="120px">{{ baseForm?.periodName }}</hc-info-table-td>
  15. <hc-info-table-td center is-title>业务日期:</hc-info-table-td>
  16. <hc-info-table-td width="120px">{{ baseForm?.businessDate }}</hc-info-table-td>
  17. </tr>
  18. <tr>
  19. <hc-info-table-td center is-title>单价:</hc-info-table-td>
  20. <hc-info-table-td v-loading="priceLoading" width="120px">
  21. <el-input v-model="baseForm.price" :disabled="!isEdits || tableInfo.status === 2" @blur="priceInputBlur" />
  22. </hc-info-table-td>
  23. <hc-info-table-td center is-title>计量数量:</hc-info-table-td>
  24. <hc-info-table-td v-loading="meterLoading" width="120px">
  25. <el-input v-model="baseForm.meterAmount" :disabled="!isEdits || tableInfo.status === 2" @blur="meterAmountInputBlur" />
  26. </hc-info-table-td>
  27. </tr>
  28. <tr>
  29. <hc-info-table-td center is-title>计量金额:</hc-info-table-td>
  30. <hc-info-table-td width="120px">{{ baseForm?.meterMoney }}</hc-info-table-td>
  31. <hc-info-table-td center is-title>备料堆放地点:</hc-info-table-td>
  32. <hc-info-table-td width="120px">{{ baseForm?.storagePlace }}</hc-info-table-td>
  33. </tr>
  34. <tr>
  35. <hc-info-table-td center is-title>存储情况:</hc-info-table-td>
  36. <hc-info-table-td width="120px">{{ baseForm?.storageStatus }}</hc-info-table-td>
  37. <hc-info-table-td center is-title>材料来源:</hc-info-table-td>
  38. <hc-info-table-td width="120px">{{ baseForm?.materialSource }}</hc-info-table-td>
  39. </tr>
  40. <tr>
  41. <hc-info-table-td center is-title>材料是否符合要求:</hc-info-table-td>
  42. <hc-info-table-td width="120px">{{ baseForm?.materialConformName }}</hc-info-table-td>
  43. <hc-info-table-td center is-title>存储方法是否符合要求:</hc-info-table-td>
  44. <hc-info-table-td width="120px">{{ baseForm?.storageConformName }}</hc-info-table-td>
  45. </tr>
  46. <tr>
  47. <hc-info-table-td center is-title>合格证号:</hc-info-table-td>
  48. <hc-info-table-td width="auto" colspan="3">{{ baseForm?.certificate }}</hc-info-table-td>
  49. </tr>
  50. <tr>
  51. <hc-info-table-td center is-title>备注:</hc-info-table-td>
  52. <hc-info-table-td width="auto" colspan="3">{{ baseForm?.remark }}</hc-info-table-td>
  53. </tr>
  54. </hc-info-table>
  55. </hc-card-item>
  56. <!-- 附件列表 -->
  57. <hc-card-item class="mt-3" title="附件列表">
  58. <template #extra>
  59. <span class="text-[13px] text-orange font-400">可上传 图片(png、jpg、jpeg)、Excel(xls、xlsx)、PDF、Word(doc、docx)文件</span>
  60. </template>
  61. <el-form :model="baseForm" label-position="left" label-width="auto">
  62. <el-form-item label="上传附件">
  63. <hc-form-upload
  64. v-model="baseForm.fileList"
  65. is-del
  66. is-res
  67. :disabled="!isEdits || taskInfo.status === 2 || taskInfo.status === 3 || tableInfo.status === 1"
  68. :options="{
  69. type: 'list',
  70. props: uploadFormProps,
  71. isArr: true,
  72. num: 0,
  73. }"
  74. :upload="{ options: { multiple: false } }"
  75. @success="uploadFileSuccess"
  76. @del="attachmentUploadDel"
  77. />
  78. </el-form-item>
  79. </el-form>
  80. </hc-card-item>
  81. </div>
  82. </template>
  83. <script setup>
  84. import { nextTick, onMounted, ref, watch } from 'vue'
  85. import { useAppStore } from '~src/store'
  86. import { getArrValue, getObjVal, getObjValue, isNullES } from 'js-fast-way'
  87. import { delMessage, isNumberReg } from '~uti/tools'
  88. import mainApi from '~api/tasks/hc-data'
  89. const props = defineProps({
  90. isEdit: {
  91. type: Boolean,
  92. default: true,
  93. },
  94. info: {
  95. type: Object,
  96. default: () => ({}),
  97. },
  98. table: {
  99. type: Object,
  100. default: () => ({}),
  101. },
  102. })
  103. const useAppState = useAppStore()
  104. const projectId = ref(useAppState.getProjectId || '')
  105. const contractId = ref(useAppState.getContractId || '')
  106. //监听可否编辑
  107. const isEdits = ref(props.isEdit)
  108. watch(() => props.isEdit, (val) => {
  109. isEdits.value = val
  110. }, { immediate: true, deep: true })
  111. //监听数据
  112. watch(() => [
  113. props.table,
  114. props.info,
  115. ], ([table, row]) => {
  116. setTaskInfo(table, row)
  117. }, { deep: true })
  118. //渲染完成
  119. onMounted(() => {
  120. setTaskInfo(props.table, props.info)
  121. })
  122. //设置任务信息
  123. const taskInfo = ref({})
  124. const tableInfo = ref({})
  125. const setTaskInfo = (table, row) => {
  126. tableInfo.value = table
  127. taskInfo.value = row
  128. if (getObjVal(table) && getObjVal(row)) {
  129. getDataDetail()
  130. }
  131. }
  132. //基础表单
  133. const baseForm = ref({ fileList: [] })
  134. //获取任务数据信息详情
  135. const isLoading = ref(false)
  136. const getDataDetail = async () => {
  137. const id = taskInfo.value.id
  138. const dataId = tableInfo.value.id
  139. const { data } = await mainApi.getDataDetail({ id, dataId })
  140. //转换数据
  141. const { attachmentFormTask, basicsInfo } = getObjValue(data)
  142. baseForm.value = getObjValue(basicsInfo) //表单信息
  143. baseForm.value.fileList = getArrValue(attachmentFormTask) //附件列表
  144. }
  145. //单价输入框失去焦点
  146. const priceLoading = ref(false)
  147. const priceInputBlur = async () => {
  148. let { id, price } = baseForm.value
  149. const isMeter = isNumberReg(price)
  150. let priceValue = price
  151. if (isNullES(price) || !isMeter) {
  152. priceValue = 0
  153. }
  154. await nextTick(() => {
  155. baseForm.value.price = priceValue
  156. })
  157. //发起请求
  158. priceLoading.value = true
  159. const { error, code, msg } = await mainApi.taskMaterialUpdate({
  160. projectId: projectId.value,
  161. contractId: contractId.value,
  162. taskId: taskInfo.value.id,
  163. price: priceValue,
  164. id,
  165. })
  166. priceLoading.value = false
  167. if (!error && code === 200) {
  168. window.$message.success('修改成功')
  169. } else {
  170. window.$message.error(msg ?? '修改失败')
  171. }
  172. }
  173. //单价输入框失去焦点
  174. const meterLoading = ref(false)
  175. const meterAmountInputBlur = async () => {
  176. let { id, meterAmount } = baseForm.value
  177. const isMeter = isNumberReg(meterAmount)
  178. let meterAmountValue = meterAmount
  179. if (isNullES(meterAmount) || !isMeter) {
  180. meterAmountValue = 0
  181. }
  182. await nextTick(() => {
  183. baseForm.value.meterAmount = meterAmountValue
  184. })
  185. //发起请求
  186. meterLoading.value = true
  187. const { error, code, msg } = await mainApi.taskMaterialUpdate({
  188. projectId: projectId.value,
  189. contractId: contractId.value,
  190. meterAmount: meterAmountValue,
  191. taskId: taskInfo.value.id,
  192. id,
  193. })
  194. meterLoading.value = false
  195. if (!error && code === 200) {
  196. window.$message.success('修改成功')
  197. } else {
  198. window.$message.error(msg ?? '修改失败')
  199. }
  200. }
  201. //文件上传
  202. const uploadFormProps = {
  203. url: 'filePdfUrl',
  204. name: 'fileName',
  205. }
  206. // 文件上传成功的回调
  207. const uploadFileSuccess = async ({ res }, resolve) => {
  208. const { link, pdfUrl, originalName } = getObjValue(res.data)
  209. if (isNullES(pdfUrl)) {
  210. window.$message.warning('该文件不能生成pdf,请更换文件上传')
  211. resolve()
  212. return
  213. }
  214. resolve({
  215. contractId: contractId.value,
  216. fileName: originalName ?? '',
  217. filePdfUrl: pdfUrl ?? '',
  218. fileUrl: link ?? '',
  219. taskId: taskInfo.value.id,
  220. })
  221. //发起请求
  222. const dataId = tableInfo.value.id
  223. const { error, code, msg } = await mainApi.taskUploadFile({
  224. projectId: projectId.value,
  225. contractId: contractId.value,
  226. fileList: baseForm.value.fileList,
  227. taskId: taskInfo.value.id,
  228. dataId,
  229. })
  230. if (!error && code === 200) {
  231. window.$message.success('上传成功')
  232. } else {
  233. window.$message.error(msg ?? '上传失败')
  234. }
  235. }
  236. //删除文件
  237. const attachmentUploadDel = ({ file }, resolve) => {
  238. if (!isEdits.value) {
  239. window.$message.error('当前状态不可删除')
  240. resolve(false)
  241. return
  242. }
  243. delMessage(async () => {
  244. const { error, code, msg } = await mainApi.removeFile({
  245. id: file.id,
  246. taskId: taskInfo.value.id,
  247. })
  248. if (!error && code === 200) {
  249. resolve(true)
  250. } else {
  251. window.$message.error(msg ?? '删除失败')
  252. resolve(false)
  253. }
  254. })
  255. }
  256. </script>
  257. <style lang="scss">
  258. .hc-task-form.white .hc-card-item-box {
  259. background: white !important;
  260. }
  261. </style>