main.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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-button
  16. type="primary"
  17. icon="el-icon-plus"
  18. size="small"
  19. @click.stop="rowAdd"
  20. :disabled="disabled"
  21. >新增</el-button
  22. >
  23. <el-button-group>
  24. <el-button
  25. type="receivableButton"
  26. :disabled="selectionList.length == 0"
  27. @click="receivable"
  28. >应收</el-button
  29. >
  30. <el-button
  31. type="copeWithButton"
  32. :disabled="selectionList.length == 0"
  33. @click="copeWith"
  34. >应付</el-button
  35. >
  36. </el-button-group>
  37. </template>
  38. <template slot="menu" slot-scope="{ row, index }">
  39. <el-button
  40. size="small"
  41. icon="el-icon-edit"
  42. type="text"
  43. @click="rowCell(row, index)"
  44. :disabled="disabled"
  45. >{{ row.$cellEdit ? "保存" : "修改" }}</el-button
  46. >
  47. <el-button
  48. size="small"
  49. icon="el-icon-delete"
  50. type="text"
  51. @click="rowDel(row, index)"
  52. :disabled="disabled"
  53. >删 除</el-button
  54. >
  55. </template>
  56. <template slot="corpId" slot-scope="{ row, index }">
  57. <crop-select
  58. v-show="row.$cellEdit"
  59. v-model="row.corpId"
  60. :cropIndex="index"
  61. @getCorpData="getCorpData"
  62. corpType="KH"
  63. ></crop-select>
  64. <span v-show="!row.$cellEdit">{{ row.corpName }}</span>
  65. </template>
  66. <template slot="feeName" slot-scope="{ row, index }">
  67. <el-button
  68. size="small"
  69. type="text"
  70. @click="rePick(row, index)"
  71. :disabled="disabled || !row.$cellEdit"
  72. class="picker"
  73. style="padding:4px 10px;float:left"
  74. >选择</el-button
  75. >
  76. <span> {{ row.feeName }}</span>
  77. </template>
  78. <template slot="price" slot-scope="{ row }">
  79. <el-input
  80. v-if="row.$cellEdit"
  81. v-model="row.price"
  82. size="small"
  83. oninput='this.value=this.value.replace(/[^(\d.)]/g,"").replace(/^(\d+)\.(\d\d).*$/, "$1.$2")'
  84. @change="priceChange(row)"
  85. ></el-input>
  86. <span v-else>{{ row.price | micrometerFormat }}</span>
  87. </template>
  88. <template slot="quantity" slot-scope="{ row }">
  89. <el-input
  90. v-if="row.$cellEdit"
  91. v-model="row.quantity"
  92. size="small"
  93. oninput='this.value=this.value.replace(/[^(\d.)]/g,"").replace(/^(\d+)\.(\d\d).*$/, "$1.$2")'
  94. @change="quantityChange(row)"
  95. ></el-input>
  96. <span v-else>{{ row.quantity }}</span>
  97. </template>
  98. <template slot="amount" slot-scope="{ row }">
  99. <span>{{ row.amount | micrometerFormat }}</span>
  100. </template>
  101. <template slot="exchangeRate" slot-scope="{ row }">
  102. <el-input
  103. v-if="row.$cellEdit"
  104. v-model="row.exchangeRate"
  105. size="small"
  106. oninput='this.value=this.value.replace(/[^(\d.)]/g,"").replace(/^(\d+)\.(\d\d).*$/, "$1.$2")'
  107. @change="rateChange(row)"
  108. placeholder="请输入"
  109. disabled
  110. ></el-input>
  111. <span v-else>{{ row.exchangeRate | isPercentage }}</span>
  112. </template>
  113. <template slot="currency" slot-scope="{ row }">
  114. <el-select
  115. v-if="row.$cellEdit"
  116. v-model="row.currency"
  117. filterable
  118. allow-create
  119. default-first-option
  120. placeholder="请输入"
  121. size="small"
  122. @change="currencyChange(row)"
  123. >
  124. <el-option
  125. v-for="(item, index) in currencyList"
  126. :key="index"
  127. :label="item.dictValue"
  128. :value="item.dictValue"
  129. >
  130. </el-option>
  131. </el-select>
  132. <span v-else>{{ row.currency }}</span>
  133. </template>
  134. </avue-crud>
  135. </basic-container>
  136. <el-dialog
  137. title="导入费用"
  138. append-to-body
  139. :visible.sync="feeDialog"
  140. top="5vh"
  141. width="60%"
  142. :close-on-click-modal="false"
  143. @closed="feeClose"
  144. class="el-dialogDeep"
  145. v-dialog-drag
  146. >
  147. <el-row style="height: 0;">
  148. <el-col :span="5">
  149. <div style="margin-top:45px">
  150. <el-scrollbar>
  151. <basic-container>
  152. <avue-tree
  153. :option="treeOption"
  154. :data="treeData"
  155. @node-click="nodeClick"
  156. />
  157. </basic-container>
  158. </el-scrollbar>
  159. </div>
  160. </el-col>
  161. <el-col :span="19">
  162. <avue-crud
  163. :option="option"
  164. :table-loading="loading"
  165. :data="data"
  166. ref="crud"
  167. @refresh-change="refreshChange"
  168. @selection-change="selectionChange"
  169. @current-change="currentChange"
  170. @size-change="sizeChange"
  171. :page.sync="page"
  172. @on-load="onLoad"
  173. :cell-style="cellStyle"
  174. >
  175. </avue-crud>
  176. </el-col>
  177. </el-row>
  178. <span slot="footer" class="dialog-footer">
  179. <el-button @click="feeDialog = false">取 消</el-button>
  180. <el-button
  181. type="primary"
  182. @click="importData"
  183. :disabled="this.selectionList.length == 0"
  184. >
  185. 导入
  186. </el-button>
  187. </span>
  188. </el-dialog>
  189. <crop-dialog ref="cropDialog" @importCorp="importCorp"></crop-dialog>
  190. </div>
  191. </template>
  192. <script>
  193. import feeOption from "./config/feeInfo.json";
  194. import option from "./config/feeList.json";
  195. import { getDeptLazyTree, customerList } from "@/api/basicData/basicFeesDesc";
  196. import { delItem } from "@/api/feeInfo/fee-info";
  197. import { isPercentage, micrometerFormat } from "@/util/validate";
  198. // import customerDialog from "@/components/customer-dialog/main";
  199. import cropDialog from "@/components/crop-dialog/main";
  200. import _ from "lodash";
  201. export default {
  202. name: "feeInfo",
  203. data() {
  204. return {
  205. option: option,
  206. feeOption: {},
  207. feeDialog: false,
  208. treeOption: {
  209. nodeKey: "id",
  210. lazy: true,
  211. treeLoad: function(node, resolve) {
  212. const parentId = node.level === 0 ? 0 : node.data.id;
  213. getDeptLazyTree(parentId).then(res => {
  214. resolve(
  215. res.data.data.map(item => {
  216. return {
  217. ...item,
  218. leaf: !item.hasChildren
  219. };
  220. })
  221. );
  222. });
  223. },
  224. addBtn: false,
  225. menu: false,
  226. size: "small",
  227. props: {
  228. labelText: "标题",
  229. label: "title",
  230. value: "value",
  231. children: "children"
  232. }
  233. },
  234. page: {
  235. pageSize: 10,
  236. currentPage: 1,
  237. total: 0
  238. },
  239. treeDeptId: null,
  240. loading: false,
  241. receivableButton: "primary",
  242. copeWithButton: "",
  243. data: [],
  244. feeData: [],
  245. selectionList: [],
  246. reData: null,
  247. currencyList: []
  248. };
  249. },
  250. props: {
  251. orderFeesList: {
  252. type: Array
  253. },
  254. disabled: {
  255. type: Boolean
  256. },
  257. feeUrl: {
  258. type: String
  259. }
  260. },
  261. filters: {
  262. isPercentage(val) {
  263. return isPercentage(val);
  264. },
  265. micrometerFormat(val) {
  266. return micrometerFormat(val);
  267. }
  268. },
  269. async created() {
  270. this.feeOption = await this.getColumnData(
  271. this.getColumnName(33),
  272. feeOption
  273. );
  274. this.getWorkDicts("currency").then(res => {
  275. this.currencyList = res.data.data;
  276. });
  277. },
  278. components: {
  279. cropDialog
  280. },
  281. methods: {
  282. cellStyle() {
  283. return "padding:0;height:40px;";
  284. },
  285. importCorp(row) {
  286. this.feeData.push({
  287. itemId: null,
  288. corpId: row.id,
  289. corpName: row.name,
  290. feeName: null,
  291. price: null,
  292. unit: null,
  293. quantity: null,
  294. amount: null,
  295. currency: null,
  296. exchangeRate: null,
  297. remarks: null,
  298. $cellEdit: true
  299. });
  300. },
  301. currencyChange(row) {
  302. if (row.currency == "CNY") {
  303. row.exchangeRate = 1;
  304. }
  305. if (row.currency == "USD") {
  306. row.exchangeRate = 6.3843;
  307. }
  308. },
  309. rowDel(row, index) {
  310. console.log(row, index);
  311. this.$confirm("确定删除数据?", {
  312. confirmButtonText: "确定",
  313. cancelButtonText: "取消",
  314. type: "warning"
  315. }).then(() => {
  316. //费用判断是否需要调用删除接口
  317. if (row.id) {
  318. delItem(row.id, this.feeUrl).then(res => {
  319. this.$message({
  320. type: "success",
  321. message: "删除成功!"
  322. });
  323. this.feeData.splice(index, 1);
  324. });
  325. } else {
  326. this.$message({
  327. type: "success",
  328. message: "删除成功!"
  329. });
  330. this.feeData.splice(index, 1);
  331. }
  332. });
  333. },
  334. getCorpData(row) {
  335. this.feeData[row.index].corpName = row.cname;
  336. },
  337. priceChange(row) {
  338. if (!row.price) {
  339. row.price = 0;
  340. } else {
  341. row.amount = _.multiply(row.price, row.quantity).toFixed(2);
  342. }
  343. },
  344. quantityChange(row) {
  345. if (!row.quantity) {
  346. row.quantity = 0;
  347. } else {
  348. row.amount = _.multiply(row.price, row.quantity).toFixed(2);
  349. }
  350. },
  351. rateChange(row) {
  352. row.exchangeRate;
  353. if (row.exchangeRate >= 100) {
  354. row.exchangeRate = 0;
  355. this.$message.error("汇率不能超过100%");
  356. }
  357. },
  358. currentChange(val) {
  359. this.page.currentPage = val;
  360. },
  361. sizeChange(val) {
  362. this.page.currentPage = 1;
  363. this.page.pageSize = val;
  364. },
  365. //刷新
  366. refreshChange() {
  367. this.page.currentPage = 1;
  368. this.onLoad(this.page);
  369. },
  370. //多选
  371. selectionChange(list) {
  372. this.selectionList = list;
  373. },
  374. rePick(row, index) {
  375. this.reData = {
  376. ...row,
  377. index: index
  378. };
  379. this.feeDialog = true;
  380. this.onLoad(this.page);
  381. },
  382. //费用编辑
  383. rowCell(row, index) {
  384. if (row.$cellEdit == true) {
  385. this.$set(row, "$cellEdit", false);
  386. } else {
  387. this.$set(row, "$cellEdit", true);
  388. }
  389. },
  390. //新增
  391. rowAdd() {
  392. this.$refs.cropDialog.init();
  393. },
  394. onLoad(page) {
  395. this.loading = true;
  396. let data = {
  397. size: page.pageSize,
  398. current: page.currentPage,
  399. parentId: 0,
  400. feesTypeId: this.treeDeptId
  401. };
  402. customerList(data).then(res => {
  403. const data = res.data.data;
  404. this.page.total = data.total;
  405. this.data = data.records;
  406. this.loading = false;
  407. if (this.page.total) {
  408. this.option.height = window.innerHeight - 350;
  409. }
  410. });
  411. },
  412. //导入页左费用类型查询
  413. nodeClick(data) {
  414. this.treeDeptId = data.id;
  415. this.page.currentPage = 1;
  416. this.onLoad(this.page);
  417. },
  418. feeClose() {
  419. this.selectionList = [];
  420. this.page = {
  421. pageSize: 10,
  422. currentPage: 1,
  423. total: 0
  424. };
  425. this.treeDeptId = null;
  426. this.loading = false;
  427. this.data = [];
  428. this.reData = null;
  429. },
  430. importData() {
  431. if (this.reData) {
  432. this.selectionList.length;
  433. if (this.selectionList.length != 1) {
  434. return this.$message.error("重新选择的时候只能选择一条数据");
  435. } else {
  436. this.selectionList.forEach(e => {
  437. this.feeData.forEach((item, index) => {
  438. if (index == this.reData.index) {
  439. item.itemId = e.id;
  440. item.corpId = this.reData.corpId;
  441. item.feeName = e.cname;
  442. item.price = this.reData.price;
  443. item.unit = e.unitno;
  444. item.quantity = this.reData.quantity;
  445. item.amount = this.reData.amount;
  446. item.currency = e.fcyno;
  447. item.exchangeRate = this.reData.exchangeRate;
  448. item.remarks = this.reData.remarks;
  449. item.$cellEdit = true;
  450. }
  451. });
  452. });
  453. }
  454. } else {
  455. this.selectionList.forEach(e => {
  456. this.feeData.push({
  457. itemId: e.id,
  458. corpId: null,
  459. feeName: e.cname,
  460. price: 0,
  461. unit: e.unitno,
  462. quantity: 0,
  463. amount: 0,
  464. currency: e.fcyno,
  465. exchangeRate: null,
  466. remarks: null,
  467. $cellEdit: true
  468. });
  469. });
  470. }
  471. this.feeDialog = false;
  472. },
  473. submitData() {
  474. return this.feeData;
  475. },
  476. //应收
  477. receivable() {
  478. //切换
  479. this.receivableButton = "primary";
  480. this.copeWithButton = "";
  481. this.selectionList;
  482. },
  483. //应付
  484. copeWith() {
  485. this.receivableButton = "";
  486. this.copeWithButton = "primary";
  487. },
  488. summaryMethod({ columns, data }) {
  489. const sums = [];
  490. if (columns.length > 0) {
  491. columns.forEach((item, index) => {
  492. sums[0] = "合计";
  493. if (item.property == "quantity" || item.property == "amount") {
  494. let qtySum = 0;
  495. let amountSum = 0;
  496. data.forEach(e => {
  497. qtySum = _.add(qtySum, Number(e.quantity));
  498. amountSum = _.add(amountSum, Number(e.amount));
  499. });
  500. //数量总计
  501. if (item.property == "quantity") {
  502. sums[index] = qtySum ? qtySum.toFixed(2) : "0.00";
  503. }
  504. //金额总计
  505. if (item.property == "amount") {
  506. sums[index] = micrometerFormat(amountSum);
  507. }
  508. }
  509. });
  510. }
  511. return sums;
  512. },
  513. async saveColumn() {
  514. const inSave = await this.saveColumnData(
  515. this.getColumnName(33),
  516. this.feeOption
  517. );
  518. if (inSave) {
  519. this.$message.success("保存成功");
  520. //关闭窗口
  521. this.$refs.feeCrud.$refs.dialogColumn.columnBox = false;
  522. }
  523. }
  524. },
  525. watch: {
  526. orderFeesList: function(rows) {
  527. this.feeData = rows ? rows : [];
  528. }
  529. }
  530. };
  531. </script>
  532. <style lang="scss" scoped></style>