customerFeeList.vue 13 KB

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