list.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template>
  2. <a-card size="small" :bordered="false" class="stockIncomeReportList-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 搜索条件 -->
  5. <div class="table-page-search-wrapper">
  6. <a-form-model
  7. id="chainStockReportList-form"
  8. ref="ruleForm"
  9. :model="queryParam"
  10. :rules="rules"
  11. :labelCol="labelCol"
  12. :wrapperCol="wrapperCol"
  13. @keyup.enter.native="handelSearch" >
  14. <a-row :gutter="15">
  15. <a-col :md="8" :sm="24">
  16. <a-form-model-item label="入库完成时间" prop="time">
  17. <rangeDate ref="rangeDate" @change="dateChange" />
  18. </a-form-model-item>
  19. </a-col>
  20. <a-col :md="6" :sm="24">
  21. <a-button type="primary" @click="handelSearch" id="stockIncomeReportList-refresh">查询</a-button>
  22. <a-button style="margin-left: 8px" @click="resetSearchForm" id="stockIncomeReportList-reset">重置</a-button>
  23. </a-col>
  24. </a-row>
  25. </a-form-model>
  26. </div>
  27. <!-- 列表 -->
  28. <a-row :gutter="15" style="margin-top: 50px;">
  29. <a-col :md="12" :sm="24">
  30. <div class="chart-box">
  31. <div class="chart-hj">
  32. 库存总入数量:{{ (totalData&&totalData.totalQty) ? totalData.totalQty : '--' }},
  33. 总成本:¥{{ (totalData&&totalData.totalCost) ? totalData.totalCost : '--' }}
  34. </div>
  35. <div id="con1" class="chart"></div>
  36. </div>
  37. </a-col>
  38. <a-col :md="12" :sm="24" style="margin-top: 30px;">
  39. <a-table
  40. class="sTable"
  41. ref="table"
  42. size="default"
  43. :rowKey="(record) => record.dataBizTypeDictValue"
  44. :columns="columns"
  45. :dataSource="tableData"
  46. :loading="listLoading"
  47. :pagination="false"
  48. bordered>
  49. </a-table>
  50. </a-col>
  51. </a-row>
  52. </a-spin>
  53. </a-card>
  54. </template>
  55. <script>
  56. import rangeDate from '@/views/common/rangeDate.vue'
  57. import echarts from 'echarts'
  58. import { reportStockPutList } from '@/api/reportStock'
  59. export default {
  60. components: { rangeDate },
  61. data () {
  62. return {
  63. spinning: false,
  64. queryParam: { // 查询条件
  65. time: [],
  66. beginDate: '',
  67. endDate: ''
  68. },
  69. labelCol: { span: 8 },
  70. wrapperCol: { span: 16 },
  71. rules: {
  72. 'time': [{ required: true, message: '请选择入库完成时间', trigger: 'change' }]
  73. },
  74. disabled: false, // 查询、重置按钮是否可操作
  75. columns: [
  76. { title: '明细项', dataIndex: 'dataBizTypeDictValue', align: 'center', customRender: function (text) { return text || '--' } },
  77. { title: '数量(件)', dataIndex: 'productQty', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  78. { title: '成本(元)', dataIndex: 'productCost', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  79. { title: '售价(元)', dataIndex: 'productPrice', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } }
  80. ],
  81. // 统计图
  82. pieData: [],
  83. pieColor: ['#00aaff', '#ffaa00', '#00aa00', '#ff55ff', '#1dc5d4', '#8465c7', '#00ffff'],
  84. tableData: [], // 含总计数据
  85. loadData: [], // 不含总计数据
  86. listLoading: false,
  87. chart1: null,
  88. totalData: null
  89. }
  90. },
  91. methods: {
  92. // 初始化饼图 title: 标题 data:数据 bit:单位
  93. initPie (chart, title, data, bit) {
  94. const legend = []
  95. if (bit) {
  96. data.map(item => {
  97. const p = `${item.name}: ${item.value}${bit}`
  98. legend.push(p)
  99. })
  100. }
  101. const option = {
  102. color: this.pieColor,
  103. title: {
  104. text: title,
  105. top: 20,
  106. left: 20,
  107. textStyle: {
  108. color: '#abd7ff'
  109. },
  110. textAlingn: 'left'
  111. },
  112. tooltip: {
  113. trigger: 'item',
  114. formatter: `{b} : {d}%`
  115. },
  116. legend: {
  117. orient: 'horizontal',
  118. left: 'center',
  119. bottom: '5',
  120. padding: 5,
  121. textStyle: {
  122. color: '#abd7ff',
  123. fontSize: 10
  124. },
  125. show: !!bit,
  126. formatter: function (name) {
  127. if (bit) {
  128. const p = data.find(item => item.name == name)
  129. return name + (p ? (':' + p.value + bit) : '')
  130. }
  131. }
  132. },
  133. series: [{
  134. type: 'pie',
  135. radius: ['50%', '70%'],
  136. startAngle: 75,
  137. top: 50,
  138. avoidLabelOverlap: true, // 在标签拥挤重叠的情况下会挪动各个标签的位置,防止标签间的重叠
  139. label: {
  140. normal: {
  141. formatter: params => {
  142. return (
  143. '{name|' + params.name + '}{value|' + params.percent + '%' + '}'
  144. )
  145. },
  146. padding: [0, -70, 25, -70],
  147. rich: {
  148. name: {
  149. fontSize: 12,
  150. padding: [0, 4, 0, 4],
  151. color: '#999'
  152. },
  153. value: {
  154. fontSize: 12,
  155. color: '#999'
  156. }
  157. }
  158. }
  159. },
  160. labelLine: {
  161. normal: {
  162. length: 20,
  163. length2: 70,
  164. lineStyle: {
  165. color: '#e6e6e6'
  166. }
  167. }
  168. },
  169. data: data,
  170. insideLabel: {
  171. show: true
  172. }
  173. }]
  174. }
  175. return option
  176. },
  177. // 时间 change
  178. dateChange (date) {
  179. this.queryParam.time = date
  180. this.queryParam.beginDate = date[0]
  181. this.queryParam.endDate = date[1]
  182. },
  183. handelSearch () {
  184. this.$refs.ruleForm.validate(valid => {
  185. if (valid) {
  186. this.getList()
  187. } else {
  188. console.log('error submit!!')
  189. return false
  190. }
  191. })
  192. },
  193. // 查询列表
  194. getList () {
  195. const params = {
  196. beginDate: this.queryParam.beginDate,
  197. endDate: this.queryParam.endDate
  198. }
  199. // 开始查询
  200. this.listLoading = true
  201. this.spinning = true
  202. reportStockPutList(params).then(res => {
  203. this.listLoading = false
  204. if (res.status == 200) {
  205. const reportStockPutVOList = (res.data && res.data.reportStockPutVOList) ? res.data.reportStockPutVOList : []
  206. const totalQty = (res.data && (res.data.totalQty || res.data.totalQty == 0)) ? res.data.totalQty : '--'
  207. const totalPrice = (res.data && (res.data.totalPrice || res.data.totalPrice == 0)) ? res.data.totalPrice : '--'
  208. const totalCost = (res.data && (res.data.totalCost || res.data.totalCost == 0)) ? res.data.totalCost : '--'
  209. this.totalData = {
  210. totalQty: totalQty,
  211. totalPrice: totalPrice,
  212. totalCost: totalCost
  213. }
  214. if (reportStockPutVOList) {
  215. this.loadData = res.data.reportStockPutVOList
  216. this.tableData = res.data.reportStockPutVOList
  217. const total = [{ dataBizTypeDictValue: '总入', productQty: totalQty, productCost: totalCost, productPrice: totalPrice }]
  218. this.tableData = [...this.tableData, ...total]
  219. } else {
  220. this.loadData = []
  221. this.tableData = []
  222. }
  223. this.chartInit()
  224. }
  225. this.spinning = false
  226. })
  227. },
  228. chartInit () {
  229. this.pieData = []
  230. if (this.loadData.length < 1) {
  231. this.pieData = [{ name: '总成本', value: 0 }]
  232. } else {
  233. this.loadData.map((item, index) => {
  234. if (index != this.loadData.length) {
  235. this.pieData.push({
  236. name: item.dataBizTypeDictValue + '总成本',
  237. value: item.productCost
  238. })
  239. }
  240. })
  241. }
  242. const con1 = document.getElementById('con1')
  243. const chart1 = echarts.init(con1)
  244. const option = this.initPie(chart1, '', this.pieData)
  245. chart1.setOption(option)
  246. this.chart1 = chart1
  247. this.chart1.resize()
  248. },
  249. // 重置
  250. resetSearchForm () {
  251. this.$refs.rangeDate.resetDate()
  252. this.queryParam.time = []
  253. this.queryParam.beginDate = ''
  254. this.queryParam.endDate = ''
  255. this.loadData = []
  256. this.tableData = []
  257. this.totalData = null
  258. this.chartInit()
  259. }
  260. },
  261. mounted () {
  262. window.onresize = () => {
  263. return (() => {
  264. this.chart1.resize()
  265. })()
  266. }
  267. },
  268. beforeRouteEnter (to, from, next) {
  269. next(vm => {
  270. vm.chartInit()
  271. })
  272. }
  273. }
  274. </script>
  275. <style lang="less">
  276. .stockIncomeReportList-wrap{
  277. min-height: 700px;
  278. .chart-box{
  279. height: 400px;
  280. .chart-hj{
  281. font-size: 22px;
  282. text-align: center;
  283. }
  284. .chart{
  285. width: 100%;
  286. height: 450px;
  287. overflow: auto;
  288. }
  289. }
  290. }
  291. </style>