main.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <div>
  3. <el-dialog
  4. title="配件信息"
  5. :visible.sync="partVisible"
  6. width="80%"
  7. top="5vh"
  8. append-to-body
  9. @closed="closed"
  10. class="el-dialogDeep"
  11. :close-on-click-modal="false"
  12. v-dialog-drag
  13. >
  14. <span>
  15. <avue-crud
  16. ref="crud"
  17. :data="data"
  18. :option="tableOption"
  19. @refresh-change="refreshChange"
  20. @saveColumn="saveColumn"
  21. @selection-change="selectionChange"
  22. :summary-method="summaryMethod"
  23. :cell-style="cellStyle"
  24. >
  25. <template slot="menuLeft">
  26. <el-button
  27. type="primary"
  28. icon="el-icon-plus"
  29. size="small"
  30. @click.stop="rowAdd"
  31. >选择</el-button
  32. >
  33. </template>
  34. <template slot="menu" slot-scope="{ row, index }">
  35. <el-button
  36. type="text"
  37. size="small"
  38. icon="el-icon-edit"
  39. @click.stop="rowEdit(row, index)"
  40. >修改</el-button
  41. >
  42. <el-button
  43. type="text"
  44. size="small"
  45. @click.stop="rowDel(row, index)"
  46. icon="el-icon-delete"
  47. >删除</el-button
  48. >
  49. </template>
  50. <template slot="goodName" slot-scope="{ row, index }">
  51. <el-button
  52. size="small"
  53. type="text"
  54. style="padding:4px 10px;float:left"
  55. @click="rePick(row, index)"
  56. >选择</el-button
  57. >
  58. <span> {{ row.goodName }}</span>
  59. </template>
  60. <template slot="goodNumber" slot-scope="{ row }">
  61. <el-input
  62. v-if="row.$cellEdit"
  63. v-model="row.goodNumber"
  64. size="small"
  65. oninput='this.value=this.value.replace(/[^(\d.)]/g,"").replace(/^(\d+)\.(\d\d).*$/, "$1.$2")'
  66. @change="priceChange(row)"
  67. ></el-input>
  68. <span v-else>{{ row.goodNumber }}</span>
  69. </template>
  70. <template slot="price" slot-scope="{ row }">
  71. <span>{{ row.price | micrometerFormat }}</span>
  72. </template>
  73. <template slot="corpId" slot-scope="{ row }">
  74. <span>{{ row.corpName }}</span>
  75. </template>
  76. </avue-crud>
  77. </span>
  78. <span slot="footer" class="dialog-footer">
  79. <el-button @click="partVisible = false">取 消</el-button>
  80. <el-button type="primary" @click="importPart">确 定</el-button>
  81. </span>
  82. </el-dialog>
  83. <price-library ref="library" @librayToPart="librayToPart" />
  84. </div>
  85. </template>
  86. <script>
  87. import option from "./configuration/mainList.json";
  88. import { micrometerFormat } from "@/util/validate";
  89. import { costCal } from "@/util/calculate";
  90. import priceLibrary from "@/components/price-Library/main";
  91. import { delItem } from "@/api/exportTrade/part";
  92. import _ from "lodash";
  93. export default {
  94. data() {
  95. return {
  96. loading: true,
  97. data: [],
  98. tableOption: option,
  99. page: {
  100. currentPage: 1,
  101. total: 0,
  102. pageSize: 10
  103. },
  104. partVisible: false,
  105. selectionList: [],
  106. goodsIndex: null,
  107. amoutSum: 0,
  108. partreData: null
  109. };
  110. },
  111. components: {
  112. priceLibrary
  113. },
  114. props: {
  115. partList: Array
  116. },
  117. filters: {
  118. micrometerFormat(val) {
  119. return micrometerFormat(val);
  120. }
  121. },
  122. created() {
  123. this.tableOption.height = window.innerHeight - 350;
  124. },
  125. methods: {
  126. cellStyle() {
  127. return "padding:0;height:40px;";
  128. },
  129. rePick(row, index) {
  130. this.partreData = {
  131. ...row,
  132. index: index
  133. };
  134. this.$refs.library.init(true, this.partreData);
  135. },
  136. rowCorpData(row) {
  137. this.data[row.index].corpName = row.cname;
  138. },
  139. priceChange(row) {
  140. row.amout = Number(
  141. _.multiply(
  142. Number(row.goodNumber ? row.goodNumber : 0),
  143. Number(row.price ? row.price : 0)
  144. )
  145. ).toFixed(2);
  146. },
  147. rowDel(row, index) {
  148. this.$confirm("确定删除数据?", {
  149. confirmButtonText: "确定",
  150. cancelButtonText: "取消",
  151. type: "warning"
  152. }).then(() => {
  153. if (row.id) {
  154. delItem(row.id)
  155. .then(res => {
  156. this.$message({
  157. type: "success",
  158. message: "删除成功!"
  159. });
  160. this.data.splice(index, 1);
  161. })
  162. .finally(() => {
  163. this.$emit(
  164. "importPart",
  165. this.data,
  166. this.amoutSum,
  167. this.goodsIndex
  168. );
  169. });
  170. } else {
  171. this.$message({
  172. type: "success",
  173. message: "删除成功!"
  174. });
  175. this.data.splice(index, 1);
  176. }
  177. });
  178. },
  179. rowEdit(row, index) {
  180. if (row.$cellEdit == true) {
  181. this.$set(row, "$cellEdit", false);
  182. } else {
  183. this.$set(row, "$cellEdit", true);
  184. }
  185. },
  186. rowAdd() {
  187. this.$refs.library.init(true);
  188. },
  189. init(index) {
  190. // this.data = rows;
  191. this.goodsIndex = index;
  192. this.partVisible = true;
  193. },
  194. closed() {
  195. this.amoutSum = 0;
  196. this.partreData = null;
  197. this.$refs.crud.toggleSelection();
  198. this.$emit("partClosed");
  199. },
  200. selectionChange(list) {
  201. this.selectionList = list;
  202. },
  203. importPart() {
  204. this.$emit("importPart", this.data, this.amoutSum, this.goodsIndex);
  205. this.partVisible = false;
  206. },
  207. librayToPart(rows, partreData) {
  208. this.partreData = partreData;
  209. if (this.partreData) {
  210. rows.forEach(e => {
  211. this.data.forEach((item, index) => {
  212. if (index == this.partreData.index) {
  213. item.goodId = e.itemId;
  214. item.goodTypeId = e.goodTypeId;
  215. item.goodTypeName = e.goodsTypeName;
  216. item.corpId = e.corpId;
  217. item.corpName = e.corpCode;
  218. item.goodName = e.cname;
  219. item.ename = e.ename;
  220. item.price = e.purchaseAmount;
  221. item.partsCost = costCal(e.price,e.taxRate);
  222. item.goodNumber = this.partreData.goodNumber;
  223. item.amout = _.multiply(
  224. Number(
  225. this.partreData.goodNumber ? this.partreData.goodNumber : 0
  226. ),
  227. Number(e.purchaseAmount ? e.purchaseAmount : 0)
  228. );
  229. item.$cellEdit = true;
  230. }
  231. });
  232. });
  233. } else {
  234. rows.forEach(e => {
  235. this.data.push({
  236. goodId: e.itemId,
  237. goodTypeId: e.goodTypeId,
  238. goodTypeName: e.goodsTypeName,
  239. ename: e.ename,
  240. corpId: e.corpId,
  241. corpName: e.corpCode,
  242. goodName: e.cname,
  243. price: e.purchaseAmount,
  244. goodNumber: 1,
  245. amout: e.purchaseAmount,
  246. partsCost: costCal(e.price,e.taxRate),
  247. $cellEdit: true
  248. });
  249. });
  250. }
  251. },
  252. sizeChange(val) {
  253. this.page.pageSize = val;
  254. this.getList();
  255. },
  256. currentChange(val) {
  257. this.page.currentPage = val;
  258. this.getList();
  259. },
  260. refreshChange() {
  261. this.getList(this.page, this.search);
  262. },
  263. saveColumn(row, column) {
  264. console.log(row, column);
  265. },
  266. summaryMethod({ columns, data }) {
  267. const sums = [];
  268. if (columns.length > 0) {
  269. columns.forEach((item, index) => {
  270. sums[0] = "合计";
  271. if (item.property == "goodNumber" || item.property == "amout") {
  272. let qtySum = 0;
  273. let amountSum = 0;
  274. this.amoutSum = 0;
  275. data.forEach(e => {
  276. qtySum = _.add(qtySum, Number(e.goodNumber));
  277. amountSum = _.add(amountSum, Number(e.amout));
  278. this.amoutSum = Number(amountSum).toFixed(2);
  279. });
  280. //数量总计
  281. if (item.property == "goodNumber") {
  282. sums[index] = qtySum ? qtySum.toFixed(2) : "0.00";
  283. }
  284. //金额总计
  285. if (item.property == "amout") {
  286. sums[index] = micrometerFormat(amountSum);
  287. }
  288. }
  289. });
  290. }
  291. return sums;
  292. }
  293. },
  294. watch: {
  295. partList: function(arr) {
  296. this.data = this.deepClone(arr);
  297. }
  298. }
  299. };
  300. </script>
  301. <style scoped lang="scss"></style>