main.vue 10.0 KB

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