index.vue 5.4 KB

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