table1.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <template>
  2. <div v-loading="loading">
  3. <div style="width: 100%" >
  4. <el-row style="padding: 10px 0 0 0px">
  5. <el-col :span="6" style="width: 363px">
  6. <periodDatePickerActive
  7. :start="parmValue.start_date"
  8. :end="parmValue.end_date"
  9. :placeholder="'竞价'"
  10. :width="'165px'"
  11. :size="searchSize"
  12. @timeReturned="time"
  13. />
  14. </el-col>
  15. <!-- <el-col :span="4" style="width: 66px; float: right">
  16. <el-button
  17. type="primary"
  18. style="margin-left: 30px"
  19. @click="download"
  20. :size="searchSize"
  21. class="fr"
  22. >
  23. 导出
  24. </el-button>
  25. </el-col> -->
  26. <el-col :span="3" style="width: 66px; float: right">
  27. <el-button
  28. :size="searchSize"
  29. type="primary"
  30. style="float: right; margin-left: 5px"
  31. @click="searchList"
  32. >
  33. 刷新
  34. </el-button>
  35. </el-col>
  36. <el-col :span="4" style="width: 66px; float: right">
  37. <el-button
  38. type="warning"
  39. class="fr"
  40. :size="searchSize"
  41. @click="restSearch"
  42. >
  43. 重置
  44. </el-button>
  45. </el-col>
  46. </el-row>
  47. </div>
  48. <el-table
  49. :data="tableData"
  50. :size="searchSize"
  51. :span-method="objectSpanMethod"
  52. border
  53. style="width: 100%; margin-top: 20px"
  54. >
  55. <el-table-column :prop="item.prop" :label="item.label" v-for="(item,index) in table1" :key="index"/>
  56. </el-table>
  57. <!-- <el-pagination
  58. :current-page.sync="pageInfo.curr"
  59. :page-sizes="[15, 50, 100]"
  60. :page-size="pageInfo.size"
  61. :size="searchSize"
  62. layout="total, sizes, prev, pager, next, jumper"
  63. :total="pageInfo.total"
  64. @size-change="handleSizeChange"
  65. @current-change="handleCurrentChange"
  66. /> -->
  67. </div>
  68. </template>
  69. <script>
  70. import dayjs from "dayjs"
  71. import mixinPage from "@/mixins/elPaginationHandle";
  72. import resToken from "@/mixins/resToken";
  73. import urlConfig from "@/apis/url-config";
  74. import asyncRequest from "@/apis/service/reportQuery/purchaseReport";
  75. import periodDatePickerActive from "../period-date-picker/main.vue";
  76. import { table1 } from "./columns";
  77. import { mapGetters } from "vuex";
  78. export default {
  79. name: "purchaseOrder",
  80. mixins: [mixinPage, resToken],
  81. components: {
  82. periodDatePickerActive,
  83. },
  84. computed: {
  85. ...mapGetters(["tablebtnSize", "searchSize", "size"]),
  86. },
  87. data() {
  88. return {
  89. //选中数组
  90. changeList: [],
  91. //全局url
  92. fileUrl: urlConfig.baseURL,
  93. //loading
  94. loading: false,
  95. //请求参数集合
  96. parmValue: {
  97. start_date: "", //起始时间
  98. end_date: "", // 结束时间
  99. page: 1, // 页码
  100. size: 15, // 每页显示条数
  101. },
  102. // 表格 - 数据集合
  103. tableData: [
  104. ],
  105. // 表格 - 参数
  106. // table: {
  107. // stripe: true,
  108. // border: true,
  109. // _defaultHeader_: ["setcol"],
  110. // },
  111. // 表格 - 分页
  112. pageInfo: {
  113. size: 15,
  114. curr: 1,
  115. total: 0,
  116. },
  117. // 表格表头 - 列参数
  118. table1: table1,
  119. };
  120. },
  121. mounted() {
  122. const current = dayjs(new Date()).format('YYYY-MM-DD');
  123. this.parmValue.start_date = dayjs(current).subtract(30, 'days').format('YYYY-MM-DD')
  124. this.parmValue.end_date = current
  125. this.searchList();
  126. },
  127. methods: {
  128. getDiffDay(date_1, date_2){
  129. let totalDays, diffDate
  130. let myDate_1 = Date.parse(date_1)
  131. let myDate_2 = Date.parse(date_2)
  132. diffDate = Math.abs(myDate_1 - myDate_2)
  133. totalDays = Math.floor(diffDate / (1000 * 3600 * 24))
  134. return totalDays
  135. },
  136. //分页集合
  137. handleSizeChange(val){
  138. this.parmValue.size = val;
  139. // this.pageInfo.total = val;
  140. this.parmValue.page = 1;
  141. this.searchList()
  142. },
  143. handleCurrentChange(val){
  144. this.parmValue.page = val;
  145. // this.pageInfo.total = val;
  146. this.searchList()
  147. },
  148. //合并方法
  149. objectSpanMethod({ row, column, rowIndex, columnIndex }) {
  150. if (columnIndex == 0) {
  151. //合并相同的名字
  152. let nameSpan = this.getSpanNumber(this.tableData, "addtime");
  153. return {
  154. rowspan: nameSpan[rowIndex],
  155. colspan: 1,
  156. };
  157. }
  158. },
  159. //获取要合并的行数
  160. getSpanNumber(data, prop) {
  161. //data要处理的数组,prop要合并的属性,比如name
  162. //数组的长度,有时候后台可能返回个null而不是[]
  163. let length = Array.isArray(data) ? data.length : 0;
  164. if (length > 0) {
  165. //用于标识位置
  166. let position = 0;
  167. //用于对比的数据
  168. let temp = data[0][prop];
  169. //要返回的结果
  170. let result = [1];
  171. //假设数据是AABCC,我们的目标就是返回20120
  172. for (let i = 1; i < length; i++) {
  173. if (data[i][prop] == temp) {
  174. //标识位置的数据加一
  175. result[position] += 1;
  176. //当前位置添0
  177. result[i] = 0;
  178. } else {
  179. //不相同时,修改标识位置,该位置设为1,修改对比值
  180. position = i;
  181. result[i] = 1;
  182. temp = data[i][prop];
  183. }
  184. }
  185. //返回结果
  186. return result;
  187. } else {
  188. return [0];
  189. }
  190. },
  191. //初始化http请求
  192. async searchList() {
  193. if (
  194. (this.parmValue.start_date !== "" && this.parmValue.end_date === "") ||
  195. (this.parmValue.start_date === "" && this.parmValue.end_date !== "")
  196. ) {
  197. this.$message.warning("时间区间不完整!");
  198. return;
  199. }
  200. if(!this.parmValue.start_date && !this.parmValue.end_date){
  201. this.$message.warning("请选择时间区间!")
  202. return
  203. }
  204. const { start_date, end_date } = this.parmValue
  205. const diffDays = this.getDiffDay(start_date,end_date);
  206. if(diffDays > 30){
  207. this.$message.warning("时间区间不能超过31天!")
  208. return
  209. }
  210. this.loading = true;
  211. const res = await asyncRequest.reportzixuntotal(this.parmValue);
  212. console.log(res)
  213. if (res && res.code === 0 && res.data) {
  214. this.tableData = res.data;
  215. // this.pageInfo.total = Number(res.data.count);
  216. } else if (res && res.code >= 100 && res.code <= 104) {
  217. await this.logout();
  218. } else {
  219. this.$message.warning(res.message)
  220. this.tableData = [];
  221. this.pageInfo.total = 0;
  222. }
  223. this.loading = false;
  224. },
  225. //重置
  226. restSearch() {
  227. this.parmValue = {
  228. start_date: "", //新建起始时间
  229. end_date: "", // 新建结束时间
  230. page: 1, // 页码
  231. size: 15, // 每页显示条数
  232. };
  233. const current = dayjs(new Date()).format('YYYY-MM-DD');
  234. this.parmValue.start_date = dayjs(current).subtract(30, 'days').format('YYYY-MM-DD')
  235. this.parmValue.end_date = current
  236. // 表格 - 分页
  237. this.pageInfo = {
  238. size: 15,
  239. curr: 1,
  240. total: 0,
  241. };
  242. this.searchList();
  243. },
  244. // 时间函数
  245. async time(e) {
  246. this.parmValue.start_date = e.startTime || "";
  247. this.parmValue.end_date = e.endTime || "";
  248. if (
  249. (this.parmValue.start_date !== "" && this.parmValue.end_date === "") ||
  250. (this.parmValue.start_date === "" && this.parmValue.end_date !== "")
  251. ) {
  252. this.$message.warning("时间区间不完整!");
  253. return;
  254. }
  255. this.pageInfo.curr = 1;
  256. this.parmValue.page = 1;
  257. await this.searchList();
  258. },
  259. //选中触发函数
  260. selection_change(e) {
  261. const { list } = e;
  262. //选中的数组集合
  263. this.changeList = list.length > 0 ? JSON.parse(JSON.stringify(list)) : [];
  264. },
  265. //导出文件
  266. // async download() {
  267. // if (this.changeList.length <= 0) {
  268. // this.$message.warning("请选择有效数据");
  269. // return;
  270. // }
  271. // let model = {
  272. // cgdNos: [],
  273. // };
  274. // this.changeList.forEach((item) => {
  275. // model.cgdNos.push(item.cgdNo);
  276. // });
  277. // // const res = await asyncRequest.exportcgdlist(model)
  278. // if (!this.loading) {
  279. // this.loading = true;
  280. // let httpType = `aplication/zip`;
  281. // axios({
  282. // method: "post",
  283. // url: this.fileUrl + "admin/exportcgdlist",
  284. // responseType: "blob",
  285. // data: model,
  286. // headers: {
  287. // // 'Content-Type': 'multipart/form-data',
  288. // // Accept: "application/vnd.ms-excel"
  289. // Accept: httpType,
  290. // },
  291. // })
  292. // .then((res) => {
  293. // // console.log(res)
  294. // // console.log(this.fileUrl)
  295. // // return;
  296. // if (res && res.status == 200 && res.data) {
  297. // let url = window.URL.createObjectURL(
  298. // new Blob([res.data], {
  299. // // type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8",
  300. // type: httpType,
  301. // })
  302. // );
  303. // let link = document.createElement("a");
  304. // link.style.display = "none";
  305. // link.href = url;
  306. // let excelName = "采购单.zip";
  307. // link.setAttribute("download", excelName);
  308. // document.body.appendChild(link);
  309. // link.click();
  310. // link.remove();
  311. // window.URL.revokeObjectURL(url); //释放掉blob对象
  312. // this.$message.success(`导出成功!`);
  313. // setTimeout(() => {
  314. // this.loading = false;
  315. // }, 500);
  316. // } else {
  317. // this.$message.error(res.data.message);
  318. // setTimeout(() => {
  319. // this.loading = false;
  320. // }, 500);
  321. // }
  322. // })
  323. // .catch((error) => {
  324. // console.log(error);
  325. // this.loading = false;
  326. // });
  327. // }
  328. // },
  329. },
  330. };
  331. </script>
  332. <style lang="scss" scoped>
  333. .purchaseOrder {
  334. // text-align: right;
  335. }
  336. /deep/ .el-pagination{
  337. float: right;
  338. margin-top: 10px;
  339. }
  340. </style>