ky-asset-list.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <basic-container>
  3. <avue-crud
  4. v-bind="bindVal"
  5. v-on="onEvent"
  6. v-model="form"
  7. :page.sync="page"
  8. :before-open="handleBeforeOpen"
  9. :permission="permissionList"
  10. >
  11. <template slot="menuLeft">
  12. <el-button
  13. v-if="!isSelAnnual"
  14. type="danger"
  15. size="small"
  16. icon="el-icon-delete"
  17. plain
  18. @click="handleDelete"
  19. >
  20. 删 除
  21. </el-button>
  22. <el-button
  23. v-if="!isSelAnnual"
  24. type="success"
  25. size="small"
  26. plain
  27. icon="el-icon-upload2"
  28. @click="handleImport"
  29. >
  30. 导入
  31. </el-button>
  32. <el-button
  33. type="warning"
  34. size="small"
  35. plain
  36. icon="el-icon-download"
  37. @click="handleExport"
  38. >
  39. 导出
  40. </el-button>
  41. <el-button
  42. v-if="!isSelAnnual"
  43. type="primary"
  44. size="small"
  45. plain
  46. @click="handleReadyLastMonData"
  47. >
  48. 读取上个月资产名单
  49. </el-button>
  50. <print-table-btn @click="printTable" />
  51. <div style="display: flex; align-items: center;">
  52. <year-month-select v-model="params.yearAndMonth"></year-month-select>
  53. </div>
  54. </template>
  55. <!-- 开始时间 -->
  56. <template slot="kssjSearch">
  57. <el-date-picker
  58. v-model="params.kssjRange"
  59. type="daterange"
  60. range-separator="至"
  61. start-placeholder="开始日期"
  62. end-placeholder="结束日期"
  63. value-format="yyyy-MM-dd"
  64. >
  65. </el-date-picker>
  66. </template>
  67. <!-- 使用寿命 -->
  68. <template slot="sysmSearch">
  69. <div style="display: flex; align-items: center;">
  70. <avue-input-number v-model="params.startSysm" :min="0"></avue-input-number>
  71. <span style="width: 70px; text-align: center;">至</span>
  72. <avue-input-number v-model="params.endSysm" :min="0"></avue-input-number>
  73. </div>
  74. </template>
  75. </avue-crud>
  76. <upload-excel-dialog ref="uploadExcelDialog" :uploadAfter="uploadAfter"/>
  77. <WideTablePrinter
  78. ref="printWideTable"
  79. :columns="wideTableColumns"
  80. :data="data"
  81. :print-title="printTitle"
  82. :rows-per-page="30"
  83. :default-landscape="true"
  84. />
  85. </basic-container>
  86. </template>
  87. <script>
  88. import { getLastMonthData } from "@/api/basicResource/kyAssetList";
  89. import {exportBloByPost} from "@/api/common";
  90. import YearMonthSelect from "@/components/year-month-select";
  91. import UploadExcelDialog from "@/components/upload-excel-dialog";
  92. import moment from "moment";
  93. import {getToken} from "@/util/auth";
  94. import {downloadXls} from "@/util/util";
  95. export default window.$crudCommon({
  96. components: {
  97. YearMonthSelect,
  98. UploadExcelDialog,
  99. },
  100. data() {
  101. return {
  102. params: {
  103. yearAndMonth: moment(new Date()).format('YYYYMM'),
  104. },
  105. isSelAnnual: false, // 是否选择全年
  106. wideTableColumns: [],
  107. printTitle: "",
  108. };
  109. },
  110. watch: {
  111. 'params.yearAndMonth'(newVal) {
  112. if (newVal.length > 4) {
  113. // 是否勾选未全年
  114. this.isSelAnnual = false;
  115. } else {
  116. this.isSelAnnual = true;
  117. }
  118. this.page.currentPage = 1;
  119. this.getList(this.page);
  120. }
  121. },
  122. computed: {
  123. permissionList() {
  124. return {
  125. addBtn: !this.isSelAnnual,
  126. editBtn: !this.isSelAnnual,
  127. delBtn: !this.isSelAnnual,
  128. };
  129. },
  130. },
  131. methods: {
  132. searchChange(params, done) {
  133. if (done) done();
  134. if (this.validatenull(params)) {
  135. Object.keys(this.params).forEach(ele => {
  136. if (!['createTime_dategt', 'createTime_datelt', 'yearAndMonth', 'kssjRange', 'startSysm', 'endSysm'].includes(ele)) {
  137. delete this.params[ele];
  138. }
  139. })
  140. } else {
  141. Object.keys(params).forEach(ele => {
  142. if (this.validatenull(params[ele])) {
  143. delete this.params[ele];
  144. delete params[ele];
  145. }
  146. })
  147. }
  148. this.params = Object.assign(this.params, params);
  149. if (this.params.kssjRange && this.params.kssjRange.length) {
  150. this.params.startTime = this.params.kssjRange[0];
  151. this.params.endTime = this.params.kssjRange[1];
  152. }
  153. this.page.currentPage = 1;
  154. this.getList();
  155. },
  156. getDelParams(row) {
  157. return [{ id: row.id, yearAndMonth: this.params.yearAndMonth }];
  158. },
  159. getBatchDelParams() {
  160. let delArr = [];
  161. this.data.forEach(item => {
  162. if (this.ids.indexOf(item.id) > -1) {
  163. delArr.push({ yearAndMonth: this.params.yearAndMonth, id: item.id });
  164. }
  165. });
  166. return delArr;
  167. },
  168. handleImport() {
  169. let excelParams = { yearAndMonth: this.params.yearAndMonth };
  170. this.$refs.uploadExcelDialog.open('/api//kd-scientific/zc/import', excelParams);
  171. },
  172. uploadAfter() {
  173. this.page.currentPage = 1;
  174. this.getList(this.page);
  175. },
  176. handleExport() {
  177. exportBloByPost(`/api//kd-scientific/zc/export-zc?${this.website.tokenHeader}=${getToken()}`, this.params).then(res => {
  178. downloadXls(res.data, `科研资产清单${this.params.yearAndMonth}.xlsx`);
  179. });
  180. },
  181. handleReadyLastMonData() {
  182. this.$confirm("确认要读取上个月的数据吗?", "提示", {
  183. confirmButtonText: "确定",
  184. cancelButtonText: "取消",
  185. type: "warning"
  186. }).then(() => {
  187. getLastMonthData({ yearAndMonth: this.params.yearAndMonth}).then(res => {
  188. let data = res.data;
  189. if (data.success) {
  190. this.$message.success('读取成功!');
  191. this.page.currentPage = 1;
  192. this.getList(this.page);
  193. }
  194. });
  195. });
  196. },
  197. /**
  198. * 打印表格
  199. * @param isLandscape 是否横向打印
  200. */
  201. printTable(isLandscape) {
  202. this.wideTableColumns = this.$refs.crud.columnOption;
  203. this.printTitle = `科研资产清单${this.params.yearAndMonth}`;
  204. this.$nextTick(() => {
  205. this.$refs.printWideTable.printTable(isLandscape);
  206. })
  207. },
  208. },
  209. }, {
  210. // 模块路径
  211. name: 'basicResource/kyAssetList',
  212. res: ({ data }) => {
  213. return data;
  214. },
  215. });
  216. </script>