provinceFeeList.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <div>
  3. <a-card size="small" :bordered="false" class="provinceFeeList-wrap searchBoxNormal">
  4. <!-- 搜索条件 -->
  5. <div class="table-page-search-wrapper" ref="tableSearch">
  6. <a-form-model
  7. id="provinceFeeList-form"
  8. ref="ruleForm"
  9. class="form-model-con"
  10. layout="inline"
  11. :rules="rules"
  12. :model="queryParam">
  13. <a-row :gutter="15">
  14. <a-col :md="5" :sm="24">
  15. <a-form-model-item label="月份" prop="beginDate">
  16. <a-month-picker
  17. id="provinceFeeList-monthBox"
  18. class="monthBox"
  19. :disabled-date="disabledDate"
  20. v-model="monthVal"
  21. placeholder="请选择月份"
  22. @change="onChangeMonth" />
  23. </a-form-model-item>
  24. </a-col>
  25. <a-col :md="5" :sm="24">
  26. <a-form-model-item label="地区">
  27. <Area id="provinceFeeList-areaList" v-model="queryParam.provinceSn" placeholder="请选择省份"></Area>
  28. </a-form-model-item>
  29. </a-col>
  30. <a-col :md="5" :sm="24">
  31. <a-form-item label="所在区域">
  32. <subarea id="provinceFeeList-subarea" ref="subarea" @change="subareaChange"></subarea>
  33. </a-form-item>
  34. </a-col>
  35. <a-col :md="5" :sm="24">
  36. <a-form-model-item label="区域负责人">
  37. <BizUser id="provinceFeeList-bizUserSn" v-model="queryParam.subareaArea.bizUserSn"></BizUser>
  38. </a-form-model-item>
  39. </a-col>
  40. <a-col :md="4" :sm="24">
  41. <a-button
  42. type="primary"
  43. @click="handleSearch"
  44. :disabled="disabled"
  45. id="provinceFeeList-refresh">查询</a-button>
  46. <a-button
  47. style="margin-left: 8px"
  48. @click="resetSearchForm"
  49. :disabled="disabled"
  50. id="provinceFeeList-reset">重置</a-button>
  51. <a-button
  52. style="margin-left: 10px"
  53. type="primary"
  54. class="button-warning"
  55. @click="handleExport"
  56. :disabled="disabled"
  57. :loading="exportLoading"
  58. v-if="$hasPermissions('B_tireFeeExport')"
  59. id="provinceFeeList-export">导出</a-button>
  60. </a-col>
  61. </a-row>
  62. </a-form-model>
  63. </div>
  64. </a-card>
  65. <a-card size="small" :bordered="false">
  66. <a-spin :spinning="spinning" tip="Loading...">
  67. <!-- 列表 -->
  68. <s-table
  69. class="sTable fixPagination"
  70. ref="table"
  71. size="small"
  72. :rowKey="(record) => record.id"
  73. :style="{ height: tableHeight+70+'px' }"
  74. :columns="columns"
  75. :data="loadData"
  76. :scroll="{x:2200, y: tableHeight-120}"
  77. :defaultLoadData="false"
  78. :showPagination="false"
  79. bordered>
  80. </s-table>
  81. </a-spin>
  82. </a-card>
  83. </div>
  84. </template>
  85. <script>
  86. import { commonMixin } from '@/utils/mixin'
  87. import { hdExportExcel } from '@/libs/exportExcel'
  88. import moment from 'moment'
  89. // 组件
  90. import { STable, VSelect } from '@/components'
  91. import subarea from '@/views/common/subarea.js'
  92. import Area from '@/views/common/area.js'
  93. import BizUser from '@/views/common/bizUser.js'
  94. import customerService from '@/views/common/customerService.vue'
  95. // 接口
  96. import { promoProvinceList, promoProvinceTableTitle, promoProvinceCount, promoProvinceExport } from '@/api/reportData'
  97. export default {
  98. name: 'ProvinceFeeList',
  99. mixins: [commonMixin],
  100. components: { STable, VSelect, subarea, Area, BizUser, customerService },
  101. data () {
  102. return {
  103. spinning: false,
  104. disabled: false, // 查询、重置按钮是否可操作
  105. tableHeight: 0, // 表格高度
  106. exportLoading: false, // 导出按钮加载状态
  107. // 查询条件
  108. monthVal: moment().format('YYYY-MM'), // 初始化月份值
  109. queryParam: {
  110. beginDate: moment().startOf('month').format('YYYY-MM-DD') + ' 00:00:00', // 月份开始时间
  111. endDate: moment().endOf('month').format('YYYY-MM-DD') + ' 23:59:59', // 月份结束时间
  112. provinceSn: undefined, // 省
  113. subareaArea: {
  114. subareaSn: '', // 区域
  115. subareaAreaSn: '', // 分区
  116. bizUserSn: undefined// 区域负责人
  117. }
  118. },
  119. countLabel: null, // 统计名称合集
  120. totalData: null, // 统计数据
  121. columns: [], // 表格列
  122. rules: {
  123. 'beginDate': [{ required: true, message: '请选择查询月份', trigger: 'change' }]
  124. },
  125. // 加载数据方法 必须为 Promise 对象
  126. loadData: parameter => {
  127. this.disabled = true
  128. this.spinning = true
  129. const params = Object.assign(parameter, this.queryParam)
  130. // 获取列表数据 有分页
  131. return promoProvinceList(params).then(res => {
  132. let data
  133. if (res.status == 200) {
  134. data = res.data
  135. // 计算表格序号
  136. for (var i = 0; i < data.length; i++) {
  137. data[i].no = i + 1
  138. }
  139. this.disabled = false
  140. // 统计
  141. // this.getCount(params)
  142. }
  143. this.spinning = false
  144. return data
  145. })
  146. }
  147. }
  148. },
  149. methods: {
  150. // 选择月份 禁用选择当月以后日期
  151. disabledDate (current) {
  152. return current && current >= moment().endOf('day')
  153. },
  154. // 选择月份 change
  155. onChangeMonth (date, dateString) {
  156. this.monthVal = dateString
  157. if (date && dateString != '') {
  158. this.queryParam.beginDate = this.getMonthRange(dateString).firstDay
  159. this.queryParam.endDate = this.getMonthRange(dateString).lastDay
  160. } else {
  161. this.queryParam.beginDate = undefined
  162. this.queryParam.endDate = undefined
  163. }
  164. },
  165. // 获取指定月份 第一天和最后一天
  166. getMonthRange (targetMonth) {
  167. // 获取指定月第一天(格式化为 YYYY-MM-DD)
  168. const firstDay = moment(targetMonth).startOf('month').format('YYYY-MM-DD') + ' 00:00:00'
  169. // 获取指定月最后一天(格式化为 YYYY-MM-DD)
  170. const lastDay = moment(targetMonth).endOf('month').format('YYYY-MM-DD') + ' 23:59:59'
  171. return { firstDay, lastDay }
  172. },
  173. // 获取表头
  174. async getTableTitle () {
  175. const _this = this
  176. const tableTitle = await promoProvinceTableTitle().then(res => res.data)
  177. this.columns = tableTitle.list
  178. this.columns.unshift({ title: '序号', customRender: 'no', dataIndex: 'no', fixed: 'left', align: 'center' })
  179. this.countLabel = tableTitle.count
  180. this.columns.map(item => {
  181. let mw = 20
  182. if (item.customRender == 'amount') {
  183. mw = 15
  184. item.customRender = function (text) { return (text || text == 0) ? _this.toThousands(text) : '--' }
  185. } else if (item.customRender == 'no') {
  186. mw = 10
  187. } else {
  188. item.customRender = function (text) { return text || '--' }
  189. }
  190. const w = item.title.length * mw
  191. const tw = w <= 80 ? mw * 5 : w
  192. item.width = tw + 'px'
  193. this.tableWidth = this.tableWidth + tw
  194. })
  195. this.resetSearchForm()
  196. },
  197. // 统计
  198. getCount (params) {
  199. promoProvinceCount(params).then(res => {
  200. if (res.status == 200 && res.data) {
  201. const mergedList = this.countLabel.map(item => {
  202. const key = item.key
  203. return key in res.data
  204. ? { ...item, [key]: res.data[key] }
  205. : item
  206. })
  207. this.totalData = mergedList
  208. } else {
  209. this.totalData = null
  210. }
  211. })
  212. },
  213. // 查询
  214. handleSearch () {
  215. const _this = this
  216. this.$refs.ruleForm.validate(valid => {
  217. if (valid) {
  218. _this.$refs.table.refresh(true)
  219. } else {
  220. _this.$message.error('请选择查询月份')
  221. return false
  222. }
  223. })
  224. },
  225. // 地区
  226. areaChange (val) {
  227. this.queryParam.dealerEntity.provinceSn = val[0] ? val[0] : undefined
  228. this.queryParam.dealerEntity.citySn = val[1] ? val[1] : undefined
  229. this.queryParam.dealerEntity.districtSn = val[2] ? val[2] : undefined
  230. },
  231. // 区域分区 change
  232. subareaChange (val) {
  233. this.queryParam.subareaArea.subareaSn = val[0] ? val[0] : ''
  234. this.queryParam.subareaArea.subareaAreaSn = val[1] ? val[1] : ''
  235. },
  236. // 重置
  237. resetSearchForm () {
  238. this.queryParam.beginDate = moment().startOf('month').format('YYYY-MM-DD') + ' 00:00:00'
  239. this.queryParam.endDate = moment().endOf('month').format('YYYY-MM-DD') + ' 23:59:59'
  240. this.monthVal = moment().format('YYYY-MM')
  241. this.queryParam.provinceSn = undefined
  242. this.queryParam.subareaArea.subareaSn = ''
  243. this.queryParam.subareaArea.subareaAreaSn = ''
  244. this.queryParam.subareaArea.bizUserSn = undefined
  245. this.$refs.subarea.clearData()
  246. this.totalData = null
  247. this.$refs.areaList.clearData()
  248. this.$refs.table.clearTable()
  249. this.$refs.ruleForm.resetFields()
  250. },
  251. // 导出 必填判断
  252. handleExport () {
  253. const _this = this
  254. this.$refs.ruleForm.validate(valid => {
  255. if (valid) {
  256. _this.exportList()
  257. } else {
  258. _this.$message.error('请选择查询月份')
  259. return false
  260. }
  261. })
  262. },
  263. // 导出
  264. exportList () {
  265. const _this = this
  266. const params = JSON.parse(JSON.stringify(_this.queryParam))
  267. _this.exportLoading = true
  268. _this.spinning = true
  269. hdExportExcel(promoProvinceExport, params, '促销费用报表(省份)', function () {
  270. _this.exportLoading = false
  271. _this.spinning = false
  272. })
  273. },
  274. // 初始化
  275. pageInit () {
  276. this.$nextTick(() => { // 页面渲染完成后的回调
  277. this.setTableH()
  278. this.resetSearchForm()
  279. })
  280. },
  281. // 计算表格高度
  282. setTableH () {
  283. const tableSearchH = this.$refs.tableSearch.offsetHeight
  284. this.tableHeight = window.innerHeight - tableSearchH - 280
  285. }
  286. },
  287. mounted () {
  288. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  289. this.pageInit()
  290. this.getTableTitle()
  291. }
  292. },
  293. activated () {
  294. // 如果是新页签打开,则重置当前页面
  295. if (this.$store.state.app.isNewTab) {
  296. this.pageInit()
  297. this.getTableTitle()
  298. }
  299. }
  300. }
  301. </script>
  302. <style lang="less" scoped>
  303. .monthBox{
  304. width: 100%;
  305. /deep/.ant-calendar-picker-icon{
  306. display:none !important;
  307. }
  308. /deep/.ant-calendar-picker input{
  309. text-align:center;
  310. }
  311. }
  312. </style>