promoFeeList.vue 13 KB

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