list.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <template>
  2. <a-card size="small" :bordered="false" class="customerReportList-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 搜索条件 -->
  5. <div class="table-page-search-wrapper">
  6. <a-form-model
  7. id="customerReportList-form"
  8. ref="ruleForm"
  9. class="form-model-con"
  10. layout="inline"
  11. :model="queryParam"
  12. :rules="rules"
  13. :labelCol="labelCol"
  14. :wrapperCol="wrapperCol"
  15. @keyup.enter.native="handleSearch" >
  16. <a-row :gutter="15">
  17. <a-col :md="6" :sm="24">
  18. <a-form-model-item label="添加时间" prop="time">
  19. <rangeDate ref="rangeDate" @change="dateChange" />
  20. </a-form-model-item>
  21. </a-col>
  22. <a-col :md="6" :sm="24">
  23. <a-form-model-item label="产品分类">
  24. <a-cascader
  25. @change="changeProductType"
  26. change-on-select
  27. v-model="productType"
  28. expand-trigger="hover"
  29. :options="productTypeList"
  30. :fieldNames="{ label: 'productTypeName', value: 'productTypeSn', children: 'children' }"
  31. id="customerReportList-productType"
  32. placeholder="请选择产品分类"
  33. allowClear />
  34. </a-form-model-item>
  35. </a-col>
  36. <template v-if="advanced">
  37. <a-col :md="12" :sm="24">
  38. <a-row>
  39. <a-form-model-item label="客户所在区" :labelCol="{span: 4}" :wrapperCol="{ span: 20 }">
  40. <a-col span="7">
  41. <a-form-model-item prop="provinceSn" style="margin: 0!important;">
  42. <a-select v-model="queryParam.provinceSn" allowClear @change="getCityList" placeholder="请选择省">
  43. <a-select-option v-for="item in addrProvinceList" :value="item.areaSn" :key="item.areaSn + 'a'">{{ item.name }}</a-select-option>
  44. </a-select>
  45. </a-form-model-item>
  46. </a-col>
  47. <a-col span="7" offset="1">
  48. <a-form-model-item prop="citySn" style="margin: 0!important;">
  49. <a-select v-model="queryParam.citySn" allowClear @change="getAreaList" placeholder="请选择市">
  50. <a-select-option v-for="item in addrCityList" :value="item.areaSn" :key="item.areaSn + 'b'">{{ item.name }}</a-select-option>
  51. </a-select>
  52. </a-form-model-item>
  53. </a-col>
  54. <a-col span="7" offset="1">
  55. <a-form-model-item prop="countySn" style="margin: 0!important;">
  56. <a-select v-model="queryParam.countySn" allowClear placeholder="请选择区/县">
  57. <a-select-option v-for="item in addrDistrictList" :value="item.areaSn" :key="item.areaSn + 'c'">{{ item.name }}</a-select-option>
  58. </a-select>
  59. </a-form-model-item>
  60. </a-col>
  61. </a-form-model-item>
  62. </a-row>
  63. </a-col>
  64. <a-col :md="6" :sm="24">
  65. <a-form-item label="客户类型">
  66. <custType v-model="queryParam.customerTypeSn" allowClear placeholder="请选择客户类型" style="max-width: 240px;"></custType>
  67. </a-form-item>
  68. </a-col>
  69. </template>
  70. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  71. <a-button type="primary" @click="handleSearch" :disabled="disabled" id="customerReportList-refresh">查询</a-button>
  72. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="customerReportList-reset">重置</a-button>
  73. <a @click="advanced=!advanced" style="margin-left: 8px">
  74. {{ advanced ? '收起' : '展开' }}
  75. <a-icon :type="advanced ? 'up' : 'down'"/>
  76. </a>
  77. </a-col>
  78. </a-row>
  79. </a-form-model>
  80. </div>
  81. <!-- 合计 -->
  82. <a-alert type="info" style="margin-bottom:10px">
  83. <div class="ftext" slot="message">
  84. 总交易金额:<strong>{{ (totalData && (totalData.totalAmount || totalData.totalAmount==0)) ? totalData.totalAmount : '--' }}</strong>;
  85. <div style="display: inline-block;" v-if="$hasPermissions('M_ShowAllCost')">
  86. 总毛利:<strong>{{ (totalData && totalData.totalGrossProfit) ? totalData.totalGrossProfit : '--' }}</strong>;
  87. 总毛利率:<strong>{{ (totalData && totalData.percentage) ? totalData.percentage+'%' : '--' }}</strong>;
  88. </div>
  89. </div>
  90. </a-alert>
  91. <!-- 列表 -->
  92. <s-table
  93. class="sTable"
  94. ref="table"
  95. size="small"
  96. :rowKey="(record) => record.salesTargetSn"
  97. :columns="columns"
  98. :data="loadData"
  99. :defaultLoadData="false"
  100. bordered>
  101. </s-table>
  102. </a-spin>
  103. </a-card>
  104. </template>
  105. <script>
  106. import { commonMixin } from '@/utils/mixin'
  107. import { STable, VSelect } from '@/components'
  108. import rangeDate from '@/views/common/rangeDate.vue'
  109. import custType from '@/views/common/custType.js'
  110. import { getArea } from '@/api/data'
  111. import { dealerProductTypeList } from '@/api/dealerProductType'
  112. import { reportBigCustomerList, reportBigCustomerCount } from '@/api/reportData'
  113. export default {
  114. mixins: [commonMixin],
  115. components: { STable, VSelect, rangeDate, custType },
  116. data () {
  117. return {
  118. spinning: false,
  119. labelCol: { span: 8 },
  120. wrapperCol: { span: 16 },
  121. advanced: true, // 高级搜索 展开/关闭
  122. tableHeight: 0,
  123. queryParam: { // 查询条件
  124. time: [],
  125. beginDate: '',
  126. endDate: '',
  127. productTypeSn1: '', // 产品一级分类
  128. productTypeSn2: '', // 产品二级分类
  129. productTypeSn3: '', // 产品三级分类
  130. provinceSn: undefined, // 省
  131. citySn: undefined, // 市
  132. countySn: undefined, // 区
  133. customerTypeSn: undefined // 客户类型
  134. },
  135. productType: [],
  136. rules: {
  137. 'time': [{ required: true, message: '请选择添加时间', trigger: 'change' }]
  138. },
  139. disabled: false, // 查询、重置按钮是否可操作
  140. exportLoading: false,
  141. // 加载数据方法 必须为 Promise 对象
  142. loadData: parameter => {
  143. this.disabled = true
  144. const params = Object.assign(parameter, this.queryParam)
  145. this.spinning = true
  146. delete params.time
  147. if (params.beginDate) {
  148. return reportBigCustomerList(params).then(res => {
  149. let data
  150. if (res.status == 200) {
  151. data = res.data
  152. // 总计
  153. this.getCount(params)
  154. const no = (data.pageNo - 1) * data.pageSize
  155. for (var i = 0; i < data.list.length; i++) {
  156. data.list[i].no = no + i + 1
  157. data.list[i].percentageUnit = data.list[i].percentage ? data.list[i].percentage + '%' : undefined
  158. }
  159. this.disabled = false
  160. }
  161. this.spinning = false
  162. return data
  163. })
  164. } else {
  165. const _this = this
  166. return new Promise(function (resolve, reject) {
  167. const data = {
  168. pageNo: 1,
  169. pageSize: 10,
  170. list: [],
  171. count: 0
  172. }
  173. _this.disabled = false
  174. _this.spinning = false
  175. _this.$message.info('请选择添加时间')
  176. resolve(data)
  177. })
  178. }
  179. },
  180. totalData: null, // 合计
  181. addrProvinceList: [], // 省下拉
  182. addrCityList: [], // 市下拉
  183. addrDistrictList: [], // 区下拉
  184. productTypeList: [] // 分类下拉数据
  185. }
  186. },
  187. computed: {
  188. columns () {
  189. const arr = [
  190. { title: '序号', dataIndex: 'no', width: '10%', align: 'center' },
  191. { title: '客户名称', dataIndex: 'salesTargetName', width: '30%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true, sorter: true },
  192. { title: '客户类型', dataIndex: 'customerTypeName', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  193. { title: '交易金额', dataIndex: 'totalAmount', width: '15%', align: 'center', customRender: function (text) { return ((text || text == 0) ? ('¥' + text) : '--') }, sorter: true }
  194. ]
  195. if (this.$hasPermissions('M_ShowAllCost')) {
  196. arr.splice(4, 0, { title: '毛利', dataIndex: 'totalGrossProfit', width: '15%', align: 'center', customRender: function (text) { return ((text || text == 0) ? ('¥' + text) : '--') } })
  197. arr.splice(5, 0, { title: '毛利率', dataIndex: 'percentageUnit', width: '15%', align: 'center', customRender: function (text) { return text || '--' }, sorter: true })
  198. }
  199. return arr
  200. }
  201. },
  202. methods: {
  203. // 合计
  204. getCount (params) {
  205. reportBigCustomerCount(params).then(res => {
  206. if (res.status == 200) {
  207. this.totalData = res.data
  208. } else {
  209. this.totalData = null
  210. }
  211. })
  212. },
  213. // 创建时间 change
  214. dateChange (date) {
  215. this.queryParam.time = date
  216. this.queryParam.beginDate = date[0] || ''
  217. this.queryParam.endDate = date[1] || ''
  218. },
  219. // 查询
  220. handleSearch () {
  221. this.$refs.ruleForm.validate(valid => {
  222. if (valid) {
  223. this.$refs.table.refresh(true)
  224. } else {
  225. console.log('error submit!!')
  226. return false
  227. }
  228. })
  229. },
  230. // 重置
  231. resetSearchForm () {
  232. this.$refs.rangeDate.resetDate()
  233. this.queryParam.time = []
  234. this.queryParam.beginDate = ''
  235. this.queryParam.endDate = ''
  236. this.queryParam.productTypeSn1 = ''
  237. this.queryParam.productTypeSn2 = ''
  238. this.queryParam.productTypeSn3 = ''
  239. this.queryParam.provinceSn = undefined
  240. this.queryParam.citySn = undefined
  241. this.queryParam.countySn = undefined
  242. this.queryParam.customerTypeSn = undefined
  243. this.productType = []
  244. this.$refs.ruleForm.resetFields()
  245. this.totalData = null
  246. this.$refs.table.clearTable()
  247. },
  248. filterOption (input, option) {
  249. return (
  250. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  251. )
  252. },
  253. // 产品分类 change
  254. changeProductType (val, opt) {
  255. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  256. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  257. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  258. },
  259. // 产品分类 列表
  260. getProductType () {
  261. dealerProductTypeList({}).then(res => {
  262. if (res.status == 200) {
  263. this.productTypeList = res.data
  264. } else {
  265. this.productTypeList = []
  266. }
  267. })
  268. },
  269. // 获取城市列表
  270. getCityList (val) {
  271. this.addrCityList = []
  272. this.addrDistrictList = []
  273. this.queryParam.citySn = undefined
  274. this.queryParam.countySn = undefined
  275. if (val) {
  276. this.getArea('city', val)
  277. }
  278. },
  279. // 获取区县列表
  280. getAreaList (val) {
  281. this.addrDistrictList = []
  282. this.queryParam.countySn = undefined
  283. if (val) {
  284. this.getArea('district', val)
  285. }
  286. },
  287. // 省/市/区
  288. getArea (leve, sn) {
  289. let params
  290. if (leve == 'province') {
  291. params = { type: '2' }
  292. } else {
  293. params = { parentId: sn, type: leve == 'city' ? '3' : '4' }
  294. }
  295. getArea(params).then(res => {
  296. if (res.status == 200) {
  297. if (leve == 'province') {
  298. this.addrProvinceList = res.data || []
  299. } else if (leve == 'city') {
  300. this.addrCityList = res.data || []
  301. } else if (leve == 'district') {
  302. this.addrDistrictList = res.data || []
  303. }
  304. } else {
  305. if (leve == 'province') {
  306. this.addrProvinceList = []
  307. } else if (leve == 'city') {
  308. this.addrCityList = []
  309. } else if (leve == 'district') {
  310. this.addrDistrictList = []
  311. }
  312. }
  313. })
  314. },
  315. pageInit () {
  316. this.getArea('province')
  317. this.getProductType()
  318. }
  319. },
  320. mounted () {
  321. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  322. this.pageInit()
  323. this.resetSearchForm()
  324. }
  325. },
  326. activated () {
  327. // 如果是新页签打开,则重置当前页面
  328. if (this.$store.state.app.isNewTab) {
  329. this.pageInit()
  330. this.resetSearchForm()
  331. }
  332. },
  333. beforeRouteEnter (to, from, next) {
  334. next(vm => {})
  335. }
  336. }
  337. </script>