index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <ws-dropdown @command="selectOptions"
  3. v-if="showType">
  4. <span class="ws-dropdown-link">
  5. {{ selectOption.vesselName }}
  6. <i class="el-icon-caret-bottom el-icon--right" />
  7. </span>
  8. <ws-dropdown-menu slot="dropdown"
  9. class="myDropdown">
  10. <ws-dropdown-item v-for="item in shipGather"
  11. :key="item.vesselId"
  12. :command="item.vesselId">
  13. {{ item.vesselName }}
  14. </ws-dropdown-item>
  15. <!-- 其他选项 -->
  16. <ws-dropdown-item v-show="showOtherOption"
  17. divided
  18. command>{{
  19. otherOption
  20. }}</ws-dropdown-item>
  21. </ws-dropdown-menu>
  22. </ws-dropdown>
  23. <span v-else>{{ selectOption.vesselName }}</span>
  24. </template>
  25. <script>
  26. export default {
  27. name: 'shipDrop',
  28. props: [
  29. 'showOtherOption',
  30. 'otherOption',
  31. 'defaultShowOption',
  32. 'setShowType',
  33. 'setDefaultShipId'
  34. ],
  35. data () {
  36. return {
  37. selectOption: {},
  38. showType: true,
  39. defaultShipId: '',
  40. shipGather: []
  41. }
  42. },
  43. watch: {
  44. setShowType (val) {
  45. this.showType = val
  46. },
  47. setDefaultShipId (val) {
  48. this.defaultShipId = val
  49. }
  50. },
  51. created () {
  52. this.shipGather = JSON.parse(localStorage.getItem('ws-pf_vessels'))
  53. this.shipGather.unshift({ vesselId: '', vesselName: '全部船舶' })
  54. // this.selectOption.vesselName = this.shipGather[0].vesselName;
  55. this.selectOption.vesselName = this.defaultShowOption
  56. if (localStorage.getItem('ws-pf_vesselBankFlag') === 'V') {
  57. // 当为V时是船端,当为B时是岸端
  58. this.showType = false
  59. this.defaultShipId = localStorage.getItem('ws-pf_vesselId')
  60. this.$emit('command', this.defaultShipId)
  61. this.getOptions()
  62. } else {
  63. if (typeof this.setShowType === 'boolean') {
  64. this.showType = this.setShowType
  65. }
  66. this.defaultShipId = this.setDefaultShipId
  67. this.getOptions()
  68. }
  69. },
  70. methods: {
  71. // 选择
  72. selectOptions (id) {
  73. if (id) {
  74. for (const k in this.shipGather) {
  75. if (this.shipGather[k].vesselId == id) {
  76. this.selectOption.vesselName = this.shipGather[k].vesselName
  77. }
  78. }
  79. } else {
  80. // this.selectOption.vesselName = this.otherOption;
  81. this.selectOption.vesselName = this.shipGather[0].vesselName
  82. }
  83. this.$forceUpdate()
  84. this.$emit('command', id)
  85. },
  86. // 数据获取
  87. getOptions () {
  88. if (this.showType) {
  89. this.selectOption.vesselName = this.shipGather[0].vesselName
  90. if (!this.showOtherOption) {
  91. this.selectOptions(this.shipGather[0].vesselId)
  92. } else {
  93. this.selectOption.vesselName = this.otherOption
  94. }
  95. } else {
  96. for (const k in this.shipGather) {
  97. if (this.shipGather[k].vesselId === this.defaultShipId) {
  98. this.selectOption.vesselName = this.shipGather[k].vesselName
  99. } else {
  100. this.selectOption.vesselName = this.shipGather[0].vesselName
  101. }
  102. }
  103. this.$forceUpdate()
  104. }
  105. // getAppShips({
  106. // compId: compId
  107. // }).then(succ => {
  108. // this.options = succ.data;
  109. // if (this.showType) {
  110. // this.selectOption = this.options[0];
  111. // if (!this.showOtherOption) {
  112. // this.selectOption.vesselName = this.options[
  113. // this.options.length - 1
  114. // ].vesselName;
  115. // this.selectOptions(this.options[0].vesselId);
  116. // } else {
  117. // this.selectOption.vesselName = this.otherOption;
  118. // }
  119. // } else {
  120. // for (const k in this.options) {
  121. // if (this.options[k].vesselId === this.defaultShipId) {
  122. // this.selectOption.vesselName = this.options[k].vesselName;
  123. // }
  124. // }
  125. // this.$forceUpdate();
  126. // }
  127. // });
  128. }
  129. }
  130. }
  131. </script>
  132. <style lang="scss" scoped>
  133. .allShips {
  134. float: right;
  135. margin-top: 10px;
  136. margin-right: 10px;
  137. }
  138. .myDropdown {
  139. border: 0px solid red;
  140. overflow: auto;
  141. }
  142. </style>