index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <!-- 商户管理 -->
  3. <div class="merchantPage flex-col">
  4. <s-header :name="$t('merchantManage.merchantManagement')" :noback="false"></s-header>
  5. <div class="merchantBox flex-col">
  6. <van-list v-model:loading="loading" v-model:error="error" :error-text="$t('public.requestFailed')"
  7. :finished="finished" :finished-text="$t('public.noMore')" offset="300" :immediate-check="false" @load="onLoad">
  8. <div class="searchRow flex-row justify-between">
  9. <div class="flex-col">
  10. <div class="flex-row justify-between bd3">
  11. <span class="info2">{{ $t('merchantManage.total') }}</span>
  12. <span class="info3">{{ adminTotal }}</span>
  13. <span class="info4">{{ $t('merchantManage.recordsInTotal') }}</span>
  14. </div>
  15. </div>
  16. <div class="flex-col">
  17. <div class="main5 flex-row justify-between" @click="searchClick">
  18. <img class="label2" src="../../assets/device/searchIcon.png" />
  19. <div class="TextGroup2 flex-col">
  20. <span class="txt3">{{ $t('merchantManage.search') }}</span>
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. <div class="main4 flex-col">
  26. <div class="bd1 flex-col" v-for="(item, index) in adminList" :key="index">
  27. <div class="outer2 flex-col">
  28. <div class="box2 flex-row justify-between">
  29. <span class="word3" v-html="item.username + '&nbsp;' + item.name"></span>
  30. <!-- <div class="group6 flex-col"></div> -->
  31. </div>
  32. <span class="word4"
  33. v-html="`${$t('merchantManage.telephone')}:` + (item.phone == null ? '' : item.phone)"></span>
  34. <span class="word5"
  35. v-html="`${$t('merchantManage.mailbox')}:` + (item.email == null ? '' : item.email)"></span>
  36. <span class="word6"
  37. v-html="`${$t('merchantManage.loginTime')}:` + (item.loginDate == null ? '' : Format_time(item.loginDate))"></span>
  38. <span class="info6"
  39. v-html="`${$t('merchantManage.loginIPAddress')}:` + (item.loginIp == null ? '' : item.loginIp)"></span>
  40. <span class="txt2"
  41. v-html="`${$t('merchantManage.managementSystemId')}:` + (item.managerId == null ? '' : item.managerId)"></span>
  42. <div class="box3 flex-col">
  43. <span class="txt3" v-html="`${$t('merchantManage.creationTime')}:` + Format_time(item.createDate)"></span>
  44. </div>
  45. <div class="button-container">
  46. <van-button v-if="user.type < 2" class="btn1" round type="success" @click="autoLogin(item.id)">切换登陆</van-button>
  47. <van-button class="btn1" round type="primary" @click="merchantSet(item)">详细信息</van-button>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. </van-list>
  53. </div>
  54. <merchantSearch ref="searchRef" @search="search($event)"></merchantSearch>
  55. </div>
  56. </template>
  57. <script>
  58. import { onMounted, reactive, ref } from "vue";
  59. import sHeader from "../../components/SimpleHeader";
  60. import { getAdminList, autoLoginMerchant } from '../../service/merchantManage';
  61. import { getLoginUser, Format_time, styleUrl, setLocal } from "../../common/js/utils";
  62. import { Toast, Dialog } from 'vant';
  63. import merchantSearch from './merchantSearch.vue';
  64. import { useRouter } from "vue-router";
  65. import { useI18n } from "vue-i18n";
  66. export default {
  67. components: { sHeader, merchantSearch },
  68. setup() {
  69. const { t } = useI18n();
  70. const user = getLoginUser();
  71. const router = useRouter();
  72. const searchRef = ref(null);
  73. const adminList = ref([]);
  74. const adminTotal = ref(0); // 列表总数
  75. const loading = ref(false); // 加载状态
  76. const error = ref(false); // 错误状态
  77. const finished = ref(false); // 结束翻页状态
  78. let searchParams = reactive({
  79. id: user.id,
  80. current: 1, // 页数
  81. size: 20, // 页大小
  82. });
  83. onMounted(async () => {
  84. // 加载样式
  85. styleUrl('merchantManage');
  86. searchGetList();
  87. });
  88. // 查询列表
  89. const searchGetList = () => {
  90. adminList.value = [];
  91. searchParams.current = 1;
  92. getList();
  93. }
  94. // 滚动加载
  95. const onLoad = () => { if (!finished.value) { searchParams.current = searchParams.current + 1; getList(); } };
  96. // 获取设备列表数据
  97. const getList = async () => {
  98. const { data } = await getAdminList(Object.assign({}, searchParams));
  99. if (data.code === "00000") {
  100. // 列表值叠加
  101. adminList.value = adminList.value.concat(data.data.records);
  102. adminTotal.value = data.data.total;
  103. if (adminList.value.length === data.data.total) { finished.value = true; }
  104. loading.value = false;
  105. } else { Toast.fail(data.message); }
  106. };
  107. // 搜索点击
  108. const searchClick = () => { searchRef.value.showSearch(); };
  109. // 搜索弹窗触发搜索
  110. const search = (data) => {
  111. searchParams = Object.assign(searchParams, data);
  112. searchGetList();
  113. };
  114. // 跳转设备编辑
  115. const merchantSet = (e) => { router.push({ path: 'merchantSet', query: { merchantId: e.id } }) }
  116. // 切换登陆
  117. const autoLogin = (id) => {
  118. Dialog.confirm({
  119. title: t('merchantManage.tips'),
  120. message: t('merchantManage.autoLogin'),
  121. }).then(() => {
  122. autoLoginMerchant({ id }).then(res =>{
  123. if (res.data.code === "00000") {
  124. // 获取缓存的语言
  125. const curLang = localStorage.getItem("curLang");
  126. // 清空缓存
  127. localStorage.clear();
  128. localStorage.setItem("curLang", curLang);
  129. setLocal("loginUser", JSON.stringify(res.data.data));
  130. // console.log('loginUser JSON:', JSON.stringify(data.data));
  131. Toast.success(t('login.loginSucess'));
  132. // 需要刷新页面,否则 axios.js 文件里的 token 不会被重置
  133. window.location.href = '/shenze/';
  134. setTimeout(() => {
  135. router.push("/home");
  136. }, 200);
  137. } else {
  138. Toast.fail(res.data.message);
  139. }
  140. });
  141. }).catch((error) => {
  142. console.error(error);
  143. })
  144. }
  145. return {
  146. adminList,
  147. adminTotal,
  148. loading,
  149. error,
  150. finished,
  151. onLoad,
  152. searchClick,
  153. searchRef,
  154. search,
  155. merchantSet,
  156. autoLogin,
  157. Format_time,
  158. user,
  159. };
  160. },
  161. };
  162. </script>
  163. <style lang="less" scoped>
  164. @import "../../common/style/common.less";
  165. </style>