company-month.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <div v-loading="loading">
  3. <div class="search" style="align-items: center;">
  4. <div style="float:left;font-size:16px;line-height:30px">
  5. 年度完成情况
  6. </div>
  7. <div style="float:right">
  8. <el-select size="small" style="margin-right:10px;width:160px" v-model="companyNo" @change="requestData"
  9. :disabled="isEmpty">
  10. <el-option v-for="depart in cp_companies" :key="depart.id" :value="depart.value" :label="depart.label" />
  11. </el-select>
  12. <el-date-picker class="fr picker no-padding" v-model="daytime" style=";width:65px" value-format="yyyy"
  13. :editable="false" :disabled="isEmpty" :clearable="false" :size="'small'" type="year" format="yyyy" align="right"
  14. placeholder="选择日期" :picker-options="{ disabledDate(time) { return time.getTime() > Date.now(); } }"
  15. @change="requestData" />
  16. </div>
  17. </div>
  18. <el-row style="margin-top:10px;margin-top:10px" v-if="!isEmpty">
  19. <el-table border size="mini" :data="tableData" :header-cell-class-name="setHeaderClassName" :row-class-name="setRowClassName"
  20. :cell-class-name="setCellClassName">
  21. <el-table-column fixed="left" label="月度" prop="month" align="center" width="45px" />
  22. <el-table-column label="营收目标" align="center" min-width="115px">
  23. <template slot-scope="scope">
  24. {{ unit2TenThousand(scope.row.total_tips, isTenThound) }}
  25. </template>
  26. </el-table-column>
  27. <el-table-column label="营业收入(净)" align="center" min-width="115px">
  28. <template slot-scope="scope">
  29. <div :style="getCurrentValueStyle(scope.row.pure_sale, scope.row.total_tips, scope.row.month)">
  30. {{ unit2TenThousand(scope.row.pure_sale, isTenThound) }}
  31. </div>
  32. </template>
  33. </el-table-column>
  34. <el-table-column label="营收完成%" align="center" min-width="95px">
  35. <template slot-scope="scope">
  36. <div :style="getCurrentRateStyle(scope.row.completion_rate, scope.row.month)">
  37. {{ Number(scope.row.completion_rate).toFixed(2) + "%" }}
  38. </div>
  39. </template>
  40. </el-table-column>
  41. <!-- <template v-if="costField"> -->
  42. <el-table-column label="毛利目标" align="center" min-width="115px">
  43. <template slot-scope="scope">
  44. {{ costField ? unit2TenThousand(scope.row.cost_tips, isTenThound) : '***' }}
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="毛利完成" align="center" min-width="115px">
  48. <template slot-scope="scope">
  49. <div :style="getCurrentValueStyle(scope.row.pure_profit, scope.row.cost_tips, scope.row.month)">
  50. {{ costField ? unit2TenThousand(scope.row.pure_profit, isTenThound) : '***' }}
  51. </div>
  52. </template>
  53. </el-table-column>
  54. <el-table-column label="毛利完成%" align="center" min-width="95px">
  55. <template slot-scope="scope">
  56. <div :style="getCurrentRateStyle(scope.row.cost_rate, scope.row.month)">
  57. {{ Number(scope.row.cost_rate).toFixed(2) + "%" }}
  58. </div>
  59. </template>
  60. </el-table-column>
  61. <!-- </template> -->
  62. </el-table>
  63. <div style="height:100px"></div>
  64. </el-row>
  65. <template v-else>
  66. <div style="text-align:center;line-height:60px;user-select:none">当前账号没有访问权限</div>
  67. </template>
  68. </div>
  69. </template>
  70. <script>
  71. import asyncRequest from "@/api/newResults";
  72. import { unit2TenThousand, subtraction, multiplication, division, addition } from "../newReport/src/_utils";
  73. import { mapCompany } from "./mapCompany";
  74. import dayjs from "dayjs"
  75. export default {
  76. props: ['companies', 'costField', 'isTenThound'],
  77. data() {
  78. return {
  79. loading: false,
  80. daytime: "",
  81. tableData: [],
  82. companyNo: "",
  83. cp_companies: [],
  84. isEmpty: false
  85. }
  86. },
  87. mounted() {
  88. let hasCompose = false;
  89. const jxIndex = this.companies.findIndex((item) => item.label === "北京锦兴弘昌科技有限公司");
  90. const prIndex = this.companies.findIndex((item) => item.label === "北京普润心堂商贸有限公司");
  91. const zsIndex = this.companies.findIndex((item) => item.label === "北京知事文化产业发展有限公司");
  92. if (jxIndex !== -1 || prIndex !== -1 || zsIndex !== -1) hasCompose = true;
  93. this.cp_companies = this.companies.filter((item) => item.label !== "北京锦兴弘昌科技有限公司" && item.label !== "北京普润心堂商贸有限公司" && item.label !== "北京知事文化产业发展有限公司")
  94. if (hasCompose) this.cp_companies = [...this.cp_companies, { value: "GS2401181650538135", label: "普润&锦兴&知事" }]
  95. // if (this.cp_companies.length === 4) this.cp_companies = [{ value: "", label: "所有公司" }, ...this.cp_companies];
  96. this.isEmpty = this.cp_companies.length === 0;
  97. if (this.isEmpty) return;
  98. this.cp_companies = this.cp_companies.map((item,index) => {
  99. let label = '';
  100. if (item.label === '所有公司') {
  101. label = '所有公司'
  102. }
  103. if (item.label === '北京万宇恒通国际科贸有限公司') {
  104. label = '平台公司: 万宇'
  105. }
  106. if (item.label === "普润&锦兴&知事") label = `业务公司: 普润&锦兴&知事`
  107. if (label === '') label = `业务公司: ${mapCompany[item.label]}`;
  108. return ({ ...item, label })
  109. })
  110. let list = ['所有公司','平台公司: 万宇','业务公司: 百辰','业务公司: 泓源','业务公司: 普润&锦兴&知事']
  111. const cp_list = this.cp_companies.map((item) => item.label);
  112. list = list.filter(item => cp_list.includes(item));
  113. this.cp_companies = list.map((item) => this.cp_companies.find((cp_item) => cp_item.label === item));
  114. this.companyNo = this.cp_companies[0].value;
  115. this.daytime = this.transformTime();
  116. this.requestData();
  117. },
  118. methods: {
  119. unit2TenThousand,
  120. setRowClassName({row}){
  121. if(row.month === '合计') return 'table-header-color'
  122. },
  123. getCurrentRateStyle(current, month) {
  124. const days = dayjs().daysInMonth();
  125. const currentMonth = dayjs().month() + 1;
  126. if (Number(month) > Number(currentMonth)) return;
  127. if (month === '合计') return;
  128. const oneDay = Number(division(100, days)).toFixed(2);
  129. const currentDay = dayjs().date();
  130. const currentTotalTip = Number(multiplication(currentDay, oneDay)).toFixed(2);
  131. return Number(currentTotalTip) > Number(current) ? 'color:red' : ''
  132. },
  133. getCurrentValueStyle(current, total, month) {
  134. const days = dayjs().daysInMonth();
  135. const currentMonth = dayjs().month() + 1;
  136. if (Number(month) > Number(currentMonth)) return;
  137. if (month === '合计') return;
  138. const oneDay = Number(division(total, days)).toFixed(2);
  139. // console.log(month,oneDay)
  140. const currentDay = dayjs().date();
  141. const currentTotalTip = Number(multiplication(currentDay, oneDay)).toFixed(2);
  142. return Number(currentTotalTip) > Number(current) ? 'color: red' : '';
  143. },
  144. setCellClassName({ column,row }) {
  145. if(row.month === '合计') return;
  146. const { label } = column;
  147. // if (label === "营业收入(净)" || label === '当月成本合计') return "pure__cell";
  148. if (label === "营收目标") return "bg__success"
  149. if (label.indexOf('营业') !== -1 || label.indexOf('营收') !== -1) return "bg__success_1"
  150. if (label === "毛利目标") return "bg__primary"
  151. if (label.indexOf('毛利') !== -1) return "bg__primary_1"
  152. if (label.indexOf('成本') !== -1) return "bg__warning_1"
  153. },
  154. setHeaderClassName({ column }) {
  155. const { label } = column;
  156. if (label === "营收目标") return "bg__success"
  157. if (label.indexOf('营业') !== -1 || label.indexOf('营收') !== -1) return "bg__success_1"
  158. if (label === "毛利目标") return "bg__primary"
  159. if (label.indexOf('毛利') !== -1) return "bg__primary_1"
  160. if (label.indexOf('成本') !== -1) return "bg__warning_1"
  161. },
  162. transformTime() {
  163. let time = new Date();
  164. let y = time.getFullYear();
  165. let M = time.getMonth() + 1;
  166. let d = time.getDate();
  167. return y + "-" + (M < 10 ? "0" + M : M) + "-" + (d < 10 ? "0" + d : d);
  168. },
  169. async requestData() {
  170. this.loading = true;
  171. const result = await asyncRequest.companyEvery({ year: (this.daytime.split('-'))[0], companyNo: this.companyNo })
  172. // if(this.companyNo === "GS2302231124114965"){
  173. // const jxResult = await asyncRequest.companyEvery({ year: (this.daytime.split('-'))[0], companyNo: "GS2304031312553746" })
  174. // result.data = result.data.map((_,index) => {
  175. // const prItem = result.data[index];
  176. // const jxItem = jxResult.data[index];
  177. // return {
  178. // month:prItem.month,
  179. // cgd_th_total: Number(addition(prItem['cgd_th_total'],jxItem['cgd_th_total'])).toFixed(2),
  180. // cgd_total:Number(addition(prItem['cgd_total'],jxItem['cgd_total'])).toFixed(2),
  181. // cost_tips:Number(addition(prItem['cost_tips'],jxItem['cost_tips'])).toFixed(2),
  182. // sale_total:Number(addition(prItem['sale_total'],jxItem['sale_total'])).toFixed(2),
  183. // th_total:Number(addition(prItem['th_total'],jxItem['th_total'])).toFixed(2),
  184. // total_tips:Number(prItem['total_tips']).toFixed(2),
  185. // }
  186. // })
  187. // };
  188. // if(this.companyNo === ""){
  189. // result.data.forEach((item) => item.total_tips = 0);
  190. // for(const c of this.cp_companies.filter(({value}) => value !== "")){
  191. // const res = await asyncRequest.companyEvery({ year: (this.daytime.split('-'))[0], companyNo: c.value });
  192. // result.data = result.data.reduce((prev,curr,index) => {
  193. // return [
  194. // ...prev,
  195. // {
  196. // ...curr,
  197. // total_tips:Number(addition(Number(curr.total_tips).toFixed(2),Number(res.data[index].total_tips).toFixed(2))).toFixed(2)
  198. // }
  199. // ]
  200. // },[])
  201. // }
  202. // }
  203. switch (Number(result.code)) {
  204. case 0:
  205. this.tableData = (result.data || []).map(tableItem => {
  206. /* 销售净额 = 销售额 - 退货额 **/
  207. const pure_sale = subtraction(tableItem.sale_total, tableItem.th_total)
  208. /* 指标达成率 = 销售净额 / 销售指标 **/
  209. const completion_rate = multiplication(division(pure_sale, tableItem.total_tips), 100)
  210. /* 采购净额 = 采购额 - 采购退货额 **/
  211. const pure_purch = subtraction(tableItem.cgd_total, tableItem.cgd_th_total)
  212. /* 毛利润 = (本月销售净额 - 本月采购净额) **/
  213. const pure_profit = subtraction(pure_sale, pure_purch)
  214. /* 毛利率 = (本月毛利润 / 本月销售净额) * 100 **/
  215. const pure_interest_rate = multiplication(division(pure_profit, pure_sale) || 0, 100)
  216. return {
  217. pure_sale,
  218. pure_purch,
  219. pure_profit,
  220. completion_rate,
  221. pure_interest_rate,
  222. month: tableItem.month,
  223. cost_tips: tableItem.cost_tips,
  224. total_tips: tableItem.total_tips,
  225. cost_rate: Number(tableItem.cost_tips) === 0 ? 0 : multiplication(division(pure_profit, tableItem.cost_tips) || 0, 100).toFixed(2)
  226. }
  227. })
  228. const totalItem = this.tableData.reduce((prev, curr) => {
  229. return {
  230. pure_sale: Number(addition(prev.pure_sale, curr.pure_sale)).toFixed(2),
  231. pure_purch: Number( addition(prev.pure_purch, curr.pure_purch)).toFixed(2),
  232. pure_profit: Number(addition(prev.pure_profit, curr.pure_profit)).toFixed(2),
  233. completion_rate:Number( addition(prev.completion_rate, curr.completion_rate)).toFixed(2),
  234. pure_interest_rate:Number( addition(prev.pure_interest_rate, curr.pure_interest_rate)).toFixed(2),
  235. total_tips:Number( addition(prev.total_tips, curr.total_tips)).toFixed(2),
  236. cost_tips:Number( addition(prev.cost_tips, curr.cost_tips)).toFixed(2),
  237. cost_rate:Number( addition(prev.cost_rate, curr.cost_rate)).toFixed(2),
  238. month: '合计',
  239. }
  240. }, {
  241. pure_sale: 0,
  242. pure_purch: 0,
  243. pure_profit: 0,
  244. completion_rate: 0,
  245. pure_interest_rate: 0,
  246. month: '合计',
  247. cost_tips: 0,
  248. total_tips: 0,
  249. cost_rate: 0
  250. })
  251. totalItem.completion_rate = multiplication(division(totalItem.pure_sale, totalItem.total_tips) || 0, 100)
  252. totalItem.cost_rate = Number(totalItem.cost_tips) === 0 ? 0 : multiplication(division(totalItem.pure_profit, totalItem.cost_tips) || 0, 100).toFixed(2)
  253. this.tableData = [...this.tableData, totalItem];
  254. // const totalItem = createTotalItem(tableData)
  255. // totalItem.month = "年度合计"
  256. // /* 年度指标达成率 = (年度销售净额 / 年度销售指标) **/
  257. // totalItem.completion_rate = multiplication(division(totalItem.pure_sale,totalItem.total_tips),100)
  258. // /* 年度毛利润 = 年度销售额 - 年度采购额 **/
  259. // totalItem.pure_profit = subtraction(totalItem.pure_sale,totalItem.pure_purch)
  260. // /* 年度毛利率 = (年度毛利润 / 年度销售额) **/
  261. // totalItem.pure_interest_rate = multiplication(division(totalItem.pure_profit,totalItem.pure_sale),100)
  262. // this.tableData = [...tableData,totalItem]
  263. break
  264. default:
  265. break
  266. }
  267. // this.getHeight();
  268. this.loading = false;
  269. }
  270. }
  271. }
  272. </script>
  273. <style lang="scss" scoped>
  274. .new-results {
  275. .search {
  276. height: 36px;
  277. padding: 0px 10px;
  278. margin-top: 10px
  279. }
  280. }
  281. </style>