You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

service.vue 7.0KB

1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <template>
  2. <view class="wrapper">
  3. <navBar title="九州ETC"></navBar>
  4. <view class="search-box">
  5. <image :src="`${$imgUrl}service/icon-search.png`" class="icon" mode="aspectFill" @click="search()"></image>
  6. <input class="search" placeholder="请输入业务名称" v-model="state.searchVal" @confirm="search()" />
  7. </view>
  8. <view class="content">
  9. <view class="left">
  10. <view v-for="(item,index) in menuShow.list" :key="index"
  11. :class="activeTab === item.name ? 'menu active' : 'menu'" @click="tabHandle(item.name,index)">
  12. <view :class="activeTab === item.name ? 'border on' : 'border'"></view>
  13. <view class="menu-text">{{item.name}}</view>
  14. </view>
  15. </view>
  16. <view class="right">
  17. <view class="right-content">
  18. <block v-if="menuShow.list.length > 0">
  19. <view v-for="(item,index) in menuShow.list[tableSelectIndex].children" :key='index'
  20. class="item-box" @click="toNext(item.link)">
  21. <view class="item bg-blue" :style="{ '--background': bgBlue }">
  22. <image :src="`${fileURLList}${item.iconPath}`" mode="aspectFill" />
  23. </view>
  24. <view class="text">{{item.name}}</view>
  25. </view>
  26. </block>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <script lang="ts" setup>
  33. import { source } from "@/utils/network/difference";
  34. import navBar from "@/components/nav-bar/nav-bar.vue";
  35. import {
  36. ref,
  37. reactive,
  38. } from "vue";
  39. import {
  40. onLoad
  41. } from "@dcloudio/uni-app";
  42. import {
  43. fileURL, fileURLList
  44. } from "@/datas/fileURL.js";
  45. import {
  46. msg
  47. } from "@/utils/utils";
  48. import {
  49. queryMenuConfig
  50. } from "@/utils/network/api.js";
  51. import {
  52. request
  53. } from "@/utils/network/request.js";
  54. import {
  55. getItem,
  56. StorageKeys,
  57. } from "@/utils/storage";
  58. import {
  59. stringToJson
  60. } from "@/utils/network/encryption";
  61. const bgOrange = `url(${fileURL}image/service/bg-orange.png) center center no-repeat`;
  62. const bgBlue = `url(${fileURL}image/service/bg-blue.png) center center no-repeat`;
  63. const activeTab = ref("");
  64. const tableSelectIndex = ref(0);
  65. // 切换
  66. function tabHandle(val, index) {
  67. activeTab.value = val;
  68. tableSelectIndex.value = index
  69. console.log(tableSelectIndex.value)
  70. }
  71. const menu = reactive({
  72. list: [] //请求的真正的不会变得
  73. });
  74. const menuShow = reactive({
  75. list: [],//展示的
  76. });
  77. const state = reactive({
  78. searchVal: '', //input输入值
  79. newArr: []
  80. });
  81. onLoad(() => {
  82. queryMenuConfigAction().then((val : any) => {
  83. menu.list = val.menuList ? val.menuList : [],
  84. menu.list = deepClone(menu.list)
  85. state.newArr = deepClone(menu.list);
  86. menuShow.list = val.menuList ? val.menuList : [],
  87. activeTab.value = val.menuList[0]['name']
  88. })
  89. });
  90. // 深拷贝
  91. const deepClone = (obj) => {
  92. if (typeof obj !== 'object' || obj === null) {
  93. return obj;
  94. }
  95. let clone = Array.isArray(obj) ? [] : {};
  96. for (let key in obj) {
  97. if (obj.hasOwnProperty(key)) {
  98. clone[key] = deepClone(obj[key]);
  99. }
  100. }
  101. return clone;
  102. }
  103. const search = () => {
  104. for (var i = 0; i < menu.list.length; i++) {
  105. state.newArr[i]['children'] = [];
  106. for (var j = 0; j < menu.list[i]['children'].length; j++) {
  107. const name = menu.list[i]['children'][j].name;
  108. if (name.indexOf(state.searchVal) >= 0) {
  109. state.newArr[i]['children'].push(menu.list[i]['children'][j])
  110. }
  111. }
  112. }
  113. // 清除没有孩子的父亲
  114. const lastArr = []
  115. for (var k = 0; k < state.newArr.length; k++) {
  116. if (state.newArr[k]['children'].length != 0) {
  117. lastArr.push(state.newArr[k])
  118. }
  119. }
  120. console.log("lastArr", lastArr)
  121. if (state.searchVal) {
  122. tableSelectIndex.value = 0
  123. }
  124. menuShow.list = lastArr
  125. console.log("menuShow.list", menuShow.list, tableSelectIndex.value)
  126. }
  127. const queryMenuConfigAction = () => {
  128. var data = {
  129. openId: getItem(StorageKeys.OpenId),
  130. systemType: source == "WECHAT" ? '6' : "9",
  131. loginSource: getItem("loginSource")
  132. };
  133. const options = {
  134. type: 2,
  135. data: data,
  136. method: "POST",
  137. showLoading: true,
  138. };
  139. return new Promise(async (resolve, reject) => {
  140. const res = await request(queryMenuConfig, options);
  141. const data = stringToJson(res.bizContent);
  142. console.log("data", data.menuList)
  143. resolve(data);
  144. }).catch((error) => {
  145. reject(error);
  146. });
  147. }
  148. function toNext(url) {
  149. uni.navigateTo({
  150. url: url,
  151. });
  152. }
  153. </script>
  154. <style>
  155. page {
  156. height: 100%;
  157. background: white;
  158. }
  159. .wrapper {
  160. display: flex;
  161. background: linear-gradient(to left, #43a1e0 0%, #13e7c1 100%);
  162. flex-direction: column;
  163. height: 100%;
  164. }
  165. .search-box {
  166. margin: 50rpx 40rpx;
  167. height: 72rpx;
  168. border-radius: 36rpx;
  169. background: #f7f7f7;
  170. display: flex;
  171. justify-content: center;
  172. align-items: center;
  173. }
  174. .search-box .icon {
  175. width: 48rpx;
  176. height: 48rpx;
  177. margin: 0 20rpx;
  178. }
  179. .search-box .search {
  180. flex: 1;
  181. margin-right: 20rpx;
  182. height: 100%;
  183. padding: 0 10rpx;
  184. font-size: 28rpx;
  185. color: black;
  186. background: transparent;
  187. }
  188. .content {
  189. display: flex;
  190. flex: 1;
  191. flex-grow: 1;
  192. background: #fff;
  193. border-radius: 30rpx 30rpx 0 0;
  194. padding-top: 40rpx;
  195. }
  196. .left {
  197. width: 180rpx;
  198. border-right: 1px solid #dcdcdc;
  199. margin-right: 29rpx;
  200. }
  201. .left .menu-text {
  202. font-size: 26rpx;
  203. color: #666666;
  204. width: 120rpx;
  205. }
  206. .left .menu {
  207. padding-left: 15rpx;
  208. display: flex;
  209. align-items: center;
  210. margin: 20rpx 0 60rpx 0;
  211. }
  212. .left .active .menu-text {
  213. font-weight: bold;
  214. color: #00b38b;
  215. font-size: 28rpx;
  216. line-height: 32rpx;
  217. }
  218. .left .border {
  219. width: 9rpx;
  220. height: 26rpx;
  221. border-radius: 4rpx;
  222. margin-right: 20rpx;
  223. }
  224. .left .on {
  225. background: linear-gradient(0deg, #43a1e0 0%, #13e7c1 100%);
  226. font-size: 28rpx;
  227. }
  228. .right {
  229. flex: 1;
  230. }
  231. .right-content {
  232. display: flex;
  233. flex-wrap: wrap;
  234. }
  235. // #ifdef MP-ALIPAY
  236. .item {
  237. width: 95rpx;
  238. height: 95rpx;
  239. display: flex;
  240. justify-content: center;
  241. align-items: center;
  242. border-radius: 20rpx;
  243. }
  244. .right .item-box {
  245. display: flex;
  246. flex-direction: column;
  247. justify-content: center;
  248. align-items: center;
  249. margin-right: 26rpx;
  250. margin-bottom: 39rpx;
  251. }
  252. // #endif
  253. // #ifdef MP-WEIXIN
  254. .item {
  255. width: 105rpx;
  256. height: 105rpx;
  257. display: flex;
  258. justify-content: center;
  259. align-items: center;
  260. border-radius: 20rpx;
  261. }
  262. .right .item-box {
  263. display: flex;
  264. flex-direction: column;
  265. justify-content: center;
  266. align-items: center;
  267. margin-right: 30rpx;
  268. margin-bottom: 39rpx;
  269. }
  270. // #endif
  271. .item image {
  272. width: 64rpx;
  273. height: 64rpx;
  274. }
  275. .right .text {
  276. width: 105rpx;
  277. font-size: 22rpx;
  278. text-align: center;
  279. height: 60rpx;
  280. display: flex;
  281. justify-content: center;
  282. align-items: center;
  283. margin-top: 19rpx;
  284. color: #666666;
  285. }
  286. .bg-blue {
  287. background: var(--background);
  288. }
  289. .bg-orange {
  290. background: var(--background);
  291. }
  292. .right .text-orange {
  293. color: #fd8362;
  294. }
  295. </style>