rubbishDeliveryTotal.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <template>
  2. <a-card :bordered="false" class="shopOrder-table-page-search-wrapper">
  3. <div class="network-searchForm">
  4. <a-form-model ref="queryForm" :model="queryParam" layout="inline" v-bind="formItemLayout" @keyup.enter.native="$refs.table.refresh(true)">
  5. <a-row :gutter="24">
  6. <a-col :span="6">
  7. <a-form-model-item label="投递时间" :label-col="{ span:7 }" :wrapper-col="{ span:17}">
  8. <a-range-picker
  9. id="rubbishTotal-time"
  10. v-model="time"
  11. style="width: 100%;"
  12. :format="dateFormat"
  13. :placeholder="['开始时间','结束时间']"
  14. :disabledDate="disabledDate"
  15. @change="onChange" />
  16. </a-form-model-item>
  17. </a-col>
  18. <a-col :span="6">
  19. <a-form-model-item prop="provinceCode" label="所属区域:" :label-col="{ span:8 }" :wrapper-col="{ span:16}">
  20. <a-select id="rubbishTotal-provinceCode" allowClear v-model="queryParam.provinceCode" @change="getCityList" placeholder="请选择省">
  21. <a-select-option v-for="item in addrProvinceList" :value="item.id" :key="item.id + 'a'">{{ item.name }}</a-select-option>
  22. </a-select>
  23. </a-form-model-item>
  24. </a-col>
  25. <a-col :span="5">
  26. <a-form-model-item prop="cityCode" label=" " :colon="false" :label-col="{ span:1 }" :wrapper-col="{ span:22}">
  27. <a-select allowClear id="rubbishTotal-cityCode" v-model="queryParam.cityCode" @change="getAreaList" placeholder="请选择市">
  28. <a-select-option v-for="item in addrCityList" :value="item.id" :key="item.id + 'b'">{{ item.name }}</a-select-option>
  29. </a-select>
  30. </a-form-model-item>
  31. </a-col>
  32. <a-col :span="5">
  33. <a-form-model-item prop="districtCode" label=" " :colon="false" :label-col="{ span:0 }" :wrapper-col="{ span:20}">
  34. <a-select allowClear id="rubbishTotal-districtCode" v-model="queryParam.districtCode" placeholder="请选择区/县">
  35. <a-select-option v-for="item in addrDistrictList" :value="item.id" :key="item.id + 'c'">{{ item.name }}</a-select-option>
  36. </a-select>
  37. </a-form-model-item>
  38. </a-col>
  39. </a-row>
  40. <a-row :gutter="24">
  41. <a-col :span="6">
  42. <a-form-model-item label="网点名称" prop="stationNo" :label-col="{ span:7 }" :wrapper-col="{ span:17}">
  43. <a-select
  44. id="rubbishTotal-stationNo"
  45. placeholder="请选择网点名称"
  46. allowClear
  47. v-model="queryParam.stationNo"
  48. :showSearch="true"
  49. option-filter-prop="children"
  50. :filter-option="filterOption">
  51. <a-select-option v-for="item in optionData" :key="item.stationNo" :value="item.stationNo">{{ item.name }}</a-select-option>
  52. </a-select>
  53. </a-form-model-item>
  54. </a-col>
  55. <a-col :span="10">
  56. <a-button class="handle-btn serach-btn" id="rubbishTotal-btn-serach" type="primary" @click="$refs.table.refresh(true)">查询</a-button>
  57. <a-button class="handle-btn serach-btn" type="" id="rubbishTotal-btn-reset" @click="handleReset">重置</a-button>
  58. <a-button class="export-btn" id="rubbishTotal-export" v-hasPermission="'M_rubbishTotal_export'" :loading="loading" @click="handleExport">导出</a-button>
  59. </a-col>
  60. </a-row>
  61. </a-form-model>
  62. </div>
  63. <!-- 合计 -->
  64. <a-alert type="info" showIcon style="margin-bottom:15px">
  65. <div class="ftext" slot="message">总计<span> {{ totalNum }} </span>条,可回收垃圾总计<span> {{ recyclTotal }} </span>千克,有害垃圾总计<span> {{ harmTotal }} </span>千克</div>
  66. </a-alert>
  67. <s-table
  68. ref="table"
  69. size="default"
  70. :rowKey="(record) => record.id"
  71. :columns="columns"
  72. :data="loadData"
  73. bordered>
  74. </s-table>
  75. </a-card>
  76. </template>
  77. <script>
  78. import {
  79. STable,
  80. VSelect
  81. } from '@/components'
  82. import {
  83. stationList
  84. } from '@/api/releaseRecord.js'
  85. import {
  86. getProvince,
  87. getCityByPro,
  88. getDistrictByCity
  89. } from '@/api/station'
  90. import {
  91. getSumList,
  92. exportSumForm,
  93. getSumTotal
  94. } from '@/api/reportForm.js'
  95. import moment from 'moment'
  96. import getDate from '@/libs/getDate.js'
  97. export default {
  98. components: {
  99. STable,
  100. VSelect
  101. },
  102. data () {
  103. return {
  104. loading: false,
  105. form: this.$form.createForm(this),
  106. formItemLayout: {
  107. labelCol: {
  108. span: 7
  109. },
  110. wrapperCol: {
  111. span: 17
  112. }
  113. },
  114. // 将默认近七天时间日期回显在时间选择框中
  115. time: [
  116. moment(getDate.getRecentday().starttime, 'YYYY-MM-DD HH'),
  117. moment(getDate.getRecentday().endtime, 'YYYY-MM-DD HH')
  118. ],
  119. dateFormat: 'YYYY-MM-DD',
  120. // 查询参数
  121. queryParam: {
  122. beginDate: null, // 开始时间
  123. endDate: null, // 结束时间
  124. stationNo: undefined, // 网点名称
  125. provinceCode: undefined, // 省
  126. cityCode: undefined, // 市
  127. districtCode: undefined // 区
  128. },
  129. addrProvinceList: [], // 省下拉
  130. addrCityList: [], // 市下拉
  131. addrDistrictList: [], // 区下拉
  132. optionData: [],
  133. totalNum: 0, // 总条数
  134. recyclTotal: 0, // 可回收总计
  135. harmTotal: 0, // 有害垃圾总计
  136. // 表头
  137. columns: [{
  138. title: '序号',
  139. dataIndex: 'no',
  140. width: 60,
  141. align: 'center'
  142. },
  143. {
  144. title: '网点名称',
  145. dataIndex: 'stationName',
  146. width: 100,
  147. align: 'center'
  148. },
  149. {
  150. title: '可回收垃圾投递量(kg)',
  151. children: [{
  152. title: '废旧衣物',
  153. width: 100,
  154. align: 'center',
  155. dataIndex: 'clothesWeight',
  156. customRender: (text) => {
  157. return text || 0
  158. }
  159. },
  160. {
  161. title: '废旧纸张',
  162. width: 100,
  163. align: 'center',
  164. dataIndex: 'paperWeight',
  165. customRender: (text) => {
  166. return text || 0
  167. }
  168. },
  169. {
  170. title: '废旧塑料',
  171. width: 100,
  172. align: 'center',
  173. dataIndex: 'plasticWeight',
  174. customRender: (text) => {
  175. return text || 0
  176. }
  177. },
  178. {
  179. title: '废旧金属',
  180. width: 100,
  181. align: 'center',
  182. dataIndex: 'metalWeight',
  183. customRender: (text) => {
  184. return text || 0
  185. }
  186. },
  187. {
  188. title: '废旧金属/塑料',
  189. width: 100,
  190. align: 'center',
  191. dataIndex: 'plasticOrMetalWeight',
  192. customRender: (text) => {
  193. return text || 0
  194. }
  195. },
  196. {
  197. title: '废旧玻璃',
  198. width: 100,
  199. align: 'center',
  200. dataIndex: 'glassWeight',
  201. customRender: (text) => {
  202. return text || 0
  203. }
  204. },
  205. {
  206. title: '可回收物',
  207. width: 100,
  208. align: 'center',
  209. dataIndex: 'recyclingWeight',
  210. customRender: (text) => {
  211. return text || 0
  212. }
  213. }
  214. ]
  215. },
  216. {
  217. title: '可回收垃圾小计(kg)',
  218. dataIndex: 'recyclTotalWeight',
  219. width: 100,
  220. align: 'center'
  221. },
  222. {
  223. title: '有害垃圾(kg)',
  224. dataIndex: 'harmWeight',
  225. width: 100,
  226. align: 'center'
  227. }
  228. ],
  229. // 加载数据方法 必须为 Promise 对象
  230. loadData: parameter => {
  231. const searchData = Object.assign(parameter, this.queryParam)
  232. if (this.time && this.time.length) {
  233. searchData.beginDate = moment(this.time[0]).format('YYYY-MM-DD')
  234. searchData.endDate = moment(this.time[1]).format('YYYY-MM-DD')
  235. } else {
  236. searchData.beginDate = ''
  237. searchData.endDate = ''
  238. }
  239. return getSumList(searchData).then(res => {
  240. if (res.status == 200) {
  241. const no = (res.data.pageNo - 1) * res.data.pageSize
  242. for (let i = 0; i < res.data.list.length; i++) {
  243. const _item = res.data.list[i]
  244. _item.no = no + i + 1
  245. }
  246. this.totalNum = res.data.count
  247. this.getListTotal()
  248. return res.data
  249. } else {
  250. this.totalNum = 0
  251. }
  252. })
  253. }
  254. }
  255. },
  256. beforeRouteEnter (to, from, next) {
  257. next(vm => {
  258. vm.time = [
  259. moment(getDate.getRecentday().starttime, 'YYYY-MM-DD HH'),
  260. moment(getDate.getRecentday().endtime, 'YYYY-MM-DD HH')
  261. ]
  262. vm.$refs.queryForm.resetFields()
  263. vm.getStationList()
  264. vm.getProvinceList()
  265. })
  266. },
  267. methods: {
  268. // 不可选日期
  269. disabledDate (date, dateStrings) {
  270. return date && date.valueOf() > Date.now()
  271. },
  272. // 创建时间change
  273. onChange (dates, dateStrings) {
  274. if ((dates, dateStrings)) {
  275. this.queryParam.beginDate = dateStrings[0]
  276. this.queryParam.endDate = dateStrings[1]
  277. }
  278. },
  279. filterOption (input, option) {
  280. return (
  281. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  282. )
  283. },
  284. // 获取省列表'
  285. getProvinceList () {
  286. getProvince().then(res => {
  287. if (res.status == 200) {
  288. this.addrProvinceList = res.data || []
  289. } else {
  290. this.addrProvinceList = []
  291. }
  292. })
  293. },
  294. // 获取城市列表
  295. getCityList (val) {
  296. this.addrCityList = []
  297. this.addrDistrictList = []
  298. this.queryParam.cityCode = undefined
  299. this.queryParam.districtCode = undefined
  300. this.getCityListRequest(val)
  301. },
  302. getCityListRequest (val) {
  303. getCityByPro({
  304. id: val
  305. }).then(res => {
  306. if (res.status == 200) {
  307. this.addrCityList = res.data || []
  308. } else {
  309. this.addrCityList = []
  310. }
  311. })
  312. },
  313. // 获取区县列表
  314. getAreaList (val) {
  315. this.addrDistrictList = []
  316. this.queryParam.districtCode = undefined
  317. this.getAreaListRequest(val)
  318. },
  319. getAreaListRequest (val) {
  320. getDistrictByCity({
  321. id: val
  322. }).then(res => {
  323. if (res.status == 200) {
  324. this.addrDistrictList = res.data || []
  325. } else {
  326. this.addrDistrictList = []
  327. }
  328. })
  329. },
  330. // 导出
  331. handleExport () {
  332. const params = this.queryParam
  333. if (this.time && this.time.length) {
  334. params.beginDate = moment(this.time[0]).format('YYYY-MM-DD')
  335. params.endDate = moment(this.time[1]).format('YYYY-MM-DD')
  336. } else {
  337. params.beginDate = ''
  338. params.endDate = ''
  339. }
  340. if (!params.beginDate && !params.endDate) {
  341. this.$message.error('请先选择需要导出的投放时间区间再进行导出!')
  342. return
  343. }
  344. // 判断两个时间段是否相差m个月 第二个参数指相差单位,第三个参数指是否返回浮点形式(小数)
  345. if (moment(params.endDate).diff(moment(params.beginDate), 'months', true) > 3) {
  346. this.$message.error('单次最多只能导出3个月的数据,请缩小查询区间后再进行导出!')
  347. return
  348. }
  349. this.$confirm({
  350. title: '提示',
  351. content: '导出过程可能需要一些时间,且导出期间不能进行其它操作,确定要导出吗?',
  352. onOk: () => {
  353. this.loading = true
  354. exportSumForm(params).then(res => {
  355. this.loading = false
  356. this.download(res)
  357. })
  358. },
  359. onCancel () {
  360. console.log('Cancel')
  361. }
  362. })
  363. },
  364. download (data) {
  365. if (!data) {
  366. return
  367. }
  368. const url = window.URL.createObjectURL(new Blob([data]))
  369. const link = document.createElement('a')
  370. link.style.display = 'none'
  371. link.href = url
  372. const a = moment(this.queryParam.beginDate).format('LL') + '-' + moment(this.queryParam.endDate).format('LL')
  373. const address = this.queryParam.provinceCode ? this.addrProvinceList.find(item => item.id == this.queryParam.provinceCode).name +
  374. (this.queryParam.cityCode ? this.addrCityList.find(item => item.id == this.queryParam.cityCode).name : '') +
  375. (this.queryParam.districtCode ? this.addrDistrictList.find(item => item.id == this.queryParam.districtCode).name : '') : ''
  376. const fname = a + '垃圾分类投递量统计表' + (address ? '(' + address + ')' : '')
  377. link.setAttribute('download', fname + '.xlsx')
  378. document.body.appendChild(link)
  379. link.click()
  380. },
  381. // 查询
  382. refresh () {
  383. this.$refs.table.refresh(true)
  384. },
  385. // 获取合作商数据
  386. getStationList () {
  387. stationList().then(res => {
  388. if (res.status == 200) {
  389. this.optionData = res.data || []
  390. }
  391. })
  392. },
  393. // 合计
  394. getListTotal () {
  395. const params = this.queryParam
  396. if (this.time && this.time.length) {
  397. params.beginDate = moment(this.time[0]).format('YYYY-MM-DD')
  398. params.endDate = moment(this.time[1]).format('YYYY-MM-DD')
  399. } else {
  400. params.beginDate = ''
  401. params.endDate = ''
  402. }
  403. getSumTotal(params).then(res => {
  404. if (res.status == 200) {
  405. if (res.data) {
  406. this.recyclTotal = res.data.recyclAll || 0
  407. this.harmTotal = res.data.harmAll || 0
  408. } else {
  409. this.recyclTotal = 0
  410. this.harmTotal = 0
  411. }
  412. }
  413. })
  414. },
  415. // 重置
  416. handleReset () {
  417. this.time = [
  418. moment(getDate.getRecentday().starttime, 'YYYY-MM-DD HH'),
  419. moment(getDate.getRecentday().endtime, 'YYYY-MM-DD HH')
  420. ]
  421. this.$refs.queryForm.resetFields()
  422. this.$refs.table.refresh(true)
  423. }
  424. }
  425. }
  426. </script>
  427. <style lang="less" scoped>
  428. .shopOrder-table-page-search-wrapper {
  429. .network-searchForm {
  430. .ant-form-inline .ant-form-item {
  431. width: 100%;
  432. }
  433. // 搜索框的下间距
  434. .ant-form-item {
  435. margin-bottom: 10px;
  436. }
  437. .handle-btn {
  438. margin-top: 4px;
  439. }
  440. .serach-btn {
  441. margin-right: 10px;
  442. }
  443. }
  444. .export-btn {
  445. background-color: #ff9900;
  446. border-color: #ff9900;
  447. color: #fff;
  448. }
  449. .export-btn.ant-btn:focus:not(.ant-btn-primary):not(.ant-btn-danger),
  450. .export-btn.ant-btn:hover:not(.ant-btn-primary):not(.ant-btn-danger) {
  451. color: #fff;
  452. border-color: #ff9900;
  453. }
  454. .actionBtn {
  455. font-size: 20px;
  456. padding: 0 10px;
  457. }
  458. .blue {
  459. color: #1890FF;
  460. }
  461. .green {
  462. color: #16b50e;
  463. }
  464. .red {
  465. color: red;
  466. }
  467. }
  468. </style>