main.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <div>
  3. <el-dialog
  4. title="配件信息"
  5. :visible.sync="partVisible"
  6. width="60%"
  7. append-to-body
  8. @closed="closed"
  9. v-dialog-drag
  10. >
  11. <span>
  12. <avue-crud
  13. ref="crud"
  14. :data="data"
  15. :option="tableOption"
  16. @refresh-change="refreshChange"
  17. @saveColumn="saveColumn"
  18. @selection-change="selectionChange"
  19. :summary-method="summaryMethod"
  20. >
  21. <template slot="menuLeft">
  22. <el-button
  23. type="primary"
  24. icon="el-icon-plus"
  25. size="small"
  26. @click.stop="rowAdd"
  27. >选择</el-button
  28. >
  29. </template>
  30. <template slot="menu" slot-scope="{ row, index }">
  31. <el-button type="text" size="small" @click.stop="rowDel(row, index)"
  32. >删除</el-button
  33. >
  34. </template>
  35. <template slot="goodName" slot-scope="{ row, index }">
  36. <el-button
  37. size="small"
  38. type="text"
  39. style="padding:4px 10px;float:left"
  40. @click="rePick(row.index)"
  41. >选择</el-button
  42. >
  43. <span> {{ row.goodName }}</span>
  44. </template>
  45. <template slot="goodNumber" slot-scope="{ row }">
  46. <el-input
  47. v-if="row.$cellEdit"
  48. v-model="row.goodNumber"
  49. size="small"
  50. oninput='this.value=this.value.replace(/[^(\d.)]/g,"").replace(/^(\d+)\.(\d\d).*$/, "$1.$2")'
  51. @change="priceChange(row)"
  52. ></el-input>
  53. <span v-else>{{ row.goodNumber }}</span>
  54. </template>
  55. <template slot="price" slot-scope="{ row }">
  56. <el-input
  57. v-if="row.$cellEdit"
  58. v-model="row.price"
  59. size="small"
  60. oninput='this.value=this.value.replace(/[^(\d.)]/g,"").replace(/^(\d+)\.(\d\d).*$/, "$1.$2")'
  61. @change="priceChange(row)"
  62. ></el-input>
  63. <span v-else>{{ row.price | micrometerFormat }}</span>
  64. </template>
  65. </avue-crud>
  66. </span>
  67. <span slot="footer" class="dialog-footer">
  68. <el-button @click="partVisible = false">取 消</el-button>
  69. <el-button type="primary" @click="importPart">确 定</el-button>
  70. </span>
  71. </el-dialog>
  72. </div>
  73. </template>
  74. <script>
  75. import option from "./configuration/mainList.json";
  76. import { micrometerFormat } from "@/util/validate";
  77. import _ from "lodash";
  78. export default {
  79. data() {
  80. return {
  81. loading: true,
  82. data: [],
  83. tableOption: option,
  84. height: window.innerHeight - 500,
  85. page: {
  86. currentPage: 1,
  87. total: 0,
  88. pageSize: 10
  89. },
  90. partVisible: false,
  91. selectionList: [],
  92. goodsIndex: null,
  93. amoutSum:0
  94. };
  95. },
  96. props: {
  97. partList: Array
  98. },
  99. filters: {
  100. micrometerFormat(val) {
  101. return micrometerFormat(val);
  102. }
  103. },
  104. created() {},
  105. methods: {
  106. rePick(row,index){
  107. this.$message({
  108. type: "warning",
  109. message: "正在开发中!"
  110. });
  111. },
  112. priceChange(row) {
  113. row.amout = _.multiply(
  114. Number(row.goodNumber ? row.goodNumber : 0),
  115. Number(row.price ? row.price : 0)
  116. );
  117. },
  118. rowDel(row, index) {
  119. this.$message({
  120. type: "success",
  121. message: "删除成功!"
  122. });
  123. this.data.splice(index, 1);
  124. },
  125. rowAdd() {
  126. this.$emit("partOpen", true);
  127. },
  128. init(rows, index) {
  129. this.data = rows;
  130. this.goodsIndex = index;
  131. this.partVisible = true;
  132. },
  133. closed() {
  134. this.amoutSum=0
  135. this.$refs.crud.toggleSelection();
  136. this.$emit("partClosed");
  137. },
  138. selectionChange(list) {
  139. this.selectionList = list;
  140. },
  141. importPart() {
  142. this.$emit("importPart", this.data,this.amoutSum, this.goodsIndex);
  143. this.partVisible = false;
  144. },
  145. sizeChange(val) {
  146. this.page.pageSize = val;
  147. this.getList();
  148. },
  149. currentChange(val) {
  150. this.page.currentPage = val;
  151. this.getList();
  152. },
  153. refreshChange() {
  154. this.getList(this.page, this.search);
  155. },
  156. saveColumn(row, column) {
  157. console.log(row, column);
  158. },
  159. summaryMethod({ columns, data }) {
  160. const sums = [];
  161. if (columns.length > 0) {
  162. columns.forEach((item, index) => {
  163. sums[0] = "合计";
  164. if (
  165. item.property == "goodNumber" ||
  166. item.property == "amout"
  167. ) {
  168. let qtySum = 0;
  169. let amountSum = 0;
  170. this.amoutSum=0
  171. data.forEach(e => {
  172. qtySum = _.add(qtySum, Number(e.goodNumber));
  173. amountSum = _.add(amountSum, Number(e.amout));
  174. this.amoutSum=amountSum
  175. });
  176. //数量总计
  177. if (item.property == "goodNumber") {
  178. sums[index] = qtySum ? qtySum.toFixed(2) : "0.00";
  179. }
  180. //金额总计
  181. if (item.property == "amout") {
  182. sums[index] = micrometerFormat(amountSum);
  183. }
  184. }
  185. });
  186. }
  187. return sums;
  188. }
  189. },
  190. watch: {
  191. partList: function(arr) {
  192. console.log(arr);
  193. this.data = arr;
  194. }
  195. }
  196. };
  197. </script>
  198. <style scoped lang="scss"></style>