main.vue 8.2 KB

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