department.vue 11 KB

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