index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <HcCard>
  3. <!-- <template #header>
  4. <div class="w-36">
  5. <el-select v-model="searchForm.planType" block clearable placeholder="年度" size="large">
  6. <el-option v-for="item in planType" :label="item.name" :value="item.key"/>
  7. </el-select>
  8. </div>
  9. </template> -->
  10. <template #extra>
  11. <el-button size="large" type="primary" hc-btn @click="addRowClick">
  12. <HcIcon name="add"/>
  13. <span>新增经营预算</span>
  14. </el-button>
  15. </template>
  16. <HcTable :column="tableColumn" :datas="tableData" :loading="tableLoading">
  17. <template #name="{row}">
  18. <span class="text-blue text-hover" @click="rowNameClick(row)">{{row.name}}</span>
  19. </template>
  20. <template #key2="{row}">
  21. <span >{{row.budgetStartTime?row.budgetStartTime:''}}</span>
  22. <span v-if="row.budgetEndTime">~</span>
  23. <span >{{row.budgetEndTime?row.budgetEndTime:''}}</span>
  24. </template>
  25. <template #action="{row,index}">
  26. <el-button plain size="small" type="primary" @click="editRowClick(row)">编辑</el-button>
  27. <el-button plain size="small" type="danger" @click="rowCancel(row)">删除</el-button>
  28. </template>
  29. </HcTable>
  30. <template #action>
  31. <HcPages :pages="searchForm" @change="pageChange"/>
  32. </template>
  33. </HcCard>
  34. </template>
  35. <script setup>
  36. import {ref,onMounted,onActivated} from "vue";
  37. import annualApi from '~api/program/annual.js';
  38. import {getArrValue} from "js-fast-way"
  39. import {delMessage} from "~uti/tools";
  40. import {useRouter, useRoute} from 'vue-router'
  41. const router = useRouter()
  42. // onMounted(()=>{
  43. // getTableData()
  44. // })
  45. onActivated(()=>{
  46. getTableData()
  47. })
  48. //计划类型
  49. const planType = ref([
  50. {name: '临时计划', key: '1'},
  51. {name: '月度计划', key: '2'},
  52. {name: '年度计划', key: '3'},
  53. ])
  54. //搜索表单
  55. const searchForm = ref({
  56. planType: null, current: 1, size: 20, total: 0
  57. })
  58. //分页被点击
  59. const pageChange = ({current, size}) => {
  60. searchForm.value.current = current
  61. searchForm.value.size = size
  62. getTableData()
  63. }
  64. //获取数据
  65. const tableLoading = ref(false)
  66. const tableColumn = [
  67. {key: 'name', name: '预算名称'},
  68. {key: 'key2', name: '起止日期', width: '220', align: 'center'},
  69. {key: 'totalBudget', name: '总经营预算', width: '120', align: 'center'},
  70. {key: 'annualContractTarget', name: '年度合同额指标', width: '140', align: 'center'},
  71. {key: 'annualProfitTarget', name: '年度利润指标', width: '120', align: 'center'},
  72. {key: 'staffCost', name: '工资支出', width: '120', align: 'center'},
  73. {key: 'manageDisburse', name: '其他管理支出', width: '120', align: 'center'},
  74. {key: 'action', name: '操作', width: '150', align: 'center'},
  75. ]
  76. const tableData = ref([
  77. {id: 1, key1: '2023年5月度计划', key2: '2022-07-01~2027-04-12', key3: '111', key4: '36', key5: '30', key6: '6', key7: '张三'},
  78. {id: 2, key1: '2023年5月度计划', key2: '2022-07-01~2027-04-12', key3: '111', key4: '36', key5: '30', key6: '6', key7: '张三'},
  79. {id: 3, key1: '2023年5月度计划', key2: '2022-07-01~2027-04-12', key3: '111', key4: '36', key5: '30', key6: '6', key7: '张三'},
  80. {id: 4, key1: '2023年5月度计划', key2: '2022-07-01~2027-04-12', key3: '111', key4: '36', key5: '30', key6: '6', key7: '张三'},
  81. ])
  82. const getTableData = async() => {
  83. tableLoading.value = true
  84. const {error, code, data} = await annualApi.getPage(searchForm.value)
  85. tableLoading.value = false
  86. if (!error && code === 200) {
  87. tableData.value = getArrValue(data['records'])
  88. searchForm.value.total = data['total'] || 0
  89. } else {
  90. tableData.value = []
  91. searchForm.value.total = 0
  92. }
  93. }
  94. //名称被点击
  95. const rowNameClick = (row) => {
  96. router.push({
  97. name: 'program-annual-view',
  98. query: {
  99. id: row.id,
  100. name:row.name
  101. }
  102. })
  103. }
  104. //新增计划
  105. const addRowClick = () => {
  106. router.push({
  107. name: 'program-annual-form',
  108. query:{
  109. type:'add'
  110. }
  111. })
  112. }
  113. //编辑预算
  114. const editRowClick = (row) => {
  115. router.push({
  116. name: 'program-annual-form',
  117. query: {
  118. id: row.id,
  119. type:'edit'
  120. }
  121. })
  122. }
  123. //删除
  124. const rowCancel = (row) => {
  125. delMessage(async () => {
  126. const {error, code, msg} = await annualApi.deleteAnnualBudget({
  127. id: row.id
  128. })
  129. //判断状态
  130. if (!error && code === 200) {
  131. window.$message?.success(msg)
  132. getTableData().then()
  133. } else {
  134. window.$message?.error(msg)
  135. }
  136. })
  137. }
  138. </script>