TransportMode.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <script setup lang="ts">
  2. import { ref, onMounted, onBeforeMount, watch, computed } from 'vue'
  3. import type { DropdownInstance } from 'element-plus'
  4. import emitter from '@/utils/bus'
  5. interface ListItem {
  6. name: string
  7. number: number
  8. icon: string
  9. checked: boolean
  10. }
  11. interface Props {
  12. TransportListItem: ListItem[]
  13. isShipment: Boolean
  14. }
  15. const props = withDefaults(defineProps<Props>(), {})
  16. const TransportList = ref(props.TransportListItem)
  17. watch(
  18. () => props.TransportListItem,
  19. (current) => {
  20. TransportList.value = current
  21. }
  22. )
  23. onMounted(() => {
  24. emitter.on('clearTag', (tag: any) => {
  25. if (tag.includes('Transport Mode')) {
  26. clearList()
  27. }
  28. })
  29. defaultTransport()
  30. })
  31. onBeforeMount(() => {
  32. emitter.off('clearTag')
  33. })
  34. const checkAll = ref(false)
  35. const dropdown1 = ref<DropdownInstance>()
  36. let checkedCount: any[] = []
  37. const TotalAll = computed(() => {
  38. var total_sum = 0
  39. if (TransportList.value != undefined) {
  40. TransportList.value.map((item) => {
  41. total_sum += item.number
  42. })
  43. }
  44. return total_sum
  45. })
  46. const handleCheckAllChange = (val: any) => {
  47. checkedCount = []
  48. TransportList.value.forEach((item: any) => {
  49. if (val) {
  50. item.checked = true
  51. checkedCount.push(item.name)
  52. } else {
  53. item.checked = false
  54. checkedCount = []
  55. }
  56. })
  57. }
  58. const handleCheckedTransportChange = (value: any, checked: any, index: any) => {
  59. if (checked) {
  60. checkedCount.push(value)
  61. const map = new Map()
  62. checkedCount.forEach((item) => map.set(item, true))
  63. checkedCount = [...map.keys()]
  64. } else {
  65. if (checkedCount.length == 1) {
  66. checkedCount.splice(0, 1)
  67. } else {
  68. checkedCount.splice(index, 1)
  69. }
  70. }
  71. checkAll.value = checkedCount.length === TransportList.value.length
  72. }
  73. // 清除选中
  74. const clearList = () => {
  75. checkAll.value = false
  76. if (TransportList.value != undefined) {
  77. TransportList.value.forEach((item: any) => {
  78. item.checked = false
  79. })
  80. }
  81. changedata.value = ''
  82. checkedCount = []
  83. emit('clearTransportTags')
  84. }
  85. const emit = defineEmits(['TransportSearch', 'clearTransportTags', 'defaultTransport'])
  86. const changedata = ref()
  87. //点击搜索
  88. const TransportData = {
  89. title: 'Transport Mode',
  90. data: ''
  91. }
  92. const TransportSearch = (visible: any) => {
  93. TransportList.value.forEach((item: any) => {
  94. if (item.checked) {
  95. checkedCount.push(item.name)
  96. const map = new Map()
  97. checkedCount.forEach((item) => map.set(item, true))
  98. checkedCount = [...map.keys()]
  99. }
  100. })
  101. if (checkedCount.length == TransportList.value.length) {
  102. changedata.value = 'All'
  103. } else {
  104. changedata.value = checkedCount.join(', ')
  105. }
  106. TransportData.data = changedata.value
  107. emit('TransportSearch', TransportData)
  108. if (!dropdown1.value) return
  109. if (visible) {
  110. dropdown1.value.handleClose()
  111. } else {
  112. dropdown1.value.handleOpen()
  113. }
  114. }
  115. const searchTableQeury = ref()
  116. const searchTableQeuryTracking = ref()
  117. const defaultTransport = () => {
  118. if (props.isShipment) {
  119. if (
  120. sessionStorage.getItem('clickParams') == null ||
  121. sessionStorage.getItem('clickParams') == '{}'
  122. ) {
  123. if (sessionStorage.getItem('searchTableQeuryTracking') == null) {
  124. checkAll.value = true
  125. TransportData.data = 'All'
  126. } else {
  127. searchTableQeuryTracking.value =
  128. JSON.parse(sessionStorage.getItem('searchTableQeuryTracking') as string) || {}
  129. if (searchTableQeuryTracking.value.transport_mode == 'All') {
  130. checkAll.value = true
  131. TransportData.data = 'All'
  132. } else {
  133. TransportData.data = ''
  134. }
  135. }
  136. emit('defaultTransport', TransportData, searchTableQeuryTracking.value)
  137. }
  138. } else {
  139. if (sessionStorage.getItem('searchTableQeury') == null) {
  140. checkAll.value = true
  141. TransportData.data = 'All'
  142. } else {
  143. searchTableQeury.value =
  144. JSON.parse(sessionStorage.getItem('searchTableQeury') as string) || {}
  145. if (searchTableQeury.value.transport_mode == 'All') {
  146. checkAll.value = true
  147. TransportData.data = 'All'
  148. } else {
  149. TransportData.data = ''
  150. }
  151. }
  152. emit('defaultTransport', TransportData, searchTableQeury.value)
  153. }
  154. }
  155. </script>
  156. <template>
  157. <div class="select">
  158. <el-dropdown ref="dropdown1" trigger="click" :hide-on-click="false">
  159. <div class="el-dropdown-link">
  160. <div class="select_title">Transport Mode</div>
  161. <span class="iconfont_icon">
  162. <svg class="iconfont" aria-hidden="true">
  163. <use xlink:href="#icon-icon_dropdown_b"></use>
  164. </svg>
  165. </span>
  166. </div>
  167. <template #dropdown>
  168. <div class="dropdownwidth">
  169. <div class="title">Transport Mode</div>
  170. <el-dropdown-menu>
  171. <el-dropdown-item>
  172. <el-checkbox v-model="checkAll" class="checkbox" @change="handleCheckAllChange">
  173. <div class="checkbox_title">
  174. <span class="iconfont_icon">
  175. <svg class="iconfont iconfont_select" aria-hidden="true">
  176. <use xlink:href="#icon-icon_all_b"></use>
  177. </svg>
  178. </span>
  179. Select All
  180. </div>
  181. <div class="checkbox_number">({{ TotalAll }})</div>
  182. </el-checkbox>
  183. </el-dropdown-item>
  184. <el-divider></el-divider>
  185. <el-dropdown-item v-for="(item, index) in TransportList" :key="index">
  186. <el-checkbox
  187. :value="item.name"
  188. v-model="item.checked"
  189. class="checkbox"
  190. @change="handleCheckedTransportChange(item.name, item.checked, index)"
  191. >
  192. <div class="checkbox_title">
  193. <span class="iconfont_icon">
  194. <svg class="iconfont iconfont_select" aria-hidden="true">
  195. <use :xlink:href="item.icon"></use>
  196. </svg>
  197. </span>
  198. {{ item.name }}
  199. </div>
  200. <div class="checkbox_number">({{ item.number }})</div>
  201. </el-checkbox>
  202. </el-dropdown-item>
  203. <div class="transport_bottom">
  204. <div>
  205. <el-button class="clear" type="default" @click="clearList">Reset</el-button>
  206. </div>
  207. <div>
  208. <el-button class="search el-button--dark" @click="TransportSearch"
  209. >Search</el-button
  210. >
  211. </div>
  212. </div>
  213. </el-dropdown-menu>
  214. </div>
  215. </template>
  216. </el-dropdown>
  217. </div>
  218. </template>
  219. <style lang="scss" scoped>
  220. .iconfont_icon {
  221. margin-right: 8px;
  222. }
  223. .iconfont_select {
  224. width: 17px;
  225. height: 17px;
  226. }
  227. .select {
  228. width: 186px;
  229. margin-left: 8px;
  230. cursor: pointer;
  231. display: flex;
  232. align-items: center;
  233. border: 1px solid var(--color-border);
  234. border-radius: var(--border-radius-6);
  235. }
  236. .select:hover {
  237. border: 1px solid var(--color-theme);
  238. }
  239. .el-dropdown-link {
  240. width: 186px;
  241. display: flex;
  242. align-items: center;
  243. justify-content: space-between;
  244. }
  245. .select_title {
  246. font-size: var(--font-size-3);
  247. font-weight: 400;
  248. margin-left: 8.53px;
  249. color: var(--color-neutral-1);
  250. }
  251. .title {
  252. font-weight: 700;
  253. font-size: var(--font-size-5);
  254. background-color: var(--color-header-bg);
  255. height: 48px;
  256. display: flex;
  257. align-items: center;
  258. padding-left: 16px;
  259. }
  260. .checkbox {
  261. width: 216px;
  262. font-weight: 400;
  263. font-size: var(--font-size-3);
  264. padding: 0 12px;
  265. height: 40px;
  266. }
  267. :deep(.el-popper__arrow, .el-popper__arrow:before) {
  268. height: 0;
  269. width: 0;
  270. }
  271. :deep(.el-checkbox__label) {
  272. width: 176px;
  273. padding-left: 13px;
  274. display: flex;
  275. align-items: center;
  276. justify-content: space-between;
  277. }
  278. .checkbox_title {
  279. color: var(--color-neutral-1);
  280. }
  281. .checkbox_number {
  282. color: var(--color-neutral-3);
  283. }
  284. .transport_bottom {
  285. display: flex;
  286. justify-content: flex-end;
  287. align-items: center;
  288. height: 48px;
  289. border-top: 1px solid var(--color-border);
  290. margin-top: 5px;
  291. font-weight: 400;
  292. font-size: var(--font-size-3);
  293. }
  294. .clear {
  295. width: 81px;
  296. height: 32px;
  297. margin-right: 7.82px;
  298. }
  299. .search {
  300. width: 86px;
  301. height: 32px;
  302. margin-right: 16px;
  303. }
  304. .search:hover {
  305. color: var(--color-theme);
  306. }
  307. :deep(.el-dropdown-menu__item:hover) {
  308. background-color: var(--border-hover-color);
  309. border-radius: var(--border-radius-6);
  310. border-color: var(--border-hover-color);
  311. }
  312. :deep(.el-dropdown-menu__item) {
  313. padding: 0;
  314. margin: 10px 16px;
  315. }
  316. :deep(.el-dropdown-menu__item:not(.is-disabled):focus) {
  317. background-color: var(--border-hover-color);
  318. border-radius: var(--border-radius-6);
  319. border-color: var(--border-hover-color);
  320. }
  321. .dropdownwidth {
  322. width: 248px;
  323. }
  324. @media only screen and (min-width: 1280px) {
  325. .el-dropdown-link,
  326. .select {
  327. width: 224px;
  328. }
  329. .dropdownwidth {
  330. width: 248px;
  331. }
  332. }
  333. @media only screen and (min-width: 1440px) {
  334. .el-dropdown-link,
  335. .select {
  336. width: 336px;
  337. }
  338. .dropdownwidth {
  339. width: 336px;
  340. }
  341. }
  342. .el-divider--horizontal {
  343. margin: 8px 0;
  344. border-top-color: var(--color-border);
  345. }
  346. </style>