newResults.vue 5.7 KB

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