tab-cost.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <template>
  2. <HcCard>
  3. <div class="hc-page-layout-box system-parameter">
  4. <HcCardItem ui="hac-card-item w-60 mr-5">
  5. <template #header>
  6. <span class="mr-2">成本测算分类:</span>
  7. <el-button _icon hc-btn size="small" type="primary" @click="openpriceEdit(1)">
  8. <HcIcon name="add"/>
  9. </el-button>
  10. </template>
  11. <div> <span class="mt-2">测算一级科目:</span></div>
  12. <div class="hc-layout-left-box menu mt-3">
  13. <div class="hc-menu-contents-box">
  14. <el-scrollbar>
  15. <HcMenuSimple :datas="menuOptions" :keys="menuKey" :props="menusProps"
  16. :menus="contextMenu" @menuTap="contextMenuClick"
  17. @change="menuChange"/>
  18. </el-scrollbar>
  19. </div>
  20. <!--预算分类新增编辑弹窗-->
  21. <HcDialog bgColor="#ffffff" widths="22rem" isToBody :show="priceModal" :title="priceTitle" @close="priceModalClose" @save="saveparentClick">
  22. <el-form :model="priceform" label-position="top" label-width="auto" size="large">
  23. <el-form-item label="预算一级科目名称:">
  24. <el-input v-model="priceform.dictName"/>
  25. </el-form-item>
  26. </el-form>
  27. </HcDialog>
  28. </div>
  29. </HcCardItem>
  30. <div class="hc-page-content-box">
  31. <HcCardItem ui="hac-card-item" actionSize="lg">
  32. <template #header>
  33. <span class="mr-2">测算二级科目:</span>
  34. <el-button _icon hc-btn size="small" type="primary" @click="openEdit(1)">
  35. <HcIcon name="add"/>
  36. </el-button>
  37. </template>
  38. <HcTable :column="tableColumn" :datas="tableData" :isIndex="false" :loading="tableLoaing">
  39. <template #action="{row, index}">
  40. <el-button size="small" type="primary" @click="openEdit(2,row)">编辑</el-button>
  41. <el-button size="small" type="primary" @click="delTask(row)">删除</el-button>
  42. </template>
  43. </HcTable>
  44. <!--任务明细弹窗-->
  45. <HcDialog bgColor="#ffffff" widths="24rem" isToBody :show="editTaskModal" :title="taskTitle" @close="testModalClose" @save="savechilidClick">
  46. <el-form label-position="top" label-width="auto" :model="formLabelAlign" size="large">
  47. <el-form-item label="预算二级科目名称:">
  48. <el-input v-model="formLabelAlign.dictName"/>
  49. </el-form-item>
  50. </el-form>
  51. </HcDialog>
  52. </HcCardItem>
  53. </div>
  54. </div>
  55. </HcCard>
  56. </template>
  57. <script setup>
  58. import {onMounted, ref, watch} from "vue";
  59. import {submitDictionary,removeDictionary,getParentList,getChildList} from '~api/system/parameter.js';
  60. import {getArrValue} from "js-fast-way"
  61. const props = defineProps({
  62. cur: {
  63. type: [String,Number],
  64. default: ''
  65. },
  66. type:{
  67. type: [String,Number],
  68. default: ''
  69. }
  70. })
  71. const tabsKey = ref(props.cur)
  72. const tabsType = ref(props.type)
  73. //监听
  74. watch(() => [
  75. props.cur,
  76. props.type,
  77. ], ([key,type]) => {
  78. tabsKey.value = key
  79. tabsType.value = type
  80. })
  81. onMounted(() => {
  82. setContextMenu()
  83. getParentListData()
  84. })
  85. //左侧菜单
  86. const menuKey = ref('')
  87. const menuOptions = ref([]);
  88. const menuItem=ref({})
  89. const menuChange = (item) => {
  90. console.log(item)
  91. menuKey.value = item?.id
  92. menuItem.value=item
  93. getChildListData()
  94. }
  95. const menusProps = ref({
  96. key: 'id',
  97. label: 'dictName'
  98. })
  99. //菜单的右键菜单
  100. const contextMenu = ref([])
  101. const setContextMenu = () => {
  102. let newArr = [];
  103. newArr.push({icon: 'draft', label: '编辑分类', key: "edit"})
  104. newArr.push({icon: 'delete-bin', label: '删除分类', key: "del"})
  105. contextMenu.value = newArr
  106. }
  107. //菜单的右键菜单被点击
  108. const contextMenuClick = ({key, item}) => {
  109. console.log(item,'item');
  110. menuKey.value = item?.id
  111. if (key === 'edit') {
  112. openpriceEdit(2)
  113. menuKey.value = item?.id
  114. priceform.value.dictName=item.dictName
  115. } else if (key === 'del') {
  116. window?.$messageBox?.alert('您确定要删除该预算分类信息吗? 一旦注销数据将彻底清除,请谨慎操作?', '删除提醒', {
  117. showCancelButton: true,
  118. confirmButtonText: '确认注销',
  119. cancelButtonText: '取消',
  120. type: 'warning',
  121. callback: async(action) => {
  122. if (action === 'confirm') {
  123. const {error, code, msg} = await removeDictionary({
  124. ids: item?.id,
  125. })
  126. if (!error && code === 200) {
  127. window?.$message?.success('删除成功')
  128. getParentListData()
  129. } else {
  130. window?.$message?.warning(msg)
  131. }
  132. }
  133. }
  134. })
  135. }
  136. }
  137. const priceTitle = ref('')
  138. const priceModal = ref(false)
  139. const openpriceEdit = (type) => {
  140. if (type === 1) {
  141. priceTitle.value = '新增分类'
  142. priceform.value={}
  143. menuKey.value=''
  144. } else {
  145. priceTitle.value = '编辑分类'
  146. }
  147. priceModal.value = true
  148. }
  149. const priceform = ref({})
  150. const priceModalClose = () => {
  151. priceModal.value = false
  152. }
  153. const taskTitle = ref('')
  154. const openEdit = (type,row) => {
  155. if (type === 1) {
  156. formLabelAlign.value.dictName=''
  157. formLabelAlign.value.id=''
  158. taskTitle.value = '新增'
  159. } else {
  160. formLabelAlign.value.dictName=row.dictName
  161. formLabelAlign.value.id=row.id
  162. taskTitle.value = '编辑'
  163. }
  164. if(menuKey.value){
  165. editTaskModal.value = true
  166. }else{
  167. window.$message.warning('请先选择一级科目')
  168. }
  169. }
  170. const editTaskModal = ref(false)
  171. const testModalClose = () => {
  172. editTaskModal.value = false
  173. }
  174. const delTask = (item) => {
  175. window?.$messageBox?.alert('您确定要删除该预算科目信息吗? 一旦注销数据将彻底清除,请谨慎操作?', '删除提醒', {
  176. showCancelButton: true,
  177. confirmButtonText: '确认注销',
  178. cancelButtonText: '取消',
  179. type: 'warning',
  180. callback: async(action) => {
  181. if (action === 'confirm') {
  182. const {error, code, msg} = await removeDictionary({
  183. ids: item?.id,
  184. })
  185. if (!error && code === 200) {
  186. window?.$message?.success('删除成功')
  187. getParentListData()
  188. } else {
  189. window?.$message?.warning(msg)
  190. }
  191. }
  192. }
  193. })
  194. }
  195. const tableColumn = [
  196. {key: 'dictName', name: '预算二级科目',align:'center'},
  197. // {key: 'text', name: '任务内容'},
  198. // {key: 'color', name: '完成指标'},
  199. {key: 'action', name: '操作', width: 200}
  200. ]
  201. const tableData = ref([])
  202. const tableLoaing=ref(false)
  203. const formLabelAlign = ref({
  204. name: '',
  205. region: '',
  206. type: '',
  207. })
  208. //新增一级科目
  209. const saveparentClick=async()=>{
  210. const { error, code, data,msg } = await submitDictionary({
  211. type:tabsType.value,
  212. dictName:priceform.value?.dictName,
  213. id:menuKey.value||null,
  214. })
  215. if (!error && code === 200) {
  216. window.$message?.success(msg)
  217. priceModal.value=false
  218. getParentListData()
  219. }
  220. else {
  221. window.$message?.warning(msg)
  222. }
  223. }
  224. //新增二级级科目
  225. const savechilidClick=async()=>{
  226. const { error, code, data,msg } = await submitDictionary({
  227. type:tabsType.value,
  228. dictName:formLabelAlign.value?.dictName,
  229. id:formLabelAlign.value.id||null,
  230. parentId:menuKey.value
  231. })
  232. if (!error && code === 200) {
  233. window.$message?.success(msg)
  234. editTaskModal.value=false
  235. getChildListData()
  236. }
  237. else {
  238. window.$message?.warning(msg)
  239. }
  240. }
  241. //获取一级科目
  242. const getParentListData=async()=>{
  243. const { error, code, data,msg } = await getParentList({
  244. type:tabsType.value,
  245. })
  246. if (!error && code === 200) {
  247. menuOptions.value = getArrValue(data['records'])
  248. if( menuOptions.value.length>0){
  249. menuKey.value= menuOptions.value[0]?.id
  250. menuItem.value.id = menuOptions.value[0]?.id
  251. getChildListData()
  252. }
  253. }
  254. else {
  255. menuOptions.value =[]
  256. window.$message?.warning(msg)
  257. }
  258. }
  259. //获取二级科目
  260. const getChildListData=async()=>{
  261. tableLoaing.value=true
  262. const { error, code, data,msg } = await getChildList({
  263. parentId: menuItem.value.id,
  264. type:tabsType.value,
  265. })
  266. tableLoaing.value=false
  267. if (!error && code === 200) {
  268. tableData.value=getArrValue(data)
  269. // tab.value = getArrValue(data['records'])
  270. }
  271. else {
  272. window.$message?.warning(msg)
  273. }
  274. }
  275. </script>
  276. <style lang="scss">
  277. .hc-page-layout-box.system-parameter {
  278. display: flex;
  279. position: relative;
  280. // height: calc(100vh - 228px);
  281. .hc-layout-left-box.menu {
  282. width: 100%;
  283. height: 100%;
  284. position: relative;
  285. background: inherit;
  286. margin-right: auto;
  287. border-radius: 0;
  288. box-shadow: none;
  289. .hc-menu-contents-box {
  290. position: relative;
  291. padding: 0;
  292. height: 100%;
  293. // height: calc(100% - 60px);
  294. }
  295. .hc-menu-simple-box {
  296. padding: 0;
  297. .item-box {
  298. box-shadow: none;
  299. padding: 8px 10px;
  300. border-radius: 4px;
  301. background: var(--el-color-primary-light-8);
  302. .label-box {
  303. color: #8c8c8c;
  304. }
  305. .menu-icon {
  306. margin-left: 20px;
  307. background: inherit;
  308. .menu-popover-icon {
  309. color: #8c8c8c;
  310. .hc-icon-i {
  311. font-size: 20px;
  312. line-height: initial;
  313. }
  314. }
  315. }
  316. }
  317. .item-box.active {
  318. background: var(--el-color-primary-light-5);
  319. .label-box {
  320. color: white;
  321. }
  322. .menu-icon .menu-popover-icon {
  323. color: white;
  324. }
  325. }
  326. }
  327. .hc-menu-header-box {
  328. position: relative;
  329. padding: 15px 18px;
  330. display: flex;
  331. align-items: center;
  332. border-bottom: 1px solid #E9E9E9;
  333. .name {
  334. flex: auto;
  335. position: relative;
  336. }
  337. }
  338. }
  339. .hc-page-content-box {
  340. flex: 1;
  341. position: relative;
  342. }
  343. }
  344. </style>