construction.vue 11 KB

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