index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. <template>
  2. <div class="tenant">
  3. <!-- <Banner /> -->
  4. <div class="content">
  5. <byTable
  6. :source="sourceList.data"
  7. :pagination="sourceList.pagination"
  8. :config="config"
  9. :loading="loading"
  10. highlight-current-row
  11. :selectConfig="selectConfig"
  12. :table-events="{
  13. select: select,
  14. }"
  15. :action-list="[
  16. {
  17. text: '导出Excel',
  18. action: () => deriveExcel(),
  19. },
  20. ]"
  21. @moreSearch="moreSearch"
  22. @get-list="getList">
  23. <template #amount="{ item }">
  24. <div :style="'color: ' + (item.status === '10' ? '#04cb04;' : 'red;')">
  25. <span style="padding-right: 4px">{{ item.currency }}</span>
  26. <span v-if="item.status === '20'">-</span>
  27. <span>{{ moneyFormat(item.amount, 2) }}</span>
  28. </div>
  29. </template>
  30. </byTable>
  31. </div>
  32. <el-dialog title="拆分" v-if="dialogVisible" v-model="dialogVisible" width="800" v-loading="loading">
  33. <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="submit">
  34. <template #money>
  35. <div style="width: 100%">
  36. <el-row :gutter="10">
  37. <el-col :span="6">
  38. <el-form-item>
  39. <el-select v-model="formData.data.status" style="width: 100%" disabled>
  40. <el-option v-for="item in status" :key="item.value" :label="item.label" :value="item.value" />
  41. </el-select>
  42. </el-form-item>
  43. </el-col>
  44. <el-col :span="12">
  45. <el-form-item>
  46. <el-input v-model="formData.data.amount" placeholder="请输入金额" class="input-with-select" disabled>
  47. <template #prepend>
  48. <el-select v-model="formData.data.currency" placeholder="请选择币种" style="width: 100px" disabled>
  49. <el-option v-for="item in accountCurrency" :key="item.value" :label="item.value" :value="item.value" />
  50. </el-select>
  51. </template>
  52. </el-input>
  53. </el-form-item>
  54. </el-col>
  55. </el-row>
  56. </div>
  57. </template>
  58. <template #slot>
  59. <div style="width: 100%">
  60. <el-button type="primary" @click="addRow"> 添加 </el-button>
  61. <br />
  62. <el-table :data="formData.data.accountDeptRunningWaterDetailList">
  63. <el-table-column prop="deptId" label="部门">
  64. <template #default="{ row, $index }">
  65. <el-form-item :prop="'accountDeptRunningWaterDetailList.' + $index + '.deptId'" :rules="rules.deptId" :inline-message="true">
  66. <el-cascader
  67. v-model="row.deptId"
  68. :options="deptTreeData"
  69. :props="{
  70. value: 'deptId',
  71. }"
  72. clearable
  73. filterable
  74. style="width: 100%" />
  75. </el-form-item>
  76. </template>
  77. </el-table-column>
  78. <el-table-column prop="amount" label="分拆金额">
  79. <template #default="{ row, $index }">
  80. <el-form-item :prop="'accountDeptRunningWaterDetailList.' + $index + '.amount'" :rules="rules.amount" :inline-message="true">
  81. <el-input-number
  82. onmousewheel="return false;"
  83. v-model="row.amount"
  84. placeholder="请输入金额"
  85. style="width: 100%"
  86. :precision="2"
  87. :controls="false"
  88. :min="0" />
  89. </el-form-item>
  90. </template>
  91. </el-table-column>
  92. <el-table-column prop="remarks" label="备注">
  93. <template #default="{ row, $index }">
  94. <el-form-item :prop="'accountDeptRunningWaterDetailList.' + $index + '.remarks'" :rules="rules.remarks" :inline-message="true">
  95. <el-input v-model="row.remarks" placeholder="请输入" />
  96. </el-form-item>
  97. </template>
  98. </el-table-column>
  99. <el-table-column prop="zip" align="center" label="操作" width="80">
  100. <template #default="{ $index }">
  101. <el-button type="primary" link @click="handleRemove($index)">删除</el-button>
  102. </template>
  103. </el-table-column>
  104. </el-table>
  105. </div>
  106. </template>
  107. </byForm>
  108. <template #footer>
  109. <el-button @click="dialogVisible = false" size="large">取 消</el-button>
  110. <el-button type="primary" @click="submitForm()" size="large" :loading="submitLoading"> 确 定 </el-button>
  111. </template>
  112. </el-dialog>
  113. <el-dialog title="调整部门" v-if="depModal" v-model="depModal" width="600" v-loading="loading">
  114. <p>部门名称</p>
  115. <el-cascader
  116. v-model="departmentId"
  117. :options="deptTreeData"
  118. :props="{
  119. value: 'deptId',
  120. }"
  121. clearable
  122. filterable
  123. style="width: 100%" />
  124. <template #footer>
  125. <el-button @click="depModal = false" size="large">取 消</el-button>
  126. <el-button type="primary" @click="submitDeptForm(departmentId)" size="large" :loading="submitLoading"> 确 定 </el-button>
  127. </template>
  128. </el-dialog>
  129. <el-dialog title="高级检索" v-if="openSearch" v-model="openSearch" width="600" :before-close="cancelSearch">
  130. <byForm :formConfig="formSearchConfig" :formOption="formOption" v-model="sourceList.pagination">
  131. <template #deptId>
  132. <div>
  133. <el-tree-select
  134. v-model="sourceList.pagination.deptId"
  135. :data="deptTreeData"
  136. check-strictly
  137. :render-after-expand="false"
  138. node-key="deptId"
  139. style="width: 100%"
  140. :props="defaultProps"
  141. clearable />
  142. </div>
  143. </template>
  144. <template #time>
  145. <div style="width: 100%">
  146. <el-row :gutter="10">
  147. <el-col :span="11">
  148. <el-date-picker
  149. v-model="sourceList.pagination.beginTime"
  150. type="datetime"
  151. placeholder="请选择"
  152. style="width: 100%"
  153. value-format="YYYY-MM-DD HH:mm:ss" />
  154. </el-col>
  155. <el-col :span="2" style="text-align: center">到</el-col>
  156. <el-col :span="11">
  157. <el-date-picker
  158. v-model="sourceList.pagination.endTime"
  159. type="datetime"
  160. placeholder="请选择"
  161. style="width: 100%"
  162. value-format="YYYY-MM-DD HH:mm:ss" />
  163. </el-col>
  164. </el-row>
  165. </div>
  166. </template>
  167. </byForm>
  168. <template #footer>
  169. <el-button @click="cancelSearch()" size="large">取 消</el-button>
  170. <el-button type="primary" @click="submitSearch()" size="large">确 定</el-button>
  171. </template>
  172. </el-dialog>
  173. </div>
  174. </template>
  175. <script setup>
  176. import { ElMessage } from "element-plus";
  177. import byTable from "@/components/byTable/index";
  178. import byForm from "@/components/byForm/index";
  179. import { computed, ref } from "vue";
  180. import useUserStore from "@/store/modules/user";
  181. const loading = ref(false);
  182. const submitLoading = ref(false);
  183. const sourceList = ref({
  184. data: [],
  185. pagination: {
  186. total: 3,
  187. pageNum: 1,
  188. pageSize: 10,
  189. status: "",
  190. currency: "",
  191. type: "",
  192. corporationId: "",
  193. remarks: "",
  194. beginTime: "",
  195. endTime: "",
  196. },
  197. });
  198. let dialogVisible = ref(false);
  199. let modalType = ref("add");
  200. let rules = ref({
  201. type: [{ required: true, message: "请选择类型", trigger: "change" }],
  202. contactNumber: [{ required: true, message: "请输入联系号码", trigger: "blur" }],
  203. amount: [{ required: true, message: "请输入金额", trigger: "blur" }],
  204. });
  205. const status = ref([
  206. {
  207. label: "收入",
  208. value: "10",
  209. },
  210. {
  211. label: "支出",
  212. value: "20",
  213. },
  214. ]);
  215. const accountCurrency = ref([]);
  216. import Cookies from "js-cookie";
  217. const { proxy } = getCurrentInstance();
  218. const selectConfig = computed(() => {
  219. return [
  220. {
  221. label: "收支类型",
  222. prop: "status",
  223. data: status.value,
  224. },
  225. {
  226. label: "币种",
  227. prop: "currency",
  228. data: accountCurrency.value,
  229. },
  230. {
  231. label: "归属部门",
  232. prop: "deptId",
  233. data: deptTreeData.value,
  234. },
  235. ];
  236. });
  237. const config = computed(() => {
  238. return [
  239. {
  240. attrs: {
  241. label: "部门",
  242. prop: "deptName",
  243. },
  244. },
  245. {
  246. attrs: {
  247. label: "交易时间",
  248. prop: "transactionTime",
  249. },
  250. },
  251. {
  252. attrs: {
  253. label: "交易金额",
  254. slot: "amount",
  255. },
  256. },
  257. // {
  258. // attrs: {
  259. // prop: "accountOpening",
  260. // label: "对方账户",
  261. // },
  262. // },
  263. // {
  264. // attrs: {
  265. // prop: "openingBank",
  266. // label: "对方银行",
  267. // },
  268. // },
  269. // {
  270. // attrs: {
  271. // prop: "name",
  272. // label: "对方账号",
  273. // },
  274. // },
  275. {
  276. attrs: {
  277. prop: "remarks",
  278. label: "摘要",
  279. "min-width": "200",
  280. },
  281. },
  282. // {
  283. // attrs: {
  284. // label: "操作",
  285. // width: "200",
  286. // align: "right",
  287. // },
  288. // renderHTML(row) {
  289. // return [
  290. // {
  291. // attrs: {
  292. // label: "调整部门",
  293. // type: "primary",
  294. // text: true,
  295. // },
  296. // el: "button",
  297. // click() {
  298. // depModal.value = true;
  299. // dtlData.value = row;
  300. // departmentId.value = [];
  301. // },
  302. // },
  303. // {
  304. // attrs: {
  305. // label: "分拆",
  306. // type: "primary",
  307. // text: true,
  308. // },
  309. // el: "button",
  310. // click() {
  311. // getDtl(row);
  312. // },
  313. // },
  314. // ];
  315. // },
  316. // },
  317. ];
  318. });
  319. const dtlData = ref({});
  320. let formData = reactive({
  321. data: {
  322. type: "1",
  323. },
  324. treeData: [],
  325. });
  326. const formOption = reactive({
  327. inline: true,
  328. labelWidth: 100,
  329. itemWidth: 100,
  330. rules: [],
  331. });
  332. const submit = ref(null);
  333. const depModal = ref(false);
  334. let deptTreeData = ref([]);
  335. let departmentId = ref([]);
  336. const getDept = async () => {
  337. // 部门树
  338. proxy
  339. .get("/tenantDept/list", {
  340. pageNum: 1,
  341. pageSize: 9999,
  342. tenantId: Cookies.get("tenantId"),
  343. })
  344. .then((message) => {
  345. recursive(message.data);
  346. if(message.data && message.data.length > 0) {
  347. message.data = message.data.map(item => {
  348. item.value = item.deptId
  349. return item
  350. })
  351. }
  352. deptTreeData.value = proxy.handleTree(message.data, "corporationId");
  353. });
  354. };
  355. getDept();
  356. const submitDeptForm = async (departmentId) => {
  357. if (departmentId.length == 0) {
  358. ElMessage.error("请选择部门");
  359. return;
  360. }
  361. let params = {
  362. deptId: departmentId[departmentId.length - 1],
  363. accountDeptRunningWaterId: dtlData.value.accountDeptRunningWaterId,
  364. id: dtlData.value.id,
  365. amount: dtlData.value.amount,
  366. };
  367. proxy
  368. .post("/accountDeptRunningWaterDetail/add", params)
  369. .then(() => {
  370. ElMessage.success("调整部门成功");
  371. depModal.value = false;
  372. getList();
  373. })
  374. .catch((error) => {
  375. ElMessage.error(error);
  376. });
  377. };
  378. const recursive = (data) => {
  379. data.map((item) => {
  380. item.label = item.deptName;
  381. item.id = item.corporationId;
  382. if (item.children) {
  383. recursive(item.children);
  384. } else {
  385. item.children = [];
  386. }
  387. });
  388. };
  389. const formConfig = computed(() => {
  390. return [
  391. {
  392. type: "select",
  393. prop: "accountManagementId",
  394. label: "付款账户",
  395. required: true,
  396. disabled: true,
  397. isLoad: {
  398. url: "/accountManagement/page",
  399. req: {
  400. pageNum: 1,
  401. pageSize: 9999,
  402. },
  403. labelKey: "name",
  404. labelVal: "id",
  405. method: "post",
  406. resUrl: "rows",
  407. },
  408. },
  409. {
  410. type: "date",
  411. prop: "transactionTime",
  412. label: "交易时间",
  413. disabled: true,
  414. },
  415. // {
  416. // type: "selectInput",
  417. // label: "交易金额",
  418. // itemWidth: 60,
  419. // data: accountCurrency.value,
  420. // placeholder: "请输入",
  421. // selectPlaceholder: "币种",
  422. // selectProp: "currency",
  423. // prop: "amount",
  424. // disabled: true,
  425. // },
  426. {
  427. type: "slot",
  428. prop: "money",
  429. slotName: "money",
  430. label: "交易金额",
  431. },
  432. {
  433. type: "input",
  434. prop: "remarks",
  435. label: "摘要",
  436. disabled: true,
  437. itemType: "textarea",
  438. disabled: true,
  439. },
  440. {
  441. type: "slot",
  442. label: "拆分明细",
  443. slotName: "slot",
  444. },
  445. ];
  446. });
  447. const getList = async (req) => {
  448. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  449. loading.value = true;
  450. proxy.post("/accountDeptRunningWater/page", sourceList.value.pagination).then((message) => {
  451. sourceList.value.data = message.rows;
  452. sourceList.value.pagination.total = message.total;
  453. setTimeout(() => {
  454. loading.value = false;
  455. }, 200);
  456. });
  457. };
  458. proxy.getDict(["account_currency"]).then((res) => {
  459. accountCurrency.value = res.account_currency.map((item) => {
  460. return {
  461. label: item.dictValue,
  462. value: item.dictKey,
  463. };
  464. });
  465. });
  466. const submitForm = async () => {
  467. submit.value.handleSubmit(() => {
  468. if (!(formData.data.accountDeptRunningWaterDetailList && formData.data.accountDeptRunningWaterDetailList.length > 0)) {
  469. return ElMessage("请添加拆分明细!");
  470. }
  471. let money = 0;
  472. for (let i = 0; i < formData.data.accountDeptRunningWaterDetailList.length; i++) {
  473. if (formData.data.accountDeptRunningWaterDetailList[i].amount && Number(formData.data.accountDeptRunningWaterDetailList[i].amount) !== 0) {
  474. money = Number(parseFloat(Number(money) + Number(formData.data.accountDeptRunningWaterDetailList[i].amount)));
  475. } else {
  476. return ElMessage("金额不能为0");
  477. }
  478. }
  479. if (Number(money) !== Number(formData.data.amount)) {
  480. return ElMessage("分拆总金额需等于交易金额");
  481. }
  482. submitLoading.value = true;
  483. let params = {
  484. id: formData.data.id,
  485. deptRunningWaterDetailList: formData.data.accountDeptRunningWaterDetailList,
  486. accountDeptRunningWaterId: formData.data.accountDeptRunningWaterId,
  487. };
  488. params.deptRunningWaterDetailList.map((item) => {
  489. item.deptId = item.deptId[item.deptId.length - 1];
  490. });
  491. proxy
  492. .post("/accountDeptRunningWaterDetail/add", {
  493. ...params,
  494. })
  495. .then(
  496. () => {
  497. ElMessage({
  498. message: "拆分成功",
  499. type: "success",
  500. });
  501. dialogVisible.value = false;
  502. submitLoading.value = false;
  503. getList();
  504. },
  505. (err) => (submitLoading.value = false)
  506. );
  507. });
  508. };
  509. const getDtl = (row) => {
  510. modalType.value = "edit";
  511. dialogVisible.value = true;
  512. proxy.post("/accountDeptRunningWaterDetail/detail", { id: row.id }).then((res) => {
  513. if (res.deptRunningWaterDetailList && res.deptRunningWaterDetailList.length > 0) {
  514. res.accountDeptRunningWaterDetailList = res.deptRunningWaterDetailList.map((item) => {
  515. item.deptId = [item.deptId];
  516. return item;
  517. });
  518. } else {
  519. res.accountDeptRunningWaterDetailList = [];
  520. }
  521. formData.data = res;
  522. dialogVisible.value = true;
  523. });
  524. };
  525. const addRow = () => {
  526. formData.data.accountDeptRunningWaterDetailList.push({
  527. remarks: "",
  528. amount: null,
  529. deptId: [],
  530. });
  531. };
  532. const handleRemove = (index) => {
  533. formData.data.accountDeptRunningWaterDetailList.splice(index, 1);
  534. return ElMessage({
  535. message: "删除成功!",
  536. type: "success",
  537. });
  538. };
  539. getList();
  540. const defaultProps = {
  541. children: "children",
  542. label: "deptName",
  543. };
  544. const openSearch = ref(false);
  545. const formSearchConfig = computed(() => {
  546. return [
  547. {
  548. type: "select",
  549. prop: "status",
  550. label: "收支类型",
  551. data: status.value,
  552. clearable: true,
  553. },
  554. {
  555. type: "select",
  556. prop: "currency",
  557. label: "币种",
  558. data: accountCurrency.value,
  559. clearable: true,
  560. },
  561. {
  562. type: "slot",
  563. slotName: "deptId",
  564. label: "归属部门",
  565. itemWidth: 50,
  566. },
  567. {
  568. type: "slot",
  569. slotName: "time",
  570. label: "交易时间",
  571. },
  572. {
  573. type: "input",
  574. itemType: "textarea",
  575. prop: "remarks",
  576. label: "摘要",
  577. },
  578. ];
  579. });
  580. let copySearch = ref({});
  581. const moreSearch = () => {
  582. copySearch.value = proxy.deepClone(sourceList.value.pagination);
  583. openSearch.value = true;
  584. };
  585. const cancelSearch = () => {
  586. sourceList.value.pagination = copySearch.value;
  587. openSearch.value = false;
  588. };
  589. const submitSearch = () => {
  590. if (
  591. sourceList.value.pagination.beginTime &&
  592. sourceList.value.pagination.endTime &&
  593. sourceList.value.pagination.beginTime > sourceList.value.pagination.endTime
  594. ) {
  595. return ElMessage("开始时间不能大于结束时间");
  596. }
  597. openSearch.value = false;
  598. sourceList.value.pagination.keyword = "";
  599. sourceList.value.pagination.pageNum = 1;
  600. getList();
  601. };
  602. const deriveExcel = () => {
  603. let queryParams = proxy.deepClone(sourceList.value.pagination);
  604. proxy.postTwo("/accountDeptRunningWater/export", queryParams).then((res) => {
  605. exportData(res, "部门费用管理.xlsx");
  606. });
  607. };
  608. const exportData = (res, name) => {
  609. const content = res;
  610. const blob = new Blob([content], { type: "application/ms-excel" });
  611. const fileName = name;
  612. if ("download" in document.createElement("a")) {
  613. // 非IE下载
  614. const elink = document.createElement("a");
  615. elink.download = fileName;
  616. elink.style.display = "none";
  617. elink.href = URL.createObjectURL(blob);
  618. document.body.appendChild(elink);
  619. elink.click();
  620. URL.revokeObjectURL(elink.href); // 释放URL 对象
  621. document.body.removeChild(elink);
  622. } else {
  623. navigator.msSaveBlob(blob, fileName);
  624. }
  625. };
  626. </script>
  627. <style lang="scss" scoped>
  628. .tenant {
  629. padding: 20px;
  630. }
  631. ::v-deep(.el-input-number .el-input__inner) {
  632. text-align: left;
  633. }
  634. </style>