provinceFeeList.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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_promotionFeeExport')"
  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}"
  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, 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].id = i + 1
  138. }
  139. this.disabled = false
  140. }
  141. this.spinning = false
  142. return data
  143. })
  144. }
  145. }
  146. },
  147. methods: {
  148. // 选择月份 禁用选择当月以后日期
  149. disabledDate (current) {
  150. return current && current >= moment().endOf('day')
  151. },
  152. // 选择月份 change
  153. onChangeMonth (date, dateString) {
  154. this.monthVal = dateString
  155. if (date && dateString != '') {
  156. this.queryParam.beginDate = this.getMonthRange(dateString).firstDay
  157. this.queryParam.endDate = this.getMonthRange(dateString).lastDay
  158. } else {
  159. this.queryParam.beginDate = undefined
  160. this.queryParam.endDate = undefined
  161. }
  162. },
  163. // 获取指定月份 第一天和最后一天
  164. getMonthRange (targetMonth) {
  165. // 获取指定月第一天(格式化为 YYYY-MM-DD)
  166. const firstDay = moment(targetMonth).startOf('month').format('YYYY-MM-DD') + ' 00:00:00'
  167. // 获取指定月最后一天(格式化为 YYYY-MM-DD)
  168. const lastDay = moment(targetMonth).endOf('month').format('YYYY-MM-DD') + ' 23:59:59'
  169. return { firstDay, lastDay }
  170. },
  171. // 获取表头
  172. async getTableTitle () {
  173. const _this = this
  174. const tableTitle = await promoProvinceTableTitle().then(res => res.data)
  175. this.columns = tableTitle.list
  176. this.countLabel = tableTitle.count
  177. this.columns.map(item => {
  178. item.titleNum = item.title
  179. let mw = 20
  180. if (item.customRender == 'amount') {
  181. mw = 15
  182. if (item.colour && item.colour === 'red') {
  183. item.title = <span style="color:red;">{item.titleNum}</span>
  184. item.customRender = (text) => { return <span style="color:red;">{(text || text == 0) ? _this.toThousands(text) : '--'}</span> }
  185. } else {
  186. item.customRender = function (text) { return (text || text == 0) ? _this.toThousands(text) : '--' }
  187. }
  188. } else {
  189. item.customRender = function (text) { return text || '--' }
  190. }
  191. const w = item.titleNum.length * mw
  192. const tw = w <= 80 ? mw * 5 : w
  193. item.width = tw + 'px'
  194. this.tableWidth = this.tableWidth + tw
  195. })
  196. this.resetSearchForm()
  197. },
  198. // 查询
  199. handleSearch () {
  200. const _this = this
  201. this.$refs.ruleForm.validate(valid => {
  202. if (valid) {
  203. _this.$refs.table.refresh(true)
  204. } else {
  205. _this.$message.error('请选择查询月份')
  206. return false
  207. }
  208. })
  209. },
  210. // 地区
  211. areaChange (val) {
  212. this.queryParam.dealerEntity.provinceSn = val[0] ? val[0] : undefined
  213. this.queryParam.dealerEntity.citySn = val[1] ? val[1] : undefined
  214. this.queryParam.dealerEntity.districtSn = val[2] ? val[2] : undefined
  215. },
  216. // 区域分区 change
  217. subareaChange (val) {
  218. this.queryParam.subareaArea.subareaSn = val[0] ? val[0] : ''
  219. this.queryParam.subareaArea.subareaAreaSn = val[1] ? val[1] : ''
  220. },
  221. // 重置
  222. resetSearchForm () {
  223. this.queryParam.beginDate = moment().startOf('month').format('YYYY-MM-DD') + ' 00:00:00'
  224. this.queryParam.endDate = moment().endOf('month').format('YYYY-MM-DD') + ' 23:59:59'
  225. this.monthVal = moment().format('YYYY-MM')
  226. this.queryParam.provinceSn = undefined
  227. this.queryParam.subareaArea.subareaSn = ''
  228. this.queryParam.subareaArea.subareaAreaSn = ''
  229. this.queryParam.subareaArea.bizUserSn = undefined
  230. this.totalData = null
  231. this.$refs.subarea && this.$refs.subarea.clearData()
  232. this.$refs.areaList && this.$refs.areaList.clearData()
  233. this.$refs.table.clearTable()
  234. this.$refs.ruleForm.resetFields()
  235. },
  236. // 导出 必填判断
  237. handleExport () {
  238. const _this = this
  239. this.$refs.ruleForm.validate(valid => {
  240. if (valid) {
  241. _this.exportList()
  242. } else {
  243. _this.$message.error('请选择查询月份')
  244. return false
  245. }
  246. })
  247. },
  248. // 导出
  249. exportList () {
  250. const _this = this
  251. const params = JSON.parse(JSON.stringify(_this.queryParam))
  252. _this.exportLoading = true
  253. _this.spinning = true
  254. hdExportExcel(promoProvinceExport, params, '促销费用报表(省份)', function () {
  255. _this.exportLoading = false
  256. _this.spinning = false
  257. })
  258. },
  259. // 初始化
  260. pageInit () {
  261. this.$nextTick(() => { // 页面渲染完成后的回调
  262. this.setTableH()
  263. this.resetSearchForm()
  264. })
  265. },
  266. // 计算表格高度
  267. setTableH () {
  268. const tableSearchH = this.$refs.tableSearch.offsetHeight
  269. this.tableHeight = window.innerHeight - tableSearchH - 280
  270. }
  271. },
  272. mounted () {
  273. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  274. this.pageInit()
  275. this.getTableTitle()
  276. }
  277. },
  278. activated () {
  279. // 如果是新页签打开,则重置当前页面
  280. if (this.$store.state.app.isNewTab) {
  281. this.pageInit()
  282. this.getTableTitle()
  283. }
  284. }
  285. }
  286. </script>
  287. <style lang="less" scoped>
  288. .monthBox{
  289. width: 100%;
  290. /deep/.ant-calendar-picker-icon{
  291. display:none !important;
  292. }
  293. /deep/.ant-calendar-picker input{
  294. text-align:center;
  295. }
  296. }
  297. </style>