middlepay.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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 :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:'null',
  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. }
  180. //分页
  181. const pageChange = ({ current, size }) => {
  182. searchForm.value.current = current
  183. searchForm.value.size = size
  184. getTableData()
  185. }
  186. //表格数据
  187. const tableLoading = ref(false)
  188. const tableColumn = ref([
  189. { key: 'meterNumber', name: '计量单编号' },
  190. { key: 'contractPeriodId', name: '计量期' },
  191. { key: 'engineerDivide', name: '工程划分部位' },
  192. { key: 'meterMoney', name: '计量金额' },
  193. { key: 'businessDate', name: '业务日期' },
  194. { key: 'approveStatus', name: '审核状态' },
  195. { key: 'action', name: '操作', width: 130, align: 'center' },
  196. ])
  197. const tableData = ref([])
  198. const getTableData = async () => {
  199. tableData.value = []
  200. tableLoading.value = true
  201. const { data } = await mainApi.getPage({
  202. ...searchForm.value,
  203. contractId: contractId.value,
  204. })
  205. tableData.value = getArrValue(data['records'])
  206. if (tableData.value.length > 0) {
  207. if (tableData.value[0].approveStatusName !== '未上报') {
  208. rawUrl.value = tableData.value[0]?.periodPdfUrl
  209. } else {
  210. rawUrl.value = ''
  211. }
  212. } else {
  213. rawUrl.value = ''
  214. }
  215. searchForm.value.total = data.total || 0
  216. tableLoading.value = false
  217. }
  218. //排序
  219. const sortClick = (type) => {
  220. searchForm.value.type = type
  221. searchForm.value.current = 1
  222. getTableData()
  223. }
  224. //查看报表
  225. const rawUrl = ref('')
  226. const viewPdf = ()=>{
  227. toPdfPage(rawUrl.value)
  228. }
  229. //获取表格计量期
  230. const getTablePeriod = ({ contractPeriodId }) => {
  231. const periods = key1Data.value
  232. const periodData = periods.find((item) => item.id === contractPeriodId)
  233. return periodData?.periodNumber || ''
  234. }
  235. //获取表格状态
  236. const getTableStatus = ({ approveStatus }) => {
  237. if (approveStatus === 0) {
  238. return '未上报'
  239. } else if (approveStatus === 1) {
  240. return '待审批'
  241. } else if (approveStatus === 2) {
  242. return '已审批'
  243. } else if (approveStatus === 3) {
  244. return '已废除'
  245. }
  246. }
  247. //表格选择
  248. //表格勾选
  249. const tableCheck = ref([])
  250. const tableCheckChange = (rows) => {
  251. tableCheck.value = rows
  252. }
  253. //中间收方新增
  254. const addModalShow = ref(false)
  255. const addModalClick = () => {
  256. isView.value = false
  257. addModalIds.value = ''
  258. nextTick(() => {
  259. addModalShow.value = true
  260. })
  261. }
  262. //修改
  263. const addModalIds = ref('')
  264. const rowEditClick = (row) => {
  265. addModalIds.value = row.id
  266. isView.value = false
  267. nextTick(() => {
  268. addModalShow.value = true
  269. })
  270. }
  271. //预览rowViewClick
  272. const isView = ref(false)
  273. const rowViewClick = (row) => {
  274. addModalIds.value = row.id
  275. isView.value = true
  276. nextTick(() => {
  277. addModalShow.value = true
  278. })
  279. }
  280. //删除
  281. const rowDelClick = (row) => {
  282. delMessage(async () => {
  283. const { code, msg } = await mainApi.remove({ ids: row.id })
  284. if (code === 200) {
  285. window.$message.success('删除成功')
  286. getTableData().then()
  287. } else {
  288. window.$message.error(msg ?? '删除失败')
  289. }
  290. })
  291. }
  292. //保存完成
  293. const addModalFinish = () => {
  294. addModalShow.value = false
  295. TreeAutoExpandKeys.value = getStoreValue('middlepay-tree-auto-expand-keys') || []
  296. getTableData()
  297. }
  298. //收方清单明细
  299. const detailsModalShow = ref(false)
  300. const detailsModalClick = () => {
  301. detailsModalShow.value = true
  302. }
  303. //是否上报
  304. const isReport = ref(false)
  305. const reportInfo = ref({})
  306. const reportClick = () => {
  307. reportInfo.value = {
  308. type: 1,
  309. periodId: searchForm.value.contractPeriodId,
  310. }
  311. nextTick(() => {
  312. isReport.value = true
  313. })
  314. }
  315. //上报完成
  316. const reportFinish = () => {
  317. window.location.reload()
  318. }
  319. //自动批量计量
  320. const autoLoading = ref(false)
  321. const autoClick = async ()=>{
  322. const { code, msg } = await mainApi.autoBatchMeter(
  323. {
  324. PeriodId:searchForm.value.contractPeriodId,
  325. contractId:contractId.value,
  326. projectId:projectId.value,
  327. },
  328. )
  329. if (code === 200) {
  330. window.$message.success(msg)
  331. getTableData().then()
  332. } else {
  333. window.$message.error(msg ?? '删除失败')
  334. }
  335. }
  336. // const isReportDrawer = ref(false)
  337. </script>