addModal.vue 35 KB

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