department.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template>
  2. <div v-loading="loading">
  3. <div class="search clear">
  4. <div style="float:left;line-height:30px">部门完成情况</div>
  5. <div style="float:right">
  6. <el-select size="small" style="margin-right:10px;width:135px" v-model="companyNo" @change="requestData"
  7. :disabled="isEmpty">
  8. <el-option v-for="depart in cp_companies" :key="depart.value" :label="depart.label" :value="depart.value" />
  9. </el-select>
  10. <el-date-picker :disabled="isEmpty" class="fr picker no-padding" v-model="daytime"
  11. :picker-options="{ disbaledData(time) { return time.getTime() > Date.now(); } }" style=";width:100px"
  12. value-format="yyyy-MM-dd" format="yyyy-MM-dd" :editable="false" :clearable="false" placeholder="选择日期"
  13. :size="'small'" align="right" type="date" />
  14. </div>
  15. </div>
  16. <el-row style="margin-top: 10px; display: flex;width:100%;margin-top:10px" v-if="!isEmpty">
  17. <el-table border size="mini" :data="list" :header-cell-class-name="setHeaderClassName" height="315px"
  18. :cell-class-name="setCellClassName">
  19. <!-- <el-table-column fixed="left" label="公司" prop="company" align="center" width="45px" /> -->
  20. <el-table-column fixed="left" label="部门" prop="depart" align="center" width="60px">
  21. <template slot-scope="scope">
  22. <p style="margin:0px" v-for="(chunk, index) in scope.row.depart.split('@')" :key="index">
  23. {{ chunk }}
  24. </p>
  25. </template>
  26. </el-table-column>
  27. <el-table-column label="当日" align="center" min-width="120px">
  28. <el-table-column label="营业收入" align="center">
  29. <template slot-scope="scope">{{ unit2TenThousand(scope.row.dayinfo.sale_total, isTenThound) }}</template>
  30. </el-table-column>
  31. </el-table-column>
  32. <el-table-column label="当月" align="center">
  33. <el-table-column label="当月营收目标" align="center" min-width="115px">
  34. <template slot-scope="scope">{{ unit2TenThousand(scope.row.total_tips, isTenThound) }}</template>
  35. </el-table-column>
  36. <el-table-column label="营业收入(净)" align="center" min-width="120px">
  37. <template slot-scope="scope">
  38. <div style="display:flex;flex-direction: column;">
  39. <div style="display:flex;flex-direction: column;">
  40. <el-popover placement="top" :width="200" trigger="hover">
  41. <div class="table-size">
  42. <p>直营/自营: {{ unit2TenThousand(scope.row.currentMonthPure[0].zy, isTenThound) }}</p>
  43. <p>支付渠道: {{ unit2TenThousand(scope.row.currentMonthPure[0].qd, isTenThound) }}</p>
  44. </div>
  45. <template #reference>
  46. <p
  47. :style="`text-align: center;${getCurrentValueStyle(scope.row.monthinfo.monthNetSales, scope.row.total_tips)}`">
  48. <i class="el-icon-warning-outline" style="font-size:16px;cursor:pointer"></i>
  49. {{ unit2TenThousand(scope.row.monthinfo.monthNetSales, isTenThound) }}
  50. </p>
  51. </template>
  52. </el-popover>
  53. </div>
  54. </div>
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="成本" align="center" min-width="120px" v-if="costField">
  58. <template slot-scope="scope">
  59. <div style="display:flex;flex-direction: column;">
  60. <el-popover placement="top" :width="200" trigger="hover">
  61. <div class="table-size">
  62. <p>直营/自营: {{ unit2TenThousand(scope.row.zy_cost, isTenThound) }}</p>
  63. <p>渠道: {{ unit2TenThousand(scope.row.qd_cost, isTenThound) }}</p>
  64. </div>
  65. <template #reference>
  66. <p style="text-align: center;">
  67. <i class="el-icon-warning-outline" style="font-size:16px;cursor:pointer"></i>
  68. {{
  69. unit2TenThousand(Number(addition(scope.row.zy_cost, scope.row.qd_cost)).toFixed(2), isTenThound) }}
  70. </p>
  71. </template>
  72. </el-popover>
  73. </div>
  74. </template>
  75. </el-table-column>
  76. <el-table-column align="center" label="毛利" min-width="120px">
  77. <template slot-scope="scope">
  78. <div style="display:flex;flex-direction: column;">
  79. <el-popover placement="top" :width="200" trigger="hover">
  80. <div class="table-size">
  81. <p>直营/自营: {{ unit2TenThousand(scope.row.zy_gross, isTenThound) }}</p>
  82. <p>支付渠道: {{ unit2TenThousand(scope.row.qd_gross, isTenThound) }}</p>
  83. </div>
  84. <template #reference>
  85. <p style="text-align: center;">
  86. <i class="el-icon-warning-outline" style="font-size:16px;cursor:pointer"></i>
  87. {{
  88. unit2TenThousand(Number(addition(scope.row.zy_gross, scope.row.qd_gross)).toFixed(2), isTenThound)
  89. }}
  90. </p>
  91. </template>
  92. </el-popover>
  93. </div>
  94. </template>
  95. </el-table-column>
  96. </el-table-column>
  97. </el-table>
  98. </el-row>
  99. <template v-else>
  100. <div style="text-align:center;line-height:60px;user-select:none">当前账号没有访问权限</div>
  101. </template>
  102. </div>
  103. </template>
  104. <script>
  105. import asyncRequest from "@/api/newResults";
  106. import setHeight from "@/mixins/index";
  107. import { mapCompany } from "./mapCompany"
  108. import dayjs from "dayjs";
  109. import {
  110. addition,
  111. division,
  112. subtraction,
  113. multiplication,
  114. unit2TenThousand
  115. } from "../newReport/src/_utils";
  116. export default {
  117. mixins: [setHeight],
  118. props: ['companies', 'costField', 'isTenThound'],
  119. data() {
  120. return {
  121. list: [],
  122. daytime: "",
  123. companyNo: "",
  124. loading: false,
  125. isEmpty: false,
  126. cp_companies:[]
  127. }
  128. },
  129. computed: {
  130. currentCompanyName() {
  131. return this.companies.find(item => item.value === this.companyNo).label;
  132. }
  133. },
  134. mounted() {
  135. this.isEmpty = this.companies.length === 0;
  136. if (this.isEmpty) return;
  137. this.companyNo = this.companies[0].value;
  138. this.cp_companies = this.companies.map(item => ({
  139. ...item,
  140. label: mapCompany[item.label] === '万宇' ? `平台公司: 万宇` : `业务公司: ${mapCompany[item.label]}`
  141. }))
  142. this.daytime = this.transformTime();
  143. this.requestData();
  144. },
  145. watch: { daytime: { handler() { this.requestData() } } },
  146. methods: {
  147. addition,
  148. unit2TenThousand,
  149. setCellClassName({ column }) {
  150. const { label } = column;
  151. // if (label === "营业收入(净)" || label === '当月成本合计') return "pure__cell";
  152. if (label === "营收目标") return "bg__success"
  153. if (label.indexOf('营业') !== -1 || label.indexOf('营收') !== -1) return "bg__success_1"
  154. if (label === "毛利目标") return "bg__primary"
  155. if (label.indexOf('毛利') !== -1) return "bg__primary_1"
  156. if (label.indexOf('成本') !== -1) return "bg__warning_1"
  157. },
  158. setHeaderClassName({ column }) {
  159. const { label } = column;
  160. if (label === "营收目标") return "bg__success"
  161. if (label.indexOf('营业') !== -1 || label.indexOf('营收') !== -1) return "bg__success_1"
  162. if (label === "毛利目标") return "bg__primary"
  163. if (label.indexOf('毛利') !== -1) return "bg__primary_1"
  164. if (label.indexOf('成本') !== -1) return "bg__warning_1"
  165. },
  166. getCurrentRateStyle(current) {
  167. const days = dayjs().daysInMonth();
  168. const oneDay = Number(division(100, days)).toFixed(2);
  169. const currentDay = dayjs().date();
  170. const currentTotalTip = Number(multiplication(currentDay, oneDay)).toFixed(2);
  171. return Number(currentTotalTip) > Number(current) ? 'color:red' : ''
  172. },
  173. getCurrentValueStyle(current, total) {
  174. const days = dayjs().daysInMonth();
  175. const oneDay = Number(division(total, days)).toFixed(2);
  176. const currentDay = dayjs().date();
  177. const currentTotalTip = Number(multiplication(currentDay, oneDay)).toFixed(2);
  178. return Number(currentTotalTip) > Number(current) ? 'color: red' : '';
  179. },
  180. transformTime() {
  181. let time = new Date();
  182. let y = time.getFullYear();
  183. let M = time.getMonth() + 1;
  184. let d = time.getDate();
  185. return y + "-" + (M < 10 ? "0" + M : M) + "-" + (d < 10 ? "0" + d : d);
  186. },
  187. /* 表格合并列和行 */
  188. spanMethod({ rowIndex, columnIndex }) {
  189. if (columnIndex === 0) {
  190. const _row = this.flitterData(this.list).one[rowIndex];
  191. const _col = _row > 0 ? 1 : 0;
  192. return { rowspan: _row, colspan: _col };
  193. }
  194. },
  195. /**合并表格的第一列,处理表格数据 */
  196. flitterData(arr) {
  197. let spanOneArr = [];
  198. let concatOne = 0;
  199. arr.forEach((item, index) => {
  200. if (index === 0) {
  201. spanOneArr.push(1);
  202. } else {
  203. //注意这里的quarterly是表格绑定的字段,根据自己的需求来改
  204. if (item.company === arr[index - 1].company) {
  205. //第一列需合并相同内容的判断条件
  206. spanOneArr[concatOne] += 1;
  207. spanOneArr.push(0);
  208. } else {
  209. spanOneArr.push(1);
  210. concatOne = index;
  211. }
  212. }
  213. });
  214. return { one: spanOneArr };
  215. },
  216. async requestData() {
  217. this.loading = true;
  218. this.list = [];
  219. const res = await asyncRequest.departmentEveryDay({ daytime: this.daytime, companyNo: this.companyNo });
  220. if (res.code === 0 && res.data && res.data.length > 0) {
  221. // 非万宇 营业目标重取
  222. if (this.companyNo !== "GS2203161855277894") {
  223. const r = await asyncRequest.companyEveryMonth({ daytime: this.daytime, companyNo: this.companyNo });
  224. const { total_tips, companyName } = r.data[0] || {};
  225. res.data.forEach(item => {
  226. const index = companyName.indexOf(item.depart);
  227. item.total_tips = (index === -1 && !(item.depart === "普润" && this.companyNo === "GS2304031312553746")) ? '0.00' : total_tips;
  228. })
  229. }
  230. let list = (res.data || [])
  231. .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 }) => {
  232. return {
  233. depart, total_tips, mzy_sale_total, mchannel_sale_total, channel_cost_total, zy_cost_total, mchannel_cost_total, mzy_cost_total,
  234. dayinfo: { sale_total, th_total }, monthinfo: { msale_total, mth_total }
  235. }
  236. });
  237. list = list.filter(item => Number(item.monthinfo.msale_total) !== 0)
  238. this.total = list.reduce((prev, current) => {
  239. const { total_tips = 0, day = 0, month = 0 } = current;
  240. return { total_tips: addition(total_tips, prev.total_tips), month: addition(month, prev.month), day: addition(day, prev.day) }
  241. },
  242. { total_tips: 0, month: 0, day: 0 }
  243. )
  244. let mapDepart = list.map(({ depart }) => depart);
  245. list = mapDepart.map(d => list.find(({ depart }) => depart === d))
  246. const mapToDepartment = { 百辰: "客服部@百辰", 泓源: "网络部@泓源", 普润: " 项目部@普润", 平台: " 平台部@万宇" }
  247. const company = this.companies.find(item => item.value === this.companyNo);
  248. this.list = list.map(({ depart, total_tips, dayinfo, monthinfo, mchannel_sale_total, mzy_sale_total, zy_cost_total, mchannel_cost_total, mzy_cost_total }) => {
  249. /* 月净销售 = 月销售 - 月退货 **/
  250. const monthNetSales = subtraction(monthinfo.msale_total, monthinfo.mth_total)
  251. /* 月经销售完成率 = 月净销售 / 销售指标 **/
  252. const monthProportion = multiplication(division(monthNetSales, total_tips), 100).toFixed(2)
  253. return {
  254. total_tips, // 营收目标
  255. zy_cost: mzy_cost_total, // 自营成本
  256. qd_cost: mchannel_cost_total, // 渠道成本
  257. depart: mapToDepartment[depart],
  258. company: company.label,
  259. currentMonthPure: [{ zy: mzy_sale_total, qd: mchannel_sale_total }], // 当月营业收入(净)
  260. zy_gross: Number(subtraction(mzy_sale_total, mzy_cost_total)).toFixed(2), // 自营毛利 = 自营营收 - 自营成本
  261. qd_gross: Number(subtraction(mchannel_sale_total, mchannel_cost_total)).toFixed(2), // 渠道毛利 = 渠道营收 - 渠道成本
  262. dayinfo: { ...dayinfo, /** 日销售额 = 日销售额 - 日退货额 */ sale_total: subtraction(dayinfo.sale_total, dayinfo.th_total) },
  263. /* 占比 = (当前部门销售额 / 各部门总销售额) / 100 **/
  264. proportion: multiplication(division(monthinfo.msale_total, this.total.month) || 0, 100) || 0,
  265. monthinfo: { monthNetSales, monthProportion: monthProportion }
  266. }
  267. })
  268. } else {
  269. this.list = [];
  270. }
  271. this.getHeight();
  272. this.loading = false;
  273. },
  274. },
  275. }
  276. </script>
  277. <style lang="scss" scoped>
  278. .new-results {
  279. .search {
  280. height: 36px;
  281. padding: 0px 10px;
  282. margin-top: 10px;
  283. width: 100%;
  284. box-sizing: border-box;
  285. justify-content: space-between;
  286. }
  287. }
  288. .table-size {
  289. display: flex;
  290. width: 200px;
  291. border: 1px solid #ebeef5;
  292. flex-direction: column;
  293. p {
  294. flex: 1;
  295. border-bottom: 1px solid #ebeef5;
  296. padding: 5px 10px;
  297. margin: 0px;
  298. &:last-child {
  299. border: none;
  300. }
  301. }
  302. }
  303. </style>