main.vue 21 KB

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