company.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <div v-loading="loading">
  3. <div class="search clear" style="align-items: center;;">
  4. <div style="float:left">
  5. 业绩毛利完成情况-年度
  6. </div>
  7. <div style="float:right">
  8. <el-switch style="margin-right: 10px;" v-model="isTenThound" active-text="万元" inactive-text="元"
  9. :disabled="isEmpty" />
  10. <el-select size="small" style="margin-right:10px;width:125px" v-model="companyNo" @change="requestData"
  11. :disabled="isEmpty">
  12. <el-option v-for="company in cp_companies" :key="company.value" :value="company.value" :label="company.label" />
  13. </el-select>
  14. <el-date-picker class="fr picker" v-model="daytime" style=";width:140px" value-format="yyyy-MM-dd"
  15. :editable="false" :disabled="isEmpty" :clearable="false" :size="'small'" format="yyyy-MM-dd" type="date"
  16. align="right" placeholder="选择日期"
  17. :picker-options="{ disabledDate(time) { return time.getTime() > Date.now(); } }" @change="requestData" />
  18. </div>
  19. </div>
  20. <el-row style="margin-top:10px;margin-top:10px" v-if="!isEmpty">
  21. <el-table border size="mini" :data="tableData" :header-cell-class-name="setHeaderClassName"
  22. :cell-class-name="setCellClassName">
  23. <el-table-column fixed="left" label="业务公司" prop="companyName" align="center" width="70px">
  24. <template slot-scope="scope">
  25. <div v-if="scope.row.companyName.indexOf('普润') === -1">{{ mapCompany[scope.row.companyName] ||
  26. scope.row.companyName }}</div>
  27. <div v-else>
  28. <p style="margin:0px">普润</p>
  29. <p style="margin:0px">锦兴</p>
  30. <p style="margin:0px">知事</p>
  31. </div>
  32. </template>
  33. </el-table-column>
  34. <el-table-column label="当日营业收入" align="center" width="95px">
  35. <template slot-scope="scope">
  36. {{ unit2TenThousand(scope.row.sale_total, isTenThound) }}
  37. </template>
  38. </el-table-column>
  39. <el-table-column label="当月营收目标" align="center" width="95px">
  40. <template slot-scope="scope">
  41. {{ unit2TenThousand(scope.row.total_tips, isTenThound) }}
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="当月营业收入(净)" align="center" min-width="420px">
  45. <template slot-scope="scope">
  46. <div style="display:flex;flex-direction: column;">
  47. <p :style="`text-align: center;${getCurrentValueStyle(scope.row.msale_total, scope.row.total_tips)}`">
  48. {{ unit2TenThousand(scope.row.msale_total, isTenThound) }}
  49. </p>
  50. <div class="table-size">
  51. <p>直营/自营: {{ unit2TenThousand(scope.row.info[0][0].monthinfo.msale_total, isTenThound) }}</p>
  52. <p>渠道: {{ unit2TenThousand(scope.row.info[0][1].monthinfo.msale_total, isTenThound) }}</p>
  53. <p>供应商端: {{ unit2TenThousand(scope.row.info[0][2].monthinfo.msale_total, isTenThound) }}</p>
  54. </div>
  55. </div>
  56. </template>
  57. </el-table-column>
  58. <el-table-column label="当月营收完成%" align="center" min-width="105px">
  59. <template slot-scope="scope">
  60. <div :style="`${getCurrentRateStyle(scope.row.completion_rate)}`">{{ scope.row.completion_rate + "%" }}</div>
  61. </template>
  62. </el-table-column>
  63. <template v-if="costField">
  64. <el-table-column label="当月毛利目标" align="center" width="95px">
  65. <template slot-scope="scope">
  66. {{ unit2TenThousand(scope.row.cost_tips, isTenThound) }}
  67. </template>
  68. </el-table-column>
  69. <el-table-column label="当月毛利完成" align="center" width="95px">
  70. <template slot-scope="scope">
  71. <div :style="`${getCurrentValueStyle(scope.row.gross_completion, scope.row.cost_tips)}`">
  72. {{ unit2TenThousand(scope.row.gross_completion, isTenThound) }}
  73. </div>
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="当月实际毛利率" align="center" width="105px">
  77. <template slot-scope="scope">
  78. <!-- <div :style="`${getCurrentRateStyle(scope.row.gross_sale_completion_rate)}`"> -->
  79. {{ unit2TenThousand(scope.row.gross_sale_completion_rate) + "%" }}
  80. <!-- </div> -->
  81. </template>
  82. </el-table-column>
  83. <el-table-column label="当月毛利完成%" align="center" min-width="105px">
  84. <template slot-scope="scope">
  85. <div :style="getCurrentRateStyle(scope.row.gross_completion_rate)">
  86. {{ scope.row.gross_completion_rate + '%' }}
  87. </div>
  88. </template>
  89. </el-table-column>
  90. <el-table-column label="当月成本合计" align="center" width="425px">
  91. <template slot-scope="scope">
  92. <div style="display:flex;flex-direction: column;">
  93. <p style="text-align: center;"> {{ unit2TenThousand(scope.row.mcost_total, isTenThound) }}</p>
  94. <div class="table-size">
  95. <p>直营/自营: {{ unit2TenThousand(scope.row.info[0][0].monthinfo.mcost_total, isTenThound) }}</p>
  96. <p>渠道: {{ unit2TenThousand(scope.row.info[0][1].monthinfo.mcost_total, isTenThound) }}</p>
  97. <p>供应商端: {{ unit2TenThousand(scope.row.info[0][2].monthinfo.mcost_total, isTenThound) }}</p>
  98. </div>
  99. </div>
  100. </template>
  101. </el-table-column>
  102. </template>
  103. </el-table>
  104. </el-row>
  105. <template v-else>
  106. <div style="text-align:center;line-height:60px;user-select:none">当前账号没有访问权限</div>
  107. </template>
  108. </div>
  109. </template>
  110. <script>
  111. import asyncRequest from "@/api/newResults";
  112. import { addition, unit2TenThousand, subtraction, multiplication, division } from "../newReport/src/_utils";
  113. import { mapCompany } from "./mapCompany";
  114. import dayjs from "dayjs"
  115. export default {
  116. props: ['companies', 'costField'],
  117. data() {
  118. return {
  119. isTenThound: true,
  120. daytime: "",
  121. loading: false,
  122. tableData: [],
  123. companyNo: "",
  124. cp_companies: [],
  125. isEmpty: false,
  126. mapCompany
  127. }
  128. },
  129. mounted() {
  130. const hasCompose = false;
  131. const jxIndex = this.companies.findIndex((item) => item.label === "北京锦兴弘昌科技有限公司");
  132. const prIndex = this.companies.findIndex((item) => item.label === "北京普润心堂商贸有限公司");
  133. if (jxIndex !== -1 || prIndex !== -1) this.hasCompose = true;
  134. this.cp_companies = this.companies.filter((item) => item.label !== "北京锦兴弘昌科技有限公司" && item.label !== "北京普润心堂商贸有限公司")
  135. if (this.hasCompose) this.cp_companies = [...this.cp_companies, { value: "GS2302231124114965", label: "普润&锦兴&知事" }]
  136. if (this.cp_companies.length === 4) this.cp_companies = [{ value: "", label: "所有公司" }, ...this.cp_companies];
  137. this.isEmpty = this.cp_companies.length === 0;
  138. if (this.isEmpty) return;
  139. this.cp_companies = this.cp_companies.map(item => ({ ...item, label: mapCompany[item.label] || item.label }))
  140. this.companyNo = this.cp_companies[0].value;
  141. this.daytime = this.transformTime();
  142. this.requestData();
  143. },
  144. methods: {
  145. unit2TenThousand,
  146. getCurrentRateStyle(current) {
  147. const days = dayjs().daysInMonth();
  148. const oneDay = Number(division(100, days)).toFixed(2);
  149. const currentDay = dayjs().date();
  150. const currentTotalTip = Number(multiplication(currentDay, oneDay)).toFixed(2);
  151. return Number(currentTotalTip) > Number(current) ? 'color:red' : ''
  152. },
  153. getCurrentValueStyle(current, total) {
  154. const days = dayjs().daysInMonth();
  155. const oneDay = Number(division(total, days)).toFixed(2);
  156. const currentDay = dayjs().date();
  157. const currentTotalTip = Number(multiplication(currentDay, oneDay)).toFixed(2);
  158. return Number(currentTotalTip) > Number(current) ? 'color: red' : '';
  159. },
  160. addDataToCompany(c1, c2) {
  161. // Number(addition(c1.total_tips,c2.total_tips)).toFixed(2)
  162. return {
  163. companyName: '普润\n锦兴\n知事',
  164. cost_tips: Number(addition(c1.cost_tips, c2.cost_tips)).toFixed(2),
  165. total_tips: Number(c1.total_tips).toFixed(2),
  166. monthinfo: c1.monthinfo.map((item, index) => ({
  167. mcgd_th_total: Number(addition(item.mcgd_th_total, c2.monthinfo[index].mcgd_th_total)).toFixed(2),
  168. mcgd_total: Number(addition(item.mcgd_total, c2.monthinfo[index].mcgd_total)).toFixed(2),
  169. msale_total: Number(addition(item.msale_total, c2.monthinfo[index].msale_total)).toFixed(2),
  170. mth_total: Number(addition(item.mth_total, c2.monthinfo[index].mth_total)).toFixed(2),
  171. type: item.type
  172. })),
  173. dayinfo: c1.dayinfo.map((item, index) => {
  174. return {
  175. cgd_th_total: Number(addition(item.cgd_th_total, c2.dayinfo[index].cgd_th_total)).toFixed(2),
  176. cgd_total: Number(addition(item.cgd_total, c2.dayinfo[index].cgd_total)).toFixed(2),
  177. sale_total: Number(addition(item.sale_total, c2.dayinfo[index].sale_total)).toFixed(2),
  178. th_total: Number(addition(item.th_total, c2.dayinfo[index].th_total)).toFixed(2),
  179. type: item.type
  180. }
  181. }),
  182. }
  183. },
  184. setCellClassName({ column }) {
  185. const { label } = column;
  186. if (label === "当月营业收入(净)" || label === '当月成本合计') return "pure__cell";
  187. if (label === "当月营收目标") return "bg__yellow"
  188. if (label === "当月毛利目标") return "bg__red"
  189. },
  190. setHeaderClassName({ column }) {
  191. const { label } = column;
  192. if (label === "当月营收目标") return "bg__yellow"
  193. if (label === "当月毛利目标") return "bg__red"
  194. },
  195. transformTime() {
  196. let time = new Date();
  197. let y = time.getFullYear();
  198. let M = time.getMonth() + 1;
  199. let d = time.getDate();
  200. return y + "-" + (M < 10 ? "0" + M : M) + "-" + (d < 10 ? "0" + d : d);
  201. },
  202. async requestData() {
  203. this.loading = true;
  204. this.tableData = [];
  205. const res = await asyncRequest.companyEveryMonth({ daytime: this.daytime, companyNo: this.companyNo });
  206. const jxIndex = res.data.findIndex((item) => item.companyName === "北京锦兴弘昌科技有限公司");
  207. const prIndex = res.data.findIndex((item) => item.companyName === "北京普润心堂商贸有限公司");
  208. if (jxIndex >= 0 && prIndex >= 0) {
  209. const jxItem = res.data[jxIndex];
  210. res.data[prIndex] = this.addDataToCompany(jxItem, res.data[prIndex]);
  211. res.data.splice(jxIndex, 1);
  212. console.log(res.data);
  213. }
  214. if (this.companyNo === "GS2302231124114965") {
  215. const jxResult = await asyncRequest.companyEveryMonth({ daytime: this.daytime, companyNo: "GS2304031312553746" });
  216. res.data[prIndex] = this.addDataToCompany(jxResult.data[0], res.data[prIndex]);
  217. }
  218. // const isBeforeDate = this.getDiffDay() < 0 && this.companyNo === "GS2302231323386950"
  219. if (res.code === 0 && res.data && res.data.length > 0) {
  220. res.data.forEach(({ companyName, monthinfo, dayinfo, total_tips, cost_tips }) => {
  221. // monthinfo[1] = {
  222. // ...(isBeforeDate ? {
  223. // msale_total:addition(monthinfo[1].msale_total,monthinfo[2].msale_total),
  224. // mth_total:addition(monthinfo[1].mth_total,monthinfo[2].mth_total),
  225. // type:'2'
  226. // } : monthinfo[1])
  227. // }
  228. // monthinfo[0] = {
  229. // ...(isBeforeDate ? {
  230. // msale_total:0,
  231. // mth_total:0,
  232. // type:'1'
  233. // } : monthinfo[0])
  234. // }
  235. // monthinfo[2] = {
  236. // ...(isBeforeDate ? {
  237. // msale_total:0,
  238. // mth_total:0,
  239. // type:'3'
  240. // } : monthinfo[2])
  241. // }
  242. // this.companyName = companyName
  243. const mapResponseType = { '1': '自营', '2': '渠道', '3': '供应商端' }
  244. const types = Object.keys(mapResponseType)
  245. let prev_sale_total = 0;
  246. let prev_msale_total = 0;
  247. let prev_cost_total = 0;
  248. let prev_mcost_total = 0;
  249. const item = types.map(type => {
  250. const _monthinfo = monthinfo.find(month => String(month.type) === type) || {}
  251. const _dayinfo = dayinfo.find(day => String(day.type) === type) || {}
  252. /** 月营业收入 = 月销售额 - 月退货额 */
  253. const msale_total = subtraction(_monthinfo.msale_total, _monthinfo.mth_total) || 0
  254. /** 日营业收入 = 日销售额 - 日退货额 */
  255. const sale_total = subtraction(_dayinfo.sale_total, _dayinfo.th_total) || 0;
  256. /** 日成本 = 日采购额 - 日退货额 */
  257. const cost_total = subtraction(_dayinfo.cgd_total, _dayinfo.cgd_th_total) || 0;
  258. /** 月成本 = 月采购额 - 月退货额 */
  259. const mcost_total = subtraction(_monthinfo.mcgd_total, _monthinfo.mcgd_th_total) || 0;
  260. prev_sale_total = Number(addition(prev_sale_total, sale_total)).toFixed(2);
  261. prev_msale_total = Number(addition(prev_msale_total, msale_total)).toFixed(2);
  262. prev_cost_total = Number(addition(prev_cost_total, cost_total)).toFixed(2);
  263. prev_mcost_total = Number(addition(prev_mcost_total, mcost_total)).toFixed(2);
  264. return {
  265. type: mapResponseType[type],
  266. dayinfo: { ..._dayinfo, sale_total },
  267. monthinfo: { ...monthinfo, msale_total, mcost_total }
  268. }
  269. })
  270. const gross_completion = Number(subtraction(prev_msale_total, prev_mcost_total)).toFixed(2) //当月毛利完成 = 月营收 - 月成本
  271. this.tableData = [
  272. ...this.tableData,
  273. {
  274. companyName, // 公司名称
  275. cost_tips, // 当月成本指标
  276. total_tips, // 当月营收目标
  277. info: [{ ...item }], // 直营..渠道 销售
  278. sale_total: prev_sale_total, // 当日营业收入
  279. cost_total: prev_cost_total, // 当日成本总额
  280. msale_total: prev_msale_total, // 当月营业收入
  281. mcost_total: prev_mcost_total,// 当月成本总额
  282. gross_completion, //当月毛利完成 = 月营收 - 月成本
  283. completion_rate: multiplication(division(prev_msale_total, total_tips), 100).toFixed(2), // 当月应收完成率
  284. gross_completion_rate: Number(cost_tips) === 0 ? 0 : multiplication(division(gross_completion, cost_tips) || 0, 100).toFixed(2), // 当月毛利完成率
  285. gross_sale_completion_rate: Number(multiplication(division(gross_completion, prev_msale_total) || 0, 100)).toFixed(2), // 本月毛利率 = 当月毛利完成 / 当月营业收入
  286. }
  287. ]
  288. })
  289. } else {
  290. this.tableData = [];
  291. }
  292. // this.getHeight();
  293. this.loading = false;
  294. }
  295. }
  296. }
  297. </script>
  298. <style lang="scss" scoped>
  299. .new-results {
  300. .search {
  301. height: 36px;
  302. padding: 0px 10px;
  303. margin-top: 10px;
  304. flex-wrap:wrap;
  305. }
  306. .table-size {
  307. display: flex;
  308. border-top: 1px solid #ebeef5;
  309. p {
  310. flex: 1;
  311. border-right: 1px solid #ebeef5;
  312. padding: 5px 10px;
  313. margin: 0px;
  314. &:last-child {
  315. border: none;
  316. }
  317. }
  318. }
  319. }
  320. </style>