material-component.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <el-select
  3. v-model="value"
  4. ref="select"
  5. placeholder="请选择"
  6. clearable
  7. filterable
  8. remote
  9. :remote-method="remoteMethod"
  10. @change = "onChange"
  11. @focus="cancelReadOnly"
  12. @hook:mounted="cancelReadOnly"
  13. @visible-change="cancelReadOnly"
  14. style="width: 200px">
  15. <el-option
  16. v-for="item in options"
  17. :key="item.value"
  18. :label="item.label"
  19. :value="item.value">
  20. </el-option>
  21. <el-option v-if="options.length > 0" label="加载更多" style="font-style: italic; color: #8a979e" value="undefined" @click.native="handleClick()"></el-option>
  22. </el-select>
  23. </template>
  24. <script>
  25. export default {
  26. name: 'material-component',
  27. props: {
  28. materialId: {
  29. type: String,
  30. default: ''
  31. },
  32. materialType: {
  33. type: String,
  34. default: ''
  35. },
  36. bizType: {
  37. type: String,
  38. default: ''
  39. },
  40. material: {
  41. type: Object,
  42. default: () => {}
  43. }
  44. },
  45. model: {
  46. prop: 'material',
  47. event: 'materialSelected'
  48. },
  49. data () {
  50. return {
  51. value: '',
  52. current: 1,
  53. size: 10,
  54. name: '',
  55. options: [],
  56. loading: false,
  57. noMore: false
  58. }
  59. },
  60. watch: {
  61. materialId (value) {
  62. this.value = value
  63. },
  64. materialType (value) {
  65. this.options = []
  66. this.getList()
  67. }
  68. },
  69. mounted () {
  70. this.init()
  71. },
  72. methods: {
  73. async init () {
  74. this.getList()
  75. },
  76. remoteMethod (query) {
  77. this.options = []
  78. this.current = 1
  79. this.name = query
  80. this.getList()
  81. },
  82. getList () {
  83. this.$http({
  84. url: this.$http.adornUrl(`/biz-service/stock-mg-ctl/list`),
  85. method: 'get',
  86. params: this.$http.adornParams({
  87. 'current': this.current,
  88. 'size': this.size,
  89. 'materialName': this.name,
  90. 'materialTypeId': this.materialType
  91. })
  92. }).then(({data}) => {
  93. if (data && data.code === '200') {
  94. if (this.current > data.data.pages) {
  95. return
  96. }
  97. if (this.bizType === 'in') {
  98. data.data.records.forEach(item => {
  99. this.options.push({...item,
  100. label: item.materialName + ' - ' + item.specifications,
  101. value: item.materialId,
  102. specification: item.specifications,
  103. cntLimit: Number(item.cnt) - Number(item.lockCnt),
  104. cnt: 0,
  105. sourceCategory: '2'
  106. })
  107. })
  108. } else if (this.bizType === 'check') {
  109. data.data.records.forEach(item => {
  110. this.options.push({...item,
  111. label: item.materialName + ' - ' + item.mapNumber + ' - ' + item.specifications + ' - ' + item.cnt,
  112. value: item.materialId,
  113. specification: item.specifications,
  114. cntLimit: Number(item.cnt) - Number(item.lockCnt)
  115. })
  116. })
  117. } else {
  118. data.data.records.forEach(item => {
  119. this.options.push({...item,
  120. label: item.materialName + ' - ' + item.specifications,
  121. value: item.materialId,
  122. specification: item.specifications,
  123. cntLimit: Number(item.cnt) - Number(item.lockCnt)
  124. })
  125. })
  126. }
  127. } else {
  128. this.options = []
  129. }
  130. })
  131. },
  132. handleClick () {
  133. this.loadMore()
  134. },
  135. loadMore () {
  136. this.current ++
  137. this.getList()
  138. },
  139. onChange (item) {
  140. if (item === 'undefined') {
  141. this.value = null
  142. }
  143. let selectedItem = this.options.find(item1 => item1.value === item)
  144. if (selectedItem) {
  145. selectedItem.buttonType = '0'
  146. }
  147. // console.log(JSON.stringify(selectedItem))
  148. this.$emit('materialSelected', selectedItem)
  149. },
  150. cancelReadOnly (onOff) {
  151. this.$nextTick(() => {
  152. if (!onOff) {
  153. const input = this.$refs.select.$el.querySelector('.el-input__inner')
  154. const timer = setTimeout(() => {
  155. input.removeAttribute('readonly')
  156. clearTimeout(timer)
  157. }, 200)
  158. }
  159. })
  160. }
  161. }
  162. }
  163. </script>
  164. <style scoped>
  165. </style>