department.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <div v-loading="loading">
  3. <div class="search clear" style="align-items: center;">
  4. <el-switch
  5. style="margin-right: 10px;"
  6. v-model="isTenThound"
  7. active-text="万元"
  8. inactive-text="元"
  9. />
  10. <el-select size="small" style="margin-right:10px" v-model="companyNo" @change="requestData">
  11. <el-option
  12. v-for="depart in companies"
  13. :key="depart.value"
  14. :label="depart.label"
  15. :value="depart.value"
  16. />
  17. </el-select>
  18. <el-date-picker
  19. class="fr picker"
  20. v-model="daytime"
  21. :picker-options="{
  22. disbaledData(time) { return time.getTime() > Date.now(); }
  23. }"
  24. placeholder="选择日期"
  25. style=";width:150px"
  26. value-format="yyyy-MM-dd"
  27. format="yyyy-MM-dd"
  28. :editable="false"
  29. :clearable="false"
  30. :size="'small'"
  31. align="right"
  32. type="date"
  33. />
  34. </div>
  35. <el-row style="margin-top: 10px; display: flex;">
  36. <el-table border size="mini" :data="list" :span-method="spanMethod" :cell-class-name="setCellClassName">
  37. <el-table-column fixed="left" label="公司" prop="company" align="center" width="140px" />
  38. <el-table-column fixed="left" label="部门" prop="depart" align="center" width="140px" />
  39. <el-table-column label="当日营业收入" align="center" width="120px">
  40. <template slot-scope="scope">{{ unit2TenThousand(scope.row.dayinfo.sale_total,isTenThound) }}</template>
  41. </el-table-column>
  42. <el-table-column label="当月营收目标" align="center" width="120px">
  43. <template slot-scope="scope">{{ unit2TenThousand(scope.row.total_tips,isTenThound) }}</template>
  44. </el-table-column>
  45. <el-table-column label="当月营业收入(净)" align="center" width="400px">
  46. <template slot-scope="scope">
  47. <div style="display:flex;flex-direction: column;">
  48. <p style="text-align: center;">{{ unit2TenThousand(scope.row.monthinfo.monthNetSales,isTenThound)}}</p>
  49. <div class="table-size">
  50. <p>直营/自营: {{ unit2TenThousand(scope.row.currentMonthPure[0].zy,isTenThound) }}</p>
  51. <p>渠道: {{unit2TenThousand(scope.row.currentMonthPure[0].qd,isTenThound)}}</p>
  52. </div>
  53. </div>
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="成本" align="center" min-width="400px">
  57. <!-- <el-table-column align="center" label="直营/自营">
  58. <template slot-scope="scope">{{unit2TenThousand(scope.row.zy_cost,isTenThound)}}</template>
  59. </el-table-column>
  60. <el-table-column align="center" label="渠道">
  61. <template slot-scope="scope">{{unit2TenThousand(scope.row.qd_cost,isTenThound)}}</template>
  62. </el-table-column> -->
  63. <template slot-scope="scope">
  64. <div style="display:flex;flex-direction: column;">
  65. <p style="text-align: center;">{{ unit2TenThousand(Number(addition(scope.row.zy_cost,scope.row.qd_cost)).toFixed(2),isTenThound) }}</p>
  66. <div class="table-size">
  67. <p>直营/自营: {{ unit2TenThousand(scope.row.zy_cost,isTenThound) }}</p>
  68. <p>渠道: {{unit2TenThousand(scope.row.qd_cost,isTenThound)}}</p>
  69. </div>
  70. </div>
  71. </template>
  72. </el-table-column>
  73. <el-table-column align="center" label="毛利" min-width="400px">
  74. <!-- <el-table-column align="center" label="直营/自营">
  75. <template slot-scope="scope">{{unit2TenThousand(scope.row.zy_gross,isTenThound)}}</template>
  76. </el-table-column>
  77. <el-table-column align="center" label="渠道">
  78. <template slot-scope="scope">{{unit2TenThousand(scope.row.qd_gross,isTenThound)}}</template>
  79. </el-table-column> -->
  80. <template slot-scope="scope">
  81. <div style="display:flex;flex-direction: column;">
  82. <p style="text-align: center;">{{ unit2TenThousand(Number(addition(scope.row.zy_gross,scope.row.qd_gross)).toFixed(2),isTenThound) }}</p>
  83. <div class="table-size">
  84. <p>直营/自营: {{ unit2TenThousand(scope.row.zy_gross,isTenThound) }}</p>
  85. <p>渠道: {{unit2TenThousand(scope.row.qd_gross,isTenThound)}}</p>
  86. </div>
  87. </div>
  88. </template>
  89. </el-table-column>
  90. </el-table>
  91. </el-row>
  92. </div>
  93. </template>
  94. <script>
  95. import asyncRequest from "@/api/newResults";
  96. import setHeight from "@/mixins/index";
  97. import {
  98. addition,
  99. division,
  100. subtraction,
  101. multiplication,
  102. unit2TenThousand
  103. } from "../newReport/src/_utils";
  104. export default {
  105. mixins: [ setHeight ],
  106. data(){
  107. return {
  108. list: [],
  109. daytime: "",
  110. companyNo: "GS2203161855277894",
  111. loading: false,
  112. isTenThound: true,
  113. companies:[
  114. { value : "GS2302231125079621", label : "北京百辰荣达国际科贸有限公司"},
  115. { value : "GS2302231323386950", label : "北京泓源广诚国际商贸有限公司"},
  116. { value : "GS2203161855277894", label : "北京万宇恒通国际科贸有限公司"},
  117. { value : "GS2302231124114965", label : "北京普润心堂商贸有限公司"},
  118. { value : "GS2304031312553746", label : "北京锦兴弘昌科技有限公司"}
  119. ]
  120. }
  121. },
  122. computed:{
  123. currentCompanyName(){
  124. return this.companies.find(item => item.value === this.companyNo).label;
  125. }
  126. },
  127. mounted() {
  128. this.daytime = this.transformTime();
  129. this.requestData();
  130. },
  131. watch:{ daytime:{ handler(){ this.requestData() }}},
  132. methods: {
  133. addition,
  134. unit2TenThousand,
  135. transformTime() {
  136. let time = new Date();
  137. let y = time.getFullYear();
  138. let M = time.getMonth() + 1;
  139. let d = time.getDate();
  140. return y + "-" + (M < 10 ? "0" + M : M) + "-" + (d < 10 ? "0" + d : d);
  141. },
  142. /* 表格合并列和行 */
  143. spanMethod({ rowIndex, columnIndex }) {
  144. if (columnIndex === 0) {
  145. const _row = this.flitterData(this.list).one[rowIndex];
  146. const _col = _row > 0 ? 1 : 0;
  147. return { rowspan: _row, colspan: _col };
  148. }
  149. },
  150. /**合并表格的第一列,处理表格数据 */
  151. flitterData(arr) {
  152. let spanOneArr = [];
  153. let concatOne = 0;
  154. arr.forEach((item, index) => {
  155. if (index === 0) {
  156. spanOneArr.push(1);
  157. } else {
  158. //注意这里的quarterly是表格绑定的字段,根据自己的需求来改
  159. if (item.company === arr[index - 1].company) {
  160. //第一列需合并相同内容的判断条件
  161. spanOneArr[concatOne] += 1;
  162. spanOneArr.push(0);
  163. } else {
  164. spanOneArr.push(1);
  165. concatOne = index;
  166. }
  167. }
  168. });
  169. return { one: spanOneArr };
  170. },
  171. setCellClassName({ column }) {
  172. const { label } = column;
  173. return label === "当月营业收入(净)" || label=== "成本" || label === "毛利" ? "pure__cell" : "";
  174. },
  175. async requestData() {
  176. this.loading = true;
  177. this.list = [];
  178. const res = await asyncRequest.departmentEveryDay({ daytime: this.daytime, companyNo: this.companyNo });
  179. if (res.code === 0 && res.data && res.data.length > 0) {
  180. let list = (res.data || [])
  181. .map(({depart, msale_total, mth_total, sale_total, th_total, total_tips ,mzy_sale_total, mchannel_sale_total,channel_cost_total,zy_cost_total,mchannel_cost_total}) => {
  182. return {
  183. depart, total_tips,mzy_sale_total, mchannel_sale_total, channel_cost_total, zy_cost_total,mchannel_cost_total,
  184. dayinfo: { sale_total, th_total }, monthinfo:{ msale_total, mth_total }
  185. }
  186. });
  187. this.total = list.reduce((prev,current) => {
  188. const { total_tips = 0, day = 0, month = 0 } = current;
  189. return { total_tips: addition(total_tips,prev.total_tips), month: addition(month,prev.month), day: addition(day, prev.day) }
  190. },
  191. { total_tips: 0, month: 0, day: 0}
  192. )
  193. let mapDepart = ["百辰","泓源","普润","平台"]
  194. list = mapDepart.map(d => list.find(({ depart }) => depart === d))
  195. const mapToDepartment = { 百辰:"客服部@百辰荣达", 泓源:"网络部@泓源广诚", 普润:" 项目部@普润心堂", 平台:" 平台部@万宇恒通" }
  196. const company = this.companies.find(item => item.value === this.companyNo);
  197. this.list = list.map(({depart,total_tips,dayinfo,monthinfo,mchannel_sale_total,mzy_sale_total,zy_cost_total,mchannel_cost_total}) => {
  198. /* 月净销售 = 月销售 - 月退货 **/
  199. const monthNetSales = subtraction(monthinfo.msale_total, monthinfo.mth_total)
  200. /* 月经销售完成率 = 月净销售 / 销售指标 **/
  201. const monthProportion = multiplication(division(monthNetSales,total_tips),100).toFixed(2)
  202. return {
  203. total_tips, // 营收目标
  204. zy_cost: zy_cost_total, // 自营成本
  205. qd_cost: mchannel_cost_total, // 渠道成本
  206. depart: mapToDepartment[depart],
  207. company: company.label,
  208. currentMonthPure:[ { zy : mzy_sale_total, qd: mchannel_sale_total } ], // 当月营业收入(净)
  209. zy_gross:Number(subtraction(mzy_sale_total,zy_cost_total)).toFixed(2), // 自营毛利 = 自营营收 - 自营成本
  210. qd_gross:Number(subtraction(mchannel_sale_total,mchannel_cost_total)).toFixed(2), // 渠道毛利 = 渠道营收 - 渠道成本
  211. dayinfo:{ ...dayinfo, /** 日销售额 = 日销售额 - 日退货额 */ sale_total:subtraction(dayinfo.sale_total,dayinfo.th_total) },
  212. /* 占比 = (当前部门销售额 / 各部门总销售额) / 100 **/
  213. proportion:multiplication( division(monthinfo.msale_total,this.total.month) || 0 ,100) || 0,
  214. monthinfo:{ monthNetSales,monthProportion: monthProportion }
  215. }
  216. })
  217. } else {
  218. this.list = [];
  219. }
  220. this.getHeight();
  221. this.loading = false;
  222. },
  223. },
  224. }
  225. </script>
  226. <style lang="scss" scoped>
  227. .new-results{
  228. .search {
  229. height:36px;
  230. display: flex;
  231. justify-content: end;
  232. padding:0px 10px;
  233. margin-top:10px
  234. }
  235. .table-size{
  236. display: flex;
  237. border-top: 1px solid #ebeef5;
  238. p {
  239. flex:1;
  240. border-right: 1px solid #ebeef5;
  241. padding: 5px 10px;
  242. margin: 0px;
  243. &:last-child {
  244. border: none;
  245. }
  246. }
  247. }
  248. }
  249. </style>