middlepay.vue 10 KB

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