construction.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <HcNewCard>
  3. <HcTable :column="tableConstructionColumn" :datas="tableConstructionData" :loading="tableConstructionLoading" is-new :index-style="{ width: 60 }">
  4. <template #action="{ row }">
  5. <HcTooltip keys="write_construction_edit">
  6. <el-button plain size="small" type="primary" @click="tableConstructionEdit(row)">
  7. <HcIcon name="edit" />
  8. <span>编辑</span>
  9. </el-button>
  10. </HcTooltip>
  11. </template>
  12. </HcTable>
  13. <template #action>
  14. <HcPages :pages="searchConstructionForm" @change="pageConstructionChange" />
  15. </template>
  16. </HcNewCard>
  17. <!-- 编辑施工台账 -->
  18. <hc-new-dialog v-model="showConstructionEditModal" title="编辑施工台账" widths="38rem">
  19. <el-form ref="constructionFormRef" :model="constructionFormModel" :rules="constructionFormRules" label-position="top" label-width="auto" size="large">
  20. <div class="flex">
  21. <el-form-item class="flex-1" label="施工起始日期" prop="siteStartTime">
  22. <el-date-picker v-model="constructionFormModel.siteStartTime" class="block" format="YYYY-MM-DD" placeholder="施工起始日期" type="date" value-format="YYYY-MM-DD" />
  23. </el-form-item>
  24. <el-form-item class="mx-4" label=" ">至</el-form-item>
  25. <el-form-item class="flex-1" label="施工停止日期" prop="siteEndTime">
  26. <el-date-picker v-model="constructionFormModel.siteEndTime" class="block" format="YYYY-MM-DD" placeholder="施工停止日期" type="date" value-format="YYYY-MM-DD" />
  27. </el-form-item>
  28. </div>
  29. <div class="flex">
  30. <el-form-item class="flex-1" label="检测起始日期" prop="detectionStartTime">
  31. <el-date-picker
  32. v-model="constructionFormModel.detectionStartTime" :disabled="!constructionFormModel.siteStartTime || !constructionFormModel.siteEndTime"
  33. class="block"
  34. format="YYYY-MM-DD" placeholder="检测起始日期" type="date"
  35. value-format="YYYY-MM-DD"
  36. />
  37. </el-form-item>
  38. <el-form-item class="mx-4" label=" ">至</el-form-item>
  39. <el-form-item class="flex-1" label="检测停止日期" prop="detectionEndTime">
  40. <el-date-picker
  41. v-model="constructionFormModel.detectionEndTime" :disabled="!constructionFormModel.siteStartTime || !constructionFormModel.siteEndTime"
  42. class="block"
  43. format="YYYY-MM-DD" placeholder="检测停止日期" type="date"
  44. value-format="YYYY-MM-DD"
  45. />
  46. </el-form-item>
  47. </div>
  48. <el-form-item label="设计方量">
  49. <el-input v-model="constructionFormModel.designVolume" placeholder="请输入设计方量" />
  50. </el-form-item>
  51. <el-form-item label="实际方量">
  52. <el-input v-model="constructionFormModel.actualVolume" placeholder="请输入实际方量" />
  53. </el-form-item>
  54. </el-form>
  55. <template #footer>
  56. <div class="dialog-footer">
  57. <el-button size="large" @click="showConstructionEditModal = false">
  58. <HcIcon name="close" />
  59. <span>取消</span>
  60. </el-button>
  61. <el-button :loading="saveConstructionLoading" hc-btn type="primary" @click="saveConstructionClick">
  62. <HcIcon name="save" />
  63. <span>提交保存</span>
  64. </el-button>
  65. </div>
  66. </template>
  67. </hc-new-dialog>
  68. </template>
  69. <script setup>
  70. import { nextTick, ref, watch } from 'vue'
  71. import { deepClone, formValidate, getArrValue } from 'js-fast-way'
  72. import constructionApi from '~api/ledger/construction'
  73. //参数
  74. const props = defineProps({
  75. projectId: {
  76. type: [String, Number],
  77. default: '',
  78. },
  79. contractId: {
  80. type: [String, Number],
  81. default: '',
  82. },
  83. treeData: {
  84. type: Object,
  85. default: () => ({}),
  86. },
  87. })
  88. //变量
  89. const projectId = ref(props.projectId)
  90. const contractId = ref(props.contractId)
  91. const nodeData = ref(props.treeData)
  92. //监听
  93. watch(() => [
  94. props.treeData,
  95. ], ([treeData]) => {
  96. nodeData.value = treeData
  97. setQueryData(treeData)
  98. })
  99. //渲染完成
  100. nextTick(() => {
  101. setQueryData(props.treeData)
  102. })
  103. //获取相关数据
  104. const setQueryData = (data) => {
  105. const cid = data?.contractIdRelation || ''
  106. const wbsId = data['contractIdRelation'] ? data['id'] : data['primaryKeyId']
  107. if (wbsId) {
  108. searchConstructionForm.value.contractId = cid ? cid : contractId.value
  109. searchConstructionForm.value.contractIdRelation = data['contractIdRelation']
  110. searchConstructionForm.value.wbsIds = [wbsId]
  111. searchConstructionClick()
  112. }
  113. }
  114. //搜索表单
  115. const searchConstructionForm = ref({ current: 1, size: 20, total: 0 })
  116. //搜索
  117. const searchConstructionClick = () => {
  118. if (searchConstructionForm.value?.wbsIds) {
  119. searchConstructionForm.value.current = 1
  120. getTableConstructionData()
  121. } else {
  122. window?.$message?.warning('请先选择一个树节点')
  123. }
  124. }
  125. //分页被点击
  126. const pageConstructionChange = ({ current, size }) => {
  127. searchConstructionForm.value.current = current
  128. searchConstructionForm.value.size = size
  129. getTableConstructionData()
  130. }
  131. //施工台账表头
  132. const tableConstructionColumn = ref([
  133. { key: 'station', name: '施工桩号' },
  134. { key: 'site', name: '施工部位' },
  135. { key: 'siteTimeStr', name: '施工起止日期' },
  136. { key: 'detectionTimeStr', name: '检测日期' },
  137. { key: 'designVolume', name: '设计方量' },
  138. { key: 'actualVolume', name: '实际方量' },
  139. { key: 'action', name: '操作', width: 100 },
  140. ])
  141. const tableConstructionData = ref([])
  142. //获取数据
  143. const tableConstructionLoading = ref(false)
  144. const getTableConstructionData = async () => {
  145. tableConstructionLoading.value = true
  146. const { error, code, data, msg } = await constructionApi.queryConstructionPage({
  147. ...searchConstructionForm.value,
  148. projectId: projectId.value,
  149. })
  150. //判断状态
  151. tableConstructionLoading.value = false
  152. if (!error && code === 200) {
  153. tableConstructionData.value = getArrValue(data?.records) || []
  154. searchConstructionForm.value.total = data?.total || 0
  155. } else {
  156. tableConstructionData.value = []
  157. searchConstructionForm.value.total = 0
  158. window?.$message?.error(msg)
  159. }
  160. }
  161. //施工台账编辑
  162. const showConstructionEditModal = ref(false)
  163. const tableConstructionEdit = (row) => {
  164. constructionFormModel.value = deepClone(row)
  165. saveConstructionLoading.value = false
  166. constructionFormRef.value?.resetFields()
  167. showConstructionEditModal.value = true
  168. }
  169. //施工台账表单
  170. const constructionFormRef = ref(null)
  171. const constructionFormModel = ref({
  172. siteStartTime: null,
  173. siteEndTime: null,
  174. detectionStartTime: null,
  175. detectionEndTime: null,
  176. designVolume: '',
  177. actualVolume: '',
  178. })
  179. const constructionFormRules = ref({
  180. siteStartTime: {
  181. required: true,
  182. validator: (rule, value, callback) => {
  183. const endTime = constructionFormModel.value?.siteEndTime ?? ''
  184. if (!value) {
  185. callback(new Error('请选择施工起始日期'))
  186. } else {
  187. callback()
  188. }
  189. },
  190. trigger: 'blur',
  191. },
  192. siteEndTime: {
  193. required: true,
  194. validator: (rule, value, callback) => {
  195. const startTime = constructionFormModel.value?.siteStartTime ?? ''
  196. if (!value) {
  197. callback(new Error('请选择施工停止日期'))
  198. } else if (value < startTime) {
  199. callback(new Error('施工停止日期 不能 小于 施工起始日期'))
  200. } else {
  201. callback()
  202. }
  203. },
  204. trigger: 'blur',
  205. },
  206. detectionStartTime: {
  207. required: true,
  208. validator: (rule, value, callback) => {
  209. const endTime = constructionFormModel.value?.siteEndTime ?? ''
  210. const startTime = constructionFormModel.value?.siteStartTime ?? ''
  211. if (!value) {
  212. callback(new Error('请选择检测起始日期'))
  213. } else if (value < startTime) {
  214. callback(new Error('检测起始日期 不能 小于 施工起始日期'))
  215. } else {
  216. callback()
  217. }
  218. },
  219. trigger: 'blur',
  220. },
  221. detectionEndTime: {
  222. required: true,
  223. validator: (rule, value, callback) => {
  224. const startTime = constructionFormModel.value?.detectionStartTime ?? ''
  225. if (!value) {
  226. callback(new Error('请选择检测停止日期'))
  227. } else if (value < startTime) {
  228. callback(new Error('检测停止日期 不能 小于 检测起始日期'))
  229. } else {
  230. callback()
  231. }
  232. },
  233. trigger: 'blur',
  234. },
  235. designVolume: {
  236. required: true,
  237. trigger: 'blur',
  238. message: '请输入设计方量',
  239. },
  240. actualVolume: {
  241. required: true,
  242. trigger: 'blur',
  243. message: '请输入实际方量',
  244. },
  245. })
  246. //提交保存
  247. const saveConstructionClick = async () => {
  248. const validate = await formValidate(constructionFormRef.value)
  249. if (validate) {
  250. const formData = constructionFormModel.value
  251. const { siteStartTime, siteEndTime, detectionStartTime, detectionEndTime } = formData
  252. //施工时间
  253. formData.siteTimeStr = siteStartTime + '~' + siteEndTime
  254. //检测时间
  255. formData.detectionTimeStr = detectionStartTime + '~' + detectionEndTime
  256. //请求保存
  257. updateConstructionPage(formData)
  258. }
  259. }
  260. //确认保存
  261. const saveConstructionLoading = ref(false)
  262. const updateConstructionPage = async (formData) => {
  263. //发起请求
  264. saveConstructionLoading.value = true
  265. const { error, code } = await constructionApi.updateConstructionPage({
  266. ...formData,
  267. projectId: projectId.value,
  268. contractId: contractId.value,
  269. }, false)
  270. //处理数据
  271. saveConstructionLoading.value = false
  272. if (!error && code === 200) {
  273. window?.$message?.success('保存成功')
  274. showConstructionEditModal.value = false
  275. getTableConstructionData()
  276. } else {
  277. window?.$message?.error('保存失败')
  278. }
  279. }
  280. </script>