company.vue 16 KB

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