DashFiters.vue 9.4 KB

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