index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <script>
  2. import { dicts } from "./dicts";
  3. import useColumns from "./columns";
  4. import { LIST, exportAll } from "@/api/business/purchase/catalogue";
  5. export default {
  6. name: "PuchaseCatalogue",
  7. dicts: dicts,
  8. components: {
  9. SeeButton: () => import("./see/index.vue"),
  10. InvButton: () => import("./invalid/index.vue"),
  11. EnaButton: () => import("./enable/index.vue"),
  12. ExpButton: () => import("./export/index.vue"),
  13. ElSuperTable: () => import("@/components/super-table/index.vue"),
  14. ElSuperSearch: () => import("@/components/super-search/index.vue"),
  15. },
  16. data() {
  17. const { TableColumns, SearchColumns } = useColumns();
  18. const params = this.$init.params(SearchColumns);
  19. return {
  20. size: "mini",
  21. loading: false,
  22. params: params,
  23. tableData: [],
  24. selectData: [],
  25. TableColumns: TableColumns,
  26. SearchColumns: SearchColumns,
  27. page: { pageNum: 1, pageSize: 20, total: 0 },
  28. };
  29. },
  30. computed: {},
  31. created() {
  32. this.useQuery(this.params, this.page);
  33. },
  34. methods: {
  35. //
  36. async fetchList(prop, page) {
  37. try {
  38. this.loading = true;
  39. const { pageNum, pageSize } = page;
  40. const { code, rows, total } = await LIST(
  41. { ...prop },
  42. { pageNum, pageSize }
  43. );
  44. if (code === 200) {
  45. this.tableData = rows.map((item, index) => ({
  46. ...item,
  47. $index: (pageNum - 1) * pageSize + index + 1,
  48. }));
  49. this.page.total = total;
  50. }
  51. } catch (err) {
  52. // catch
  53. } finally {
  54. // finally
  55. this.loading = false;
  56. }
  57. },
  58. // 查 询
  59. useQuery(prop, page) {
  60. const { invalid, createTime } = prop;
  61. const [invalidStart, invalidEnd] = invalid || [];
  62. const [createTimeStart, createTimeEnd] = createTime || [];
  63. this.fetchList(
  64. {
  65. ...prop,
  66. invalidStart,
  67. invalidEnd,
  68. createTimeStart,
  69. createTimeEnd,
  70. invalid: null,
  71. createTime: null,
  72. },
  73. page
  74. );
  75. },
  76. // 重 置
  77. useReset() {
  78. this.page.pageNum = 1;
  79. this.page.pageSize = 10;
  80. this.params = this.$init.params(this.SearchColumns);
  81. this.useQuery(this.params, this.page);
  82. },
  83. // 选 择
  84. useSelect(prop) {
  85. this.selectData = prop;
  86. },
  87. // 明 细
  88. async useSee(prop) {
  89. const { open } = this.$refs.SeeButton;
  90. await open([prop]);
  91. },
  92. // 导出全部
  93. exportAll() {
  94. this.$modal.loading("正在导出数据,请稍后...");
  95. exportAll().then(res => {
  96. this.$modal.closeLoading();
  97. const blob = new Blob([res], {
  98. type: "application/vnd.ms-excel;charset=UTF-8",
  99. });// 创建一个类文件对象:Blob对象表示一个不可变的、原始数据的类文件对象
  100. const downloadElement = document.createElement("a"); //创建a标签
  101. const href = window.URL.createObjectURL(blob); // 创建下载的链接
  102. // var temp = res.headers["content-disposition"];
  103. // var fileName = decodeURIComponent(temp.split("filename=")[1]); // 中文需要转码 (前端乱码)
  104. // var name = fileName.split(";")[0]; //切割成文件名
  105. downloadElement.href = href; //下载地址
  106. downloadElement.download = '价格目录全部导出' + this.parseTime(new Date().getTime()) + ".xlsx";
  107. document.body.appendChild(downloadElement);
  108. downloadElement.click(); // 点击下载
  109. document.body.removeChild(downloadElement); // 下载完成移除元素
  110. window.URL.revokeObjectURL(href); // 释放blob对象
  111. }).catch(err => {
  112. this.$modal.closeLoading();
  113. })
  114. },
  115. },
  116. };
  117. </script>
  118. <template>
  119. <el-card
  120. v-loading="loading"
  121. :body-style="{
  122. height: '100%',
  123. padding: 0,
  124. display: 'flex',
  125. 'flex-direction': 'column',
  126. }"
  127. >
  128. <el-super-search
  129. v-model="params"
  130. :size="size"
  131. :dict="dict"
  132. :columns="SearchColumns"
  133. @reset="useReset"
  134. @submit="useQuery(params, page)"
  135. ></el-super-search>
  136. <div class="my-4" style="text-align: right">
  137. <el-button-group>
  138. <ena-button
  139. :size="size"
  140. :select-data="selectData"
  141. status="Y"
  142. @success="useQuery(params, page)"
  143. ></ena-button>
  144. <ena-button
  145. :size="size"
  146. :select-data="selectData"
  147. status="N"
  148. @success="useQuery(params, page)"
  149. ></ena-button>
  150. </el-button-group>
  151. <el-button-group>
  152. <inv-button
  153. ref="InvButton"
  154. :size="size"
  155. :select-data="selectData"
  156. @success="useQuery(params, page)"
  157. ></inv-button>
  158. <see-button
  159. v-show="false"
  160. ref="SeeButton"
  161. :size="size"
  162. :dict="dict"
  163. :select-data="selectData"
  164. @success="useQuery(params, page)"
  165. ></see-button
  166. ></el-button-group>
  167. <el-button-group>
  168. <exp-button
  169. :size="size"
  170. :select-data="selectData"
  171. @success="useQuery(params, page)"
  172. ></exp-button>
  173. </el-button-group>
  174. <el-button-group>
  175. <el-button size="mini" @click="exportAll">全部导出</el-button>
  176. </el-button-group>
  177. </div>
  178. <el-super-table
  179. v-model="tableData"
  180. :size="size"
  181. :dict="dict"
  182. :page="page"
  183. :columns="TableColumns"
  184. index
  185. checkbox
  186. pagination
  187. convenitentOperation
  188. storage-key="PuchaseCatalogueSuperTable1"
  189. @row-dblclick="useSee"
  190. @selection-change="useSelect"
  191. @pagination="useQuery(params, page)"
  192. >
  193. </el-super-table>
  194. </el-card>
  195. </template>
  196. <style scoped lang="scss">
  197. .el-card {
  198. width: calc(100% - 32px);
  199. height: calc(100vh - 32px);
  200. margin: 16px;
  201. padding: 16px;
  202. border-radius: 8px;
  203. }
  204. .el-button-group + .el-button-group {
  205. margin: 0 0 0 10px;
  206. }
  207. </style>