addModal.vue 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  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
  278. })
  279. }
  280. // 判断数组中是否存在某个对象的 upPayRatio 字段值为 100
  281. const hasValue100 = addTableData.value.some(obj => obj.upPayRatio === 100)
  282. nextTick(()=>{
  283. if (hasValue100 && (isComparedRaVal.value === 1 )) {
  284. window.$message.warning('累计计量金额超出支付比列,如需计量100%,请完成关联对应的质保资料')
  285. }
  286. })
  287. }, { deep: true })
  288. //获取数据详情
  289. const selectId = ref('')
  290. const getDataDetail = async () => {
  291. if (!dataId.value) return
  292. const { data } = await mainApi.getDetail({ id: dataId.value })
  293. const res = getObjValue(data)
  294. res.pictureList = [{
  295. fileName: res.pictureName ?? '',
  296. filePdfUrl: res.pictureUrl ?? '',
  297. fileUrl: res.pictureUrl ?? '',
  298. }]
  299. res.pictureUrl = res.pictureUrl ?? ''
  300. res.pictureName = res.pictureName ?? ''
  301. nodeId.value = res.contractUnitId ?? ''
  302. baseForm.value = res
  303. addTableData.value = getArrValue(res.formList)
  304. selectId.value = arrToKey(res.fileList, 'selectId', ',')
  305. addTableData.value.forEach((ele)=>{
  306. ele.oldupPayRatio = ele.upPayRatio
  307. })
  308. }
  309. //数据格式
  310. const treeProps = {
  311. label: 'nodeName',
  312. children: 'children',
  313. isLeaf: 'notExsitChild',
  314. }
  315. //懒加载的数据
  316. const treeAutoExpandKeys = ref(getStoreValue('middlepay-tree-auto-expand-keys') || [])
  317. const treeLoadNode = async ({ item, level }, resolve) => {
  318. let id = 0
  319. if (level !== 0) {
  320. const nodeData = getObjValue(item)
  321. id = nodeData?.id || ''
  322. }
  323. //获取数据
  324. const { data } = await unitApi.lazyTree({
  325. id: id,
  326. contractId: cid.value,
  327. contractPeriodId: period_id.value,
  328. })
  329. resolve(getArrValue(data))
  330. }
  331. const nodeId = ref('')
  332. const isLastChild = ref(true)//是否是最底层节点
  333. const treeNodeTap = ({ data }) => {
  334. const { notExsitChild } = data
  335. isLastChild.value = notExsitChild
  336. nodeId.value = data.id
  337. baseForm.value.contractUnitId = data.id
  338. baseForm.value.fileList = []
  339. getNodeDivide(data.id)
  340. getCurrentNodeAllFormData(data.id)
  341. }
  342. //获取工程划分
  343. const getNodeDivide = async (nodeId) => {
  344. const { data } = await mainApi.getNodeDivide({ nodeId: nodeId })
  345. baseForm.value.engineerDivide = data ?? ''
  346. }
  347. //获取当前节点下,当期未被计量的所有清单
  348. const getCurrentNodeAllFormData = async (nodeId) => {
  349. const { data } = await mainApi.getCurrentNodeAllForm({ contractId: cid.value, contractPeriodId:baseForm.value.contractPeriodId, contractUnitId:nodeId })
  350. addTableData.value = getArrValue(data)
  351. }
  352. //获取变更令
  353. const getNodeToken = async () => {
  354. isLoading.value = true
  355. const { businessDate } = baseForm.value
  356. const { data } = await mainApi.getNodeToken({
  357. projectId: pid.value,
  358. contractId: cid.value,
  359. nodeId: nodeId.value,
  360. businessDate: businessDate,
  361. formIds: arrToId(addTableData.value),
  362. })
  363. //处理数据
  364. const { changeTokenNumber, changeTokenIds, files } = getObjValue(data)
  365. baseForm.value.changeTokenNumber = changeTokenNumber ?? ''
  366. baseForm.value.changeTokenIds = changeTokenIds ?? ''
  367. //处理文件
  368. let newFileList = []
  369. const fileList = deepClone(baseForm.value.fileList)
  370. //移除非手动上传的文件
  371. for (let i = 0; i < fileList.length; i++) {
  372. if (fileList[i].fileType === 1) {
  373. newFileList.push(fileList[i])
  374. }
  375. }
  376. //追加附件列表
  377. const filesArr = getArrValue(files)
  378. for (let i = 0; i < filesArr.length; i++) {
  379. newFileList.push(filesArr[i])
  380. }
  381. //更新数据
  382. baseForm.value.fileList = newFileList
  383. isLoading.value = false
  384. }
  385. //计量期被改变
  386. const periodChange = () => {
  387. setBasePeriodForm(baseForm.value.contractPeriodId)
  388. getCurrentNodeAllFormData( nodeId.value)
  389. }
  390. //计量期相关的数据
  391. const setBasePeriodForm = (periodId) => {
  392. if (dataId.value) return
  393. treeAutoExpandKeys.value = getStoreValue('middlepay-tree-auto-expand-keys') || []
  394. const periods = period.value
  395. baseForm.value.contractPeriodId = periodId
  396. const periodData = periods.find((item) => item.id === periodId)
  397. baseForm.value.periodNumber = periodData.periodNumber
  398. baseForm.value.businessDate = periodData.endDate ?? null
  399. getMeterNumber(periodId)
  400. }
  401. //获取计量单编号
  402. const getMeterNumber = async (periodId) => {
  403. const { data } = await mainApi.getMeterNumber({
  404. projectId: pid.value,
  405. contractId: cid.value,
  406. contractPeriodId: periodId,
  407. })
  408. baseForm.value.meterNumber = data ?? ''
  409. }
  410. //草图文件上传
  411. const formUpload = () => {
  412. uploadFileParams.value = { type: '草图文件' }
  413. uploadFileOptions.value.accept = 'image/png,image/jpg,image/jpeg'
  414. uploadFileOptions.value.accept_tip = '图片(png、jpg、jpeg)'
  415. uploadFileOptions.value.size = 50
  416. uploadFileRef.value?.selectFile()
  417. }
  418. const formUploadChange = (url) => {
  419. baseForm.value.pictureUrl = url
  420. }
  421. //收方清单列表
  422. const addTableColumn = ref([
  423. { key: 'formNumber', name: '清单编号', width: '120' },
  424. { key: 'formName', name: '清单名称', minWidth: '280' },
  425. { key: 'currentPrice', name: '单价(元)', width: '100' },
  426. { key: 'resolveTotal', name: '分解数量', width: '100' },
  427. { key: 'changeTotal', name: '变更后数量', width: '100' },
  428. { key: 'currentMeterTotal', name: '本期计量数量', width: '140' },
  429. { key: 'payRatio', name: '支付比例(%)', width: '140' },
  430. { key: 'containChangeTotal', name: '含变更数量', width: '100' },
  431. { key: 'currentMeterMoney', name: '本期计量金额', width: '120' },
  432. { key: 'allMeterTotal', name: '累计计数量', width: '100' },
  433. { key: 'otherMeterTotal', name: '基数', width: '80' },
  434. { key: 'action', name: '操作', fixed: 'right', width: 80, align: 'center' },
  435. ])
  436. const addTableData = ref([])
  437. const isComparedRaVal = ref(-1)
  438. //计算本期计量金额
  439. const currentMeterTotalBlur = (row) => {
  440. //如果为空
  441. let currentMeterTotal = row.currentMeterTotal
  442. const isMeter = isNumberReg(currentMeterTotal)
  443. if (isNullES(currentMeterTotal) || !isMeter) {
  444. currentMeterTotal = 0
  445. }
  446. //计算本期计量金额
  447. nextTick(() => {
  448. row.currentMeterTotal = currentMeterTotal
  449. row.currentMeterMoney = (BigNumber(currentMeterTotal).multipliedBy(row.currentPrice)).toString()
  450. row.allMeterTotal = (BigNumber(currentMeterTotal).plus(row.otherMeterTotal)).toString()
  451. //计算总计量金额
  452. let meterMoney = 0, table = addTableData.value
  453. for (let i = 0; i < table.length; i++) {
  454. meterMoney = (BigNumber(meterMoney).plus(table[i].currentMeterMoney)).toString()
  455. }
  456. baseForm.value.meterMoney = meterMoney
  457. //计算本期支付比例
  458. //本期支 付比例=本期计量数量/变更后数量
  459. row.payRatio = BigNumber(currentMeterTotal).dividedBy(row.changeTotal).toString() * 100
  460. // 每次填写完 本期计量数量或者支付比例后
  461. // 就去对比:本期支付比例+其他期支付比例
  462. // 是否大于最大支付比例
  463. // 如果大于,则提示
  464. let payRatio = new BigNumber(row.payRatio )//本期支付比例
  465. let upPayRatio = new BigNumber(row.upPayRatio )//最大支付比例
  466. let otherPayRatio = new BigNumber(row.otherPayRatio )//其他期支付比例
  467. let result = BigNumber(payRatio).plus(otherPayRatio)//本期支付比例+其他期支付比例
  468. const isComparedRa = result.comparedTo(upPayRatio)
  469. console.log(isComparedRa, 'isCompared3333333')
  470. isComparedRaVal.value = isComparedRa
  471. // //a 大于 b = 1,a 等于 b = 0,a 小于 b = -1, a 或 b 的值异常时 = null
  472. if (isComparedRa === 1 ) {
  473. isCanSave.value = true
  474. window.$message.warning('累计计量金额超出支付比列,如需计量100%,请完成关联对应的质保资料')
  475. // return '--el-table-tr-bg-color: #fe0000; --el-table-row-hover-bg-color: #fe0000; color: white;'
  476. } else {
  477. isCanSave.value = false
  478. }
  479. })
  480. }
  481. //计算含变更数量
  482. const containChangeTotalBlur = (row) => {
  483. let val = row.containChangeTotal
  484. const isMeter = isNumberReg(val)
  485. if (isNullES(val) || !isMeter) {
  486. val = 0
  487. }
  488. nextTick(() => {
  489. row.containChangeTotal = val
  490. })
  491. }
  492. const unPayRatioBlur = (row)=>{
  493. nextTick(()=>{
  494. console.log(row, 'row')
  495. //计算本期计量金额
  496. //如果为空
  497. let currentMeterTotal = row.currentMeterTotal
  498. const isMeter = isNumberReg(currentMeterTotal)
  499. if (isNullES(currentMeterTotal) || !isMeter) {
  500. currentMeterTotal = 0
  501. }
  502. //本期计量金额
  503. row.currentMeterTotal = currentMeterTotal
  504. row.currentMeterMoney = (BigNumber(currentMeterTotal).multipliedBy(row.currentPrice)).toString()
  505. row.allMeterTotal = (BigNumber(currentMeterTotal).plus(row.otherMeterTotal)).toString()
  506. //计算总计量金额
  507. let meterMoney = 0, table = addTableData.value
  508. for (let i = 0; i < table.length; i++) {
  509. meterMoney = (BigNumber(meterMoney).plus(table[i].currentMeterMoney)).toString()
  510. }
  511. baseForm.value.meterMoney = meterMoney
  512. // 计算方式:
  513. //本期支 付比例=本期计量数量/变更后数量
  514. // 会返回最大支付比例 upPayRatio
  515. // 和其他期支付比例 otherPayRatio
  516. // 每次填写完 本期计量数量或者支付比例后
  517. // 就去对比:本期支付比例+其他期支付比例
  518. // 是否大于最大支付比例
  519. // 如果大于,则提示
  520. let changeTotal = new BigNumber(row.changeTotal )//变更后数量
  521. let payRatio = new BigNumber(row.payRatio )//本期支付比例
  522. let upPayRatio = new BigNumber(row.upPayRatio )//最大支付比例
  523. let otherPayRatio = new BigNumber(row.otherPayRatio )//其他期支付比例
  524. let result = BigNumber(payRatio).plus(otherPayRatio)//本期支付比例+其他期支付比例
  525. // 本期计量数量=本期支付比例*变更后数量
  526. row.currentMeterTotal = (payRatio.dividedBy(100).multipliedBy(changeTotal)).toString()
  527. const isComparedRa = result.comparedTo(upPayRatio)
  528. isComparedRaVal.value = isComparedRa
  529. console.log(upPayRatio, 'upPayRatio')
  530. console.log(payRatio, 'payRatio')
  531. console.log(isComparedRa, 'isComparedRa')
  532. // //a 大于 b = 1,a 等于 b = 0,a 小于 b = -1, a 或 b 的值异常时 = null
  533. if (isComparedRa === 1 ) {
  534. isCanSave.value = true
  535. window.$message.warning('累计计量金额超出支付比列,如需计量100%,请完成关联对应的质保资料')
  536. // return '--el-table-tr-bg-color: #fe0000; --el-table-row-hover-bg-color: #fe0000; color: white;'
  537. } else {
  538. isCanSave.value = false
  539. }
  540. })
  541. }
  542. //判断是否红色
  543. const isCanSave = ref(false)
  544. const addTableRowStyle = ({ row }) => {
  545. console.log(row, 'rowcxxuanr')
  546. //本期支付比例+其他期支付比例
  547. // 是否大于最大支付比例
  548. // if ( isComparedRaVal.value === 1 || isComparedRaVal.value === null) {
  549. // isCanSave.value = true
  550. // return '--el-table-tr-bg-color: #fe0000; --el-table-row-hover-bg-color: #fe0000; color: white;'
  551. // } else {
  552. // isCanSave.value = false
  553. // }
  554. let payRatio = new BigNumber(row.payRatio )//本期支付比例
  555. let upPayRatio = new BigNumber(row.upPayRatio )//最大支付比例
  556. let otherPayRatio = new BigNumber(row.otherPayRatio )//其他期支付比例
  557. let result = BigNumber(payRatio).plus(otherPayRatio)//本期支付比例+其他期支付比例
  558. const isComparedRa = result.comparedTo(upPayRatio)
  559. isComparedRaVal.value = isComparedRa
  560. console.log(upPayRatio, 'upPayRatio')
  561. console.log(payRatio, 'payRatio')
  562. console.log(isComparedRa, 'isComparedRa333334444')
  563. // //a 大于 b = 1,a 等于 b = 0,a 小于 b = -1, a 或 b 的值异常时 = null
  564. if (isComparedRa === 1 ) {
  565. isCanSave.value = true
  566. return '--el-table-tr-bg-color: #fe0000; --el-table-row-hover-bg-color: #fe0000; color: white;'
  567. } else {
  568. isCanSave.value = false
  569. }
  570. // 判断施工图数量是否大于合同数据
  571. // 大于:如果超计= 1并且 划分=1
  572. // 不显示红色,否则显示
  573. // 小于:判断累计计量量是否大于变更后数量
  574. // 大于: 如果超计=1 不变红
  575. // 不等于1则变红
  576. // 小于:不变红
  577. //施工图数量是否大于合同数据
  578. let isBuildThanContract = row.isBuildThanContract
  579. //是否超计
  580. let isContractOver = row.isContractOver
  581. //是否生成划分
  582. let isCreateDivide = row.isCreateDivide
  583. if (isBuildThanContract) {
  584. if (isContractOver && isCreateDivide) {
  585. isCanSave.value = false
  586. } else {
  587. isCanSave.value = true
  588. return '--el-table-tr-bg-color: #fe0000; --el-table-row-hover-bg-color: #fe0000; color: white;'
  589. }
  590. } else {
  591. let allMeterTotal = new BigNumber(row.allMeterTotal) //a 累计计量量
  592. let changeTotal = new BigNumber(row.changeTotal) //b 变更后数量
  593. //a 大于 b = 1,a 等于 b = 0,a 小于 b = -1, a 或 b 的值异常时 = null
  594. const isCompared = allMeterTotal.comparedTo(changeTotal)
  595. if (isCompared === 1 || isCompared === null) {
  596. if (isContractOver) {
  597. isCanSave.value = false
  598. } else {
  599. isCanSave.value = true
  600. return '--el-table-tr-bg-color: #fe0000; --el-table-row-hover-bg-color: #fe0000; color: white;'
  601. }
  602. } else {
  603. isCanSave.value = false
  604. }
  605. }
  606. }
  607. //删除清单
  608. const delAddTableClick = (index) => {
  609. addTableData.value.splice(index, 1)
  610. //获取变更令
  611. nextTick(() => {
  612. getNodeToken()
  613. })
  614. }
  615. //添加分解单
  616. const addBillBaseModalShow = ref(false)
  617. const billBaseIds = ref('')
  618. const addBillBaseModalClick = () => {
  619. if (!nodeId.value) {
  620. window.$message.warning('请先选择一个树节点')
  621. return
  622. }
  623. if ( isLastChild.value) {
  624. addBillBaseModalShow.value = true
  625. } else {
  626. window.$message.warning('请选择最底层节点')
  627. }
  628. addBillBaseModalShow.value = true
  629. billBaseIds.value = arrToId(addTableData.value)
  630. }
  631. //添加完成
  632. const finishChange = (data) => {
  633. for (let i = 0; i < data.length; i++) {
  634. addTableData.value.push(data[i])
  635. }
  636. //获取变更令
  637. nextTick(() => {
  638. getNodeToken()
  639. })
  640. }
  641. //附件上传
  642. const uploadFormProps = {
  643. url: 'filePdfUrl',
  644. name: 'fileName',
  645. }
  646. const attachmentUpload = () => {
  647. uploadFileParams.value = { type: '附件文件' }
  648. uploadFileOptions.value.accept = ''
  649. uploadFileOptions.value.accept_tip = ''
  650. uploadFileOptions.value.size = null
  651. uploadFileRef.value?.selectFile()
  652. }
  653. const attachmentUploadChange = (a, b, fileList) => {
  654. baseForm.value.fileList = getArrValue(fileList)
  655. selectId.value = arrToKey( baseForm.value.fileList, 'selectId', ',')
  656. }
  657. //文件上传
  658. const uploadFileRef = ref(null)
  659. const uploadFileParams = ref({})
  660. const uploadFileOptions = ref({
  661. headers: getHeader(),
  662. multiple: false,
  663. })
  664. // 文件上传成功的回调
  665. const uploadFileSuccess = ({ echoParams, resData }) => {
  666. const { pdfUrl } = resData
  667. if (isNullES(pdfUrl)) {
  668. window.$message.warning('该文件不能生成pdf,请更换文件上传')
  669. uploadFileRef.value?.setModalShow(false)
  670. return
  671. }
  672. if (echoParams.type === '草图文件') {
  673. baseForm.value.pictureUrl = resData.link ?? ''
  674. baseForm.value.pictureName = resData.originalName ?? ''
  675. baseForm.value.pictureList = [{
  676. fileName: resData.originalName ?? '',
  677. filePdfUrl: resData.pdfUrl ?? '',
  678. fileUrl: resData.link ?? '',
  679. }]
  680. uploadFileRef.value?.setModalShow(false)
  681. } else if (echoParams.type === '附件文件') {
  682. baseForm.value.fileList.push({
  683. contractId: cid.value,
  684. fileName: resData.originalName ?? '',
  685. filePdfUrl: resData.pdfUrl ?? '',
  686. fileUrl: resData.link ?? '',
  687. fileType: 1,
  688. })
  689. uploadFileRef.value?.setModalShow(false)
  690. }
  691. }
  692. //保存
  693. const addModalSave = async () => {
  694. if (!nodeId.value) {
  695. window.$message.warning('请先选择一个树节点')
  696. return
  697. }
  698. // if (isCanSave.value) {
  699. // window.$message.warning('累计计量量 > 变更后数量,不允许修改')
  700. // return
  701. // }
  702. const form = baseForm.value
  703. form.formList = addTableData.value
  704. form.projectId = pid.value
  705. form.contractId = cid.value
  706. let res = {}
  707. if (dataId.value) {
  708. res = await mainApi.edit(form)
  709. } else {
  710. res = await mainApi.add(form)
  711. }
  712. //处理数据
  713. const { code, msg } = res
  714. if (code === 200) {
  715. window.$message.success('保存成功')
  716. addModalClose()
  717. emit('finish')
  718. } else {
  719. window.$message.error(msg ?? '保存失败')
  720. }
  721. }
  722. //关闭弹窗
  723. const addModalClose = () => {
  724. isShow.value = false
  725. baseForm.value = { fileList: [], pictureUrl: '' }
  726. addTableData.value = []
  727. selectId.value = ''
  728. setStoreValue('checkRows', [])
  729. emit('close')
  730. }
  731. //关联质检资料
  732. const qualityMoadal = ref(false)
  733. const associateQual = ()=>{
  734. if (!nodeId.value) {
  735. window.$message.warning('请先选择一个树节点')
  736. return
  737. }
  738. if ( isLastChild.value) {
  739. qualityMoadal.value = true
  740. } else {
  741. window.$message.warning('请选择最底层节点')
  742. }
  743. }
  744. const closeQual = ()=>{
  745. qualityMoadal.value = false
  746. }
  747. const finishModal = (rows, cancelcheck)=>{
  748. let fileList = []
  749. rows.forEach(ele => {
  750. const isPush = isArrIndex( baseForm.value.fileList, 'selectId', ele.selectId)
  751. if (!isPush) {
  752. fileList.push({
  753. fileName:ele.dataName,
  754. filePdfUrl:ele.evisaPdfUrl ? ele.evisaPdfUrl : ele.pdfUrl,
  755. fileType:1,
  756. fileUrl:ele.evisaPdfUrl ? ele.evisaPdfUrl : ele.pdfUrl,
  757. selectId:ele.selectId,
  758. })
  759. }
  760. })
  761. fileList.forEach((ele)=>{
  762. baseForm.value.fileList.push(ele)
  763. })
  764. //表格取消勾选回显
  765. cancelcheck.forEach((ele)=>{
  766. baseForm.value.fileList.forEach((ele1)=>{
  767. if (ele === ele1.selectId) {
  768. let arr = arrDelKey(baseForm.value.fileList, 'selectId', ele)
  769. baseForm.value.fileList = arr
  770. }
  771. })
  772. })
  773. selectId.value = arrToKey( baseForm.value.fileList, 'selectId', ',')
  774. }
  775. </script>