tenant.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. <template>
  2. <div class="tenant-dashboard">
  3. <!-- 新手引导 -->
  4. <!-- <div class="guide-section">
  5. <h2>快速开始</h2>
  6. <el-tabs v-model="activeGuideTab" type="card" class="guide-tabs">
  7. <el-tab-pane label="出资账户设置" name="account">
  8. <div class="step-desc">设置企业支付时的出资账户,当员工符合制度要求时,可由该账户出资进行企业支付</div>
  9. <el-button type="primary">去设置</el-button>
  10. </el-tab-pane>
  11. <el-tab-pane label="添加员工" name="employee">
  12. <div class="step-desc">创建部门/员工组/项目后,将员工信息填写或导入进来,完成操作后,发送二维码/链接给员工,让他们开通企业码</div>
  13. <el-button type="primary">去添加</el-button>
  14. </el-tab-pane>
  15. <el-tab-pane label="配置费控规则" name="rule">
  16. <div class="step-desc">新建费用制度,设置企业支付的规则,限定可使用的员工、时间、地点、金额、商户等信息</div>
  17. <el-button type="primary">去配置</el-button>
  18. </el-tab-pane>
  19. <el-tab-pane label="账单管理" name="bill">
  20. <div class="step-desc">企业因公消费账单,可进行账期设置、账单查看等功能</div>
  21. <el-button type="primary">去查看</el-button>
  22. </el-tab-pane>
  23. </el-tabs>
  24. </div> -->
  25. <!-- 核心数据 -->
  26. <div class="core-data-section">
  27. <div class="section-header">
  28. <h2>支付数据统计</h2>
  29. <div class="section-header-right">
  30. <el-select
  31. v-if="is_platform_user"
  32. v-model="currentTenantId"
  33. placeholder="选择商户"
  34. style="width: 180px"
  35. >
  36. <el-option
  37. v-for="tenant in allTenantData"
  38. :key="tenant.id"
  39. :label="tenant.name"
  40. :value="tenant.id"
  41. />
  42. </el-select>
  43. <el-select
  44. v-model="selectedEnterpriseId"
  45. placeholder="选择企业"
  46. filterable
  47. class="enterprise-select"
  48. @change="handleEnterpriseChange"
  49. >
  50. <el-option label="全部" :value="undefined" />
  51. <el-option
  52. v-for="item in enterpriseStore.getEnterpriseList"
  53. :key="item.enterprise_id"
  54. :label="item.name"
  55. :value="item.enterprise_id"
  56. />
  57. </el-select>
  58. <el-select
  59. v-model="selectedPayeeType"
  60. placeholder="收款方类型"
  61. clearable
  62. class="payee-select"
  63. @change="handlePayeeTypeChange"
  64. >
  65. <el-option label="支付宝" value="ALIPAY_ACCOUNT" />
  66. <el-option label="银行卡" value="BANK_CARD" />
  67. </el-select>
  68. </div>
  69. </div>
  70. <div class="data-cards">
  71. <div class="data-card">
  72. <div class="card-title">今日转账金额(元)</div>
  73. <div class="card-value">{{ statAmount.amount_of_today || "--" }}</div>
  74. </div>
  75. <div class="data-card">
  76. <div class="card-title">近7日转账金额(元)</div>
  77. <div class="card-value">{{ statAmount.amount_of_7days || "--" }}</div>
  78. </div>
  79. <div class="data-card">
  80. <div class="card-title">总转账金额(元)</div>
  81. <div class="card-value">{{ statAmount.amount_of_all || "--" }}</div>
  82. </div>
  83. </div>
  84. <div class="section-header" style="margin-top: 24px;">
  85. <h2>消费数据统计</h2>
  86. </div>
  87. <div class="data-cards">
  88. <div class="data-card consume-card">
  89. <div class="card-title">今日消费金额(元)</div>
  90. <div class="card-value">{{ consumeAmount.amount_of_today || "--" }}</div>
  91. </div>
  92. <div class="data-card consume-card">
  93. <div class="card-title">近7日消费金额(元)</div>
  94. <div class="card-value">{{ consumeAmount.amount_of_7days || "--" }}</div>
  95. </div>
  96. <div class="data-card consume-card">
  97. <div class="card-title">总消费金额(元)</div>
  98. <div class="card-value">{{ consumeAmount.amount_of_all || "--" }}</div>
  99. </div>
  100. </div>
  101. <div class="section-header" style="margin-top: 24px;">
  102. <h2>银联收款统计</h2>
  103. </div>
  104. <div class="data-cards">
  105. <div class="data-card lsy-card">
  106. <div class="card-title">今日收款金额(元)</div>
  107. <div class="card-value">{{ lsyAmount.amount_of_today || "--" }}</div>
  108. </div>
  109. <div class="data-card lsy-card">
  110. <div class="card-title">近7日收款金额(元)</div>
  111. <div class="card-value">{{ lsyAmount.amount_of_7days || "--" }}</div>
  112. </div>
  113. <div class="data-card lsy-card">
  114. <div class="card-title">总收款金额(元)</div>
  115. <div class="card-value">{{ lsyAmount.amount_of_all || "--" }}</div>
  116. </div>
  117. </div>
  118. <div class="section-header" style="margin-top: 24px;">
  119. <h2>汇总统计</h2>
  120. </div>
  121. <div class="data-cards">
  122. <div class="data-card summary-card">
  123. <div class="card-title">今日汇总(元)</div>
  124. <div class="card-value">{{ summaryAmount.amount_of_today || "--" }}</div>
  125. </div>
  126. <div class="data-card summary-card">
  127. <div class="card-title">近7日汇总(元)</div>
  128. <div class="card-value">{{ summaryAmount.amount_of_7days || "--" }}</div>
  129. </div>
  130. <div class="data-card summary-card">
  131. <div class="card-title">总汇总(元)</div>
  132. <div class="card-value">{{ summaryAmount.amount_of_all || "--" }}</div>
  133. </div>
  134. </div>
  135. </div>
  136. </div>
  137. </template>
  138. <script setup lang="ts">
  139. import { ref, computed, onMounted } from 'vue';
  140. import { ElButton, ElTabs, ElTabPane } from 'element-plus';
  141. import { useEnterpriseStore, useUserStore } from '@/store';
  142. import AccountAPI from '@/api/module_payment/account';
  143. import TenantAPI, { TenantTable } from '@/api/module_system/tenant';
  144. const userStore = useUserStore();
  145. const enterpriseStore = useEnterpriseStore();
  146. const is_platform_user = computed(() => {
  147. return userStore.is_platform_user;
  148. });
  149. const currentTenantId = ref<number | undefined>(undefined);
  150. const selectedEnterpriseId = ref<string | undefined>(
  151. enterpriseStore.getCurrentEnterprise?.enterprise_id
  152. );
  153. const selectedPayeeType = ref<string | undefined>(undefined);
  154. function handlePayeeTypeChange() {
  155. fetchStatAmount();
  156. fetchLsyAmount();
  157. fetchSummaryAmount();
  158. }
  159. const currentEnterpriseId = computed(() => enterpriseStore.getCurrentEnterprise?.enterprise_id);
  160. const currentEnterprise = computed(() => enterpriseStore.getCurrentEnterprise);
  161. const statAmount = ref<{
  162. amount_of_today?: string;
  163. amount_of_7days?: string;
  164. amount_of_all?: string;
  165. }>({});
  166. const consumeAmount = ref<{
  167. amount_of_today?: string;
  168. amount_of_7days?: string;
  169. amount_of_all?: string;
  170. }>({});
  171. /**
  172. * 「银联收款统计」卡的数据 —— 2026-10-05 起来自**乐收赢**(净额,后端已把分换成元)。
  173. * 标题当天由「支付宝收款」改过来:用户裁定 lsy = 银联收款、har = 支付宝收款,
  174. * 乐收赢的数不能挂在「支付宝收款」名下(那是汇安融的)。
  175. */
  176. const lsyAmount = ref<{
  177. amount_of_today?: string;
  178. amount_of_7days?: string;
  179. amount_of_all?: string;
  180. }>({});
  181. const summaryAmount = ref<{
  182. amount_of_today?: string;
  183. amount_of_7days?: string;
  184. amount_of_all?: string;
  185. }>({});
  186. const allTenantData = ref<TenantTable[]>([]);
  187. function handleEnterpriseChange() {
  188. enterpriseStore.setCurrentEnterprise(selectedEnterpriseId.value!);
  189. }
  190. async function fetchStatAmount() {
  191. try {
  192. const res = await AccountAPI.statAmount(currentTenantId.value, selectedEnterpriseId.value, selectedPayeeType.value);
  193. statAmount.value = res.data.data || {};
  194. } catch (error) {
  195. console.error("获取统计金额失败:", error);
  196. }
  197. }
  198. async function fetchConsumeAmount() {
  199. try {
  200. const res = await AccountAPI.statConsumeAmount(currentTenantId.value, selectedEnterpriseId.value);
  201. consumeAmount.value = res.data.data || {};
  202. } catch (error) {
  203. console.error("获取消费统计金额失败:", error);
  204. }
  205. }
  206. // 乐收赢(银联收单)统计只按租户取,**不随「企业」下拉变** —— 乐收赢无企业维度
  207. // (去企业化后新单 enterprise_id 恒 NULL,带企业筛会把新单全排除、卡片恒 0.00)。
  208. async function fetchLsyAmount() {
  209. try {
  210. const res = await AccountAPI.statLsyTradeAmount(currentTenantId.value);
  211. lsyAmount.value = res.data.data || {};
  212. } catch (error) {
  213. console.error("获取乐收赢收款统计失败:", error);
  214. }
  215. }
  216. async function fetchSummaryAmount() {
  217. try {
  218. const res = await AccountAPI.statSummaryAmount(currentTenantId.value, selectedEnterpriseId.value, selectedPayeeType.value);
  219. summaryAmount.value = res.data.data || {};
  220. } catch (error) {
  221. console.error("获取汇总统计金额失败:", error);
  222. }
  223. }
  224. async function fetchAllTenantData() {
  225. try {
  226. const res = await TenantAPI.listTenant({
  227. page_no: 1,
  228. page_size: 100,
  229. });
  230. // 增加全部选项然后合并请求的数据
  231. allTenantData.value = [{ id: undefined, name: "全部" }, ...(res.data.data?.items || [])];
  232. console.log("所有租户数据:", allTenantData.value);
  233. } catch (error) {
  234. console.error("获取所有租户数据失败:", error);
  235. }
  236. }
  237. onMounted(async () => {
  238. if (is_platform_user.value) {
  239. await fetchAllTenantData();
  240. }
  241. await enterpriseStore.loadEnterpriseList();
  242. if (!is_platform_user.value && !selectedEnterpriseId.value) {
  243. selectedEnterpriseId.value = enterpriseStore.getCurrentEnterprise?.enterprise_id;
  244. }
  245. fetchStatAmount();
  246. fetchConsumeAmount();
  247. fetchLsyAmount();
  248. fetchSummaryAmount();
  249. });
  250. watch(currentTenantId, async (newTenantId) => {
  251. // 绕过 store 缓存,按商户直接重载企业列表
  252. enterpriseStore.enterpriseList = (await enterpriseStore.fetchEnterpriseList(
  253. newTenantId || undefined
  254. )) || [];
  255. // 重置到"全部",由用户手动选择企业
  256. selectedEnterpriseId.value = undefined;
  257. fetchStatAmount();
  258. fetchConsumeAmount();
  259. fetchLsyAmount();
  260. fetchSummaryAmount();
  261. });
  262. watch(selectedEnterpriseId, () => {
  263. fetchStatAmount();
  264. fetchConsumeAmount();
  265. fetchLsyAmount();
  266. fetchSummaryAmount();
  267. });
  268. // 租户仪表盘组件
  269. </script>
  270. <style scoped>
  271. .tenant-dashboard {
  272. padding: 20px;
  273. background-color: #f5f7fa;
  274. min-height: 100vh;
  275. }
  276. .guide-section {
  277. background: white;
  278. border-radius: 8px;
  279. padding: 20px 20px 50px 20px;
  280. margin-bottom: 24px;
  281. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  282. }
  283. .guide-section h2 {
  284. font-size: 16px;
  285. font-weight: 600;
  286. margin-bottom: 16px;
  287. color: #303133;
  288. }
  289. .guide-tabs {
  290. margin-top: 16px;
  291. }
  292. .guide-tabs .el-tabs__header {
  293. margin-bottom: 16px;
  294. border-bottom: none;
  295. }
  296. .guide-tabs .el-tabs__content {
  297. padding: 20px;
  298. background: #f9f9f9;
  299. border-radius: 0 0 8px 8px;
  300. border: 1px solid #ebeef5;
  301. border-top: none;
  302. }
  303. .guide-tabs .el-tabs__item {
  304. padding: 12px 20px;
  305. font-size: 14px;
  306. }
  307. .guide-tabs .el-tabs__item.is-active {
  308. color: #409eff;
  309. font-weight: 500;
  310. }
  311. .step-desc {
  312. font-size: 12px;
  313. color: #909399;
  314. margin-bottom: 12px;
  315. line-height: 1.4;
  316. }
  317. .core-data-section {
  318. background: white;
  319. border-radius: 8px;
  320. padding: 20px;
  321. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  322. }
  323. .section-header {
  324. display: flex;
  325. justify-content: space-between;
  326. align-items: center;
  327. margin-bottom: 16px;
  328. }
  329. .section-header h2 {
  330. font-size: 16px;
  331. font-weight: 600;
  332. color: #303133;
  333. }
  334. .section-header-right {
  335. display: flex;
  336. align-items: center;
  337. gap: 12px;
  338. }
  339. .enterprise-select {
  340. width: 260px;
  341. }
  342. .payee-select {
  343. width: 140px;
  344. }
  345. .more-link {
  346. font-size: 12px;
  347. color: #409eff;
  348. text-decoration: none;
  349. }
  350. .data-cards {
  351. display: grid;
  352. grid-template-columns: repeat(4, 1fr);
  353. gap: 16px;
  354. }
  355. .data-card {
  356. padding: 16px;
  357. background: #f9f9f9;
  358. border-radius: 4px;
  359. border-left: 3px solid #409eff;
  360. }
  361. .data-card.consume-card {
  362. border-left-color: #409eff;
  363. }
  364. .data-card.consume-card .card-value {
  365. color: #409eff;
  366. }
  367. .data-card.summary-card {
  368. border-left-color: #e6a23c;
  369. }
  370. .data-card.summary-card .card-value {
  371. color: #e6a23c;
  372. }
  373. .card-title {
  374. font-size: 12px;
  375. color: #909399;
  376. margin-bottom: 8px;
  377. }
  378. .card-value {
  379. font-size: 20px;
  380. font-weight: 600;
  381. color: #303133;
  382. margin-bottom: 8px;
  383. }
  384. .card-link {
  385. font-size: 12px;
  386. color: #409eff;
  387. text-decoration: none;
  388. }
  389. @media (max-width: 1200px) {
  390. .data-cards {
  391. grid-template-columns: repeat(2, 1fr);
  392. }
  393. }
  394. @media (max-width: 768px) {
  395. .guide-steps {
  396. flex-direction: column;
  397. }
  398. .guide-step:not(:last-child)::after {
  399. content: '▼';
  400. position: relative;
  401. right: auto;
  402. top: auto;
  403. display: block;
  404. text-align: center;
  405. margin: 8px 0;
  406. }
  407. .data-cards {
  408. grid-template-columns: 1fr;
  409. }
  410. }
  411. </style>