index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <div class="base_ship_dropdown">
  3. <span class="dropdown vesselDefault"
  4. v-if="vesselBankFlag">{{ getShip }}</span>
  5. <BaseDropdown v-else
  6. trigger="click"
  7. class="dropdown"
  8. @visible-change="(val)=>changeIcon = val"
  9. @command="shipOperation">
  10. <span class="el-dropdown-link">
  11. <BaseLink class="total"
  12. :underline="false"
  13. style="font-size:12px;"
  14. type="primary">{{ getShip }}</BaseLink>
  15. <!-- {{ getShip }} -->
  16. <i class="iconfont"
  17. :class="changeIcon?'iconshangjiantou':'iconxiajiantou'" />
  18. </span>
  19. <BaseDropdownMenu slot="dropdown">
  20. <BaseDropdownItem v-for="(item, value) in options"
  21. :key="item.vesselId+value"
  22. :command="item.vesselId">
  23. {{ $t(item.vesselName) }}
  24. </BaseDropdownItem>
  25. <BaseDropdownItem v-if="(options||[]).length===0">
  26. </BaseDropdownItem>
  27. </BaseDropdownMenu>
  28. </BaseDropdown>
  29. </div>
  30. </template>
  31. <script>
  32. /**
  33. * @Author lihui
  34. * @Date 2020-11-19
  35. * @description 【船舶选择器】 岸基 船端 岸基+船端 规则: 全部> 岸基> 船端 默认请求船端船舶接口
  36. * @param {boolean} showAll - 是否显示 全部船舶
  37. * @param {boolean} landAndShipBased - 是否为岸基+船端船舶
  38. * @event emit('on-mounted', val) - 初始化后回调函数 val 加载回来具体的值
  39. * @event emit('input', val) - 双向数据绑定的值 可以直接使用 v-model
  40. * @event emit('change', val,val2) - 数据改变是触发 change 事件 val 选中的值 val2 当前选中object 节点值
  41. */
  42. import { mapActions, mapGetters, mapState } from 'vuex'
  43. import { findIndex, cloneDeep, find, get } from 'lodash';
  44. import { firstLetterToUpperCase } from 'base-core-lib'
  45. export default {
  46. name: 'BaseShipDropdown',
  47. props: {
  48. // 是否显示全部筛选项
  49. showAll: {
  50. type: Boolean,
  51. default: true
  52. },
  53. // 加载全部船舶
  54. landAndShipBased: {
  55. type: Boolean,
  56. default: false,
  57. },
  58. // 是否使用船上系统
  59. clientFlag: {
  60. type: Boolean,
  61. default: true,
  62. },
  63. // 双向数据绑定
  64. value: ''
  65. },
  66. data () {
  67. return {
  68. allShip: 'bj.qualityFeedback.allShipName',
  69. vesselBankFlag: localStorage.getItem('ws-pf_vesselBankFlag') === 'V' && localStorage.getItem('ws-pf_dutyId') !== '1', //船岸端判断
  70. options: [],
  71. value2: '',
  72. changeIcon: false,
  73. }
  74. },
  75. computed: {
  76. ...mapGetters(['language']),
  77. ...mapState('common', ['vesselList']),
  78. getShip () {
  79. return this.$t(this.allShip[`vesselName${firstLetterToUpperCase(this.language)}`])
  80. },
  81. },
  82. watch: {
  83. value (val) {
  84. this.value2 = val;
  85. this.changeValue()
  86. }
  87. },
  88. created () {
  89. this.init()
  90. },
  91. methods: {
  92. ...mapActions('common', ['getVesselsByStatistics']),
  93. async init () {
  94. // this.options = cloneDeep(this.vesselList)
  95. this.options = cloneDeep(this.landAndShipBased ? await this.getVesselsByStatistics() : this.vesselList)
  96. if (!this.clientFlag) {
  97. this.options = this.options.filter(item => {
  98. return item.clientFlag == '1'
  99. })
  100. }
  101. console.log(this.options, 'this.options')
  102. if (this.showAll) {
  103. this.options.unshift({
  104. vesselId: '',
  105. vesselName: 'bj.qualityFeedback.allShipName',
  106. vesselNameEn: 'bj.qualityFeedback.allShipName',
  107. vesselNameZh: 'bj.qualityFeedback.allShipName'
  108. })
  109. }
  110. this.changeValue()
  111. this.$emit('on-mounted', this.options);
  112. },
  113. // 船舶筛选
  114. shipOperation (val) {
  115. const boo = findIndex(this.options, (o) => o.vesselId === val);
  116. this.allShip = this.options[boo]
  117. this.$emit('input', val);
  118. this.$emit('change', val, this.options[boo]);
  119. },
  120. /**
  121. * 动态绑定值的时候赋值
  122. */
  123. changeValue () {
  124. this.allShip = find(this.options, (o) => o.vesselId === this.value2) || get(this.options, '[0]', {});
  125. }
  126. }
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. .base_ship_dropdown {
  131. line-height: 20px;
  132. height: 20px;
  133. .vesselDefault {
  134. margin-left: 10px;
  135. }
  136. .dropdown {
  137. font-size: 12px;
  138. }
  139. >>> .el-dropdown {
  140. font-size: 14px;
  141. .el-dropdown-link {
  142. font-size: 12px;
  143. display: flex;
  144. .iconxiajiantou,
  145. .iconshangjiantou {
  146. margin-left: 2px;
  147. font-size: 12px !important;
  148. }
  149. }
  150. }
  151. }
  152. </style>