main.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. console.log(this.partreData);
  208. if (this.partreData) {
  209. rows.forEach(e => {
  210. this.data.forEach((item, index) => {
  211. if (index == this.partreData.index) {
  212. item.goodId = e.itemId;
  213. item.goodTypeId = e.goodTypeId;
  214. item.goodTypeName = e.goodsTypeName;
  215. item.corpId = e.corpId;
  216. item.corpName = e.corpName;
  217. item.goodName = e.cname;
  218. item.price = e.purchaseAmount;
  219. item.goodNumber = this.partreData.goodNumber;
  220. item.amout = _.multiply(
  221. Number(
  222. this.partreData.goodNumber ? this.partreData.goodNumber : 0
  223. ),
  224. Number(e.purchaseAmount ? e.purchaseAmount : 0)
  225. );
  226. item.$cellEdit = true;
  227. }
  228. });
  229. });
  230. } else {
  231. rows.forEach(e => {
  232. this.data.push({
  233. goodId: e.itemId,
  234. goodTypeId: e.goodTypeId,
  235. goodTypeName: e.goodsTypeName,
  236. corpId: e.corpId,
  237. corpName: e.corpName,
  238. goodName: e.cname,
  239. price: e.purchaseAmount,
  240. goodNumber: 1,
  241. amout: e.purchaseAmount,
  242. $cellEdit: true
  243. });
  244. });
  245. }
  246. },
  247. sizeChange(val) {
  248. this.page.pageSize = val;
  249. this.getList();
  250. },
  251. currentChange(val) {
  252. this.page.currentPage = val;
  253. this.getList();
  254. },
  255. refreshChange() {
  256. this.getList(this.page, this.search);
  257. },
  258. saveColumn(row, column) {
  259. console.log(row, column);
  260. },
  261. summaryMethod({ columns, data }) {
  262. const sums = [];
  263. if (columns.length > 0) {
  264. columns.forEach((item, index) => {
  265. sums[0] = "合计";
  266. if (item.property == "goodNumber" || item.property == "amout") {
  267. let qtySum = 0;
  268. let amountSum = 0;
  269. this.amoutSum = 0;
  270. data.forEach(e => {
  271. qtySum = _.add(qtySum, Number(e.goodNumber));
  272. amountSum = _.add(amountSum, Number(e.amout));
  273. this.amoutSum = Number(amountSum).toFixed(2);
  274. });
  275. //数量总计
  276. if (item.property == "goodNumber") {
  277. sums[index] = qtySum ? qtySum.toFixed(2) : "0.00";
  278. }
  279. //金额总计
  280. if (item.property == "amout") {
  281. sums[index] = micrometerFormat(amountSum);
  282. }
  283. }
  284. });
  285. }
  286. return sums;
  287. }
  288. },
  289. watch: {
  290. partList: function(arr) {
  291. this.data = this.deepClone(arr);
  292. }
  293. }
  294. };
  295. </script>
  296. <style scoped lang="scss"></style>