construction.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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 } = 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. }
  159. }
  160. //施工台账编辑
  161. const showConstructionEditModal = ref(false)
  162. const tableConstructionEdit = (row) => {
  163. constructionFormModel.value = deepClone(row)
  164. saveConstructionLoading.value = false
  165. constructionFormRef.value?.resetFields()
  166. showConstructionEditModal.value = true
  167. }
  168. //施工台账表单
  169. const constructionFormRef = ref(null)
  170. const constructionFormModel = ref({
  171. siteStartTime: null,
  172. siteEndTime: null,
  173. detectionStartTime: null,
  174. detectionEndTime: null,
  175. designVolume: '',
  176. actualVolume: '',
  177. })
  178. const constructionFormRules = ref({
  179. siteStartTime: {
  180. required: true,
  181. validator: (rule, value, callback) => {
  182. const endTime = constructionFormModel.value?.siteEndTime ?? ''
  183. if (!value) {
  184. callback(new Error('请选择施工起始日期'))
  185. } else {
  186. callback()
  187. }
  188. },
  189. trigger: 'blur',
  190. },
  191. siteEndTime: {
  192. required: true,
  193. validator: (rule, value, callback) => {
  194. const startTime = constructionFormModel.value?.siteStartTime ?? ''
  195. if (!value) {
  196. callback(new Error('请选择施工停止日期'))
  197. } else if (value < startTime) {
  198. callback(new Error('施工停止日期 不能 小于 施工起始日期'))
  199. } else {
  200. callback()
  201. }
  202. },
  203. trigger: 'blur',
  204. },
  205. detectionStartTime: {
  206. required: true,
  207. validator: (rule, value, callback) => {
  208. const endTime = constructionFormModel.value?.siteEndTime ?? ''
  209. const startTime = constructionFormModel.value?.siteStartTime ?? ''
  210. if (!value) {
  211. callback(new Error('请选择检测起始日期'))
  212. } else if (value < startTime) {
  213. callback(new Error('检测起始日期 不能 小于 施工起始日期'))
  214. } else {
  215. callback()
  216. }
  217. },
  218. trigger: 'blur',
  219. },
  220. detectionEndTime: {
  221. required: true,
  222. validator: (rule, value, callback) => {
  223. const startTime = constructionFormModel.value?.detectionStartTime ?? ''
  224. if (!value) {
  225. callback(new Error('请选择检测停止日期'))
  226. } else if (value < startTime) {
  227. callback(new Error('检测停止日期 不能 小于 检测起始日期'))
  228. } else {
  229. callback()
  230. }
  231. },
  232. trigger: 'blur',
  233. },
  234. designVolume: {
  235. required: true,
  236. trigger: 'blur',
  237. message: '请输入设计方量',
  238. },
  239. actualVolume: {
  240. required: true,
  241. trigger: 'blur',
  242. message: '请输入实际方量',
  243. },
  244. })
  245. //提交保存
  246. const saveConstructionClick = async () => {
  247. const validate = await formValidate(constructionFormRef.value)
  248. if (validate) {
  249. const formData = constructionFormModel.value
  250. const { siteStartTime, siteEndTime, detectionStartTime, detectionEndTime } = formData
  251. //施工时间
  252. formData.siteTimeStr = siteStartTime + '~' + siteEndTime
  253. //检测时间
  254. formData.detectionTimeStr = detectionStartTime + '~' + detectionEndTime
  255. //请求保存
  256. updateConstructionPage(formData)
  257. }
  258. }
  259. //确认保存
  260. const saveConstructionLoading = ref(false)
  261. const updateConstructionPage = async (formData) => {
  262. //发起请求
  263. saveConstructionLoading.value = true
  264. const { error, code } = await constructionApi.updateConstructionPage({
  265. ...formData,
  266. projectId: projectId.value,
  267. contractId: contractId.value,
  268. }, false)
  269. //处理数据
  270. saveConstructionLoading.value = false
  271. if (!error && code === 200) {
  272. window?.$message?.success('保存成功')
  273. showConstructionEditModal.value = false
  274. getTableConstructionData()
  275. } else {
  276. window?.$message?.error('保存失败')
  277. }
  278. }
  279. </script>