main.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  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. </avue-crud>
  156. </basic-container>
  157. <el-dialog
  158. title="导入费用"
  159. append-to-body
  160. :visible.sync="feeDialog"
  161. top="5vh"
  162. width="60%"
  163. :close-on-click-modal="false"
  164. @closed="feeClose"
  165. class="el-dialogDeep"
  166. v-dialog-drag
  167. >
  168. <el-row style="height: 0;">
  169. <el-col :span="5">
  170. <div style="margin-top:45px">
  171. <el-scrollbar>
  172. <basic-container>
  173. <avue-tree
  174. :option="treeOption"
  175. :data="treeData"
  176. @node-click="nodeClick"
  177. />
  178. </basic-container>
  179. </el-scrollbar>
  180. </div>
  181. </el-col>
  182. <el-col :span="19">
  183. <avue-crud
  184. :option="option"
  185. :table-loading="loading"
  186. :data="data"
  187. ref="crud"
  188. @refresh-change="refreshChange"
  189. @selection-change="selectionChange"
  190. @current-change="currentChange"
  191. @size-change="sizeChange"
  192. :page.sync="page"
  193. @on-load="onLoad"
  194. :cell-style="cellStyle"
  195. >
  196. </avue-crud>
  197. </el-col>
  198. </el-row>
  199. <span slot="footer" class="dialog-footer">
  200. <el-button @click="feeDialog = false">取 消</el-button>
  201. <el-button
  202. type="primary"
  203. @click="importData"
  204. :disabled="this.selectionList.length == 0"
  205. >
  206. 导入
  207. </el-button>
  208. </span>
  209. </el-dialog>
  210. <crop-dialog ref="cropDialog" @importCorp="importCorp"></crop-dialog>
  211. <el-dialog
  212. append-to-body
  213. title="账单"
  214. class="el-dialogDeep"
  215. :visible.sync="applyPaymentDialog"
  216. width="70%"
  217. :close-on-click-modal="false"
  218. :destroy-on-close="true"
  219. :close-on-press-escape="false"
  220. v-dialog-drag
  221. >
  222. <apply-payment
  223. :billType="billType"
  224. :billData="billData"
  225. :arrList="arrList"
  226. @choceFun="choceFun"
  227. >
  228. </apply-payment>
  229. </el-dialog>
  230. </div>
  231. </template>
  232. <script>
  233. import feeOption from "./config/feeInfo.json";
  234. import option from "./config/feeList.json";
  235. import { getDeptLazyTree, customerList } from "@/api/basicData/basicFeesDesc";
  236. import { delItem } from "@/api/feeInfo/fee-info";
  237. import { isPercentage, micrometerFormat } from "@/util/validate";
  238. // import customerDialog from "@/components/customer-dialog/main";
  239. import cropDialog from "@/components/crop-dialog/main";
  240. import _ from "lodash";
  241. import ApplyPayment from "../finance/applyPayment";
  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. billData:{
  289. optionType:'JK'
  290. },
  291. currencyList: [],
  292. breakConfiguration:{
  293. multipleChoices:false,
  294. multiple:false,
  295. disabled:false,
  296. searchShow:true,
  297. collapseTags:false,
  298. clearable:true,
  299. placeholder:'请点击右边按钮选择',
  300. dicData:[]
  301. },
  302. allData:[],
  303. data_one:[],
  304. data_two:[],
  305. selectTab:1,
  306. activeName:"first",
  307. tab1:true,
  308. tab2:false,
  309. applyPaymentDialog:false,
  310. billType:'',
  311. arrList:[],
  312. };
  313. },
  314. props: {
  315. orderFeesList: {
  316. type: Array
  317. },
  318. disabled: {
  319. type: Boolean
  320. },
  321. feeUrl: {
  322. type: String
  323. }
  324. },
  325. filters: {
  326. isPercentage(val) {
  327. return isPercentage(val);
  328. },
  329. micrometerFormat(val) {
  330. return micrometerFormat(val);
  331. }
  332. },
  333. async created() {
  334. this.feeOption = await this.getColumnData(
  335. this.getColumnName(33),
  336. feeOption
  337. );
  338. this.getWorkDicts("currency").then(res => {
  339. this.currencyList = res.data.data;
  340. });
  341. },
  342. components: {
  343. cropDialog,
  344. ApplyPayment
  345. },
  346. methods: {
  347. //选择费用
  348. selectValue(value,row){
  349. this.$set(row,"feeName",value.cname)
  350. this.$set(row,"unit",value.unitno)
  351. this.$set(row,"currency",value.fcyno)
  352. this.currencyChange(row)
  353. },
  354. //选择应收应付
  355. handleClick(tab){
  356. if(tab.name == "first") {
  357. this.tab1 = true;
  358. this.tab2 = false;
  359. //将上一个tab页数据放到 对应data上
  360. this.data_two = this.feeData
  361. this.selectTab = 1
  362. this.feeData = this.data_one //切换数据
  363. this.selectionList = [];
  364. this.arrList = [];
  365. } else if(tab.name == "second") {
  366. this.tab1 = false;
  367. this.tab2 = true;
  368. if(this.selectTab === 1){
  369. this.data_one = this.feeData
  370. }
  371. this.selectTab = 2
  372. this.feeData = this.data_two
  373. this.selectionList = [];
  374. this.arrList = [];
  375. }
  376. },
  377. cellStyle() {
  378. return "padding:0;height:40px;";
  379. },
  380. importCorp(row) {
  381. this.feeData.push({
  382. itemId: null,
  383. corpId: row.id,
  384. corpName: row.name,
  385. feeName: null,
  386. price: null,
  387. unit: null,
  388. quantity: null,
  389. amount: null,
  390. currency: null,
  391. exchangeRate: null,
  392. remarks: null,
  393. $cellEdit: true,
  394. feesType:this.selectTab
  395. });
  396. },
  397. currencyChange(row) {
  398. if (row.currency == "CNY") {
  399. row.exchangeRate = 1;
  400. }
  401. if (row.currency == "USD") {
  402. row.exchangeRate = 6.3843;
  403. }
  404. },
  405. rowDel(row, index) {
  406. this.$confirm("确定删除数据?", {
  407. confirmButtonText: "确定",
  408. cancelButtonText: "取消",
  409. type: "warning"
  410. }).then(() => {
  411. //费用判断是否需要调用删除接口
  412. if (row.id) {
  413. delItem(row.id, this.feeUrl).then(res => {
  414. this.$message({
  415. type: "success",
  416. message: "删除成功!"
  417. });
  418. this.feeData.splice(index, 1);
  419. });
  420. } else {
  421. this.$message({
  422. type: "success",
  423. message: "删除成功!"
  424. });
  425. this.feeData.splice(index, 1);
  426. }
  427. });
  428. },
  429. getCorpData(row) {
  430. this.feeData[row.index].corpName = row.cname;
  431. },
  432. countChange(row) {
  433. if (row.price && row.quantity) {
  434. row.amount = _.multiply(row.quantity, row.price).toFixed(2);
  435. }
  436. },
  437. rateChange(row) {
  438. row.exchangeRate;
  439. if (row.exchangeRate >= 100) {
  440. row.exchangeRate = 0;
  441. this.$message.error("汇率不能超过100%");
  442. }
  443. },
  444. currentChange(val) {
  445. this.page.currentPage = val;
  446. },
  447. sizeChange(val) {
  448. this.page.currentPage = 1;
  449. this.page.pageSize = val;
  450. },
  451. //刷新
  452. refreshChange() {
  453. this.page.currentPage = 1;
  454. this.onLoad(this.page);
  455. },
  456. //多选
  457. selectionChange(list) {
  458. this.selectionList = list;
  459. },
  460. rePick(row, index) {
  461. this.reData = {
  462. ...row,
  463. index: index
  464. };
  465. this.feeDialog = true;
  466. this.onLoad(this.page);
  467. },
  468. //费用编辑
  469. rowCell(row, index) {
  470. if (row.$cellEdit == true) {
  471. this.$set(row, "$cellEdit", false);
  472. } else {
  473. this.$set(row, "$cellEdit", true);
  474. }
  475. },
  476. //新增
  477. rowAdd() {
  478. this.$refs.cropDialog.init();
  479. },
  480. onLoad(page) {
  481. this.loading = true;
  482. let data = {
  483. size: page.pageSize,
  484. current: page.currentPage,
  485. parentId: 0,
  486. feesTypeId: this.treeDeptId
  487. };
  488. customerList(data).then(res => {
  489. const data = res.data.data;
  490. this.page.total = data.total;
  491. this.data = data.records;
  492. this.loading = false;
  493. if (this.page.total) {
  494. this.option.height = window.innerHeight - 350;
  495. }
  496. });
  497. },
  498. //导入页左费用类型查询
  499. nodeClick(data) {
  500. this.treeDeptId = data.id;
  501. this.page.currentPage = 1;
  502. this.onLoad(this.page);
  503. },
  504. feeClose() {
  505. this.selectionList = [];
  506. this.page = {
  507. pageSize: 10,
  508. currentPage: 1,
  509. total: 0
  510. };
  511. this.treeDeptId = null;
  512. this.loading = false;
  513. this.data = [];
  514. this.reData = null;
  515. },
  516. importData() {
  517. if (this.reData) {
  518. this.selectionList.length;
  519. if (this.selectionList.length != 1) {
  520. return this.$message.error("重新选择的时候只能选择一条数据");
  521. } else {
  522. this.selectionList.forEach(e => {
  523. this.feeData.forEach((item, index) => {
  524. if (index == this.reData.index) {
  525. item.itemId = e.id;
  526. item.corpId = this.reData.corpId;
  527. item.feeName = e.cname;
  528. item.price = this.reData.price;
  529. item.unit = e.unitno;
  530. item.quantity = this.reData.quantity;
  531. item.amount = this.reData.amount;
  532. item.currency = e.fcyno;
  533. item.exchangeRate = this.reData.exchangeRate;
  534. item.remarks = this.reData.remarks;
  535. item.$cellEdit = true;
  536. }
  537. });
  538. });
  539. }
  540. } else {
  541. this.selectionList.forEach(e => {
  542. this.feeData.push({
  543. itemId: e.id,
  544. corpId: null,
  545. feeName: e.cname,
  546. price: 0,
  547. unit: e.unitno,
  548. quantity: 0,
  549. amount: 0,
  550. currency: e.fcyno,
  551. exchangeRate: null,
  552. remarks: null,
  553. $cellEdit: true,
  554. });
  555. });
  556. }
  557. this.feeDialog = false;
  558. },
  559. submitData() {
  560. this.allData = []
  561. //保存时 将所出的tab页数据赋值到相应 data上
  562. if(this.selectTab == 1){
  563. this.data_one = this.feeData
  564. }else{
  565. this.data_two = this.feeData
  566. }
  567. this.allData.push(...this.data_one,...this.data_two)
  568. return this.allData;
  569. },
  570. billingDetails(type){
  571. //查看是否改动过数据
  572. this.$emit("beforeFinance",this.submitData(),(params)=>{
  573. if(params.valid){
  574. for(let i=0;i<this.selectionList.length;i++){
  575. if(this.selectionList[i].corpId != this.selectionList[0].corpId){
  576. return this.$message.error('批量操作结算单位必须一致')
  577. }
  578. }
  579. this.billType = type
  580. if(type === '申请'){
  581. this.selectionList.map(item =>{
  582. delete item.id
  583. item.corpsName = item.corpName
  584. item.srcFeesId = item.id
  585. item.costType = item.itemId
  586. item.itemType = '采购'
  587. item.optionType = 'JK'
  588. item.srcType = 2 //费用明细申请
  589. let form = {
  590. form:{
  591. ...item,
  592. }
  593. }
  594. this.arrList.push(form)
  595. })
  596. }else{
  597. this.selectionList.map(item =>{
  598. delete item.id
  599. item.corpsName = item.corpName
  600. item.srcFeesId = item.id
  601. item.costType = item.itemId
  602. item.itemType = '采购'
  603. item.optionType = 'JK'
  604. item.srcType = 2 //费用明细申请
  605. let form = {
  606. form:{
  607. ...item,
  608. }
  609. }
  610. this.arrList.push(form)
  611. })
  612. }
  613. this.openApplyPayment()
  614. }
  615. })
  616. },
  617. //打开账单
  618. openApplyPayment(){
  619. this.applyPaymentDialog = true;
  620. },
  621. //关闭账单
  622. choceFun(){
  623. },
  624. summaryMethod({ columns, data }) {
  625. const sums = [];
  626. if (columns.length > 0) {
  627. columns.forEach((item, index) => {
  628. sums[0] = "合计";
  629. if (item.property == "quantity" || item.property == "amount") {
  630. let qtySum = 0;
  631. let amountSum = 0;
  632. data.forEach(e => {
  633. qtySum = _.add(qtySum, Number(e.quantity));
  634. amountSum = _.add(amountSum, Number(e.amount));
  635. });
  636. //数量总计
  637. if (item.property == "quantity") {
  638. sums[index] = qtySum ? qtySum.toFixed(2) : "0.00";
  639. }
  640. //金额总计
  641. if (item.property == "amount") {
  642. sums[index] = micrometerFormat(amountSum);
  643. }
  644. }
  645. });
  646. }
  647. return sums;
  648. },
  649. async saveColumn() {
  650. const inSave = await this.saveColumnData(
  651. this.getColumnName(33),
  652. this.feeOption
  653. );
  654. if (inSave) {
  655. this.$message.success("保存成功");
  656. //关闭窗口
  657. this.$refs.feeCrud.$refs.dialogColumn.columnBox = false;
  658. }
  659. }
  660. },
  661. watch: {
  662. orderFeesList: function(rows) {
  663. this.allData = rows ? rows : [];
  664. if(this.allData.length !=0){
  665. this.data_one=this.allData.filter(item=>item.feesType === 1) //应收
  666. this.data_two=this.allData.filter(item=>item.feesType === 2) //应付
  667. if( this.feeData.length != 0){
  668. this.feeData = this.data_one
  669. }
  670. }
  671. }
  672. }
  673. };
  674. </script>
  675. <style lang="scss" scoped>
  676. .required_fields{
  677. color: #F56C6C;
  678. display:inline-block;
  679. width: 7%
  680. }
  681. </style>