construction.vue 11 KB

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