index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  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 = [];
  219. const config = computed(() => {
  220. return [
  221. {
  222. attrs: {
  223. label: "部门",
  224. prop: "deptName",
  225. },
  226. },
  227. {
  228. attrs: {
  229. label: "交易时间",
  230. prop: "transactionTime",
  231. },
  232. },
  233. {
  234. attrs: {
  235. label: "交易金额",
  236. slot: "amount",
  237. },
  238. },
  239. // {
  240. // attrs: {
  241. // prop: "accountOpening",
  242. // label: "对方账户",
  243. // },
  244. // },
  245. // {
  246. // attrs: {
  247. // prop: "openingBank",
  248. // label: "对方银行",
  249. // },
  250. // },
  251. // {
  252. // attrs: {
  253. // prop: "name",
  254. // label: "对方账号",
  255. // },
  256. // },
  257. {
  258. attrs: {
  259. prop: "remarks",
  260. label: "摘要",
  261. "min-width": "200",
  262. },
  263. },
  264. // {
  265. // attrs: {
  266. // label: "操作",
  267. // width: "200",
  268. // align: "right",
  269. // },
  270. // renderHTML(row) {
  271. // return [
  272. // {
  273. // attrs: {
  274. // label: "调整部门",
  275. // type: "primary",
  276. // text: true,
  277. // },
  278. // el: "button",
  279. // click() {
  280. // depModal.value = true;
  281. // dtlData.value = row;
  282. // departmentId.value = [];
  283. // },
  284. // },
  285. // {
  286. // attrs: {
  287. // label: "分拆",
  288. // type: "primary",
  289. // text: true,
  290. // },
  291. // el: "button",
  292. // click() {
  293. // getDtl(row);
  294. // },
  295. // },
  296. // ];
  297. // },
  298. // },
  299. ];
  300. });
  301. const dtlData = ref({});
  302. let formData = reactive({
  303. data: {
  304. type: "1",
  305. },
  306. treeData: [],
  307. });
  308. const formOption = reactive({
  309. inline: true,
  310. labelWidth: 100,
  311. itemWidth: 100,
  312. rules: [],
  313. });
  314. const submit = ref(null);
  315. const depModal = ref(false);
  316. let deptTreeData = ref([]);
  317. let departmentId = ref([]);
  318. const getDept = async () => {
  319. // 部门树
  320. proxy
  321. .get("/tenantDept/list", {
  322. pageNum: 1,
  323. pageSize: 9999,
  324. tenantId: Cookies.get("tenantId"),
  325. })
  326. .then((message) => {
  327. recursive(message.data);
  328. deptTreeData.value = proxy.handleTree(message.data, "corporationId");
  329. });
  330. };
  331. getDept();
  332. const submitDeptForm = async (departmentId) => {
  333. if (departmentId.length == 0) {
  334. ElMessage.error("请选择部门");
  335. return;
  336. }
  337. let params = {
  338. deptId: departmentId[departmentId.length - 1],
  339. accountDeptRunningWaterId: dtlData.value.accountDeptRunningWaterId,
  340. id: dtlData.value.id,
  341. amount: dtlData.value.amount,
  342. };
  343. proxy
  344. .post("/accountDeptRunningWaterDetail/add", params)
  345. .then(() => {
  346. ElMessage.success("调整部门成功");
  347. depModal.value = false;
  348. getList();
  349. })
  350. .catch((error) => {
  351. ElMessage.error(error);
  352. });
  353. };
  354. const recursive = (data) => {
  355. data.map((item) => {
  356. item.label = item.deptName;
  357. item.id = item.corporationId;
  358. if (item.children) {
  359. recursive(item.children);
  360. } else {
  361. item.children = [];
  362. }
  363. });
  364. };
  365. const formConfig = computed(() => {
  366. return [
  367. {
  368. type: "select",
  369. prop: "accountManagementId",
  370. label: "付款账户",
  371. required: true,
  372. disabled: true,
  373. isLoad: {
  374. url: "/accountManagement/page",
  375. req: {
  376. pageNum: 1,
  377. pageSize: 9999,
  378. },
  379. labelKey: "name",
  380. labelVal: "id",
  381. method: "post",
  382. resUrl: "rows",
  383. },
  384. },
  385. {
  386. type: "date",
  387. prop: "transactionTime",
  388. label: "交易时间",
  389. disabled: true,
  390. },
  391. // {
  392. // type: "selectInput",
  393. // label: "交易金额",
  394. // itemWidth: 60,
  395. // data: accountCurrency.value,
  396. // placeholder: "请输入",
  397. // selectPlaceholder: "币种",
  398. // selectProp: "currency",
  399. // prop: "amount",
  400. // disabled: true,
  401. // },
  402. {
  403. type: "slot",
  404. prop: "money",
  405. slotName: "money",
  406. label: "交易金额",
  407. },
  408. {
  409. type: "input",
  410. prop: "remarks",
  411. label: "摘要",
  412. disabled: true,
  413. itemType: "textarea",
  414. disabled: true,
  415. },
  416. {
  417. type: "slot",
  418. label: "拆分明细",
  419. slotName: "slot",
  420. },
  421. ];
  422. });
  423. const getList = async (req) => {
  424. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  425. loading.value = true;
  426. proxy.post("/accountDeptRunningWater/page", sourceList.value.pagination).then((message) => {
  427. sourceList.value.data = message.rows;
  428. sourceList.value.pagination.total = message.total;
  429. setTimeout(() => {
  430. loading.value = false;
  431. }, 200);
  432. });
  433. };
  434. proxy.getDict(["account_currency"]).then((res) => {
  435. accountCurrency.value = res.account_currency.map((item) => {
  436. return {
  437. label: item.dictValue,
  438. value: item.dictKey,
  439. };
  440. });
  441. });
  442. const submitForm = async () => {
  443. submit.value.handleSubmit(() => {
  444. if (!(formData.data.accountDeptRunningWaterDetailList && formData.data.accountDeptRunningWaterDetailList.length > 0)) {
  445. return ElMessage("请添加拆分明细!");
  446. }
  447. let money = 0;
  448. for (let i = 0; i < formData.data.accountDeptRunningWaterDetailList.length; i++) {
  449. if (formData.data.accountDeptRunningWaterDetailList[i].amount && Number(formData.data.accountDeptRunningWaterDetailList[i].amount) !== 0) {
  450. money = Number(parseFloat(Number(money) + Number(formData.data.accountDeptRunningWaterDetailList[i].amount)));
  451. } else {
  452. return ElMessage("金额不能为0");
  453. }
  454. }
  455. if (Number(money) !== Number(formData.data.amount)) {
  456. return ElMessage("分拆总金额需等于交易金额");
  457. }
  458. submitLoading.value = true;
  459. let params = {
  460. id: formData.data.id,
  461. deptRunningWaterDetailList: formData.data.accountDeptRunningWaterDetailList,
  462. accountDeptRunningWaterId: formData.data.accountDeptRunningWaterId,
  463. };
  464. params.deptRunningWaterDetailList.map((item) => {
  465. item.deptId = item.deptId[item.deptId.length - 1];
  466. });
  467. proxy
  468. .post("/accountDeptRunningWaterDetail/add", {
  469. ...params,
  470. })
  471. .then(
  472. () => {
  473. ElMessage({
  474. message: "拆分成功",
  475. type: "success",
  476. });
  477. dialogVisible.value = false;
  478. submitLoading.value = false;
  479. getList();
  480. },
  481. (err) => (submitLoading.value = false)
  482. );
  483. });
  484. };
  485. const getDtl = (row) => {
  486. modalType.value = "edit";
  487. dialogVisible.value = true;
  488. proxy.post("/accountDeptRunningWaterDetail/detail", { id: row.id }).then((res) => {
  489. if (res.deptRunningWaterDetailList && res.deptRunningWaterDetailList.length > 0) {
  490. res.accountDeptRunningWaterDetailList = res.deptRunningWaterDetailList.map((item) => {
  491. item.deptId = [item.deptId];
  492. return item;
  493. });
  494. } else {
  495. res.accountDeptRunningWaterDetailList = [];
  496. }
  497. formData.data = res;
  498. dialogVisible.value = true;
  499. });
  500. };
  501. const addRow = () => {
  502. formData.data.accountDeptRunningWaterDetailList.push({
  503. remarks: "",
  504. amount: null,
  505. deptId: [],
  506. });
  507. };
  508. const handleRemove = (index) => {
  509. formData.data.accountDeptRunningWaterDetailList.splice(index, 1);
  510. return ElMessage({
  511. message: "删除成功!",
  512. type: "success",
  513. });
  514. };
  515. getList();
  516. const defaultProps = {
  517. children: "children",
  518. label: "deptName",
  519. };
  520. const openSearch = ref(false);
  521. const formSearchConfig = computed(() => {
  522. return [
  523. {
  524. type: "select",
  525. prop: "status",
  526. label: "收支类型",
  527. data: status.value,
  528. clearable: true,
  529. },
  530. {
  531. type: "select",
  532. prop: "currency",
  533. label: "币种",
  534. data: accountCurrency.value,
  535. clearable: true,
  536. },
  537. {
  538. type: "slot",
  539. slotName: "deptId",
  540. label: "归属部门",
  541. itemWidth: 50,
  542. },
  543. {
  544. type: "slot",
  545. slotName: "time",
  546. label: "交易时间",
  547. },
  548. {
  549. type: "input",
  550. itemType: "textarea",
  551. prop: "remarks",
  552. label: "摘要",
  553. },
  554. ];
  555. });
  556. let copySearch = ref({});
  557. const moreSearch = () => {
  558. copySearch.value = proxy.deepClone(sourceList.value.pagination);
  559. openSearch.value = true;
  560. };
  561. const cancelSearch = () => {
  562. sourceList.value.pagination = copySearch.value;
  563. openSearch.value = false;
  564. };
  565. const submitSearch = () => {
  566. if (
  567. sourceList.value.pagination.beginTime &&
  568. sourceList.value.pagination.endTime &&
  569. sourceList.value.pagination.beginTime > sourceList.value.pagination.endTime
  570. ) {
  571. return ElMessage("开始时间不能大于结束时间");
  572. }
  573. openSearch.value = false;
  574. sourceList.value.pagination.keyword = "";
  575. sourceList.value.pagination.pageNum = 1;
  576. getList();
  577. };
  578. const deriveExcel = () => {
  579. let queryParams = proxy.deepClone(sourceList.value.pagination);
  580. proxy.postTwo("/accountDeptRunningWater/export", queryParams).then((res) => {
  581. exportData(res, "部门费用管理.xlsx");
  582. });
  583. };
  584. const exportData = (res, name) => {
  585. const content = res;
  586. const blob = new Blob([content], { type: "application/ms-excel" });
  587. const fileName = name;
  588. if ("download" in document.createElement("a")) {
  589. // 非IE下载
  590. const elink = document.createElement("a");
  591. elink.download = fileName;
  592. elink.style.display = "none";
  593. elink.href = URL.createObjectURL(blob);
  594. document.body.appendChild(elink);
  595. elink.click();
  596. URL.revokeObjectURL(elink.href); // 释放URL 对象
  597. document.body.removeChild(elink);
  598. } else {
  599. navigator.msSaveBlob(blob, fileName);
  600. }
  601. };
  602. </script>
  603. <style lang="scss" scoped>
  604. .tenant {
  605. padding: 20px;
  606. }
  607. ::v-deep(.el-input-number .el-input__inner) {
  608. text-align: left;
  609. }
  610. </style>