middlepay.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 type="primary" @click="addModalClick">新增</el-button>
  20. <el-button hc-btn type="warning" @click="reportClick">按期上报</el-button>
  21. <el-button hc-btn type="success" @click="detailsModalClick">清单明细</el-button>
  22. <el-button hc-btn type="success" @click="isReportDrawer = true">查看报表</el-button>
  23. <el-button hc-btn color="#626aef">按部位排序</el-button>
  24. <el-button hc-btn color="#626aef">按录入时间排序</el-button>
  25. </template>
  26. <hc-table
  27. :column="tableColumn" :datas="tableData" :loading="tableLoading"
  28. is-new is-check :check-style="{ width: 29 }" :index-style="{ width: 60 }"
  29. @selection-change="tableCheckChange"
  30. >
  31. <template #contractPeriodId="{ row }">
  32. {{ getTablePeriod(row) }}
  33. </template>
  34. <template #approveStatus="{ row }">
  35. {{ getTableStatus(row) }}
  36. </template>
  37. <template #action="{ row }">
  38. <el-link type="success" @click="rowEditClick(row)">修改</el-link>
  39. <el-link type="danger" @click="rowDelClick(row)">删除</el-link>
  40. </template>
  41. </hc-table>
  42. <template #action>
  43. <hc-pages :pages="searchForm" @change="pageChange" />
  44. </template>
  45. </hc-new-card>
  46. </div>
  47. <!-- 中间计量新增 -->
  48. <HcAddModal v-model="addModalShow" :ids="addModalIds" :project-id="projectId" :contract-id="contractId" :all-periods="key1Data" :period-id="searchForm.contractPeriodId" @finish="addModalFinish" />
  49. <!-- 清单明细 -->
  50. <HcDetailsModal v-model="detailsModalShow" :project-id="projectId" :contract-id="contractId" :period-id="searchForm.contractPeriodId" />
  51. <!-- 上报弹窗 -->
  52. <hc-report-dialog v-model="isReport" />
  53. <!-- 查看报表 -->
  54. <hc-view-report v-model="isReportDrawer" />
  55. </div>
  56. </template>
  57. <script setup>
  58. import { nextTick, onMounted, ref } from 'vue'
  59. import { useAppStore } from '~src/store'
  60. import { getArrValue, getObjValue, getRandom } from 'js-fast-way'
  61. import { getStoreValue, setStoreValue } from '~src/utils/storage'
  62. import { delMessage } from '~uti/tools'
  63. import HcAddModal from './components/middlepay/addModal.vue'
  64. import HcDetailsModal from './components/middlepay/detailsModal.vue'
  65. import unitApi from '~api/project/debit/contract/unit'
  66. import mainApi from '~api/debit-pay/admin/middlepay'
  67. const useAppState = useAppStore()
  68. const projectId = ref(useAppState.getProjectId || '')
  69. const contractId = ref(useAppState.getContractId || '')
  70. defineOptions({
  71. name: 'DebitPayAdminMiddlepay',
  72. })
  73. const uuid = getRandom(4)
  74. //渲染完成
  75. onMounted(() => {
  76. setSplitRef()
  77. getKey1Data()
  78. getCurrentMeterMoney()
  79. })
  80. //初始化设置拖动分割线
  81. const setSplitRef = () => {
  82. //配置参考: https://split.js.org/#/?direction=vertical&snapOffset=0
  83. nextTick(() => {
  84. window.$split(['#hc_tree_card_' + uuid, '#hc_table_card_' + uuid], {
  85. sizes: [20, 80],
  86. snapOffset: 0,
  87. minSize: [50, 500],
  88. })
  89. })
  90. }
  91. //搜索表单
  92. const searchForm = ref({
  93. contractPeriodId: null, contractUnitId: null, contractId: contractId.value,
  94. current: 1, size: 10, total: 0,
  95. })
  96. //计量期
  97. const key1Data = ref([])
  98. const getKey1Data = async ()=>{
  99. const { error, code, data } = await mainApi.getAllPeriod({
  100. contractId:contractId.value,
  101. type:1,
  102. })
  103. if (!error && code === 200) {
  104. key1Data.value = getArrValue(data)
  105. searchForm.value.contractPeriodId = key1Data.value[ key1Data.value.length - 1].id
  106. } else {
  107. key1Data.value = []
  108. }
  109. }
  110. const searchKey1Click = () => {
  111. searchForm.value.current = 1
  112. getTableData()
  113. getCurrentMeterMoney()
  114. }
  115. //获取本期计量总金额
  116. const meterMoney = ref(0)
  117. const getCurrentMeterMoney = async () => {
  118. const { error, code, data } = await mainApi.getCurrentMeterMoney({
  119. contractId: contractId.value,
  120. contractPeriodId: searchForm.value.contractPeriodId,
  121. })
  122. if (!error && code === 200) {
  123. meterMoney.value = data
  124. } else {
  125. meterMoney.value = 0
  126. }
  127. }
  128. //数据格式
  129. const treeProps = {
  130. label: 'nodeName',
  131. children: 'children',
  132. isLeaf: 'notExsitChild',
  133. }
  134. const TreeAutoExpandKeys = ref(getStoreValue('middlepay-tree-auto-expand-keys') || [])
  135. //懒加载的数据
  136. const treeLoadNode = async ({ item, level }, resolve) => {
  137. let id = 0
  138. if (level !== 0) {
  139. const nodeData = getObjValue(item)
  140. id = nodeData?.id || ''
  141. }
  142. //获取数据
  143. const { data } = await unitApi.lazyTree({
  144. contractId: contractId.value,
  145. id:id,
  146. contractPeriodId:searchForm.value.contractPeriodId,
  147. })
  148. resolve(getArrValue(data))
  149. }
  150. const treeNodeTap = ({ data, keys }) => {
  151. searchForm.value.current = 1
  152. searchForm.value.contractUnitId = data.id
  153. TreeAutoExpandKeys.value = keys || []
  154. setStoreValue('middlepay-tree-auto-expand-keys', keys)
  155. getTableData()
  156. }
  157. //分页
  158. const pageChange = ({ current, size }) => {
  159. searchForm.value.current = current
  160. searchForm.value.size = size
  161. getTableData()
  162. }
  163. //表格数据
  164. const tableLoading = ref(false)
  165. const tableColumn = ref([
  166. { key: 'meterNumber', name: '计量单编号' },
  167. { key: 'contractPeriodId', name: '计量期' },
  168. { key: 'engineerDivide', name: '工程划分部位' },
  169. { key: 'meterMoney', name: '计量金额' },
  170. { key: 'businessDate', name: '业务日期' },
  171. { key: 'approveStatus', name: '审核状态' },
  172. { key: 'action', name: '操作', width: 130, align: 'center' },
  173. ])
  174. const tableData = ref([])
  175. const getTableData = async () => {
  176. tableData.value = []
  177. tableLoading.value = true
  178. const { data } = await mainApi.getPage({
  179. ...searchForm.value,
  180. contractId: contractId.value,
  181. })
  182. tableData.value = getArrValue(data['records'])
  183. searchForm.value.total = data.total || 0
  184. tableLoading.value = false
  185. }
  186. //获取表格计量期
  187. const getTablePeriod = ({ contractPeriodId }) => {
  188. const periods = key1Data.value
  189. const periodData = periods.find((item) => item.id === contractPeriodId)
  190. return periodData?.periodNumber || ''
  191. }
  192. //获取表格状态
  193. const getTableStatus = ({ approveStatus }) => {
  194. if (approveStatus === 0) {
  195. return '未上报'
  196. } else if (approveStatus === 1) {
  197. return '待审批'
  198. } else if (approveStatus === 2) {
  199. return '已审批'
  200. } else if (approveStatus === 3) {
  201. return '已废除'
  202. }
  203. }
  204. //表格选择
  205. const tableCheckChange = () => {
  206. }
  207. //中间收方新增
  208. const addModalShow = ref(false)
  209. const addModalClick = () => {
  210. addModalIds.value = ''
  211. addModalShow.value = true
  212. }
  213. //修改
  214. const addModalIds = ref('')
  215. const rowEditClick = (row) => {
  216. addModalIds.value = ''
  217. nextTick(() => {
  218. addModalIds.value = row.id
  219. addModalShow.value = true
  220. })
  221. }
  222. //删除
  223. const rowDelClick = (row) => {
  224. delMessage(async () => {
  225. const { code, msg } = await mainApi.remove({ ids: row.id })
  226. if (code === 200) {
  227. window.$message.success('删除成功')
  228. getTableData().then()
  229. } else {
  230. window.$message.error(msg ?? '删除失败')
  231. }
  232. })
  233. }
  234. //保存完成
  235. const addModalFinish = () => {
  236. addModalShow.value = false
  237. getTableData()
  238. }
  239. //收方清单明细
  240. const detailsModalShow = ref(false)
  241. const detailsModalClick = () => {
  242. detailsModalShow.value = true
  243. }
  244. //是否上报
  245. const isReport = ref(false)
  246. const reportClick = () => {
  247. isReport.value = true
  248. }
  249. const isReportDrawer = ref(false)
  250. </script>