index.vue 6.0 KB

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