newResults.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <div class="new-results" v-loading="state.loading" style="min-height:300px">
  3. <div v-if="!state.error && isShow">
  4. <result-company :companies="companies" :costField="costField" />
  5. <result-company-month :companies="companies" :costField="costField" />
  6. <result-department :companies="companies" :costField="costField" />
  7. </div>
  8. <template v-else-if="!state.loading">
  9. <unusual-state :hasPermission="isShow" :message="state.message" path="newReport" />
  10. </template>
  11. </div>
  12. </template>
  13. <script>
  14. import PeriodDatePicker from "../components/period-date-picker";
  15. import UnusualState from "@/components/unusual/index.vue";
  16. import ResultCompany from "@/components/newResults/company.vue"
  17. import ResultDepartment from "@/components/newResults/department.vue"
  18. import ResultCompanyMonth from "@/components/newResults/company-month.vue"
  19. import { getOpenid, getParameterByName, removeOpenid, setOpenid } from "../utils/auth";
  20. import userRequest from "@/api/index";
  21. export default {
  22. name: "newReport",
  23. components: {
  24. UnusualState,
  25. ResultCompany,
  26. ResultDepartment,
  27. PeriodDatePicker,
  28. ResultCompanyMonth
  29. },
  30. data() {
  31. return {
  32. companies:[],
  33. costField: false,
  34. zxTotal: 0,
  35. daytime: "",
  36. isDisplay: false,
  37. state:{ message: '', error: false, loading: false }
  38. };
  39. },
  40. mounted() {
  41. if(!getParameterByName('code')){
  42. this.login()
  43. }else{
  44. this.requestUserinfo()
  45. }
  46. },
  47. methods: {
  48. async time(e) {
  49. const { startTime, endTime } = e;
  50. this.start = startTime || "";
  51. this.end = endTime || "";
  52. const { start, end } = this;
  53. if ((start !== "" && end === "") || (start === "" && end !== "")) {
  54. this.$message.warning("时间区间不完整!");
  55. this.date = []
  56. return;
  57. }
  58. if(this.start && this.end){
  59. this.date = [this.start + " 00:00:00", this.end + " 23:59:59"]
  60. }else{
  61. this.date = [this.start, this.end]
  62. }
  63. },
  64. async requestUserinfo(){
  65. this.state.loading = true
  66. const openid = getOpenid()
  67. const code = getParameterByName('code')
  68. const result = await userRequest.userinfo({ ...( openid ? { openid } : { code }) })
  69. // const result = {
  70. // "code": 0,
  71. // "message": "获取成功",
  72. // "data": {
  73. // "openid": "oOpc26KiZFBKIm7SB8knFGvov1qg",
  74. // "subscribe_time": "2022-12-21 15:52:14",
  75. // "updatetime": "2023-05-09 16:22:33",
  76. // "addtime": "2023-04-10 18:11:17",
  77. // "is_show": ["1", "2", "4", "6", "cost_field"],
  78. // "nickname": "雪寒",
  79. // "addr": "\/\/",
  80. // "gender": "0",
  81. // "mobile": "",
  82. // "avatar": "",
  83. // "status": "1",
  84. // "id": "1",
  85. // "companyArr": [
  86. // {"companyNo": "GS2302231125079621", "companyName": "北京百辰荣达国际科贸有限公司", "info": [1, 2, 6]},
  87. // {"companyNo": "GS2302231323386950","companyName": "北京泓源广诚国际商贸有限公司", "info": [1, 2, 6]},
  88. // {"companyNo": "GS2203161855277894","companyName": "北京万宇恒通国际科贸有限公司", "info": [1, 2, 6]},
  89. // {"companyNo": "GS2304031312553746","companyName": "北京锦兴弘昌科技有限公司", "info": [1, 2, 6]},
  90. // {"companyNo": "GS2302231124114965","companyName": "北京普润心堂商贸有限公司", "info": [1, 2, 6]}
  91. // ]
  92. // }
  93. // }
  94. this.companies = result.data.companyArr.reduce((prev,current) => {
  95. return current.info.includes(6) || current.info.includes('6') ? [...prev,{
  96. value:current.companyNo,
  97. label:current.companyName
  98. }] : prev
  99. },[])
  100. this.state.loading = false
  101. switch(Number(result.code)){
  102. case 0:
  103. this.isShow = (result.data.is_show || []).includes(6) || (result.data.is_show || []).includes('6')
  104. this.costField = (result.data.is_show || []).includes('cost_field')
  105. setOpenid(result.data.openid)
  106. break
  107. default:
  108. this.state.error = true;
  109. this.state.message = result.message;
  110. openid && removeOpenid();
  111. break;
  112. }
  113. },
  114. login(){
  115. const redirect_url = encodeURIComponent('http://stat.caixiao365.com/accountsReceivable')
  116. var state = 'wx_' + Math.random().toString(36).substr(2, 15)
  117. const scope = 'snsapi_userinfo'
  118. const baseUrl = "https://open.weixin.qq.com/connect/oauth2/authorize";
  119. const url = `${baseUrl}?appid=${config.appId}&redirect_uri=${redirect_url}&response_type=code&scope=${scope}&state=${state}#wechat_redirect`
  120. window.location.href = url;
  121. },
  122. }
  123. }
  124. </script>
  125. <style lang="scss" scoped>
  126. .new-results {
  127. width: 100vw;
  128. height: 100vh;
  129. position: fixed;
  130. overflow: auto;
  131. }
  132. </style>