department.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. <el-table border size="mini" :data="scope.row.currentMonthPure">
  50. <el-table-column align="center" label="直营/自营">
  51. <template slot-scope="scope">{{ unit2TenThousand(scope.row.zy,isTenThound) }}</template>
  52. </el-table-column>
  53. <el-table-column align="center" label="渠道">
  54. <template slot-scope="scope">{{unit2TenThousand(scope.row.qd,isTenThound)}}</template>
  55. </el-table-column>
  56. </el-table>
  57. </div>
  58. </template>
  59. </el-table-column>
  60. <el-table-column label="成本" align="center" min-width="400px">
  61. <el-table-column align="center" label="直营/自营">
  62. <template slot-scope="scope">{{unit2TenThousand(scope.row.zy_cost,isTenThound)}}</template>
  63. </el-table-column>
  64. <el-table-column align="center" label="渠道">
  65. <template slot-scope="scope">{{unit2TenThousand(scope.row.qd_cost,isTenThound)}}</template>
  66. </el-table-column>
  67. </el-table-column>
  68. <el-table-column align="center" label="毛利" min-width="400px">
  69. <el-table-column align="center" label="直营/自营">
  70. <template slot-scope="scope">{{unit2TenThousand(scope.row.zy_gross,isTenThound)}}</template>
  71. </el-table-column>
  72. <el-table-column align="center" label="渠道">
  73. <template slot-scope="scope">{{unit2TenThousand(scope.row.qd_gross,isTenThound)}}</template>
  74. </el-table-column>
  75. </el-table-column>
  76. </el-table>
  77. </el-row>
  78. </div>
  79. </template>
  80. <script>
  81. import asyncRequest from "@/api/newResults";
  82. import setHeight from "@/mixins/index";
  83. import {
  84. addition,
  85. division,
  86. subtraction,
  87. multiplication,
  88. unit2TenThousand
  89. } from "../newReport/src/_utils";
  90. export default {
  91. mixins: [ setHeight ],
  92. data(){
  93. return {
  94. list: [],
  95. daytime: "",
  96. companyNo: "GS2203161855277894",
  97. loading: false,
  98. isTenThound: true,
  99. companies:[
  100. { value:"GS2302231125079621",label: "北京百辰荣达国际科贸有限公司"},
  101. { value:"GS2302231323386950",label: "北京泓源广诚国际商贸有限公司"},
  102. { value:"GS2203161855277894",label: "北京万宇恒通国际科贸有限公司"},
  103. { value:"GS2302231124114965",label: "普润&锦兴&知事"}
  104. ]
  105. }
  106. },
  107. computed:{
  108. currentCompanyName(){
  109. return this.companies.find(item => item.value === this.companyNo).label;
  110. }
  111. },
  112. mounted() {
  113. this.daytime = this.transformTime();
  114. this.requestData();
  115. },
  116. watch:{ daytime:{ handler(){ this.requestData() }}},
  117. methods: {
  118. unit2TenThousand,
  119. transformTime() {
  120. let time = new Date();
  121. let y = time.getFullYear();
  122. let M = time.getMonth() + 1;
  123. let d = time.getDate();
  124. return y + "-" + (M < 10 ? "0" + M : M) + "-" + (d < 10 ? "0" + d : d);
  125. },
  126. /* 表格合并列和行 */
  127. spanMethod({ rowIndex, columnIndex }) {
  128. if (columnIndex === 0) {
  129. const _row = this.flitterData(this.list).one[rowIndex];
  130. const _col = _row > 0 ? 1 : 0;
  131. return { rowspan: _row, colspan: _col };
  132. }
  133. },
  134. /**合并表格的第一列,处理表格数据 */
  135. flitterData(arr) {
  136. let spanOneArr = [];
  137. let concatOne = 0;
  138. arr.forEach((item, index) => {
  139. if (index === 0) {
  140. spanOneArr.push(1);
  141. } else {
  142. //注意这里的quarterly是表格绑定的字段,根据自己的需求来改
  143. if (item.company === arr[index - 1].company) {
  144. //第一列需合并相同内容的判断条件
  145. spanOneArr[concatOne] += 1;
  146. spanOneArr.push(0);
  147. } else {
  148. spanOneArr.push(1);
  149. concatOne = index;
  150. }
  151. }
  152. });
  153. return { one: spanOneArr };
  154. },
  155. setCellClassName({ column }) {
  156. const { label } = column; return label === "当月营业收入(净)" ? "pure__cell" : "";
  157. },
  158. async requestData() {
  159. this.loading = true;
  160. this.list = [];
  161. const res = await asyncRequest.departmentEveryDay({ daytime: this.daytime, companyNo: this.companyNo });
  162. if (res.code === 0 && res.data && res.data.length > 0) {
  163. let list = (res.data || [])
  164. .map(({depart, msale_total, mth_total, sale_total, th_total, total_tips ,mzy_sale_total, mchannel_sale_total,channel_cost_total,zy_cost_total}) => {
  165. return {
  166. depart, total_tips,mzy_sale_total, mchannel_sale_total, channel_cost_total, zy_cost_total,
  167. dayinfo: { sale_total, th_total }, monthinfo:{ msale_total, mth_total }
  168. }
  169. });
  170. this.total = list.reduce((prev,current) => {
  171. const { total_tips = 0, day = 0, month = 0 } = current;
  172. return { total_tips: addition(total_tips,prev.total_tips), month: addition(month,prev.month), day: addition(day, prev.day) }
  173. },
  174. { total_tips: 0, month: 0, day: 0}
  175. )
  176. let mapDepart = ["百辰","泓源","普润","平台"]
  177. list = mapDepart.map(d => list.find(({ depart }) => depart === d))
  178. const mapToDepartment = { 百辰:"客服部@百辰荣达", 泓源:"网络部@泓源广诚", 普润:" 项目部@普润心堂", 平台:" 平台部@万宇恒通" }
  179. const company = this.companies.find(item => item.value === this.companyNo);
  180. console.log(this.companies,'===',this.companyNo)
  181. this.list = list.map(({depart,total_tips,dayinfo,monthinfo,mchannel_sale_total,mzy_sale_total,zy_cost_total,channel_cost_total}) => {
  182. /* 月净销售 = 月销售 - 月退货 **/
  183. const monthNetSales = subtraction(monthinfo.msale_total, monthinfo.mth_total)
  184. /* 月经销售完成率 = 月净销售 / 销售指标 **/
  185. const monthProportion = multiplication(division(monthNetSales,total_tips),100).toFixed(2)
  186. return {
  187. total_tips, // 营收目标
  188. zy_cost: zy_cost_total, // 自营成本
  189. qd_cost: channel_cost_total, // 渠道成本
  190. depart: mapToDepartment[depart],
  191. company: company.label,
  192. currentMonthPure:[ { zy : mzy_sale_total, qd: mchannel_sale_total } ], // 当月营业收入(净)
  193. zy_gross:Number(subtraction(mzy_sale_total,zy_cost_total)).toFixed(2), // 自营毛利 = 自营营收 - 自营成本
  194. qd_gross:Number(subtraction(mchannel_sale_total,channel_cost_total)).toFixed(2), // 渠道毛利 = 渠道营收 - 渠道成本
  195. dayinfo:{ ...dayinfo, /** 日销售额 = 日销售额 - 日退货额 */ sale_total:subtraction(dayinfo.sale_total,dayinfo.th_total) },
  196. /* 占比 = (当前部门销售额 / 各部门总销售额) / 100 **/
  197. proportion:multiplication( division(monthinfo.msale_total,this.total.month) || 0 ,100) || 0,
  198. monthinfo:{ monthNetSales,monthProportion: monthProportion }
  199. }
  200. })
  201. } else {
  202. this.list = [];
  203. }
  204. this.getHeight();
  205. this.loading = false;
  206. },
  207. },
  208. }
  209. </script>
  210. <style lang="scss" scoped>
  211. .new-results{
  212. .search {
  213. height:36px;
  214. display: flex;
  215. justify-content: end;
  216. padding:0px 10px;
  217. margin-top:10px
  218. }
  219. }
  220. </style>