middlepay.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <div class="relative h-full flex">
  3. <div :id="`hc_tree_card_${uuid}`">
  4. <hc-new-card scrollbar>
  5. <template #header>
  6. <el-select v-model="searchForm.contractPeriodId" placeholder="选择计量期" filterable clearable block @change="searchKey1Click">
  7. <el-option v-for="item in key1Data" :key="item.id" :label="item.periodNumber" :value="item.id" clearable />
  8. </el-select>
  9. </template>
  10. <hc-lazy-tree :key="treeKey" :h-props="treeProps" tree-key="id" :auto-expand-keys="TreeAutoExpandKeys" @load="treeLoadNode" @node-tap="treeNodeTap" />
  11. </hc-new-card>
  12. </div>
  13. <div :id="`hc_table_card_${uuid}`" class="flex-1">
  14. <hc-new-card>
  15. <template #header>
  16. <div class="text-orange font-400">计量总金额:{{ meterMoney }}元</div>
  17. </template>
  18. <template #extra>
  19. <el-button hc-btn color="red" :disabled="approveStatus !== 0" :loading="autoLoading" @click="autoClick">自动批量计量</el-button>
  20. <el-button hc-btn type="primary" :disabled="approveStatus !== 0" @click="addModalClick">新增</el-button>
  21. <el-button hc-btn type="warning" :disabled="approveStatus !== 0" @click="reportClick">按期上报</el-button>
  22. <el-button hc-btn type="success" @click="detailsModalClick">清单明细</el-button>
  23. <el-button hc-btn type="success" @click="viewPdf">查看报表</el-button>
  24. <el-button hc-btn color="#626aef" @click="sortClick(1)">按部位排序</el-button>
  25. <el-button hc-btn color="#626aef" @click="sortClick(2)">按录入时间排序</el-button>
  26. </template>
  27. <hc-table
  28. :column="tableColumn" :datas="tableData" :loading="tableLoading"
  29. is-new is-check :check-style="{ width: 29 }" :index-style="{ width: 60 }"
  30. @selection-change="tableCheckChange"
  31. >
  32. <template #contractPeriodId="{ row }">
  33. {{ getTablePeriod(row) }}
  34. </template>
  35. <template #approveStatus="{ row }">
  36. {{ getTableStatus(row) }}
  37. </template>
  38. <template #action="{ row }">
  39. <el-link type="primary" @click="rowViewClick(row)">预览</el-link>
  40. <el-link type="success" :disabled="approveStatus !== 0" @click="rowEditClick(row)">修改</el-link>
  41. <el-link type="danger" :disabled="approveStatus !== 0" @click="rowDelClick(row)">删除</el-link>
  42. </template>
  43. </hc-table>
  44. <template #action>
  45. <hc-pages :pages="searchForm" @change="pageChange" />
  46. </template>
  47. </hc-new-card>
  48. </div>
  49. <!-- 中间计量新增 -->
  50. <HcAddModal v-model="addModalShow" :ids="addModalIds" :project-id="projectId" :contract-id="contractId" :all-periods="key1Data" :period-id="searchForm.contractPeriodId" :is-view="isView" @finish="addModalFinish" />
  51. <!-- 清单明细 -->
  52. <HcDetailsModal v-model="detailsModalShow" :project-id="projectId" :contract-id="contractId" :period-id="searchForm.contractPeriodId" />
  53. <!-- 上报弹窗 -->
  54. <hc-report-dialog v-model="isReport" :info="reportInfo" @finish="reportFinish" />
  55. <!-- 查看报表 -->
  56. <hc-view-report v-model="isReportDrawer" />
  57. </div>
  58. </template>
  59. <script setup>
  60. import { nextTick, onActivated, onMounted, ref, watch } from 'vue'
  61. import { useAppStore } from '~src/store'
  62. import { useRoute } from 'vue-router'
  63. import { getArrValue, getObjValue, getRandom } from 'js-fast-way'
  64. import { getStoreValue, setStoreValue } from '~src/utils/storage'
  65. import { delMessage } from '~uti/tools'
  66. import HcAddModal from './components/middlepay/addModal.vue'
  67. import HcDetailsModal from './components/middlepay/detailsModal.vue'
  68. import unitApi from '~api/project/debit/contract/unit'
  69. import mainApi from '~api/debit-pay/admin/middlepay'
  70. import { toPdfPage } from '~uti/btn-auth'
  71. const useRoutes = useRoute()
  72. const useAppState = useAppStore()
  73. const projectId = ref(useAppState.getProjectId || '')
  74. const contractId = ref(useAppState.getContractId || '')
  75. defineOptions({
  76. name: 'DebitPayAdminMiddlepay',
  77. })
  78. const uuid = getRandom(4)
  79. //渲染完成
  80. onMounted(async () => {
  81. setSplitRef()
  82. })
  83. //激活
  84. onActivated(async () => {
  85. await getKey1Data()
  86. getCurrentMeterMoney().then()
  87. })
  88. const isReportDrawer = ref(false)
  89. watch(() => useRoutes, (val) => {
  90. if (val) {
  91. isReportDrawer.value = false
  92. }
  93. }, { immediate: true, deep: true })
  94. //初始化设置拖动分割线
  95. const setSplitRef = () => {
  96. //配置参考: https://split.js.org/#/?direction=vertical&snapOffset=0
  97. nextTick(() => {
  98. window.$split(['#hc_tree_card_' + uuid, '#hc_table_card_' + uuid], {
  99. sizes: [20, 80],
  100. snapOffset: 0,
  101. minSize: [50, 500],
  102. })
  103. })
  104. }
  105. //搜索表单
  106. const searchForm = ref({
  107. contractPeriodId: null, contractUnitId: null, contractId: contractId.value, type: 1,
  108. current: 1, size: 20, total: 0,
  109. })
  110. const approveStatus = ref(0)
  111. //计量期
  112. const key1Data = ref([])
  113. const getKey1Data = async ()=>{
  114. const { error, code, data } = await mainApi.getAllPeriod({
  115. contractId: contractId.value,
  116. type: 1,
  117. })
  118. if (!error && code === 200) {
  119. let newArr = getArrValue(data), info = getObjValue(newArr[newArr.length - 1])
  120. searchForm.value.contractPeriodId = info.id
  121. approveStatus.value = info.approveStatus
  122. key1Data.value = newArr
  123. key1Data.value.unshift({
  124. id:-1,
  125. periodNumber:'全部',
  126. })
  127. } else {
  128. key1Data.value = []
  129. }
  130. }
  131. const searchKey1Click = () => {
  132. let info = getObjValue(key1Data.value.find((item) => item.id === searchForm.value.contractPeriodId))
  133. approveStatus.value = info.approveStatus
  134. searchForm.value.current = 1
  135. getTableData()
  136. getCurrentMeterMoney()
  137. }
  138. //获取本期计量总金额
  139. const meterMoney = ref(0)
  140. const getCurrentMeterMoney = async () => {
  141. const { error, code, data } = await mainApi.getCurrentMeterMoney({
  142. contractId: contractId.value,
  143. contractPeriodId: searchForm.value.contractPeriodId,
  144. })
  145. if (!error && code === 200) {
  146. meterMoney.value = data
  147. } else {
  148. meterMoney.value = 0
  149. }
  150. }
  151. //数据格式
  152. const treeProps = {
  153. label: 'nodeName',
  154. children: 'children',
  155. isLeaf: 'notExsitChild',
  156. }
  157. const TreeAutoExpandKeys = ref(getStoreValue('middlepay-tree-auto-expand-keys') || [])
  158. //懒加载的数据
  159. const treeLoadNode = async ({ item, level }, resolve) => {
  160. let id = 0
  161. if (level !== 0) {
  162. const nodeData = getObjValue(item)
  163. id = nodeData?.id || ''
  164. }
  165. //获取数据
  166. const { data } = await unitApi.lazyTree({
  167. contractId: contractId.value,
  168. id:id,
  169. contractPeriodId:searchForm.value.contractPeriodId,
  170. })
  171. resolve(getArrValue(data))
  172. }
  173. const treeNodeTap = ({ data, keys }) => {
  174. searchForm.value.current = 1
  175. searchForm.value.contractUnitId = data.id
  176. TreeAutoExpandKeys.value = keys || []
  177. setStoreValue('middlepay-tree-auto-expand-keys', keys)
  178. getTableData()
  179. getCurrentMeterMoney().then()
  180. }
  181. //分页
  182. const pageChange = ({ current, size }) => {
  183. searchForm.value.current = current
  184. searchForm.value.size = size
  185. getTableData()
  186. }
  187. //表格数据
  188. const tableLoading = ref(false)
  189. const tableColumn = ref([
  190. { key: 'meterNumber', name: '计量单编号' },
  191. { key: 'contractPeriodId', name: '计量期' },
  192. { key: 'engineerDivide', name: '工程划分部位' },
  193. { key: 'meterMoney', name: '计量金额' },
  194. { key: 'businessDate', name: '业务日期' },
  195. { key: 'approveStatus', name: '审核状态' },
  196. { key: 'action', name: '操作', width: 130, align: 'center' },
  197. ])
  198. const tableData = ref([])
  199. const getTableData = async () => {
  200. tableData.value = []
  201. tableLoading.value = true
  202. const { data } = await mainApi.getPage({
  203. ...searchForm.value,
  204. contractId: contractId.value,
  205. })
  206. tableData.value = getArrValue(data['records'])
  207. if (tableData.value.length > 0) {
  208. if (tableData.value[0].approveStatusName !== '未上报') {
  209. rawUrl.value = tableData.value[0]?.periodPdfUrl
  210. } else {
  211. rawUrl.value = ''
  212. }
  213. } else {
  214. rawUrl.value = ''
  215. }
  216. searchForm.value.total = data.total || 0
  217. tableLoading.value = false
  218. }
  219. //排序
  220. const sortClick = (type) => {
  221. searchForm.value.type = type
  222. searchForm.value.current = 1
  223. getTableData()
  224. }
  225. //查看报表
  226. const rawUrl = ref('')
  227. const viewPdf = ()=>{
  228. toPdfPage(rawUrl.value)
  229. }
  230. //获取表格计量期
  231. const getTablePeriod = ({ contractPeriodId }) => {
  232. const periods = key1Data.value
  233. const periodData = periods.find((item) => item.id === contractPeriodId)
  234. return periodData?.periodNumber || ''
  235. }
  236. //获取表格状态
  237. const getTableStatus = ({ approveStatus }) => {
  238. if (approveStatus === 0) {
  239. return '未上报'
  240. } else if (approveStatus === 1) {
  241. return '待审批'
  242. } else if (approveStatus === 2) {
  243. return '已审批'
  244. } else if (approveStatus === 3) {
  245. return '已废除'
  246. }
  247. }
  248. //表格选择
  249. //表格勾选
  250. const tableCheck = ref([])
  251. const tableCheckChange = (rows) => {
  252. tableCheck.value = rows
  253. }
  254. //中间收方新增
  255. const addModalShow = ref(false)
  256. const addModalClick = () => {
  257. isView.value = false
  258. addModalIds.value = ''
  259. nextTick(() => {
  260. addModalShow.value = true
  261. })
  262. }
  263. //修改
  264. const addModalIds = ref('')
  265. const rowEditClick = (row) => {
  266. addModalIds.value = row.id
  267. isView.value = false
  268. nextTick(() => {
  269. addModalShow.value = true
  270. })
  271. }
  272. //预览rowViewClick
  273. const isView = ref(false)
  274. const rowViewClick = (row) => {
  275. addModalIds.value = row.id
  276. isView.value = true
  277. nextTick(() => {
  278. addModalShow.value = true
  279. })
  280. }
  281. //删除
  282. const rowDelClick = (row) => {
  283. delMessage(async () => {
  284. const { code, msg } = await mainApi.remove({ ids: row.id })
  285. if (code === 200) {
  286. window.$message.success('删除成功')
  287. getTableData().then()
  288. } else {
  289. window.$message.error(msg ?? '删除失败')
  290. }
  291. })
  292. }
  293. //保存完成
  294. const treeKey = ref(getRandom(2))
  295. const addModalFinish = () => {
  296. addModalShow.value = false
  297. TreeAutoExpandKeys.value = getStoreValue('middlepay-tree-auto-expand-keys') || []
  298. treeKey.value = getRandom(2)
  299. getTableData().then()
  300. }
  301. //收方清单明细
  302. const detailsModalShow = ref(false)
  303. const detailsModalClick = () => {
  304. detailsModalShow.value = true
  305. }
  306. //是否上报
  307. const isReport = ref(false)
  308. const reportInfo = ref({})
  309. const reportClick = () => {
  310. reportInfo.value = {
  311. type: 1,
  312. periodId: searchForm.value.contractPeriodId,
  313. }
  314. nextTick(() => {
  315. isReport.value = true
  316. })
  317. }
  318. //上报完成
  319. const reportFinish = () => {
  320. window.location.reload()
  321. }
  322. //自动批量计量
  323. const autoLoading = ref(false)
  324. const autoClick = async ()=>{
  325. const { code, msg } = await mainApi.autoBatchMeter(
  326. {
  327. PeriodId:searchForm.value.contractPeriodId,
  328. contractId:contractId.value,
  329. projectId:projectId.value,
  330. },
  331. )
  332. if (code === 200) {
  333. window.$message.success(msg)
  334. getTableData().then()
  335. } else {
  336. window.$message.error(msg ?? '删除失败')
  337. }
  338. }
  339. // const isReportDrawer = ref(false)
  340. </script>