DepreciationInformation.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. <template>
  2. <div>
  3. <a-row>
  4. <a-col flex="15%" class="tree_box">
  5. <a-tree
  6. v-model:expandedKeys="expandedKeys" v-model:selectedKeys="selectedKeys"
  7. :field-names="{ title: 'text', key: 'id' }" :tree-data="treeDatas" :show-line="true"
  8. @select="categoriesSelected"
  9. />
  10. </a-col>
  11. <a-col flex="auto" class="table_box" style="width: 0;">
  12. <div class="operation_box">
  13. <a-input-search
  14. v-model:value="searchParams.name" size="small" style="width: 300px;margin:0 0 8px 0;"
  15. enter-button @search="searchChange(true)"
  16. />
  17. <a-pagination
  18. v-model:current="current" size="small" :total="infoTotal" show-quick-jumper
  19. :show-size-changer="true" :page-size-options="pageSizeOptions" :default-page-size="20"
  20. @change="getPageParams" @show-size-change="showSizeChange"
  21. />
  22. </div>
  23. <div class="operation_box">
  24. <a-space>
  25. <a-button size="small" :icon="h(FieldTimeOutlined)" @click="operation('设置折旧年限')">
  26. 设置折旧年限
  27. </a-button>
  28. <a-button size="small" :icon="h(MoneyCollectOutlined)" @click="setDepreciation">
  29. 设置计提折旧
  30. </a-button>
  31. <a-button size="small" :icon="h(PayCircleOutlined)" @click="cancelDepreciation">
  32. 设置不提折旧
  33. </a-button>
  34. <a-button size="small" :icon="h(ProfileOutlined)" @click="operation('设置折旧方法')">
  35. 设置折旧方法
  36. </a-button>
  37. <a-button size="small" :icon="h(PercentageOutlined)" @click="operation('设置残值率')">
  38. 设置残值率
  39. </a-button>
  40. <a-button size="small" :icon="h(FileProtectOutlined)" @click="operation('设置累计折旧')">
  41. 设置累计折旧
  42. </a-button>
  43. </a-space>
  44. <a-space>
  45. <!-- <a-button size="small" :icon="h(DownloadOutlined)">导出</a-button> -->
  46. </a-space>
  47. </div>
  48. <CommonTable
  49. ref="commonTable" :is-select="true" :selected-keys="selectedIds" :have-page="false"
  50. :columns="columns" :data-source="dataSource" :top-right="true" :is-loading="isLoading"
  51. @get-selected="getSelectColumn"
  52. >
  53. <template #bodyCell="{ column, record }">
  54. <template v-if="column.dataIndex === 'reservedRate'">
  55. <span v-if="record.reservedRate">{{ record.reservedRate }}%</span>
  56. <span v-else />
  57. </template>
  58. </template>
  59. </CommonTable>
  60. </a-col>
  61. </a-row>
  62. <div class="footer_box">
  63. <p>您所选的资产共计:<span style="color: red;">{{ selectedIds.length }}</span> 条</p>
  64. </div>
  65. </div>
  66. <a-modal v-model:open="visible" width="26%" :title="modalTitle" @ok="setDepreciationInfo">
  67. <a-form-item v-if="modalTitle === '设置折旧年限'" label="请输入" style="margin-top: 24px;">
  68. <a-input-number v-model:value="yearLimit" :controls="false" addon-after="月" style="width: 90%;" />
  69. </a-form-item>
  70. <a-form-item v-if="modalTitle === '设置折旧方法'" label="请选择" style="margin-top: 24px;">
  71. <a-select
  72. v-model:value="depreciationMethod" style="width: 90%" :options="depreciationMethods"
  73. :field-names="{ label: 'text', value: 'id' }"
  74. />
  75. </a-form-item>
  76. <a-form-item v-if="modalTitle === '设置累计折旧'" label="请选择" style="margin-top: 24px;">
  77. <a-select
  78. v-model:value="subject" style="width: 90%" allow-clear option-filter-prop="label" show-search
  79. :options="subjects"
  80. />
  81. </a-form-item>
  82. <a-form-item v-if="modalTitle === '设置残值率'" label="请输入" style="margin-top: 24px;">
  83. <a-input-number
  84. v-model:value="reservedRate" :controls="false" :step="0.01" :min="0" :max="100"
  85. :formatter="value => `${value}%`" :parser="value => value.replace('%', '')" style="width: 90%;"
  86. />
  87. </a-form-item>
  88. </a-modal>
  89. </template>
  90. <script setup>
  91. import { ref, reactive, onMounted, h } from 'vue';
  92. import Common from '../../common/Common';
  93. import CommonTable from '../../common/CommonTable.vue';
  94. import { FieldTimeOutlined, MoneyCollectOutlined, PayCircleOutlined, DownloadOutlined, ProfileOutlined, PercentageOutlined, FileProtectOutlined } from '@ant-design/icons-vue';
  95. import {
  96. queryCategoriesApi, queryByNameApi, updateYearApi, updateExtractApi, getMethodsApi, updateMethodApi,
  97. updateReservedRateApi, updateSubjectApi,
  98. } from '../../api/assetPeriodDepreciate';
  99. import { infoColumns, debounce } from './util.js';
  100. import { message, Modal } from 'ant-design-vue';
  101. import { SqlApi } from 'pc-component-v3';
  102. // 表格配置
  103. const commonTable = ref();
  104. const infoTotal = ref(0);
  105. const dataSource = ref([]);
  106. const columns = ref(infoColumns);
  107. const selectedIds = ref([]); // 用作表格选择的唯一key值
  108. const current = ref(1);
  109. // 树形配置
  110. const expandedKeys = ref([]);
  111. const selectedKeys = ref([]);
  112. const treeDatas = ref([]);
  113. // 折旧方法
  114. const depreciationMethod = ref('');
  115. const depreciationMethods = ref([]);
  116. const visible = ref(false);
  117. const modalTitle = ref('');
  118. const yearLimit = ref(null); // 折旧年限
  119. const reservedRate = ref(null); // 残值率
  120. const subject = ref(undefined); // 会计科目
  121. const subjects = ref([]); // 会计科目
  122. const isLoading = ref(false);
  123. const isAllSearch = ref(true);
  124. const pageSizeOptions = ref(['20', '50', '100', '200', '500']);
  125. // 查询参数
  126. const searchParams = reactive({
  127. id: null,
  128. name: '',
  129. range: {
  130. start: 0,
  131. length: 20,
  132. },
  133. });
  134. onMounted(() => {
  135. getSubjects();
  136. });
  137. const clearDatas = () => {
  138. modalTitle.value = '';
  139. yearLimit.value = null;
  140. reservedRate.value = null;
  141. depreciationMethod.value = null;
  142. visible.value = false;
  143. selectedIds.value = [];
  144. commonTable.value.clear();
  145. };
  146. // 打开模态框
  147. const operation = title => {
  148. if (!selectedIds.value || selectedIds.value.length === 0) {
  149. message.warning('请您至少选择一条分类数据。');
  150. return;
  151. }
  152. modalTitle.value = title;
  153. visible.value = true;
  154. };
  155. // 设置折旧年限/折旧方法/残值率
  156. const setDepreciationInfo = () => {
  157. if (modalTitle.value === '设置折旧年限') {
  158. const params = {
  159. usedYearLimit: yearLimit.value,
  160. assetCategoryIds: selectedIds.value,
  161. };
  162. setYearLimit(params);
  163. } else if (modalTitle.value === '设置折旧方法') {
  164. const params = {
  165. depreciationMethodId: depreciationMethod.value,
  166. assetCategoryIds: selectedIds.value,
  167. };
  168. setMethod(params);
  169. } else if (modalTitle.value === '设置累计折旧') {
  170. const params = {
  171. accountSubjectId: subject.value,
  172. assetCategoryIds: selectedIds.value,
  173. };
  174. updateSubject(params);
  175. } else {
  176. const params = {
  177. reservedRate: reservedRate.value,
  178. assetCategoryIds: selectedIds.value,
  179. };
  180. setReservedRate(params);
  181. }
  182. };
  183. // 设置折旧年限
  184. const setYearLimit = params => {
  185. updateYearApi(params).then(
  186. success => {
  187. if (success.errorCode === 0) {
  188. clearDatas();
  189. if (!searchParams.id) {
  190. searchChange(true);
  191. } else {
  192. searchChange(false);
  193. }
  194. message.success('设置折旧年限成功。');
  195. } else {
  196. message.warning(success.errorMessage);
  197. }
  198. },
  199. error => {
  200. Common.processException(error);
  201. },
  202. );
  203. };
  204. // 设置折旧方法
  205. const setMethod = params => {
  206. updateMethodApi(params).then(
  207. success => {
  208. if (success.errorCode === 0) {
  209. clearDatas();
  210. if (!searchParams.id) {
  211. searchChange(true);
  212. } else {
  213. searchChange(false);
  214. }
  215. message.success('设置折旧方法成功。');
  216. } else {
  217. message.warning(success.errorMessage);
  218. }
  219. },
  220. error => {
  221. Common.processException(error);
  222. },
  223. );
  224. };
  225. // 设置残值率
  226. const setReservedRate = params => {
  227. updateReservedRateApi(params).then(
  228. success => {
  229. if (success.errorCode === 0) {
  230. clearDatas();
  231. if (!searchParams.id) {
  232. searchChange(true);
  233. } else {
  234. searchChange(false);
  235. }
  236. message.success('设置残值率成功。');
  237. } else {
  238. message.warning(success.errorMessage);
  239. }
  240. },
  241. error => {
  242. Common.processException(error);
  243. },
  244. );
  245. };
  246. // 设置累计折旧科目
  247. const updateSubject = params => {
  248. updateSubjectApi(params).then(
  249. success => {
  250. if (success.errorCode === 0) {
  251. clearDatas();
  252. if (!searchParams.id) {
  253. searchChange(true);
  254. } else {
  255. searchChange(false);
  256. }
  257. message.success(success.errorMessage);
  258. } else {
  259. message.warning(success.errorMessage);
  260. }
  261. },
  262. error => {
  263. Common.processException(error);
  264. },
  265. );
  266. };
  267. // 设置计提折旧
  268. const setDepreciation = () => {
  269. if (!selectedIds.value || selectedIds.value.length === 0) {
  270. message.warning('请您至少选择一条分类数据。');
  271. return;
  272. }
  273. Modal.confirm({
  274. title: '提示',
  275. content: h('div', {}, '您确定要将所选数据设置为计提折旧吗?'),
  276. onOk() {
  277. updateExtractDepreciation(true);
  278. },
  279. });
  280. };
  281. // 设置不提折旧
  282. const cancelDepreciation = () => {
  283. if (!selectedIds.value || selectedIds.value.length === 0) {
  284. message.warning('请您至少选择一条分类数据。');
  285. return;
  286. }
  287. Modal.confirm({
  288. title: '提示',
  289. content: h('div', {}, '您确定要将所选数据设置为不提折旧吗?'),
  290. onOk() {
  291. updateExtractDepreciation(false);
  292. },
  293. });
  294. };
  295. // 根据分类ID查询折旧信息
  296. const categoriesSelected = key => {
  297. searchParams.id = key[0];
  298. searchChange(false);
  299. };
  300. // 获取的分页参数并查询
  301. const getPageParams = (start, length) => {
  302. current.value = start;
  303. searchParams.range.start = (start - 1) * length;
  304. searchParams.range.length = length;
  305. getInfo();
  306. };
  307. // 分页每页条数变化查询
  308. const showSizeChange = (_, size) => {
  309. setTimeout(() => {
  310. current.value = 1;
  311. searchParams.range.start = 0;
  312. searchParams.range.length = size;
  313. getInfo();
  314. });
  315. };
  316. // 查询回到第一页
  317. const searchChange = debounce(isAll => {
  318. if (isAll[0]) {
  319. isAllSearch.value = true;
  320. } else {
  321. isAllSearch.value = false;
  322. }
  323. getPageParams(1, searchParams.range.length);
  324. }, 500);
  325. // 获取所选项的数据
  326. const getSelectColumn = rows => {
  327. selectedIds.value = rows.selectedRowKeys;
  328. };
  329. // 获取资产分类
  330. const getCategories = () => {
  331. queryCategoriesApi().then(
  332. success => {
  333. if (success && success.length) {
  334. treeDatas.value = success;
  335. }
  336. },
  337. error => {
  338. Common.processException(error);
  339. },
  340. );
  341. };
  342. // 根据分类名字查询信息
  343. const getInfo = () => {
  344. if (isAllSearch.value) {
  345. searchParams.id = null;
  346. } else {
  347. searchParams.name = '';
  348. }
  349. isLoading.value = true;
  350. const params = JSON.parse(JSON.stringify(searchParams));
  351. queryByNameApi(params).then(
  352. success => {
  353. if (success.dataList) {
  354. dataSource.value = success.dataList;
  355. } else {
  356. dataSource.value = [];
  357. }
  358. infoTotal.value = success.totalSize;
  359. isLoading.value = false;
  360. },
  361. error => {
  362. isLoading.value = false;
  363. Common.processException(error);
  364. },
  365. );
  366. };
  367. // 查询所有资产折旧方法
  368. const getMethods = () => {
  369. getMethodsApi().then(
  370. success => {
  371. if (success.errorCode === 0) {
  372. if (success.datas && success.datas.length) {
  373. depreciationMethods.value = success.datas;
  374. }
  375. } else {
  376. message.warning(success.errorMessage);
  377. }
  378. },
  379. error => {
  380. Common.processException(error);
  381. },
  382. );
  383. };
  384. // 设置计提折旧或不提折旧
  385. const updateExtractDepreciation = flag => {
  386. const params = {
  387. isExtractDepreciation: flag,
  388. assetCategoryIds: selectedIds.value,
  389. };
  390. updateExtractApi(params).then(
  391. success => {
  392. if (success.errorCode === 0) {
  393. if (flag) {
  394. message.success('设置计提折旧成功。');
  395. } else {
  396. message.success('设置不提折旧成功。');
  397. }
  398. clearDatas();
  399. if (!searchParams.id) {
  400. searchChange(true);
  401. } else {
  402. searchChange(false);
  403. }
  404. } else {
  405. message.warning(success.errorMessage);
  406. }
  407. },
  408. error => {
  409. Common.processException(error);
  410. },
  411. );
  412. };
  413. // 获取所有累计折旧会计科目
  414. const getSubjects = () => {
  415. SqlApi.execute('20241120_175411').then(
  416. success => {
  417. if (success.errorCode == 0) {
  418. if (success.results) {
  419. success.results.forEach(item => {
  420. item.label = `${item.name}-${item.no}`;
  421. item.value = item.id;
  422. });
  423. subjects.value = success.results;
  424. subject.value = success.results[0].id;
  425. }
  426. } else {
  427. message.warning(success.errorMessage);
  428. }
  429. },
  430. error => {
  431. Common.processException(error);
  432. },
  433. );
  434. };
  435. getInfo();
  436. getMethods();
  437. getCategories();
  438. </script>
  439. <style scoped>
  440. .tree_box {
  441. height: 86vh;
  442. overflow: auto;
  443. border: 1px solid #dddddd;
  444. margin-right: 4px;
  445. border-bottom: none;
  446. }
  447. .table_box {
  448. padding: 6px;
  449. border: 1px solid #dddddd;
  450. border-bottom: none;
  451. }
  452. .operation_box {
  453. display: flex;
  454. justify-content: space-between;
  455. align-items: center;
  456. }
  457. .ant-btn>span {
  458. color: #267fcf;
  459. }
  460. .footer_box {
  461. background-color: #fafafa;
  462. }
  463. p {
  464. margin: 0 !important;
  465. padding: 0 !important;
  466. }
  467. :deep(.ant-form-item-label > label) {
  468. font-size: 14px !important;
  469. font-weight: 500 !important;
  470. }
  471. </style>