productBatch.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <basic-container>
  3. <avue-crud :option="option"
  4. v-model:search="search"
  5. v-model:page="page"
  6. v-model="form"
  7. :table-loading="loading"
  8. :data="data"
  9. :permission="permissionList"
  10. :before-open="beforeOpen"
  11. ref="crud"
  12. @row-update="rowUpdate"
  13. @row-save="rowSave"
  14. @row-del="rowDel"
  15. @search-change="searchChange"
  16. @search-reset="searchReset"
  17. @selection-change="selectionChange"
  18. @current-change="currentChange"
  19. @size-change="sizeChange"
  20. @refresh-change="refreshChange"
  21. @on-load="onLoad">
  22. <template #menu-left>
  23. <!-- <el-button type="danger"
  24. icon="el-icon-delete"
  25. plain
  26. v-if="permission.productBatch_delete"
  27. @click="handleDelete">删 除
  28. </el-button> -->
  29. <!-- <el-button type="warning"
  30. plain
  31. icon="el-icon-download"
  32. @click="handleExport">导 出
  33. </el-button> -->
  34. </template>
  35. <template #details-form>
  36. <avue-crud :option="optionSub" ref="detailCrud"
  37. :data="form.details">
  38. <!-- <template slot-scope="{row,index}" slot="menu">
  39. <el-button v-if="row.$cellEdit"
  40. text
  41. icon="el-icon-cancel"
  42. type="primary"
  43. @click="rowDelSub(index)">删除</el-button>
  44. </template>
  45. <template slot-scope="{row}" slot="tradeTotalPriceForm">
  46. <span>{{(row.tradeUnitPrice * row.tradeNum)? (row.tradeUnitPrice * row.tradeNum).toFixed(2):0 }}</span>
  47. </template> -->
  48. <!-- <template slot-scope="{row,index}" slot="productIdForm">
  49. <el-button v-if="row.$cellEdit"
  50. text
  51. icon="el-icon-cancel"
  52. type="primary"
  53. @click="rowDelSub(index)">删除</el-button>
  54. </template> -->
  55. </avue-crud>
  56. </template>
  57. </avue-crud>
  58. </basic-container>
  59. </template>
  60. <script>
  61. import {getList, getDetail, add, update, remove} from "@/api/productBatch/productBatch";
  62. import option from "@/option/productBatch/productBatch";
  63. import optionSub from "@/option/productBatch/product.js";
  64. import {mapGetters} from "vuex";
  65. import {exportBlob} from "@/api/common";
  66. import {getToken} from '@/utils/auth';
  67. import {downloadXls} from "@/utils/util";
  68. import {dateNow} from "@/utils/date";
  69. import NProgress from 'nprogress';
  70. import 'nprogress/nprogress.css';
  71. export default {
  72. data() {
  73. return {
  74. form: {},
  75. query: {},
  76. search: {},
  77. loading: true,
  78. page: {
  79. pageSize: 10,
  80. currentPage: 1,
  81. total: 0
  82. },
  83. selectionList: [],
  84. option: option,
  85. data: [],
  86. optionSub: optionSub
  87. };
  88. },
  89. computed: {
  90. ...mapGetters(["permission"]),
  91. permissionList() {
  92. return {
  93. addBtn: this.validData(this.permission.productBatch_add, false),
  94. viewBtn: this.validData(this.permission.productBatch_view, false),
  95. delBtn: this.validData(this.permission.productBatch_delete, false),
  96. editBtn: this.validData(this.permission.productBatch_edit, false)
  97. };
  98. },
  99. ids() {
  100. let ids = [];
  101. this.selectionList.forEach(ele => {
  102. ids.push(ele.id);
  103. });
  104. return ids.join(",");
  105. }
  106. },
  107. methods: {
  108. rowSave(row, done, loading) {
  109. this.$refs.detailCrud.$refs.cellForm.validate((valid) => {
  110. if (valid) {
  111. add(row).then(() => {
  112. this.onLoad(this.page);
  113. this.$message({
  114. type: "success",
  115. message: "操作成功!"
  116. });
  117. done();
  118. }, error => {
  119. loading();
  120. window.console.log(error);
  121. });
  122. } else {
  123. loading();
  124. return false;
  125. }
  126. })
  127. },
  128. rowUpdate(row, index, done, loading) {
  129. update(row).then(() => {
  130. this.onLoad(this.page);
  131. this.$message({
  132. type: "success",
  133. message: "操作成功!"
  134. });
  135. done();
  136. }, error => {
  137. loading();
  138. console.log(error);
  139. });
  140. },
  141. rowDel(row) {
  142. this.$confirm("确定将选择数据删除?", {
  143. confirmButtonText: "确定",
  144. cancelButtonText: "取消",
  145. type: "warning"
  146. })
  147. .then(() => {
  148. return remove(row.id);
  149. })
  150. .then(() => {
  151. this.onLoad(this.page);
  152. this.$message({
  153. type: "success",
  154. message: "操作成功!"
  155. });
  156. });
  157. },
  158. handleDelete() {
  159. if (this.selectionList.length === 0) {
  160. this.$message.warning("请选择至少一条数据");
  161. return;
  162. }
  163. this.$confirm("确定将选择数据删除?", {
  164. confirmButtonText: "确定",
  165. cancelButtonText: "取消",
  166. type: "warning"
  167. })
  168. .then(() => {
  169. return remove(this.ids);
  170. })
  171. .then(() => {
  172. this.onLoad(this.page);
  173. this.$message({
  174. type: "success",
  175. message: "操作成功!"
  176. });
  177. this.$refs.crud.toggleSelection();
  178. });
  179. },
  180. handleExport() {
  181. let downloadUrl = `/pl-productBatch/productBatch/export-productBatch?${this.website.tokenHeader}=${getToken()}`;
  182. const {
  183. batchNo,
  184. productName,
  185. productModel,
  186. } = this.query;
  187. let values = {
  188. batchNo_: batchNo,
  189. productName_: productName,
  190. productModel_: productModel,
  191. };
  192. this.$confirm("是否导出数据?", "提示", {
  193. confirmButtonText: "确定",
  194. cancelButtonText: "取消",
  195. type: "warning"
  196. }).then(() => {
  197. NProgress.start();
  198. exportBlob(downloadUrl, values).then(res => {
  199. downloadXls(res.data, `产品入库批次表${dateNow()}.xlsx`);
  200. NProgress.done();
  201. })
  202. });
  203. },
  204. beforeOpen(done, type) {
  205. if (["edit", "view"].includes(type)) {
  206. getDetail(this.form.id).then(res => {
  207. this.form = res.data.data;
  208. });
  209. }
  210. if (["add"].includes(type)) {
  211. if(!this.form.details){
  212. this.form.details = [{"$cellEdit":true},{"$cellEdit":true},{"$cellEdit":true},{"$cellEdit":true},{"$cellEdit":true},{"$cellEdit":true},{"$cellEdit":true}]
  213. }
  214. }
  215. done();
  216. },
  217. searchReset() {
  218. this.query = {};
  219. this.onLoad(this.page);
  220. },
  221. searchChange(params, done) {
  222. this.query = params;
  223. this.page.currentPage = 1;
  224. this.onLoad(this.page, params);
  225. done();
  226. },
  227. selectionChange(list) {
  228. this.selectionList = list;
  229. },
  230. selectionClear() {
  231. this.selectionList = [];
  232. this.$refs.crud.toggleSelection();
  233. },
  234. currentChange(currentPage){
  235. this.page.currentPage = currentPage;
  236. },
  237. sizeChange(pageSize){
  238. this.page.pageSize = pageSize;
  239. },
  240. refreshChange() {
  241. this.onLoad(this.page, this.query);
  242. },
  243. onLoad(page, params = {}) {
  244. this.loading = true;
  245. const {
  246. batchNo,
  247. productName,
  248. productModel,
  249. } = this.query;
  250. let values = {
  251. batchNo_: batchNo,
  252. productName_: productName,
  253. productModel_: productModel,
  254. };
  255. getList(page.currentPage, page.pageSize, values).then(res => {
  256. const data = res.data.data;
  257. this.page.total = data.total;
  258. this.data = data.records;
  259. this.loading = false;
  260. this.selectionClear();
  261. });
  262. }
  263. }
  264. };
  265. </script>
  266. <style>
  267. </style>