main.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. <template>
  2. <div>
  3. <containerTitle title="费用明细"></containerTitle>
  4. <basic-container>
  5. <avue-crud
  6. ref="feeCrud"
  7. :data="feeData"
  8. :option="feeOption"
  9. @saveColumn="saveColumn"
  10. @selection-change="selectionChange"
  11. :summary-method="summaryMethod"
  12. :cell-style="cellStyle"
  13. >
  14. <template slot="menuLeft">
  15. <el-tabs v-model="activeName" @tab-click="handleClick">
  16. <el-tab-pane label="应收" name="first" :key="'first'">
  17. </el-tab-pane>
  18. <el-tab-pane label="应付" name="second" :key="'second'">
  19. </el-tab-pane>
  20. </el-tabs>
  21. <el-button
  22. type="primary"
  23. icon="el-icon-plus"
  24. size="small"
  25. @click.stop="rowAdd"
  26. :disabled="disabled"
  27. >录入明细</el-button
  28. >
  29. <el-button
  30. type="warning"
  31. size="small"
  32. @click.stop="billingDetails('收费')"
  33. :disabled="disabled || selectionList.length == 0"
  34. v-if="selectTab === 1"
  35. >生成账单</el-button>
  36. <!-- <el-button
  37. type="info"
  38. size="small"
  39. @click.stop="rowAdd"
  40. :disabled="disabled || selectionList.length == 0"
  41. v-if="selectTab === 1"
  42. >查看生成记录</el-button>-->
  43. <el-button
  44. type="warning"
  45. size="small"
  46. @click.stop="billingDetails('申请')"
  47. :disabled="disabled || selectionList.length == 0"
  48. v-if="selectTab === 2"
  49. >申请付费</el-button>
  50. <!-- <el-button
  51. type="info"
  52. size="small"
  53. @click.stop="rowAdd"
  54. :disabled="disabled || selectionList.length == 0"
  55. v-if="selectTab === 2"
  56. >查看申请记录</el-button>-->
  57. </template>
  58. <template slot="menu" slot-scope="{ row, index }">
  59. <el-button
  60. size="small"
  61. icon="el-icon-edit"
  62. type="text"
  63. @click="rowCell(row, index)"
  64. :disabled="disabled"
  65. >{{ row.$cellEdit ? "保存" : "修改" }}</el-button
  66. >
  67. <el-button
  68. size="small"
  69. icon="el-icon-delete"
  70. type="text"
  71. @click="rowDel(row, index)"
  72. :disabled="disabled"
  73. >删 除</el-button
  74. >
  75. </template>
  76. <template slot="corpId" slot-scope="{ row, index }">
  77. <span v-if="row.$cellEdit" class="required_fields">*</span>
  78. <crop-select
  79. style="width: 90% !important;display: inline-block"
  80. v-if="row.$cellEdit"
  81. v-model="row.corpId"
  82. :cropIndex="index"
  83. @getCorpData="getCorpData"
  84. corpType="KH"
  85. ></crop-select>
  86. <span v-else>{{ row.corpName }}</span>
  87. </template>
  88. <template slot="feeName" slot-scope="{ row, index }">
  89. <span v-if="row.$cellEdit" class="required_fields">*</span>
  90. <breakdown-select
  91. style="width: 90% !important;"
  92. v-if="row.$cellEdit"
  93. v-model="row.itemId"
  94. @selectValue="(value) => selectValue(value,row)"
  95. :configuration="breakConfiguration"
  96. >
  97. </breakdown-select>
  98. <span v-else>{{ row.feeName }}</span>
  99. </template>
  100. <template slot="price" slot-scope="{ row }">
  101. <el-input
  102. v-if="row.$cellEdit"
  103. v-model="row.price"
  104. size="small"
  105. oninput='this.value=this.value.replace(/[^(\d.)]/g,"").replace(/^(\d+)\.(\d\d).*$/, "$1.$2")'
  106. @change="countChange(row)"
  107. ></el-input>
  108. <span v-else>{{ row.price | micrometerFormat }}</span>
  109. </template>
  110. <template slot="quantity" slot-scope="{ row }">
  111. <el-input
  112. v-if="row.$cellEdit"
  113. v-model="row.quantity"
  114. size="small"
  115. oninput='this.value=this.value.replace(/[^(\d.)]/g,"").replace(/^(\d+)\.(\d\d).*$/, "$1.$2")'
  116. @change="countChange(row)"
  117. ></el-input>
  118. <span v-else>{{ row.quantity }}</span>
  119. </template>
  120. <template slot="amount" slot-scope="{ row }">
  121. <span>{{ row.amount | micrometerFormat }}</span>
  122. </template>
  123. <template slot="exchangeRate" slot-scope="{ row }">
  124. <el-input
  125. v-if="row.$cellEdit"
  126. v-model="row.exchangeRate"
  127. size="small"
  128. oninput='this.value=this.value.replace(/[^(\d.)]/g,"").replace(/^(\d+)\.(\d\d).*$/, "$1.$2")'
  129. @change="rateChange(row)"
  130. placeholder="请输入"
  131. ></el-input>
  132. <span v-else>{{ row.exchangeRate }}</span>
  133. </template>
  134. <template slot="currency" slot-scope="{ row }">
  135. <el-select
  136. v-if="row.$cellEdit"
  137. v-model="row.currency"
  138. filterable
  139. allow-create
  140. default-first-option
  141. placeholder="请输入"
  142. size="small"
  143. @change="currencyChange(row)"
  144. >
  145. <el-option
  146. v-for="(item, index) in currencyList"
  147. :key="index"
  148. :label="item.dictValue"
  149. :value="item.dictValue"
  150. >
  151. </el-option>
  152. </el-select>
  153. <span v-else>{{ row.currency }}</span>
  154. </template>
  155. <template slot="unit" slot-scope="{ row }">
  156. <el-select
  157. v-if="row.$cellEdit"
  158. v-model="row.unit"
  159. filterable
  160. placeholder="请输入"
  161. size="small"
  162. >
  163. <el-option
  164. v-for="(item, index) in unitList"
  165. :key="index"
  166. :label="item.dictValue"
  167. :value="item.dictValue"
  168. >
  169. </el-option>
  170. </el-select>
  171. <span v-else>{{ row.unit }}</span>
  172. </template>
  173. </avue-crud>
  174. </basic-container>
  175. <el-dialog
  176. title="导入费用"
  177. append-to-body
  178. :visible.sync="feeDialog"
  179. top="5vh"
  180. width="60%"
  181. :close-on-click-modal="false"
  182. @closed="feeClose"
  183. class="el-dialogDeep"
  184. v-dialog-drag
  185. >
  186. <el-row style="height: 0;">
  187. <el-col :span="5">
  188. <div style="margin-top:45px">
  189. <el-scrollbar>
  190. <basic-container>
  191. <avue-tree
  192. :option="treeOption"
  193. :data="treeData"
  194. @node-click="nodeClick"
  195. />
  196. </basic-container>
  197. </el-scrollbar>
  198. </div>
  199. </el-col>
  200. <el-col :span="19">
  201. <avue-crud
  202. :option="option"
  203. :table-loading="loading"
  204. :data="data"
  205. ref="crud"
  206. @refresh-change="refreshChange"
  207. @selection-change="selectionChange"
  208. @current-change="currentChange"
  209. @size-change="sizeChange"
  210. :page.sync="page"
  211. @on-load="onLoad"
  212. :cell-style="cellStyle"
  213. >
  214. </avue-crud>
  215. </el-col>
  216. </el-row>
  217. <span slot="footer" class="dialog-footer">
  218. <el-button @click="feeDialog = false">取 消</el-button>
  219. <el-button
  220. type="primary"
  221. @click="importData"
  222. :disabled="this.selectionList.length == 0"
  223. >
  224. 导入
  225. </el-button>
  226. </span>
  227. </el-dialog>
  228. <crop-dialog ref="cropDialog" @importCorp="importCorp"></crop-dialog>
  229. </div>
  230. </template>
  231. <script>
  232. import feeOption from "./config/feeInfo.json";
  233. import option from "./config/feeList.json";
  234. import { getDeptLazyTree, customerList } from "@/api/basicData/basicFeesDesc";
  235. import { delItem } from "@/api/feeInfo/fee-info";
  236. import { isPercentage, micrometerFormat } from "@/util/validate";
  237. // import customerDialog from "@/components/customer-dialog/main";
  238. import cropDialog from "@/components/crop-dialog/main";
  239. import _ from "lodash";
  240. import ApplyPayment from "../finance/applyPayment";
  241. import {applyLoan,paymentApply} from "@/api/financialManagement/paymentRequest";
  242. export default {
  243. name: "feeInfo",
  244. data() {
  245. return {
  246. option: option,
  247. feeOption: {},
  248. feeDialog: false,
  249. treeOption: {
  250. nodeKey: "id",
  251. lazy: true,
  252. treeLoad: function(node, resolve) {
  253. const parentId = node.level === 0 ? 0 : node.data.id;
  254. getDeptLazyTree(parentId).then(res => {
  255. resolve(
  256. res.data.data.map(item => {
  257. return {
  258. ...item,
  259. leaf: !item.hasChildren
  260. };
  261. })
  262. );
  263. });
  264. },
  265. addBtn: false,
  266. menu: false,
  267. size: "small",
  268. props: {
  269. labelText: "标题",
  270. label: "title",
  271. value: "value",
  272. children: "children"
  273. }
  274. },
  275. page: {
  276. pageSize: 10,
  277. currentPage: 1,
  278. total: 0
  279. },
  280. treeDeptId: null,
  281. loading: false,
  282. receivableButton: "primary",
  283. copeWithButton: "",
  284. data: [],
  285. feeData: [],
  286. selectionList: [],
  287. reData: null,
  288. currencyList: [],
  289. unitList:[],
  290. breakConfiguration:{
  291. multipleChoices:false,
  292. multiple:false,
  293. disabled:false,
  294. searchShow:true,
  295. collapseTags:false,
  296. clearable:true,
  297. placeholder:'请点击右边按钮选择',
  298. dicData:[]
  299. },
  300. isUpdata:true,//是否需要触发监听
  301. allData:[],
  302. data_one:[],
  303. data_two:[],
  304. selectTab:1,
  305. activeName:"first",
  306. tab1:true,
  307. tab2:false,
  308. };
  309. },
  310. props: {
  311. orderFeesList: {
  312. type: Array
  313. },
  314. disabled: {
  315. type: Boolean
  316. },
  317. feeUrl: {
  318. type: String
  319. },
  320. billUrl: {
  321. type: String
  322. },
  323. optionType:{
  324. type: String
  325. }
  326. },
  327. filters: {
  328. isPercentage(val) {
  329. return isPercentage(val);
  330. },
  331. micrometerFormat(val) {
  332. return micrometerFormat(val);
  333. }
  334. },
  335. async created() {
  336. this.feeOption = await this.getColumnData(
  337. this.getColumnName(33),
  338. feeOption
  339. );
  340. this.getWorkDicts("currency").then(res => {
  341. this.currencyList = res.data.data;
  342. });
  343. this.getWorkDicts("unit").then(res =>{
  344. this.unitList = res.data.data
  345. })
  346. },
  347. components: {
  348. cropDialog,
  349. ApplyPayment
  350. },
  351. methods: {
  352. //选择费用
  353. selectValue(value,row){
  354. this.$set(row,"feeName",value.cname)
  355. // this.$set(row,"unit",value.unitno)
  356. this.$set(row,"currency",value.fcyno)
  357. this.currencyChange(row)
  358. },
  359. //选择应收应付
  360. handleClick(tab){
  361. if(tab.name == "first") {
  362. this.tab1 = true;
  363. this.tab2 = false;
  364. //将上一个tab页数据放到 对应data上
  365. this.data_two = this.feeData
  366. this.selectTab = 1
  367. this.feeData = this.data_one //切换数据
  368. // this.selectionList = [];
  369. } else if(tab.name == "second") {
  370. this.tab1 = false;
  371. this.tab2 = true;
  372. if(this.selectTab === 1){
  373. this.data_one = this.feeData
  374. }
  375. this.selectTab = 2
  376. this.feeData = this.data_two
  377. // this.selectionList = [];
  378. }
  379. },
  380. cellStyle() {
  381. return "padding:0;height:40px;";
  382. },
  383. importCorp(row) {
  384. this.feeData.push({
  385. itemId: null,
  386. corpId: row.id,
  387. corpName: row.name,
  388. feeName: null,
  389. price: null,
  390. unit: null,
  391. quantity: null,
  392. amount: null,
  393. currency: null,
  394. exchangeRate: null,
  395. remarks: null,
  396. $cellEdit: true,
  397. feesType:this.selectTab
  398. });
  399. },
  400. currencyChange(row) {
  401. if (row.currency == "CNY") {
  402. row.exchangeRate = 1;
  403. }
  404. if (row.currency == "USD") {
  405. row.exchangeRate = 6.3843;
  406. }
  407. },
  408. rowDel(row, index) {
  409. this.$confirm("确定删除数据?", {
  410. confirmButtonText: "确定",
  411. cancelButtonText: "取消",
  412. type: "warning"
  413. }).then(() => {
  414. //费用判断是否需要调用删除接口
  415. if (row.id) {
  416. delItem(row.id, this.feeUrl).then(res => {
  417. this.$message({
  418. type: "success",
  419. message: "删除成功!"
  420. });
  421. this.feeData.splice(index, 1);
  422. });
  423. } else {
  424. this.$message({
  425. type: "success",
  426. message: "删除成功!"
  427. });
  428. this.feeData.splice(index, 1);
  429. }
  430. });
  431. },
  432. getCorpData(row) {
  433. this.feeData[row.index].corpName = row.cname;
  434. },
  435. countChange(row) {
  436. if (row.price && row.quantity) {
  437. row.amount = _.multiply(row.quantity, row.price).toFixed(2);
  438. }
  439. },
  440. rateChange(row) {
  441. if (row.exchangeRate >= 100) {
  442. row.exchangeRate = 0;
  443. this.$message.error("汇率不能超过100%");
  444. }
  445. },
  446. currentChange(val) {
  447. this.page.currentPage = val;
  448. },
  449. sizeChange(val) {
  450. this.page.currentPage = 1;
  451. this.page.pageSize = val;
  452. },
  453. //刷新
  454. refreshChange() {
  455. this.page.currentPage = 1;
  456. this.onLoad(this.page);
  457. },
  458. //多选
  459. selectionChange(list) {
  460. this.selectionList = list;
  461. },
  462. rePick(row, index) {
  463. this.reData = {
  464. ...row,
  465. index: index
  466. };
  467. this.feeDialog = true;
  468. this.onLoad(this.page);
  469. },
  470. //费用编辑
  471. rowCell(row, index) {
  472. if (row.$cellEdit == true) {
  473. this.$set(row, "$cellEdit", false);
  474. } else {
  475. this.$set(row, "$cellEdit", true);
  476. }
  477. },
  478. //新增
  479. rowAdd() {
  480. this.$refs.cropDialog.init();
  481. },
  482. onLoad(page) {
  483. this.loading = true;
  484. let data = {
  485. size: page.pageSize,
  486. current: page.currentPage,
  487. parentId: 0,
  488. feesTypeId: this.treeDeptId
  489. };
  490. customerList(data).then(res => {
  491. const data = res.data.data;
  492. this.page.total = data.total;
  493. this.data = data.records;
  494. this.loading = false;
  495. if (this.page.total) {
  496. this.option.height = window.innerHeight - 350;
  497. }
  498. });
  499. },
  500. //导入页左费用类型查询
  501. nodeClick(data) {
  502. this.treeDeptId = data.id;
  503. this.page.currentPage = 1;
  504. this.onLoad(this.page);
  505. },
  506. feeClose() {
  507. this.selectionList = [];
  508. this.page = {
  509. pageSize: 10,
  510. currentPage: 1,
  511. total: 0
  512. };
  513. this.treeDeptId = null;
  514. this.loading = false;
  515. this.data = [];
  516. this.reData = null;
  517. },
  518. importData() {
  519. if (this.reData) {
  520. this.selectionList.length;
  521. if (this.selectionList.length != 1) {
  522. return this.$message.error("重新选择的时候只能选择一条数据");
  523. } else {
  524. this.selectionList.forEach(e => {
  525. this.feeData.forEach((item, index) => {
  526. if (index == this.reData.index) {
  527. item.itemId = e.id;
  528. item.corpId = this.reData.corpId;
  529. item.feeName = e.cname;
  530. item.price = this.reData.price;
  531. // item.unit = e.unitno;
  532. item.quantity = this.reData.quantity;
  533. item.amount = this.reData.amount;
  534. item.currency = e.fcyno;
  535. item.exchangeRate = this.reData.exchangeRate;
  536. item.remarks = this.reData.remarks;
  537. item.$cellEdit = true;
  538. }
  539. });
  540. });
  541. }
  542. } else {
  543. this.selectionList.forEach(e => {
  544. this.feeData.push({
  545. itemId: e.id,
  546. corpId: null,
  547. feeName: e.cname,
  548. price: 0,
  549. // unit: e.unitno,
  550. quantity: 0,
  551. amount: 0,
  552. currency: e.fcyno,
  553. exchangeRate: null,
  554. remarks: null,
  555. $cellEdit: true,
  556. });
  557. });
  558. }
  559. this.feeDialog = false;
  560. },
  561. submitData() {
  562. this.allData = []
  563. //保存时 将所出的tab页数据赋值到相应 data上
  564. if(this.selectTab == 1){
  565. this.data_one = this.feeData
  566. this.data_one.map(item =>{
  567. delete item.$cellEdit
  568. delete item.$index
  569. })
  570. }else{
  571. this.data_two = this.feeData
  572. this.data_two.map(item =>{
  573. delete item.$cellEdit
  574. delete item.$index
  575. })
  576. }
  577. this.allData.push(...this.data_one,...this.data_two)
  578. return this.allData;
  579. },
  580. billingDetails(type){
  581. //查看是否改动过数据
  582. this.$emit("beforeFinance",this.submitData(),(params)=>{
  583. if(params.valid){
  584. for(let i=0;i<this.selectionList.length;i++){
  585. if(this.selectionList[i].corpId != this.selectionList[0].corpId){
  586. return this.$message.error('批量操作结算单位必须一致')
  587. }
  588. }
  589. this.isUpdata = false
  590. this.selectionList.map(item =>{
  591. // item.url = this.billUrl
  592. item.srcOrderno = params.srcOrderno
  593. item.srcParentId = params.parentId
  594. item.corpsName = item.corpName
  595. item.srcFeesId = item.id
  596. item.costType = item.itemId
  597. item.itemType = '采购'
  598. item.optionType = this.optionType
  599. item.srcType = 2 //费用明细申请
  600. })
  601. let data = {
  602. billType: type,
  603. itemsList : this.selectionList
  604. }
  605. if(type === '申请'){
  606. this.$confirm("您确定申请货款吗?", "提示", {
  607. confirmButtonText: "确定",
  608. cancelButtonText: "取消",
  609. type: "warning",
  610. }).then(()=>{
  611. applyLoan(data).then(res=>{
  612. if(res.data.success){
  613. this.$message.success("操作成功!")
  614. }
  615. })
  616. }).finally(()=>{
  617. this.isUpdata = true
  618. })
  619. }else{
  620. this.$confirm("您确定生成账单吗?", "提示", {
  621. confirmButtonText: "确定",
  622. cancelButtonText: "取消",
  623. type: "warning",
  624. }).then(()=>{
  625. paymentApply(data).then(res=>{
  626. if(res.data.success){
  627. this.$message.success("操作成功!")
  628. }
  629. })
  630. }).finally(()=>{
  631. this.isUpdata = true
  632. })
  633. }
  634. }
  635. })
  636. },
  637. summaryMethod({ columns, data }) {
  638. const sums = [];
  639. if (columns.length > 0) {
  640. columns.forEach((item, index) => {
  641. sums[0] = "合计";
  642. if (item.property == "quantity" || item.property == "amount") {
  643. let qtySum = 0;
  644. let amountSum = 0;
  645. data.forEach(e => {
  646. qtySum = _.add(qtySum, Number(e.quantity));
  647. amountSum = _.add(amountSum, Number(e.amount));
  648. });
  649. //数量总计
  650. if (item.property == "quantity") {
  651. sums[index] = qtySum ? qtySum.toFixed(2) : "0.00";
  652. }
  653. //金额总计
  654. if (item.property == "amount") {
  655. sums[index] = micrometerFormat(amountSum);
  656. }
  657. }
  658. });
  659. }
  660. return sums;
  661. },
  662. async saveColumn() {
  663. const inSave = await this.saveColumnData(
  664. this.getColumnName(33),
  665. this.feeOption
  666. );
  667. if (inSave) {
  668. this.$message.success("保存成功");
  669. //关闭窗口
  670. this.$refs.feeCrud.$refs.dialogColumn.columnBox = false;
  671. }
  672. }
  673. },
  674. watch: {
  675. orderFeesList: function(rows) {
  676. this.allData = rows ? rows : [];
  677. if(this.allData.length !=0){
  678. this.data_one=this.allData.filter(item=>item.feesType === 1) //应收
  679. this.data_two=this.allData.filter(item=>item.feesType === 2) //应付
  680. if(this.isUpdata){
  681. if(this.selectTab == 1){
  682. this.feeData = this.data_one
  683. }else{
  684. this.feeData = this.data_two
  685. }
  686. }
  687. }
  688. },
  689. }
  690. };
  691. </script>
  692. <style lang="scss" scoped>
  693. .required_fields{
  694. color: #F56C6C;
  695. display:inline-block;
  696. width: 7%
  697. }
  698. </style>