company-month.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <div v-loading="loading">
  3. <div class="search clear" style="align-items: center;">
  4. <el-switch
  5. :disabled="isEmpty"
  6. style="margin-right: 10px;"
  7. v-model="isTenThound"
  8. active-text="万元"
  9. inactive-text="元"
  10. />
  11. <el-select size="small" style="margin-right:10px;width:125px" v-model="companyNo" @change="requestData" :disabled="isEmpty">
  12. <el-option v-for="depart in cp_companies" :key="depart.id" :value="depart.value" :label="depart.label" />
  13. </el-select>
  14. <el-date-picker class="fr picker" v-model="daytime" style=";width:100px" value-format="yyyy" :editable="false" :disabled="isEmpty"
  15. :clearable="false" :size="'small'" type="year" format="yyyy" align="right" placeholder="选择日期"
  16. :picker-options="{ disabledDate(time) { return time.getTime() > Date.now(); } }" @change="requestData" />
  17. </div>
  18. <el-row style="margin-top:10px" v-if="!isEmpty">
  19. <el-table border size="mini" :data="tableData" :cell-class-name="setCellClassName">
  20. <el-table-column fixed="left" label="月度" prop="month" align="center" width="45px" />
  21. <el-table-column label="当月营收目标" align="center" min-width="140px">
  22. <template slot-scope="scope">
  23. {{unit2TenThousand(scope.row.total_tips,isTenThound)}}
  24. </template>
  25. </el-table-column>
  26. <el-table-column label="当月营业收入(净)" align="center" min-width="140px">
  27. <template slot-scope="scope">
  28. {{unit2TenThousand(scope.row.pure_sale,isTenThound)}}
  29. </template>
  30. </el-table-column>
  31. <el-table-column label="当月营收完成%" align="center" min-width="140px">
  32. <template slot-scope="scope">
  33. {{Number(scope.row.completion_rate).toFixed(2) + "%"}}
  34. </template>
  35. </el-table-column>
  36. <el-table-column label="当月毛利完成%" align="center" min-width="140px">
  37. <template slot-scope="scope">
  38. {{Number(scope.row.cost_rate).toFixed(2) + "%"}}
  39. </template>
  40. </el-table-column>
  41. <template v-if="costField">
  42. <el-table-column label="当月毛利指标" align="center" min-width="140px">
  43. <template slot-scope="scope">
  44. {{unit2TenThousand(scope.row.cost_tips,isTenThound)}}
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="当月毛利完成" align="center" min-width="140px">
  48. <template slot-scope="scope">
  49. {{unit2TenThousand(scope.row.pure_profit,isTenThound)}}
  50. </template>
  51. </el-table-column>
  52. </template>
  53. </el-table>
  54. </el-row>
  55. <template v-else>
  56. <div style="text-align:center;line-height:60px;user-select:none">当前账号没有访问权限</div>
  57. </template>
  58. </div>
  59. </template>
  60. <script>
  61. import asyncRequest from "@/api/newResults";
  62. import { unit2TenThousand, subtraction, multiplication, division, addition } from "../newReport/src/_utils";
  63. import { mapCompany } from "./mapCompany";
  64. export default {
  65. props:['companies','costField'],
  66. data(){
  67. return {
  68. loading: false,
  69. isTenThound:true,
  70. daytime: "",
  71. tableData: [],
  72. companyNo: "",
  73. cp_companies:[],
  74. isEmpty:false
  75. }
  76. },
  77. mounted() {
  78. const hasCompose = false;
  79. const jxIndex = this.companies.findIndex((item) => item.label === "北京锦兴弘昌科技有限公司");
  80. const prIndex = this.companies.findIndex((item) => item.label === "北京普润心堂商贸有限公司");
  81. if(jxIndex !== -1 || prIndex !== -1) this.hasCompose = true;
  82. this.cp_companies = this.companies.filter((item) => item.label !== "北京锦兴弘昌科技有限公司" && item.label !== "北京普润心堂商贸有限公司")
  83. if(this.hasCompose) this.cp_companies = [...this.cp_companies,{ value:"GS2302231124114965",label: "普润&锦兴&知事"}]
  84. if(this.cp_companies.length === 4) this.cp_companies = [{ value:"",label: "所有公司"},...this.cp_companies];
  85. this.isEmpty = this.cp_companies.length === 0;
  86. if(this.isEmpty) return;
  87. this.cp_companies = this.cp_companies.map(item => ({ ...item, label:mapCompany[item.label] || item.label}))
  88. this.companyNo = this.cp_companies[0].value;
  89. this.daytime = this.transformTime();
  90. this.requestData();
  91. },
  92. methods: {
  93. unit2TenThousand,
  94. transformTime() {
  95. let time = new Date();
  96. let y = time.getFullYear();
  97. let M = time.getMonth() + 1;
  98. let d = time.getDate();
  99. return y + "-" + (M < 10 ? "0" + M : M) + "-" + (d < 10 ? "0" + d : d);
  100. },
  101. async requestData() {
  102. this.loading = true;
  103. const result = await asyncRequest.companyEvery({ year: (this.daytime.split('-'))[0], companyNo: this.companyNo })
  104. if(this.companyNo === "GS2302231124114965"){
  105. const jxResult = await asyncRequest.companyEvery({ year: (this.daytime.split('-'))[0], companyNo: "GS2304031312553746" })
  106. result.data = result.data.map((_,index) => {
  107. const prItem = result.data[index];
  108. const jxItem = jxResult.data[index];
  109. return {
  110. month:prItem.month,
  111. cgd_th_total: Number(addition(prItem['cgd_th_total'],jxItem['cgd_th_total'])).toFixed(2),
  112. cgd_total:Number(addition(prItem['cgd_total'],jxItem['cgd_total'])).toFixed(2),
  113. cost_tips:Number(addition(prItem['cost_tips'],jxItem['cost_tips'])).toFixed(2),
  114. sale_total:Number(addition(prItem['sale_total'],jxItem['sale_total'])).toFixed(2),
  115. th_total:Number(addition(prItem['th_total'],jxItem['th_total'])).toFixed(2),
  116. total_tips:Number(addition(prItem['total_tips'],jxItem['total_tips'])).toFixed(2),
  117. }
  118. })
  119. };
  120. switch(Number(result.code)){
  121. case 0:
  122. this.tableData = (result.data || []).map(tableItem => {
  123. /* 销售净额 = 销售额 - 退货额 **/
  124. const pure_sale = subtraction(tableItem.sale_total,tableItem.th_total)
  125. /* 指标达成率 = 销售净额 / 销售指标 **/
  126. const completion_rate = multiplication(division(pure_sale,tableItem.total_tips),100)
  127. /* 采购净额 = 采购额 - 采购退货额 **/
  128. const pure_purch = subtraction(tableItem.cgd_total,tableItem.cgd_th_total)
  129. /* 毛利润 = (本月销售净额 - 本月采购净额) **/
  130. const pure_profit = subtraction(pure_sale,pure_purch)
  131. /* 毛利率 = (本月毛利润 / 本月销售净额) * 100 **/
  132. const pure_interest_rate = multiplication(division(pure_profit,pure_sale) || 0,100)
  133. return {
  134. pure_sale,
  135. pure_purch,
  136. pure_profit,
  137. completion_rate,
  138. pure_interest_rate,
  139. month:tableItem.month,
  140. cost_tips:tableItem.cost_tips,
  141. total_tips:tableItem.total_tips,
  142. cost_rate: Number(tableItem.cost_tips) === 0 ? 0 : multiplication(division(pure_profit, tableItem.cost_tips) || 0, 100).toFixed(2)
  143. }
  144. })
  145. // const totalItem = createTotalItem(tableData)
  146. // totalItem.month = "年度合计"
  147. // /* 年度指标达成率 = (年度销售净额 / 年度销售指标) **/
  148. // totalItem.completion_rate = multiplication(division(totalItem.pure_sale,totalItem.total_tips),100)
  149. // /* 年度毛利润 = 年度销售额 - 年度采购额 **/
  150. // totalItem.pure_profit = subtraction(totalItem.pure_sale,totalItem.pure_purch)
  151. // /* 年度毛利率 = (年度毛利润 / 年度销售额) **/
  152. // totalItem.pure_interest_rate = multiplication(division(totalItem.pure_profit,totalItem.pure_sale),100)
  153. // this.tableData = [...tableData,totalItem]
  154. break
  155. default:
  156. break
  157. }
  158. // this.getHeight();
  159. this.loading = false;
  160. }
  161. }
  162. }
  163. </script>
  164. <style lang="scss" scoped>
  165. .new-results{
  166. .search {
  167. height:36px;
  168. display: flex;
  169. justify-content: flex-end;
  170. padding:0px 10px;
  171. margin-top:10px
  172. }
  173. }
  174. </style>