index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <basic-container>
  3. <avue-crud
  4. ref="crud"
  5. :option="option"
  6. :data="data"
  7. :page.sync="page"
  8. @search-change="searchChange"
  9. :search.sync="search"
  10. @on-load="onLoad"
  11. @row-update="rowUpdate">
  12. <template slot-scope="{row,index}" slot="menu">
  13. <el-button
  14. type="text"
  15. size="small"
  16. @click="rowCell(row,index)"
  17. >{{ row.$cellEdit ? '保存' : '修改' }}
  18. </el-button>
  19. <el-button
  20. type="text"
  21. size="small"
  22. @click="deletePrice(row,index)"
  23. >删除
  24. </el-button>
  25. </template>
  26. <template slot="menuLeft">
  27. <el-button
  28. type="primary"
  29. size="small"
  30. icon="el-icon-plus"
  31. @click="excelBox = !excelBox"
  32. >导入
  33. </el-button>
  34. <el-button
  35. type="success"
  36. icon="el-icon-upload2"
  37. size="small"
  38. @click="derivation()"
  39. >下载模板
  40. </el-button>
  41. <el-button
  42. type="info"
  43. icon="el-icon-printer"
  44. size="small"
  45. >报 表
  46. </el-button>
  47. </template>
  48. </avue-crud>
  49. <el-dialog title="导入价格"
  50. append-to-body
  51. :visible.sync="excelBox"
  52. width="555px">
  53. <avue-form :option="excelOption" v-model="excelForm" :upload-after="uploadAfter"/>
  54. </el-dialog>
  55. </basic-container>
  56. </template>
  57. <script>
  58. import option from "./configuration/mainList.json"
  59. import {deleteTemplate,customerList,typeSave} from "@/api/basicData/inventoryAccount"
  60. import {getToken} from "@/util/auth";
  61. import { defaultDate } from "@/util/date";
  62. export default {
  63. data() {
  64. return {
  65. data: [],
  66. search:{},
  67. excelForm: {},
  68. excelOption: {
  69. submitBtn: false,
  70. emptyBtn: false,
  71. column: [
  72. {
  73. label: '导入数据',
  74. prop: 'excelFile',
  75. type: 'upload',
  76. drag: true,
  77. loadText: '导入数据中,请稍等',
  78. span: 24,
  79. propsHttp: {
  80. res: 'data'
  81. },
  82. tip: '请上传 .xls,.xlsx 标准格式文件',
  83. action: "/api/blade-stock/stockgoods/import-price"
  84. }
  85. ]
  86. },
  87. excelBox: false,
  88. option: option,
  89. page: {
  90. pageSize: 10,
  91. pagerCount: 5,
  92. total: 0,
  93. }
  94. }
  95. },
  96. created() {
  97. this.search.createTime = defaultDate(1)
  98. console.log(this.search)
  99. let i = 0;
  100. this.option.column.forEach(item => {
  101. if (item.search) i++
  102. })
  103. if (i % 3 !== 0){
  104. const num = 3 - Number(i % 3)
  105. this.option.searchMenuSpan = num * 8;
  106. this.option.searchMenuPosition = "right";
  107. }
  108. },
  109. methods: {
  110. derivation() {
  111. this.$confirm("是否下载模板?", "提示", {
  112. confirmButtonText: "确定",
  113. cancelButtonText: "取消",
  114. type: "warning"
  115. }).then(() => {
  116. window.open(`/api/blade-stock/stockgoods/export-template?${this.website.tokenHeader}=${getToken()}`);
  117. });
  118. },
  119. uploadAfter(res, done, loading, column) {
  120. window.console.log(column);
  121. this.excelBox = false;
  122. this.page.currentPage = 1;
  123. this.onLoad(this.page);
  124. loading()
  125. done();
  126. },
  127. rowCell(row, index) {
  128. this.$refs.crud.rowCell(row, index)
  129. },
  130. deletePrice(row,index){
  131. if (row.id){
  132. this.$confirm("确定将选择数据删除?", {
  133. confirmButtonText: "确定",
  134. cancelButtonText: "取消",
  135. type: "warning"
  136. }).then(() => {
  137. return deleteTemplate(row.id);
  138. }).then(() => {
  139. this.$message({
  140. type: "success",
  141. message: "操作成功!"
  142. });
  143. this.page.currentPage = 1;
  144. this.onLoad(this.page);
  145. })
  146. }
  147. },
  148. //点击搜索按钮触发
  149. searchChange(params, done) {
  150. if (params.createTime) {
  151. params.createStartTime = params.createTime[0]+ " " + "00:00:00"
  152. params.createEndTime = params.createTime[1]+ " " + "23:59:59"
  153. delete params.createTime;
  154. }
  155. this.page.currentPage = 1;
  156. this.onLoad(this.page, params);
  157. done()
  158. },
  159. onLoad(page, params = {}) {
  160. if (this.search.createTime && this.search.createTime.length > 0) {
  161. params = {
  162. ...params,
  163. createStartTime: this.search.createTime[0]+ " " + "00:00:00",
  164. createEndTime: this.search.createTime[1]+ " " + "23:59:59",
  165. }
  166. delete params.createTime;
  167. }
  168. let queryParams = Object.assign({}, params, {
  169. size: page.pageSize,
  170. current: page.currentPage,
  171. })
  172. customerList(queryParams).then(res => {
  173. this.data = res.data.data.records
  174. this.page.total = res.data.data.total
  175. })
  176. },
  177. rowUpdate(form, index, done) {
  178. console.log(form)
  179. typeSave(form).then(res => {
  180. this.$message({type: "success", message: form.id ? "修改成功!" : "新增成功!"});
  181. // this.page.currentPage = 1;
  182. // this.onLoad(this.page);
  183. //成功关闭此页面回到列表页
  184. // this.backToList()
  185. })
  186. done()
  187. }
  188. }
  189. }
  190. </script>