company.vue 15 KB

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