DashFiters.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <script setup lang="ts">
  2. import { ref, watch, onMounted, computed } from 'vue'
  3. import moment from 'moment'
  4. import dayjs from 'dayjs'
  5. const props = defineProps({
  6. defaultData: {
  7. type: Object
  8. },
  9. radioisDisabled: {
  10. type: Boolean,
  11. default: false
  12. },
  13. isRecent: {
  14. type: Boolean,
  15. default: false
  16. },
  17. isETDToETA: {
  18. type: Boolean,
  19. default: false
  20. },
  21. isContainer: {
  22. type: Boolean,
  23. default: false
  24. }
  25. })
  26. const defaultfiltersData = ref(props.defaultData)
  27. watch(
  28. () => props.defaultData,
  29. (current) => {
  30. defaultfiltersData.value = current
  31. }
  32. )
  33. const isDisabled = ref(false)
  34. const checkboxGroup1 = ref(['All'])
  35. const CheckboxGroup2 = ref('ETD')
  36. const filters_visible = ref(false)
  37. const shipper = ref(['All', 'Air', 'Sea', 'Road'])
  38. const shipper_two = ref(['ETD', 'ETA'])
  39. const DashDate = ref()
  40. DashDate.value = []
  41. const startDate = ref()
  42. const EndDate = ref()
  43. let dashboardObj: any = {}
  44. const checkboxDisabled = computed(() => {
  45. if (props.isContainer && !props.isETDToETA) {
  46. return true
  47. } else {
  48. return false
  49. }
  50. })
  51. onMounted(() => {
  52. getdefaultdata()
  53. })
  54. const getdefaultdata = () => {
  55. checkboxGroup1.value = defaultfiltersData.value?.transportation
  56. CheckboxGroup2.value = defaultfiltersData.value?.date_type
  57. if (defaultfiltersData.value?.date_start == '') {
  58. DashDate.value = []
  59. isDisabled.value = true
  60. } else {
  61. if (props.isContainer) {
  62. startDate.value = defaultfiltersData.value?.date_start_two
  63. EndDate.value = defaultfiltersData.value?.date_end_two
  64. } else {
  65. DashDate.value = [
  66. dayjs(defaultfiltersData.value?.date_start_two),
  67. dayjs(defaultfiltersData.value?.date_end_two)
  68. ]
  69. }
  70. if (props.isContainer) {
  71. dashboardObj.date_start = defaultfiltersData.value?.date_start
  72. dashboardObj.date_start_two = defaultfiltersData.value?.date_start_two
  73. dashboardObj.date_end = defaultfiltersData.value?.date_end
  74. dashboardObj.date_end_two = defaultfiltersData.value?.date_end_two
  75. } else {
  76. dashboardObj.date_start = dayjs(DashDate.value[0]).format('MM/DD/YYYY')
  77. dashboardObj.date_start_two = dayjs(DashDate.value[0]).format('YYYY-MM-DD')
  78. dashboardObj.date_end = dayjs(DashDate.value[1]).format('MM/DD/YYYY')
  79. dashboardObj.date_end_two = dayjs(DashDate.value[1]).format('YYYY-MM-DD')
  80. }
  81. }
  82. dashboardObj.transportation = checkboxGroup1.value
  83. dashboardObj.date_type = CheckboxGroup2.value
  84. }
  85. const changeCheckboxGroup1 = (val: any) => {
  86. if (val.length == 3) {
  87. checkboxGroup1.value = ['All']
  88. }
  89. if (val.length == 0) {
  90. checkboxGroup1.value = ['All']
  91. } else if (val.indexOf('All') != -1) {
  92. if (val.indexOf('All') == 1 && val.length == 2) {
  93. checkboxGroup1.value = ['All']
  94. } else {
  95. checkboxGroup1.value.splice(val.indexOf('All'), 1)
  96. }
  97. }
  98. dashboardObj.transportation = checkboxGroup1.value
  99. }
  100. const changeCheckboxGroup2 = (val: any) => {
  101. dashboardObj.date_type = val
  102. }
  103. const emit = defineEmits(['FilterSearch'])
  104. const DateChange = (value: any) => {
  105. dashboardObj.date_start = value[0]
  106. dashboardObj.date_start_two = dayjs(value[0]).format('YYYY-MM-DD')
  107. dashboardObj.date_end = value[1]
  108. dashboardObj.date_end_two = dayjs(value[1]).format('YYYY-MM-DD')
  109. }
  110. const StartChange = (val: any) => {
  111. if (!props.isETDToETA) {
  112. const nextMonth = new Date(val)
  113. let currentYear = nextMonth.getFullYear() + 1
  114. let currentMonth = nextMonth.getMonth()
  115. let current = currentYear + '-' + currentMonth
  116. EndDate.value = current
  117. }
  118. const date1 = moment(String(val)).format('MM/YYYY')
  119. const date1_two = moment(String(val)).format('MM-YYYY')
  120. const date2 = moment(EndDate.value).format('MM/YYYY')
  121. const date2_two = moment(EndDate.value).format('MM-YYYY')
  122. dashboardObj.date_start = date1
  123. dashboardObj.date_start_two = date1_two
  124. dashboardObj.date_end = date2
  125. dashboardObj.date_end_two = date2_two
  126. }
  127. const EndChange = (val: any) => {
  128. if (!props.isETDToETA) {
  129. const nextMonth = new Date(val)
  130. let currentYear = nextMonth.getFullYear() - 1
  131. let currentMonth = nextMonth.getMonth() + 2
  132. let current = currentYear + '-' + currentMonth
  133. startDate.value = current
  134. }
  135. const date1 = moment(startDate.value).format('MM/YYYY')
  136. const date1_two = moment(startDate.value).format('MM-YYYY')
  137. const date2 = moment(String(val)).format('MM/YYYY')
  138. const date2_two = moment(String(val)).format('MM-YYYY')
  139. dashboardObj.date_start = date1
  140. dashboardObj.date_start_two = date1_two
  141. dashboardObj.date_end = date2
  142. dashboardObj.date_end_two = date2_two
  143. }
  144. // 清除
  145. const clearrest = () => {
  146. getdefaultdata()
  147. }
  148. // 查询
  149. const DateRangeSearch = () => {
  150. if (props.isRecent) {
  151. emit('FilterSearch', false, dashboardObj)
  152. } else {
  153. emit('FilterSearch', dashboardObj)
  154. }
  155. filters_visible.value = false
  156. }
  157. </script>
  158. <template>
  159. <div class="DashFilters">
  160. <el-popover
  161. trigger="click"
  162. popper-class="dash_popver"
  163. :visible="filters_visible"
  164. :width="400"
  165. :offset="8"
  166. >
  167. <template #reference>
  168. <el-button class="el-button--default" @click="filters_visible = !filters_visible">
  169. <span class="iconfont_icon">
  170. <svg class="iconfont" aria-hidden="true">
  171. <use xlink:href="#icon-icon_filter_b"></use>
  172. </svg>
  173. </span>
  174. Filters
  175. <span class="iconfont_icon">
  176. <svg class="iconfont" aria-hidden="true">
  177. <use xlink:href="#icon-icon_dropdown_b"></use>
  178. </svg>
  179. </span>
  180. </el-button>
  181. </template>
  182. <div class="Dash_title">Transport Mode</div>
  183. <div class="filter_filter">
  184. <el-checkbox-group
  185. @change="changeCheckboxGroup1"
  186. v-model="checkboxGroup1"
  187. size="large"
  188. :disabled="checkboxDisabled"
  189. >
  190. <el-checkbox-button v-for="item in shipper" :key="item" :value="item">
  191. {{ item }}
  192. </el-checkbox-button>
  193. </el-checkbox-group>
  194. </div>
  195. <div class="Dash_title">
  196. <div>Date Range</div>
  197. <div v-if="props.isContainer && !props.isETDToETA" class="dash_tips">
  198. The time range is fixed at 12 months.
  199. </div>
  200. </div>
  201. <div class="dash_flex">
  202. <div class="filter_filter">
  203. <el-radio-group
  204. v-model="CheckboxGroup2"
  205. @change="changeCheckboxGroup2"
  206. :disabled="props.radioisDisabled"
  207. >
  208. <el-radio-button v-for="item in shipper_two" :key="item" :value="item" :label="item">
  209. </el-radio-button>
  210. </el-radio-group>
  211. </div>
  212. <div class="filter_filter" style="margin-left: 8px">
  213. <div v-if="props.isContainer">
  214. <el-date-picker
  215. style="width: 120px; height: 40px"
  216. v-model="startDate"
  217. format="MMM-YYYY"
  218. type="month"
  219. @change="StartChange"
  220. :clearable="false"
  221. placeholder="Start month"
  222. placement="bottom"
  223. />
  224. <el-date-picker
  225. style="width: 120px; margin-left: 8px; height: 40px"
  226. v-model="EndDate"
  227. format="MMM-YYYY"
  228. type="month"
  229. @change="EndChange"
  230. :clearable="false"
  231. placeholder="End month"
  232. placement="bottom"
  233. />
  234. </div>
  235. <QuickCalendarDate
  236. v-else
  237. @DateChange="DateChange"
  238. :Date="DashDate"
  239. :isDisabled="isDisabled"
  240. ></QuickCalendarDate>
  241. </div>
  242. </div>
  243. <div class="daterange_bottom">
  244. <div><el-button type="default" @click="clearrest" class="Clear">Reset</el-button></div>
  245. <div>
  246. <el-button class="search el-button--dark" @click="DateRangeSearch">Search</el-button>
  247. </div>
  248. </div>
  249. </el-popover>
  250. </div>
  251. </template>
  252. <style lang="scss" scoped>
  253. .DashFilters {
  254. display: flex;
  255. align-items: center;
  256. }
  257. :deep(.el-checkbox-button__inner) {
  258. color: var(--tag-info-text-color);
  259. font-size: var(--font-size-3);
  260. font-weight: 400;
  261. padding: 0;
  262. width: 92px;
  263. height: 40px;
  264. display: flex;
  265. align-items: center;
  266. justify-content: center;
  267. border: 1px solid var(--color-border);
  268. margin-bottom: 8px;
  269. }
  270. :deep(.el-checkbox-button__inner:hover) {
  271. color: var(--color-theme);
  272. background-color: var(--color-btn-default-bg-hover);
  273. border-color: var(--color-btn-default-bg-hover);
  274. }
  275. :deep(.el-checkbox-button.is-focus .el-checkbox-button__inner) {
  276. border-color: var(--color-border);
  277. }
  278. :deep(.el-checkbox-button:first-child .el-checkbox-button__inner) {
  279. border-left: 1px solid var(--color-border);
  280. border-top-left-radius: var(--border-radius-6);
  281. border-bottom-left-radius: var(--border-radius-6);
  282. }
  283. :deep(.el-checkbox-button:last-child .el-checkbox-button__inner) {
  284. border-top-right-radius: var(--border-radius-6);
  285. border-bottom-right-radius: var(--border-radius-6);
  286. }
  287. :deep(.el-checkbox-button.is-checked .el-checkbox-button__inner) {
  288. color: var(--color-theme);
  289. background-color: transparent;
  290. border-color: var(--color-theme);
  291. box-shadow: none;
  292. font-weight: 700;
  293. }
  294. :deep(.el-checkbox-button.is-checked:first-child .el-checkbox-button__inner) {
  295. border-left-color: var(--color-theme);
  296. }
  297. :deep(.el-checkbox-button.is-disabled.is-checked .el-checkbox-button__inner) {
  298. background-color: #eaebed;
  299. border-color: var(--color-border);
  300. color: #2b2f36;
  301. font-weight: 700;
  302. }
  303. // :deep(.el-checkbox-button.is-focus .el-checkbox-button__inner) {
  304. // border-color: var(--color-border);
  305. // }
  306. .Dash_title {
  307. height: 48px;
  308. font-size: 16px;
  309. font-weight: 700;
  310. display: flex;
  311. flex-direction: column;
  312. justify-content: center;
  313. margin: 8px 16px 0 16px;
  314. }
  315. .filter_filter {
  316. margin-left: 16px;
  317. }
  318. .dash_flex {
  319. display: flex;
  320. align-items: center;
  321. height: 40px;
  322. margin-bottom: 16px;
  323. }
  324. .daterange_bottom {
  325. display: flex;
  326. justify-content: flex-end;
  327. align-items: center;
  328. height: 48px;
  329. border-top: 1px solid var(--color-border);
  330. margin-top: 5px;
  331. font-weight: 400;
  332. font-size: var(--font-size-3);
  333. }
  334. .Clear {
  335. width: 81px;
  336. height: 32px;
  337. margin-right: 7.82px;
  338. }
  339. .search {
  340. width: 86px;
  341. height: 32px;
  342. margin-right: 16px;
  343. }
  344. .dash_tips {
  345. font-weight: 100;
  346. font-size: 12px;
  347. color: var(--color-neutral-5);
  348. }
  349. :deep(.el-radio-button, .el-radio-button__inner) {
  350. height: 40px;
  351. display: flex;
  352. align-items: center;
  353. }
  354. </style>