customerFeeList.vue 14 KB

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