main.vue 13 KB

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