statisticsHeaderNew.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <template>
  2. <div class="flight-statistics-header">
  3. <template v-if="title">
  4. <div class="title">{{ title }}</div>
  5. </template>
  6. <el-form ref="form" class="form" :model="formData">
  7. <el-form-item v-for="item in formItems" :key="item.prop" :prop="item.prop" :label="item.label" :style="{
  8. width: item.width || '120px'
  9. }">
  10. <template v-if="item.inputType === 'input'">
  11. <el-input v-model="formData[item.prop]" :size="item.size || 'small'" :placeholder="item.placeholder || '请输入'"
  12. :clearable="item.clearable" />
  13. </template>
  14. <template v-if="item.inputType === 'select'">
  15. <el-select v-model="formData[item.prop]" :filterable="item.filterable" :default-first-option="item.filterable"
  16. :size="item.size || 'small'" :placeholder="item.placeholder || '请选择'" :multiple="item.multiple"
  17. :collapse-tags="item.multiple" :clearable="item.clearable" :disabled="item.disabled" @change="change()">
  18. <el-option v-for="option in item.options" :key="option.value" :value="option.value" :label="option.label" />
  19. </el-select>
  20. </template>
  21. <template v-if="item.inputType === 'datePicker'">
  22. <el-date-picker v-model="formData[item.prop]" :size="item.size || 'small'" type="daterange"
  23. value-format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" />
  24. </template>
  25. <template v-if="item.inputType === 'cascader'">
  26. <el-cascader v-model="formData[item.prop]" :size="item.size || 'small'"
  27. :placeholder="item.placeholder || '请选择'" :options="item.options" :props="item.props"
  28. :clearable="item.clearable" :disabled="item.disabled" />
  29. </template>
  30. </el-form-item>
  31. <el-form-item v-if="formItems.length">
  32. <el-button type="primary" size="small" @click="getData">{{ buttonText }}</el-button>
  33. </el-form-item>
  34. <el-form-item v-if="withExport">
  35. <img src="../../../assets/nav/ic_export.png" title="导出" class="btn-icon-only" @click="exportClickHandler">
  36. </el-form-item>
  37. <el-form-item v-if="withSetting">
  38. <img src="../../../assets/nav/ic_setting.png" title="节点设置" class="btn-icon-only" @click="settingClickHandler">
  39. </el-form-item>
  40. </el-form>
  41. </div>
  42. </template>
  43. <script>
  44. import { TempQuery } from '@/api/temp'
  45. import { mapGetters } from 'vuex'
  46. export default {
  47. name: 'StatisticsHeader',
  48. props: {
  49. title: {
  50. type: String,
  51. default: ''
  52. },
  53. items: {
  54. type: Array,
  55. default: undefined
  56. },
  57. customItems: {
  58. type: Array,
  59. default: () => []
  60. },
  61. data: {
  62. type: Object,
  63. default: undefined
  64. },
  65. buttonText: {
  66. type: String,
  67. default: '查询'
  68. },
  69. withExport: {
  70. type: Boolean,
  71. default: true
  72. },
  73. withSetting: {
  74. type: Boolean,
  75. default: false
  76. }
  77. },
  78. data() {
  79. return {
  80. formData: {
  81. },
  82. formItems: []
  83. }
  84. },
  85. computed: {
  86. ...mapGetters(['savedFormDataMap']),
  87. formDataObj() {
  88. return JSON.parse(JSON.stringify(this.formData))
  89. }
  90. },
  91. watch: {
  92. items: {
  93. handler(val) {
  94. val && (this.formItems = val)
  95. },
  96. deep: true,
  97. immediate: true
  98. },
  99. data: {
  100. handler(val) {
  101. val && (this.formData = val)
  102. },
  103. deep: true,
  104. immediate: true
  105. },
  106. formDataObj: {
  107. handler(val, oldVal) {
  108. this.formItems.forEach(item => {
  109. if (item.changeHandler && String(val[item.prop]) !== String(oldVal[item.prop])) {
  110. item.changeHandler.call(this, val[item.prop])
  111. }
  112. })
  113. },
  114. deep: true
  115. }
  116. },
  117. created() {
  118. this.customItems.forEach(item => {
  119. if (typeof item.itemIndex === 'number') {
  120. if (item.prop) {
  121. this.formItems.splice(item.itemIndex, item.replaceNum, item)
  122. } else {
  123. this.formItems.splice(item.itemIndex, item.replaceNum)
  124. }
  125. } else {
  126. this.formItems.push(item)
  127. }
  128. })
  129. const savedFormData = this.savedFormDataMap[this.$route.name]
  130. const obj = {}
  131. this.formItems.forEach(item => {
  132. if (item.queryId && item.setKey) {
  133. this.getOptions(item.queryId, item.setKey, item.prop, item.authId)
  134. }
  135. // if (savedFormData?.[item.prop]) {
  136. // obj[item.prop] = savedFormData[item.prop]
  137. // } else if (item.defaultOption) {
  138. // obj[item.prop] = item.defaultOption
  139. // }
  140. // if(savedFormData?.['fd1']&&savedFormData?.['fd2']){
  141. // obj['fd1,fd2'] = [savedFormData['fd1'],savedFormData['fd2']]
  142. // }
  143. // console.log(obj)
  144. })
  145. if (savedFormData) {
  146. this.formData = savedFormData
  147. this.getData()
  148. }
  149. // this.$emit('update:data', this.formData)
  150. },
  151. methods: {
  152. change() {
  153. // console.log(this.formData)
  154. },
  155. getData() {
  156. try {
  157. this.formItems.forEach(item => {
  158. if (item.requiredWarning && (!this.formData[item.prop] || this.formData[item.prop].length === 0)) {
  159. throw new Error(item.requiredWarning)
  160. }
  161. })
  162. } catch (error) {
  163. this.$message.warning(error.message)
  164. return
  165. }
  166. if (this.formData.range === '航线' && !this.formData.airline) {
  167. this.$message.warning('请先选择航线')
  168. return
  169. } else if (this.formData.range === '航站' && !this.formData.airport) {
  170. this.$message.warning('请先选择航站')
  171. return
  172. } else if (this.formData.range === '基地分公司' && !this.formData.area) {
  173. this.$message.warning('请先选择基地分公司')
  174. return
  175. }
  176. this.$emit('getFormData', _.cloneDeep(this.formData))
  177. this.$store.dispatch('savedSettings/saveFormData', {
  178. formData: _.cloneDeep(this.formData)
  179. })
  180. },
  181. exportClickHandler() {
  182. this.$emit('export')
  183. },
  184. settingClickHandler() {
  185. this.$emit('setting')
  186. },
  187. setInOrOutOptions(range) {
  188. const theInOrOutItem = this.formItems.find(item => item.prop === 'inOrOut')
  189. switch (range) {
  190. case '全部':
  191. case '航线':
  192. if (theInOrOutItem) {
  193. theInOrOutItem.options = [
  194. {
  195. label: '全部',
  196. value: '全部'
  197. }
  198. ]
  199. theInOrOutItem.disabled = true
  200. }
  201. this.formData.inOrOut = '全部'
  202. break
  203. case '基地分公司':
  204. case '航站':
  205. case '航站楼':
  206. if (theInOrOutItem) {
  207. theInOrOutItem.options = [
  208. {
  209. value: '全部',
  210. label: '全部'
  211. },
  212. {
  213. value: '进港',
  214. label: '进港'
  215. },
  216. {
  217. value: '离港',
  218. label: '离港'
  219. }
  220. ]
  221. theInOrOutItem.disabled = false
  222. }
  223. break
  224. default:
  225. if (theInOrOutItem) {
  226. theInOrOutItem.options = []
  227. theInOrOutItem.disabled = false
  228. }
  229. break
  230. }
  231. },
  232. async getOptions(queryId, setKey, prop, authId) {
  233. console.log(queryId)
  234. const p = {
  235. serviceId: queryId,
  236. dataContent: [],
  237. event: '0',
  238. pageSize: '9999',
  239. }
  240. if (queryId != '8200233') {
  241. p['authId'] = authId
  242. }
  243. try {
  244. const { code, returnData, message } = await TempQuery(p)
  245. if (Number(code) === 0) {
  246. const arr = returnData.map(element => ({
  247. label: element[setKey],
  248. value: element[setKey]
  249. }))
  250. const theItem = this.formItems.find(item => item.prop === prop)
  251. theItem.options = arr
  252. } else {
  253. this.$message.error(message)
  254. }
  255. } catch (error) {
  256. this.$message.error('失败')
  257. }
  258. }
  259. }
  260. }
  261. </script>
  262. <style lang="scss" scoped>
  263. .flight-statistics-header {
  264. padding-top: 24px;
  265. min-height: 80px;
  266. display: flex;
  267. justify-content: space-between;
  268. align-items: flex-start;
  269. .title {
  270. margin-right: 24px;
  271. padding-left: 16px;
  272. // min-width: 190px;
  273. height: 32px;
  274. line-height: 32px;
  275. font-size: 18px;
  276. font-family: Helvetica, "Microsoft YaHei";
  277. font-weight: bold;
  278. white-space: nowrap;
  279. position: relative;
  280. &::before {
  281. content: "";
  282. width: 4px;
  283. height: 20px;
  284. background: #2d67e3;
  285. position: absolute;
  286. top: 0;
  287. bottom: 0;
  288. left: 0;
  289. margin: auto;
  290. }
  291. }
  292. ::v-deep .form {
  293. display: flex;
  294. flex-wrap: wrap;
  295. >.el-form-item {
  296. margin-bottom: 24px;
  297. // width: 185px;
  298. &:not(:last-child) {
  299. margin-right: 8px;
  300. }
  301. &:nth-last-child(2),
  302. &:nth-last-child(3) {
  303. margin-right: 16px;
  304. }
  305. .el-form-item__content {
  306. height: 32px;
  307. line-height: 30px;
  308. .el-input {
  309. &.is-disabled .el-input__inner {
  310. border: none;
  311. }
  312. .el-input__inner {
  313. border-radius: 4px;
  314. font-family: Helvetica, "Microsoft YaHei";
  315. color: #303133;
  316. border-color: #ffffff;
  317. &:hover {
  318. border-color: #c0c4cc;
  319. }
  320. &:focus {
  321. border-color: #409eff;
  322. }
  323. }
  324. }
  325. .el-date-editor--daterange.el-input,
  326. .el-date-editor--daterange.el-input__inner,
  327. .el-date-editor--timerange.el-input,
  328. .el-date-editor--timerange.el-input__inner {
  329. width: 100%;
  330. border-radius: 4px;
  331. border-color: #ffffff;
  332. color: #303133;
  333. font-family: Helvetica, "Microsoft YaHei";
  334. &:hover {
  335. border-color: #c0c4cc;
  336. }
  337. &.is-active {
  338. border-color: #409eff;
  339. }
  340. .el-input__icon {
  341. color: #303133;
  342. }
  343. .el-range-separator {
  344. line-height: 28px;
  345. }
  346. }
  347. .el-select,
  348. .el-cascader {
  349. .el-input {
  350. .el-icon-arrow-up::before {
  351. content: "\e78f";
  352. }
  353. .el-icon-arrow-down::before {
  354. content: "\e790";
  355. }
  356. &:not(.is-disabled) {
  357. .el-input__icon,
  358. .el-input__inner::-webkit-input-placeholder {
  359. color: #303133;
  360. }
  361. }
  362. }
  363. }
  364. .el-button {
  365. border-radius: 4px;
  366. font-family: Helvetica, "Microsoft YaHei";
  367. }
  368. .btn-icon-only {
  369. width: 32px;
  370. height: 32px;
  371. cursor: pointer;
  372. }
  373. }
  374. }
  375. }
  376. }
  377. </style>