list.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <a-card size="small" :bordered="false" class="chainStockIncomeReportList-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 搜索条件 -->
  5. <div class="table-page-search-wrapper">
  6. <a-form-model
  7. id="chainStockIncomeReportList-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="handelSearch" >
  16. <a-row :gutter="15">
  17. <a-col :md="6" :sm="24">
  18. <a-form-model-item label="连锁店" prop="tenantId">
  19. <a-select
  20. placeholder="请选择连锁店"
  21. id="chainStockIncomeReportList-tenantId"
  22. allowClear
  23. v-model="queryParam.tenantId"
  24. :showSearch="true"
  25. option-filter-prop="children"
  26. :filter-option="filterOption">
  27. <a-select-option v-for="item in linkageGroupData" :id="item.dealerSn" :key="item.dealerSn" :value="item.dealerSn">{{ item.dealerName }}</a-select-option>
  28. </a-select>
  29. </a-form-model-item>
  30. </a-col>
  31. <a-col :md="6" :sm="24">
  32. <a-form-model-item label="入库完成时间" prop="time">
  33. <rangeDate id="chainStockIncomeReportList-time" ref="rangeDate" :value="queryParam.time" @change="dateChange" />
  34. </a-form-model-item>
  35. </a-col>
  36. <a-col :md="6" :sm="24">
  37. <a-button type="primary" @click="handelSearch" id="chainStockIncomeReportList-refresh">查询</a-button>
  38. <a-button style="margin-left: 8px" @click="resetSearchForm" id="chainStockIncomeReportList-reset">重置</a-button>
  39. </a-col>
  40. </a-row>
  41. </a-form-model>
  42. </div>
  43. <!-- 列表 -->
  44. <a-row :gutter="15" style="margin-top: 50px;">
  45. <a-col :md="12" :sm="24">
  46. <div class="chart-box">
  47. <div class="chart-hj">
  48. 库存总入数量:{{ (totalData&&totalData.totalQty) ? toThousands(totalData.totalQty,0) : '--' }}
  49. &nbsp;&nbsp;&nbsp;&nbsp;
  50. 总成本:{{ (totalData&&totalData.totalCost) ? toThousands(totalData.totalCost) : '--' }}
  51. </div>
  52. <div id="con1" class="chart"></div>
  53. </div>
  54. </a-col>
  55. <a-col :md="12" :sm="24" style="margin-top: 30px;">
  56. <a-table
  57. class="sTable"
  58. ref="table"
  59. size="small"
  60. :rowKey="(record) => record.dataBizTypeDictValue"
  61. :columns="columns"
  62. :dataSource="tableData"
  63. :loading="listLoading"
  64. :pagination="false"
  65. bordered>
  66. </a-table>
  67. </a-col>
  68. </a-row>
  69. </a-spin>
  70. </a-card>
  71. </template>
  72. <script>
  73. import { commonMixin } from '@/utils/mixin'
  74. import rangeDate from '@/views/common/rangeDate.vue'
  75. import echarts from 'echarts'
  76. import { reportStockPutList } from '@/api/reportStock'
  77. import { linkageGroupList } from '@/api/reportData'
  78. import { on, off } from '@/libs/tools'
  79. export default {
  80. components: { rangeDate },
  81. mixins: [commonMixin],
  82. data () {
  83. const _this = this
  84. return {
  85. spinning: false,
  86. queryParam: { // 查询条件
  87. time: [],
  88. beginDate: '',
  89. endDate: '',
  90. tenantId: undefined
  91. },
  92. labelCol: { span: 8 },
  93. wrapperCol: { span: 16 },
  94. rules: {
  95. 'tenantId': [{ required: true, message: '请选择连锁店', trigger: 'change' }],
  96. 'time': [{ required: true, message: '请选择入库完成时间', trigger: 'change' }]
  97. },
  98. disabled: false, // 查询、重置按钮是否可操作
  99. columns: [
  100. { title: '明细项', dataIndex: 'dataBizTypeDictValue', width: '25%', align: 'center', customRender: function (text) { return text || '--' } },
  101. { title: '数量(件)', dataIndex: 'productQty', width: '25%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  102. { title: '成本(元)', dataIndex: 'productCost', width: '25%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
  103. { title: '售价(元)', dataIndex: 'productPrice', width: '25%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } }
  104. ],
  105. // 统计图
  106. pieData: [],
  107. pieColor: ['#00aaff', '#ffaa00', '#00aa00', '#ff55ff', '#1dc5d4', '#8465c7', '#00ffff'],
  108. tableData: [], // 含总计数据
  109. loadData: [], // 不含总计数据
  110. listLoading: false, // loading
  111. chart1: null, // 图表对象
  112. totalData: null, // 统计
  113. linkageGroupData: [] // 连锁店下拉
  114. }
  115. },
  116. methods: {
  117. // 初始化饼图 title: 标题 data:数据 bit:单位
  118. initPie (chart, title, data, bit) {
  119. const legend = []
  120. if (bit) {
  121. data.map(item => {
  122. const p = `${item.name}: ${item.value}${bit}`
  123. legend.push(p)
  124. })
  125. }
  126. const option = {
  127. color: this.pieColor,
  128. title: {
  129. text: title,
  130. top: 20,
  131. left: 20,
  132. textStyle: {
  133. color: '#abd7ff'
  134. },
  135. textAlingn: 'left'
  136. },
  137. tooltip: {
  138. trigger: 'item',
  139. formatter: `{b} : {d}%`
  140. },
  141. legend: {
  142. orient: 'horizontal',
  143. left: 'center',
  144. bottom: '5',
  145. padding: 5,
  146. textStyle: {
  147. color: '#abd7ff',
  148. fontSize: 10
  149. },
  150. show: !!bit,
  151. formatter: function (name) {
  152. if (bit) {
  153. const p = data.find(item => item.name == name)
  154. return name + (p ? (':' + p.value + bit) : '')
  155. }
  156. }
  157. },
  158. series: [{
  159. type: 'pie',
  160. radius: ['50%', '70%'],
  161. startAngle: 75,
  162. top: 50,
  163. avoidLabelOverlap: true, // 在标签拥挤重叠的情况下会挪动各个标签的位置,防止标签间的重叠
  164. label: {
  165. normal: {
  166. formatter: params => {
  167. return (
  168. '{name|' + params.name + '}{value|' + params.percent + '%' + '}'
  169. )
  170. },
  171. padding: [0, -70, 25, -70],
  172. rich: {
  173. name: {
  174. fontSize: 12,
  175. padding: [0, 4, 0, 4],
  176. color: '#999'
  177. },
  178. value: {
  179. fontSize: 12,
  180. color: '#999'
  181. }
  182. }
  183. }
  184. },
  185. labelLine: {
  186. normal: {
  187. length: 20,
  188. length2: 70,
  189. lineStyle: {
  190. color: '#e6e6e6'
  191. }
  192. }
  193. },
  194. data: data,
  195. insideLabel: {
  196. show: true
  197. }
  198. }]
  199. }
  200. return option
  201. },
  202. // 时间 change
  203. dateChange (date) {
  204. this.queryParam.time = date
  205. this.queryParam.beginDate = date[0] || ''
  206. this.queryParam.endDate = date[1] || ''
  207. },
  208. // 查询
  209. handelSearch () {
  210. this.$refs.ruleForm.validate(valid => {
  211. if (valid) {
  212. this.getList()
  213. } else {
  214. return false
  215. }
  216. })
  217. },
  218. // 查询列表
  219. getList () {
  220. const params = {
  221. beginDate: this.queryParam.beginDate,
  222. endDate: this.queryParam.endDate,
  223. tenantId: this.queryParam.tenantId
  224. }
  225. // 开始查询
  226. this.listLoading = true
  227. this.spinning = true
  228. reportStockPutList(params).then(res => {
  229. this.listLoading = false
  230. if (res.status == 200 && res.data) {
  231. const reportStockPutVOList = (res.data && res.data.reportStockPutVOList) ? res.data.reportStockPutVOList : []
  232. const totalQty = (res.data && (res.data.totalQty || res.data.totalQty == 0)) ? res.data.totalQty : '--'
  233. const totalPrice = (res.data && (res.data.totalPrice || res.data.totalPrice == 0)) ? res.data.totalPrice : '--'
  234. const totalCost = (res.data && (res.data.totalCost || res.data.totalCost == 0)) ? res.data.totalCost : '--'
  235. this.totalData = {
  236. totalQty: totalQty,
  237. totalPrice: totalPrice,
  238. totalCost: totalCost
  239. }
  240. if (reportStockPutVOList) {
  241. this.loadData = res.data.reportStockPutVOList
  242. this.tableData = res.data.reportStockPutVOList
  243. const total = [{ dataBizTypeDictValue: '总入', productQty: totalQty, productCost: totalCost, productPrice: totalPrice }]
  244. this.tableData = [...this.tableData, ...total]
  245. } else {
  246. this.loadData = []
  247. this.tableData = []
  248. }
  249. this.chartInit()
  250. } else {
  251. this.loadData = []
  252. this.tableData = []
  253. this.totalData = null
  254. this.chartInit()
  255. }
  256. this.spinning = false
  257. })
  258. },
  259. // 图表初始化
  260. chartInit () {
  261. this.pieData = []
  262. if (this.loadData.length < 1) {
  263. this.pieData = [{ name: '总成本', value: 0 }]
  264. } else {
  265. this.loadData.map((item, index) => {
  266. if (index != this.loadData.length) {
  267. this.pieData.push({
  268. name: item.dataBizTypeDictValue + '总成本',
  269. value: item.productCost
  270. })
  271. }
  272. })
  273. }
  274. const con1 = document.getElementById('con1')
  275. const chart1 = echarts.init(con1)
  276. const option = this.initPie(chart1, '', this.pieData)
  277. chart1.setOption(option)
  278. this.chart1 = chart1
  279. this.chart1.resize()
  280. },
  281. // 重置
  282. resetSearchForm () {
  283. this.$refs.rangeDate.resetDate()
  284. this.queryParam.time = []
  285. this.queryParam.beginDate = ''
  286. this.queryParam.endDate = ''
  287. this.queryParam.tenantId = undefined
  288. this.loadData = []
  289. this.tableData = []
  290. this.totalData = null
  291. this.chartInit()
  292. },
  293. // 连锁店筛选
  294. filterOption (input, option) {
  295. return (
  296. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  297. )
  298. },
  299. // 连锁店
  300. getLinkageGroup () {
  301. linkageGroupList({}).then(res => {
  302. if (res.status == 200) {
  303. const data = res.data || []
  304. if (data.length > 0) {
  305. this.linkageGroupData = data
  306. } else {
  307. this.linkageGroupData = []
  308. }
  309. } else {
  310. this.linkageGroupData = []
  311. }
  312. })
  313. },
  314. chartResize () {
  315. this.chart1.resize()
  316. },
  317. pageInit () {
  318. this.getLinkageGroup()
  319. }
  320. },
  321. mounted () {
  322. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  323. this.pageInit()
  324. this.resetSearchForm()
  325. }
  326. },
  327. activated () {
  328. on(window, 'resize', this.chartResize)
  329. // 如果是新页签打开,则重置当前页面
  330. if (this.$store.state.app.isNewTab) {
  331. this.pageInit()
  332. this.resetSearchForm()
  333. }
  334. },
  335. deactivated () {
  336. off(window, 'resize', this.chartResize)
  337. },
  338. beforeDestroy () {
  339. off(window, 'resize', this.chartResize)
  340. },
  341. beforeRouteEnter (to, from, next) {
  342. next(vm => {})
  343. }
  344. }
  345. </script>
  346. <style lang="less">
  347. .chainStockIncomeReportList-wrap{
  348. min-height: 700px;
  349. .chart-box{
  350. height: 400px;
  351. .chart-hj{
  352. font-size: 22px;
  353. text-align: center;
  354. }
  355. .chart{
  356. width: 100%;
  357. height: 450px;
  358. overflow: auto;
  359. }
  360. }
  361. }
  362. </style>