table2.vue 10 KB

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