addModal.vue 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  1. <template>
  2. <hc-new-dialog is-table widths="95%" :show="isShow" :title="`中间计量${dataId ? isView ? '查看' : '修改' : '新增'}`" :footer="!isView " @save="addModalSave" @close="addModalClose">
  3. <div v-loading="isLoading" class="relative h-full flex">
  4. <div v-if="!dataId" :id="`hc_tree_card_${uuid}`" class="hc_tree_card_border relative">
  5. <hc-body scrollbar padding="0px">
  6. <hc-lazy-tree :h-props="treeProps" tree-key="id" :auto-expand-keys="treeAutoExpandKeys" @load="treeLoadNode" @node-tap="treeNodeTap" />
  7. </hc-body>
  8. </div>
  9. <div :id="`hc_table_card_${uuid}`" class="relative flex-1">
  10. <hc-body scrollbar padding="0px">
  11. <!-- 基础表单 -->
  12. <hc-card-item>
  13. <el-form ref="baseFormRef" :model="baseForm" :rules="baseFormRules" label-position="left" label-width="auto" :disabled="isView">
  14. <el-row :gutter="20">
  15. <el-col :span="8">
  16. <el-form-item label="计量期:" prop="contractPeriodId">
  17. <el-select v-model="baseForm.contractPeriodId" placeholder="选择计量期" filterable block @change="periodChange">
  18. <el-option v-for="item in period" :key="item.id" :label="item.periodNumber" :value="item.id" />
  19. </el-select>
  20. </el-form-item>
  21. </el-col>
  22. <el-col :span="8">
  23. <el-form-item label="计量单编号:">
  24. <el-input v-model="baseForm.meterNumber" disabled />
  25. </el-form-item>
  26. </el-col>
  27. <el-col :span="8">
  28. <el-form-item label="业务日期:" prop="businessDate">
  29. <el-date-picker v-model="baseForm.businessDate" class="block" format="YYYY-MM-DD" type="date" value-format="YYYY-MM-DD" disabled />
  30. </el-form-item>
  31. </el-col>
  32. <el-col :span="16">
  33. <el-form-item label="工程划分:">
  34. <el-input v-model="baseForm.engineerDivide" disabled />
  35. </el-form-item>
  36. </el-col>
  37. <el-col :span="8">
  38. <el-form-item label="部位名称:">
  39. <el-input v-model="baseForm.partName" />
  40. </el-form-item>
  41. </el-col>
  42. <el-col :span="8">
  43. <el-form-item label="交工证书编号:">
  44. <el-input v-model="baseForm.certificateNumber" />
  45. </el-form-item>
  46. </el-col>
  47. <el-col :span="8">
  48. <el-form-item label="计量金额:">
  49. <el-input v-model="baseForm.meterMoney" disabled />
  50. </el-form-item>
  51. </el-col>
  52. <el-col :span="8">
  53. <el-form-item label="变更令:">
  54. <el-input v-model="baseForm.changeTokenNumber" disabled />
  55. </el-form-item>
  56. </el-col>
  57. <el-col :span="8">
  58. <el-form-item label="收方单:">
  59. <el-input v-model="baseForm.debitFormId" disabled />
  60. </el-form-item>
  61. </el-col>
  62. <el-col :span="8">
  63. <el-form-item label="草图文件:">
  64. <hc-form-upload :src="baseForm.pictureList" :h-props="uploadFormProps" :disabled="isView" @upload="formUpload" @change="formUploadChange" />
  65. </el-form-item>
  66. </el-col>
  67. <el-col :span="8">
  68. <el-button type="warning" class="w-full" style="height: 70%;" @click="associateQual">
  69. <span>点击关联质检资料</span>
  70. </el-button>
  71. </el-col>
  72. <el-col :span="24">
  73. <el-form-item label="计算式:">
  74. <el-input v-model="baseForm.calculateFormula" :autosize="{ minRows: 4, maxRows: 8 }" type="textarea" />
  75. </el-form-item>
  76. </el-col>
  77. </el-row>
  78. </el-form>
  79. </hc-card-item>
  80. <!-- 收方清单列表 -->
  81. <hc-card-item class="mt-3">
  82. <template #header>
  83. <span class="mr-3">计量清单列表</span>
  84. <span class="text-orange font-400">温馨提示:超计,累计计量量> 变更后数量,分解清单超计整行红色</span>
  85. </template>
  86. <template #extra>
  87. <el-button type="primary" text :disabled="isView" @click="addBillBaseModalClick">
  88. <HcIcon name="add" />
  89. <span>添加清单</span>
  90. </el-button>
  91. </template>
  92. <hc-table :key="tableKey" is-new :index-style="{ width: 60 }" :is-stripe="false" :column="addTableColumn" :datas="addTableData" :row-style="addTableRowStyle">
  93. <template #currentPrice="{ row }">
  94. <hc-table-input v-model="row.currentPrice" disabled />
  95. </template>
  96. <template #changeTotal="{ row }">
  97. <hc-table-input v-model="row.changeTotal" disabled />
  98. </template>
  99. <template #currentMeterTotal="{ row }">
  100. <hc-table-input v-model="row.currentMeterTotal" :disabled="isView" @blur="currentMeterTotalBlur(row)" />
  101. </template>
  102. <template #containChangeTotal="{ row }">
  103. <hc-table-input v-model="row.containChangeTotal" :disabled="isView" @blur="containChangeTotalBlur(row)" />
  104. </template>
  105. <template #payRatio="{ row }">
  106. <hc-table-input v-model="row.payRatio" :disabled="isView" @blur="unPayRatioBlur(row)" />
  107. </template>
  108. <template #currentMeterMoney="{ row }">
  109. <hc-table-input v-model="row.currentMeterMoney" disabled />
  110. </template>
  111. <template #allMeterTotal="{ row }">
  112. <hc-table-input v-model="row.allMeterTotal" disabled />
  113. </template>
  114. <template #action="{ index }">
  115. <el-link type="danger" :disabled="isView" @click="delAddTableClick(index)">删除</el-link>
  116. </template>
  117. </hc-table>
  118. </hc-card-item>
  119. <!-- 附件列表 -->
  120. <hc-card-item class="mt-3" title="附件列表">
  121. <template #extra>
  122. <span class="text-orange font-400">可上传 图片(png、jpg、jpeg)、Excel(xls、xlsx)、PDF、Word(doc、docx)文件</span>
  123. </template>
  124. <el-form :model="baseForm" label-position="left" label-width="auto">
  125. <el-form-item label="上传附件">
  126. <hc-form-upload type="list" :src="baseForm.fileList" :h-props="uploadFormProps" :disabled="isView" @upload="attachmentUpload" @change="attachmentUploadChange" />
  127. </el-form-item>
  128. </el-form>
  129. </hc-card-item>
  130. </hc-body>
  131. </div>
  132. </div>
  133. </hc-new-dialog>
  134. <!-- 添加分解清单 -->
  135. <HcBillBaseModal v-model="addBillBaseModalShow" :data-id="dataId" :ids="billBaseIds" :idn="nodeId" :period-id="baseForm.contractPeriodId" :contract-id="cid" @finish="finishChange" />
  136. <!-- 文件上传组件 -->
  137. <hc-upload-file
  138. ref="uploadFileRef"
  139. :echo-params="uploadFileParams"
  140. :options="uploadFileOptions"
  141. @success="uploadFileSuccess"
  142. />
  143. <!-- 关联质检资料 -->
  144. <qualityRleation :quality-moadal="qualityMoadal" :cid="cid" :period-id="period_id" :select-id="selectId" @close="closeQual" @finish="finishModal" />
  145. </template>
  146. <script setup>
  147. import { nextTick, ref, watch } from 'vue'
  148. import { isNumberReg } from '~uti/tools'
  149. import HcBillBaseModal from './addBillBaseModal.vue'
  150. import qualityRleation from './qualityRleation.vue'
  151. import { arrDelKey, arrToId, arrToKey, deepClone, getArrValue, getObjValue, getRandom, getUUID, isArrIndex, isNullES } from 'js-fast-way'
  152. import BigNumber from 'bignumber.js'
  153. import { getHeader } from 'hc-vue3-ui'
  154. import unitApi from '~api/project/debit/contract/unit'
  155. import mainApi from '~api/debit-pay/admin/middlepay'
  156. import { getStoreValue, setStoreValue } from '~src/utils/storage'
  157. const props = defineProps({
  158. projectId: {
  159. type: [String, Number],
  160. default: '',
  161. },
  162. contractId: {
  163. type: [String, Number],
  164. default: '',
  165. },
  166. allPeriods: {
  167. type: Array,
  168. default: () => ([]),
  169. },
  170. periodId: {
  171. type: [String, Number],
  172. default: '',
  173. },
  174. ids: {
  175. type: [String, Number],
  176. default: '',
  177. },
  178. isView:{
  179. type:Boolean,
  180. default:false, //是否预览
  181. },
  182. })
  183. //事件
  184. const emit = defineEmits(['finish', 'close'])
  185. const uuid = getRandom(4)
  186. const dataId = ref(props.ids)
  187. const period = ref(props.allPeriods)
  188. const period_id = ref(props.periodId)
  189. const pid = ref(props.projectId)
  190. const cid = ref(props.contractId)
  191. const isLoading = ref(false)
  192. const isView = ref(props.isView)
  193. //双向绑定
  194. // eslint-disable-next-line no-undef
  195. const isShow = defineModel('modelValue', {
  196. default: false,
  197. })
  198. //监听
  199. watch(() => [
  200. props.projectId,
  201. props.contractId,
  202. props.allPeriods,
  203. props.periodId,
  204. props.isView,
  205. ], ([projectId, contractId, periods, periodId, view]) => {
  206. period.value = periods
  207. pid.value = projectId
  208. cid.value = contractId
  209. period_id.value = periodId
  210. isView.value = view
  211. setBasePeriodForm(periodId)
  212. }, { deep: true })
  213. //监听
  214. watch(() => props.ids, (id) => {
  215. dataId.value = id
  216. }, { deep: true })
  217. //监听
  218. watch(isShow, (val) => {
  219. if (val) {
  220. if (dataId.value ) {
  221. getDataDetail()
  222. } else {
  223. setBasePeriodForm(period_id.value)
  224. nextTick(() => {
  225. setSplitRef()
  226. })
  227. }
  228. } else {
  229. baseForm.value = { fileList: [], pictureUrl: '', pictureName:'', pictureList:[] }
  230. }
  231. })
  232. //初始化设置拖动分割线
  233. const setSplitRef = () => {
  234. //配置参考: https://split.js.org/#/?direction=vertical&snapOffset=0
  235. try {
  236. window.$split(['#hc_tree_card_' + uuid, '#hc_table_card_' + uuid], {
  237. sizes: [20, 80],
  238. snapOffset: 0,
  239. minSize: [50, 500],
  240. })
  241. } catch (error) {
  242. console.log(error)
  243. }
  244. }
  245. //基础表单
  246. const baseFormRef = ref(null)
  247. const baseForm = ref({ fileList: [], pictureUrl: '', pictureName:'' })
  248. const baseFormRules = {
  249. contractPeriodId: {
  250. required: true,
  251. trigger: 'blur',
  252. message: '请选择计量期',
  253. },
  254. businessDate: {
  255. required: true,
  256. trigger: 'blur',
  257. message: '请选择业务日期',
  258. },
  259. }
  260. const isRelationData = ref(false)//是否管理质检资料
  261. const tableKey = ref(getUUID())
  262. //监听
  263. watch(() => baseForm.value.fileList, (list) => {
  264. console.log(list, 'list')
  265. tableKey.value = getUUID()
  266. // 验证数组中的对象是否包含名为 'selectId' 的字段
  267. const fieldName = 'selectId'
  268. const containsField = list.some(obj => obj.hasOwnProperty(fieldName))
  269. if (containsField) {
  270. isRelationData.value = true//关联质检资料后最大支付比例变为100
  271. addTableData.value.forEach((ele)=>{
  272. ele.upPayRatio = 100
  273. })
  274. } else {
  275. isRelationData.value = false
  276. addTableData.value.forEach((ele)=>{
  277. ele.upPayRatio = ele.oldupPayRatio || '0.00'
  278. })
  279. }
  280. nextTick(()=>{
  281. console.log(isComparedRaVal.value, 'isComparedRaVal.value ')
  282. if (isComparedRaVal.value === 1 ) {
  283. window.$message.warning('累计计量金额超出支付比列,如需计量100%,请完成关联对应的质保资料')
  284. }
  285. })
  286. }, { deep: true })
  287. //获取数据详情
  288. const selectId = ref('')
  289. const getDataDetail = async () => {
  290. if (!dataId.value) return
  291. const { data } = await mainApi.getDetail({ id: dataId.value })
  292. const res = getObjValue(data)
  293. res.pictureList = [{
  294. fileName: res.pictureName ?? '',
  295. filePdfUrl: res.pictureUrl ?? '',
  296. fileUrl: res.pictureUrl ?? '',
  297. }]
  298. res.pictureUrl = res.pictureUrl ?? ''
  299. res.pictureName = res.pictureName ?? ''
  300. nodeId.value = res.contractUnitId ?? ''
  301. baseForm.value = res
  302. addTableData.value = getArrValue(res.formList)
  303. selectId.value = arrToKey(res.fileList, 'selectId', ',')
  304. addTableData.value.forEach((ele)=>{
  305. ele.oldupPayRatio = ele.upPayRatio
  306. })
  307. }
  308. //数据格式
  309. const treeProps = {
  310. label: 'nodeName',
  311. children: 'children',
  312. isLeaf: 'notExsitChild',
  313. }
  314. //懒加载的数据
  315. const treeAutoExpandKeys = ref(getStoreValue('middlepay-tree-auto-expand-keys') || [])
  316. const treeLoadNode = async ({ item, level }, resolve) => {
  317. let id = 0
  318. if (level !== 0) {
  319. const nodeData = getObjValue(item)
  320. id = nodeData?.id || ''
  321. }
  322. //获取数据
  323. const { data } = await unitApi.lazyTree({
  324. id: id,
  325. contractId: cid.value,
  326. contractPeriodId: period_id.value,
  327. })
  328. resolve(getArrValue(data))
  329. }
  330. const nodeId = ref('')
  331. const isLastChild = ref(true)//是否是最底层节点
  332. const treeNodeTap = ({ data }) => {
  333. const { notExsitChild } = data
  334. isLastChild.value = notExsitChild
  335. nodeId.value = data.id
  336. baseForm.value.contractUnitId = data.id
  337. baseForm.value.fileList = []
  338. getNodeDivide(data.id)
  339. getCurrentNodeAllFormData(data.id)
  340. }
  341. //获取工程划分
  342. const getNodeDivide = async (nodeId) => {
  343. const { data } = await mainApi.getNodeDivide({ nodeId: nodeId })
  344. baseForm.value.engineerDivide = data ?? ''
  345. }
  346. //获取当前节点下,当期未被计量的所有清单
  347. const getCurrentNodeAllFormData = async (nodeId) => {
  348. const { data } = await mainApi.getCurrentNodeAllForm({ contractId: cid.value, contractPeriodId:baseForm.value.contractPeriodId, contractUnitId:nodeId })
  349. addTableData.value = getArrValue(data)
  350. }
  351. //获取变更令
  352. const getNodeToken = async () => {
  353. isLoading.value = true
  354. const { businessDate } = baseForm.value
  355. const { data } = await mainApi.getNodeToken({
  356. projectId: pid.value,
  357. contractId: cid.value,
  358. nodeId: nodeId.value,
  359. businessDate: businessDate,
  360. formIds: arrToId(addTableData.value),
  361. })
  362. //处理数据
  363. const { changeTokenNumber, changeTokenIds, files } = getObjValue(data)
  364. baseForm.value.changeTokenNumber = changeTokenNumber ?? ''
  365. baseForm.value.changeTokenIds = changeTokenIds ?? ''
  366. //处理文件
  367. let newFileList = []
  368. const fileList = deepClone(baseForm.value.fileList)
  369. //移除非手动上传的文件
  370. for (let i = 0; i < fileList.length; i++) {
  371. if (fileList[i].fileType === 1) {
  372. newFileList.push(fileList[i])
  373. }
  374. }
  375. //追加附件列表
  376. const filesArr = getArrValue(files)
  377. for (let i = 0; i < filesArr.length; i++) {
  378. newFileList.push(filesArr[i])
  379. }
  380. //更新数据
  381. baseForm.value.fileList = newFileList
  382. isLoading.value = false
  383. }
  384. //计量期被改变
  385. const periodChange = () => {
  386. setBasePeriodForm(baseForm.value.contractPeriodId)
  387. getCurrentNodeAllFormData( nodeId.value)
  388. }
  389. //计量期相关的数据
  390. const setBasePeriodForm = (periodId) => {
  391. if (dataId.value) return
  392. treeAutoExpandKeys.value = getStoreValue('middlepay-tree-auto-expand-keys') || []
  393. const periods = period.value
  394. baseForm.value.contractPeriodId = periodId
  395. const periodData = periods.find((item) => item.id === periodId)
  396. baseForm.value.periodNumber = periodData.periodNumber
  397. baseForm.value.businessDate = periodData.endDate ?? null
  398. getMeterNumber(periodId)
  399. }
  400. //获取计量单编号
  401. const getMeterNumber = async (periodId) => {
  402. const { data } = await mainApi.getMeterNumber({
  403. projectId: pid.value,
  404. contractId: cid.value,
  405. contractPeriodId: periodId,
  406. })
  407. baseForm.value.meterNumber = data ?? ''
  408. }
  409. //草图文件上传
  410. const formUpload = () => {
  411. uploadFileParams.value = { type: '草图文件' }
  412. uploadFileOptions.value.accept = 'image/png,image/jpg,image/jpeg'
  413. uploadFileOptions.value.accept_tip = '图片(png、jpg、jpeg)'
  414. uploadFileOptions.value.size = 50
  415. uploadFileRef.value?.selectFile()
  416. }
  417. const formUploadChange = (url) => {
  418. baseForm.value.pictureUrl = url
  419. }
  420. //收方清单列表
  421. const addTableColumn = ref([
  422. { key: 'formNumber', name: '清单编号', width: '120' },
  423. { key: 'formName', name: '清单名称', minWidth: '280' },
  424. { key: 'currentPrice', name: '单价(元)', width: '100' },
  425. { key: 'resolveTotal', name: '分解数量', width: '100' },
  426. { key: 'changeTotal', name: '变更后数量', width: '100' },
  427. { key: 'currentMeterTotal', name: '本期计量数量', width: '140' },
  428. { key: 'payRatio', name: '支付比例(%)', width: '140' },
  429. { key: 'containChangeTotal', name: '含变更数量', width: '100' },
  430. { key: 'currentMeterMoney', name: '本期计量金额', width: '120' },
  431. { key: 'allMeterTotal', name: '累计计数量', width: '100' },
  432. { key: 'otherMeterTotal', name: '基数', width: '80' },
  433. { key: 'action', name: '操作', fixed: 'right', width: 80, align: 'center' },
  434. ])
  435. const addTableData = ref([])
  436. const isComparedRaVal = ref(-1)
  437. //计算本期计量金额
  438. const currentMeterTotalBlur = (row) => {
  439. //如果为空
  440. let currentMeterTotal = row.currentMeterTotal
  441. const isMeter = isNumberReg(currentMeterTotal)
  442. if (isNullES(currentMeterTotal) || !isMeter) {
  443. currentMeterTotal = 0
  444. }
  445. //计算本期计量金额
  446. nextTick(() => {
  447. row.currentMeterTotal = currentMeterTotal
  448. row.currentMeterMoney = (BigNumber(currentMeterTotal).multipliedBy(row.currentPrice)).toString()
  449. row.allMeterTotal = (BigNumber(currentMeterTotal).plus(row.otherMeterTotal)).toString()
  450. //计算总计量金额
  451. let meterMoney = 0, table = addTableData.value
  452. for (let i = 0; i < table.length; i++) {
  453. meterMoney = (BigNumber(meterMoney).plus(table[i].currentMeterMoney)).toString()
  454. }
  455. baseForm.value.meterMoney = meterMoney
  456. //计算本期支付比例
  457. //本期支 付比例=本期计量数量/变更后数量
  458. row.payRatio = BigNumber(currentMeterTotal).dividedBy(row.changeTotal).toString() * 100
  459. compareRowUnpayRatio(row, 1)
  460. })
  461. }
  462. //计算含变更数量
  463. const containChangeTotalBlur = (row) => {
  464. let val = row.containChangeTotal
  465. const isMeter = isNumberReg(val)
  466. if (isNullES(val) || !isMeter) {
  467. val = 0
  468. }
  469. nextTick(() => {
  470. row.containChangeTotal = val
  471. })
  472. }
  473. const compareRowUnpayRatio = (row, type)=>{
  474. // 计算方式:
  475. //本期支 付比例=本期计量数量/变更后数量
  476. //本期支付比例=本期计量数量/变更后数量
  477. //本期计量数量=本期支付比例*变更后数量
  478. // 会返回最大支付比例 upPayRatio
  479. // 和其他期支付比例 otherPayRatio
  480. // 每次填写完 本期计量数量或者支付比例后
  481. // 就去对比:本期支付比例+其他期支付比例
  482. // 是否大于最大支付比例
  483. // 如果大于,则提示
  484. let payRatio = new BigNumber(row.payRatio )//本期支付比例
  485. let upPayRatio = new BigNumber(row.upPayRatio )//最大支付比例
  486. let otherPayRatio = new BigNumber(row.otherPayRatio )//其他期支付比例
  487. let result = BigNumber(payRatio).plus(otherPayRatio)//本期支付比例+其他期支付比例
  488. const isComparedRa = result.comparedTo(upPayRatio)
  489. isComparedRaVal.value = isComparedRa
  490. if (isComparedRa === 1 ) {
  491. isCanSave.value = true
  492. if (type === 1) {
  493. window.$message.warning('累计计量金额超出支付比列,如需计量100%,请完成关联对应的质保资料')
  494. } else if (type === 2) {
  495. return isComparedRa
  496. }
  497. } else {
  498. isCanSave.value = false
  499. }
  500. }
  501. const unPayRatioBlur = (row)=>{
  502. nextTick(()=>{
  503. console.log(row, 'rowzhifubili')
  504. let payRatio = new BigNumber(row.payRatio )//本期支付比例
  505. let changeTotal = new BigNumber(row.changeTotal )//变更后数量
  506. // 本期计量数量=本期支付比例*变更后数量
  507. row.currentMeterTotal = (payRatio.dividedBy(100).multipliedBy(changeTotal)).toString()
  508. row.currentMeterMoney = (BigNumber(row.currentMeterTotal).multipliedBy(row.currentPrice)).toString()//本期计量金额额
  509. row.allMeterTotal = (BigNumber(row.currentMeterTotal).plus(row.otherMeterTotal)).toString()
  510. // 就去对比:本期支付比例+其他期支付比例
  511. // 是否大于最大支付比例
  512. compareRowUnpayRatio(row, 1)
  513. //计算总计量金额
  514. let meterMoney = 0, table = addTableData.value
  515. for (let i = 0; i < table.length; i++) {
  516. meterMoney = (BigNumber(meterMoney).plus(table[i].currentMeterMoney)).toString()
  517. }
  518. baseForm.value.meterMoney = meterMoney
  519. })
  520. }
  521. //判断是否红色
  522. const isCanSave = ref(false)
  523. const addTableRowStyle = ({ row }) => {
  524. console.log(row, 'xuan')
  525. //本期支付比例+其他期支付比例
  526. // 是否大于最大支付比例
  527. const isComparedRa = compareRowUnpayRatio(row, 2)
  528. if (isComparedRa === 1 ) {
  529. isCanSave.value = true
  530. return '--el-table-tr-bg-color: #fe0000; --el-table-row-hover-bg-color: #fe0000; color: white;'
  531. } else {
  532. isCanSave.value = false
  533. }
  534. // 判断施工图数量是否大于合同数据
  535. // 大于:如果超计= 1并且 划分=1
  536. // 不显示红色,否则显示
  537. // 小于:判断累计计量量是否大于变更后数量
  538. // 大于: 如果超计=1 不变红
  539. // 不等于1则变红
  540. // 小于:不变红
  541. //施工图数量是否大于合同数据
  542. let isBuildThanContract = row.isBuildThanContract
  543. //是否超计
  544. let isContractOver = row.isContractOver
  545. //是否生成划分
  546. let isCreateDivide = row.isCreateDivide
  547. if (isBuildThanContract) {
  548. if (isContractOver && isCreateDivide) {
  549. isCanSave.value = false
  550. } else {
  551. isCanSave.value = true
  552. return '--el-table-tr-bg-color: #fe0000; --el-table-row-hover-bg-color: #fe0000; color: white;'
  553. }
  554. } else {
  555. let allMeterTotal = new BigNumber(row.allMeterTotal) //a 累计计量量
  556. let changeTotal = new BigNumber(row.changeTotal) //b 变更后数量
  557. //a 大于 b = 1,a 等于 b = 0,a 小于 b = -1, a 或 b 的值异常时 = null
  558. const isCompared = allMeterTotal.comparedTo(changeTotal)
  559. if (isCompared === 1 || isCompared === null) {
  560. if (isContractOver) {
  561. isCanSave.value = false
  562. } else {
  563. isCanSave.value = true
  564. return '--el-table-tr-bg-color: #fe0000; --el-table-row-hover-bg-color: #fe0000; color: white;'
  565. }
  566. } else {
  567. isCanSave.value = false
  568. }
  569. }
  570. }
  571. //删除清单
  572. const delAddTableClick = (index) => {
  573. addTableData.value.splice(index, 1)
  574. //获取变更令
  575. nextTick(() => {
  576. getNodeToken()
  577. })
  578. }
  579. //添加分解单
  580. const addBillBaseModalShow = ref(false)
  581. const billBaseIds = ref('')
  582. const addBillBaseModalClick = () => {
  583. if (!nodeId.value) {
  584. window.$message.warning('请先选择一个树节点')
  585. return
  586. }
  587. if ( isLastChild.value) {
  588. addBillBaseModalShow.value = true
  589. } else {
  590. window.$message.warning('请选择最底层节点')
  591. }
  592. addBillBaseModalShow.value = true
  593. billBaseIds.value = arrToId(addTableData.value)
  594. }
  595. //添加完成
  596. const finishChange = (data) => {
  597. for (let i = 0; i < data.length; i++) {
  598. addTableData.value.push(data[i])
  599. }
  600. //获取变更令
  601. nextTick(() => {
  602. getNodeToken()
  603. })
  604. }
  605. //附件上传
  606. const uploadFormProps = {
  607. url: 'filePdfUrl',
  608. name: 'fileName',
  609. }
  610. const attachmentUpload = () => {
  611. uploadFileParams.value = { type: '附件文件' }
  612. uploadFileOptions.value.accept = ''
  613. uploadFileOptions.value.accept_tip = ''
  614. uploadFileOptions.value.size = null
  615. uploadFileRef.value?.selectFile()
  616. }
  617. const attachmentUploadChange = (a, b, fileList) => {
  618. baseForm.value.fileList = getArrValue(fileList)
  619. selectId.value = arrToKey( baseForm.value.fileList, 'selectId', ',')
  620. }
  621. //文件上传
  622. const uploadFileRef = ref(null)
  623. const uploadFileParams = ref({})
  624. const uploadFileOptions = ref({
  625. headers: getHeader(),
  626. multiple: false,
  627. })
  628. // 文件上传成功的回调
  629. const uploadFileSuccess = ({ echoParams, resData }) => {
  630. const { pdfUrl } = resData
  631. if (isNullES(pdfUrl)) {
  632. window.$message.warning('该文件不能生成pdf,请更换文件上传')
  633. uploadFileRef.value?.setModalShow(false)
  634. return
  635. }
  636. if (echoParams.type === '草图文件') {
  637. baseForm.value.pictureUrl = resData.link ?? ''
  638. baseForm.value.pictureName = resData.originalName ?? ''
  639. baseForm.value.pictureList = [{
  640. fileName: resData.originalName ?? '',
  641. filePdfUrl: resData.pdfUrl ?? '',
  642. fileUrl: resData.link ?? '',
  643. }]
  644. uploadFileRef.value?.setModalShow(false)
  645. } else if (echoParams.type === '附件文件') {
  646. baseForm.value.fileList.push({
  647. contractId: cid.value,
  648. fileName: resData.originalName ?? '',
  649. filePdfUrl: resData.pdfUrl ?? '',
  650. fileUrl: resData.link ?? '',
  651. fileType: 1,
  652. })
  653. uploadFileRef.value?.setModalShow(false)
  654. }
  655. }
  656. //保存
  657. const addModalSave = async () => {
  658. if (!nodeId.value) {
  659. window.$message.warning('请先选择一个树节点')
  660. return
  661. }
  662. // if (isCanSave.value) {
  663. // window.$message.warning('累计计量量 > 变更后数量,不允许修改')
  664. // return
  665. // }
  666. const form = baseForm.value
  667. form.formList = addTableData.value
  668. form.projectId = pid.value
  669. form.contractId = cid.value
  670. let res = {}
  671. if (dataId.value) {
  672. res = await mainApi.edit(form)
  673. } else {
  674. res = await mainApi.add(form)
  675. }
  676. //处理数据
  677. const { code, msg } = res
  678. if (code === 200) {
  679. window.$message.success('保存成功')
  680. addModalClose()
  681. emit('finish')
  682. } else {
  683. window.$message.error(msg ?? '保存失败')
  684. }
  685. }
  686. //关闭弹窗
  687. const addModalClose = () => {
  688. isShow.value = false
  689. baseForm.value = { fileList: [], pictureUrl: '' }
  690. addTableData.value = []
  691. selectId.value = ''
  692. setStoreValue('checkRows', [])
  693. emit('close')
  694. }
  695. //关联质检资料
  696. const qualityMoadal = ref(false)
  697. const associateQual = ()=>{
  698. if (!nodeId.value) {
  699. window.$message.warning('请先选择一个树节点')
  700. return
  701. }
  702. if ( isLastChild.value) {
  703. qualityMoadal.value = true
  704. } else {
  705. window.$message.warning('请选择最底层节点')
  706. }
  707. }
  708. const closeQual = ()=>{
  709. qualityMoadal.value = false
  710. }
  711. const finishModal = (rows, cancelcheck)=>{
  712. let fileList = []
  713. rows.forEach(ele => {
  714. const isPush = isArrIndex( baseForm.value.fileList, 'selectId', ele.selectId)
  715. if (!isPush) {
  716. fileList.push({
  717. fileName:ele.dataName,
  718. filePdfUrl:ele.evisaPdfUrl ? ele.evisaPdfUrl : ele.pdfUrl,
  719. fileType:1,
  720. fileUrl:ele.evisaPdfUrl ? ele.evisaPdfUrl : ele.pdfUrl,
  721. selectId:ele.selectId,
  722. })
  723. }
  724. })
  725. fileList.forEach((ele)=>{
  726. baseForm.value.fileList.push(ele)
  727. })
  728. //表格取消勾选回显
  729. cancelcheck.forEach((ele)=>{
  730. baseForm.value.fileList.forEach((ele1)=>{
  731. if (ele === ele1.selectId) {
  732. let arr = arrDelKey(baseForm.value.fileList, 'selectId', ele)
  733. baseForm.value.fileList = arr
  734. }
  735. })
  736. })
  737. selectId.value = arrToKey( baseForm.value.fileList, 'selectId', ',')
  738. }
  739. </script>