index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <HcCard>
  3. <template #header>
  4. <div class="w-36">
  5. <el-select v-model="searchForm.departmentType" block clearable placeholder="选择部门" size="large">
  6. <el-option v-for="item in department" :label="item.deptName" :value="item.deptCategory"/>
  7. </el-select>
  8. </div>
  9. <div class="w-36 ml-4">
  10. <el-date-picker class="block" v-model="searchForm.planStartDate" type="month" value-format="YYYY-MM" placeholder="开始日期" clearable size="large"/>
  11. </div>
  12. <div class="mx-2">~</div>
  13. <div class="w-36">
  14. <el-date-picker class="block" v-model="searchForm.planEndDate" type="month" value-format="YYYY-MM" placeholder="结束日期" clearable size="large"/>
  15. </div>
  16. <div class="ml-4">
  17. <el-button size="large" type="primary" @click="searchClick">
  18. <HcIcon name="search-2"/>
  19. <span>搜索</span>
  20. </el-button>
  21. </div>
  22. <div class="ml-2">
  23. <el-button size="large" @click="resetClick">
  24. <HcIcon name="close-circle"/>
  25. <span>重置</span>
  26. </el-button>
  27. </div>
  28. </template>
  29. <template #extra>
  30. <el-button size="large" type="primary" hc-btn @click="addRowClick">
  31. <HcIcon name="add"/>
  32. <span>新增预算计划</span>
  33. </el-button>
  34. </template>
  35. <HcTable :column="tableColumn" :datas="tableData" :loading="tableLoading">
  36. <template #planName="{row}">
  37. <span class="text-blue" @click="rowNameClick(row)">{{row.planName}}</span>
  38. </template>
  39. <template #key2="{row}">
  40. <span >{{row.planStartDate?row.planStartDate:''}}</span>
  41. <span v-if="row.planStartDate">~</span>
  42. <span >{{row.planStartDate?row.planStartDate:''}}</span>
  43. </template>
  44. <template #planTotal="{row}">
  45. <span>{{row.planTotal}}条</span>
  46. </template>
  47. <template #finishPlanTotal="{row}">
  48. <span>{{row.finishPlanTotal}}条</span>
  49. </template>
  50. <template #beginPlanTotal="{row}">
  51. <span>{{row.beginPlanTotal}}条</span>
  52. </template>
  53. <template #action="{row,index}">
  54. <el-button size="small" type="primary" @click="editRowClick(row)">编辑</el-button>
  55. <el-button size="small" type="danger" @click="delRowClick(row)">删除</el-button>
  56. </template>
  57. </HcTable>
  58. <template #action>
  59. <HcPages :pages="searchForm" @change="pageChange"/>
  60. </template>
  61. <!--选择计划所属月份-->
  62. <HcDialog bgColor="#ffffff" isToBody title="选择计划所属月份" widths="26rem" saveText="确认"
  63. :show="monthModal" @close="monthCloseClick" @save="monthSaveClick"
  64. >
  65. <el-form ref="formMonthRef" label-position="top" size="large" :model="formMonthModel" :rules="formMonthRules">
  66. <el-form-item label="选择部门" prop="section">
  67. <el-select v-model="formMonthModel.section" block placeholder="选择部门" @change="changeDpt">
  68. <el-option v-for="item in department" :label="item.deptName" :value="item.deptCategory"/>
  69. </el-select>
  70. </el-form-item>
  71. <el-form-item label="选择月份" prop="month">
  72. <el-date-picker type="month" class="block" v-model="formMonthModel.month" format="YYYY-MM" value-format="YYYY-MM"/>
  73. </el-form-item>
  74. </el-form>
  75. </HcDialog>
  76. </HcCard>
  77. </template>
  78. <script setup>
  79. import {ref,onMounted,onActivated,watch} from "vue";
  80. import {useRouter} from 'vue-router'
  81. import sectionApi from '~api/program/section.js';
  82. import {getArrValue,getObjValue,formValidate} from "js-fast-way"
  83. import { getdepartmentList} from "~api/other";
  84. import {delMessage} from "~uti/tools";
  85. const router = useRouter()
  86. onActivated(()=>{
  87. getTableData()
  88. getDepartmentDict()//获取部门字典
  89. })
  90. //选择部门
  91. const department = ref([
  92. ])
  93. //搜索表单
  94. const searchForm = ref({
  95. planType: null, planStartDate: null, planEndDate: null, departmentType: null,
  96. current: 1, size: 20, total: 0
  97. })
  98. //搜索
  99. const searchClick = () => {
  100. searchForm.value.current = 1;
  101. getTableData()
  102. }
  103. //重置搜索表单
  104. const resetClick = () => {
  105. searchForm.value = {current: 1, size: 20, total: 0}
  106. }
  107. //分页被点击
  108. const pageChange = ({current, size}) => {
  109. searchForm.value.current = current
  110. searchForm.value.size = size
  111. getTableData()
  112. }
  113. //获取数据
  114. const tableLoading = ref(false)
  115. const tableColumn = [
  116. {key: 'planName', name: '计划名称'},
  117. {key: 'key2', name: '计划起止日期', width: '220', align: 'center'},
  118. {key: 'planTotal', name: '计划数量', width: '120', align: 'center'},
  119. {key: 'finishPlanTotal', name: '已完成计划', width: '120', align: 'center'},
  120. {key: 'beginPlanTotal', name: '未完成计划', width: '120', align: 'center'},
  121. {key: 'planDesigner', name: '计划制定人', width: '120', align: 'center'},
  122. {key: 'action', name: '操作', width: '160', align: 'center'},
  123. ]
  124. const tableData = ref([
  125. {id: 1, key1: '2023年5月度计划', key2: '2022-07-01~2027-04-12', key3: '36', key4: '30', key5: '6', key6: '张三'},
  126. {id: 2, key1: '2023年5月度计划', key2: '2022-07-01~2027-04-12', key3: '36', key4: '30', key5: '6', key6: '张三'},
  127. {id: 3, key1: '2023年5月度计划', key2: '2022-07-01~2027-04-12', key3: '36', key4: '30', key5: '6', key6: '张三'},
  128. ])
  129. const getTableData = async() => {
  130. tableLoading.value = true
  131. const {error, code, data} = await sectionApi.getPage(searchForm.value)
  132. tableLoading.value = false
  133. if (!error && code === 200) {
  134. tableData.value = getArrValue(data)
  135. searchForm.value.total = data['total'] || 0
  136. } else {
  137. tableData.value = []
  138. searchForm.value.total = 0
  139. }
  140. }
  141. //表格名称被点击
  142. const rowNameClick = (row) => {
  143. }
  144. //新增计划
  145. const addRowClick = () => {
  146. monthModal.value = true
  147. }
  148. //获取所属部门列表
  149. const getDepartmentDict=async()=>{
  150. const {error, code, data} = await getdepartmentList({deptType:2})
  151. if (!error && code === 200) {
  152. department.value = getArrValue(data)
  153. } else {
  154. department.value = []
  155. }
  156. }
  157. //选择月份
  158. const monthModal = ref(false)
  159. //选择月份的表单数据
  160. const formMonthRef = ref(null)
  161. const formMonthModel = ref({
  162. section: null, month: null
  163. })
  164. const formMonthRules = {
  165. section: [{required: true, message: '请选择部门', trigger: 'blur'}],
  166. month: [{required: true, message: '请选择月份', trigger: 'blur'}],
  167. }
  168. const monthCloseClick = () => {
  169. monthModal.value = false
  170. }
  171. //选择部门
  172. const deptId=ref('')
  173. const changeDpt=(val)=>{
  174. department.value.forEach((ele)=>{
  175. if(ele.deptCategory=val){
  176. deptId.value=ele.id
  177. }
  178. })
  179. }
  180. //新增部门月计划
  181. const addPlan=async(obj)=>{;
  182. const {error, code, data,msg} = await sectionApi.addDepartmentPlan( {
  183. planDate:obj.month,
  184. departmentType:obj.section
  185. })
  186. if (!error && code === 200) {
  187. window.$message.success(msg)
  188. monthModal.value = false
  189. router.push({
  190. name: 'program-section-form',
  191. query: {...formMonthModel.value,type:'add',deptId:deptId.value},
  192. })
  193. }
  194. }
  195. //确认下一步
  196. const monthSaveClick =async() => {
  197. const res = await formValidate(formMonthRef.value)
  198. if(res){
  199. addPlan(formMonthModel.value)
  200. }
  201. monthModal.value = false
  202. }
  203. //编辑
  204. const editRowClick = (row) => {
  205. changeDpt(row.departmentType)
  206. router.push({
  207. name: 'program-section-form',
  208. query: {
  209. id: row.id,
  210. month:row.planDate,
  211. section:row.departmentType,
  212. type:'edit',
  213. deptId:deptId.value
  214. }
  215. })
  216. }
  217. //删除
  218. const delRowClick = async(row) => {
  219. delMessage(async() => {
  220. const {error, code, data,msg} = await sectionApi.deleteById({id:row.id})
  221. if (!error && code === 200) {
  222. window.$message.success(msg)
  223. getTableData()
  224. } else {
  225. getTableData()
  226. }
  227. })
  228. }
  229. </script>