JSelectList.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <div>
  3. <a-input-group v-if="kind === 'material'" compact style="width: 100%; top: 0px">
  4. <a-select
  5. placeholder="输入条码或名称"
  6. :dropdownMatchSelectWidth="false"
  7. showSearch
  8. :showArrow="false"
  9. v-model="names"
  10. optionFilterProp="children"
  11. :style="searchWidth"
  12. notFoundContent="需在商品管理先新增才能使用"
  13. @search="handleSearch"
  14. @change="handleChange"
  15. >
  16. <div slot="dropdownRender" slot-scope="menu">
  17. <v-nodes :vnodes="menu" />
  18. <a-divider v-if="materialData.length === 20" style="margin: 4px 0" />
  19. <div
  20. v-if="materialData.length === 20"
  21. style="padding: 4px 8px; cursor: pointer"
  22. @mousedown="(e) => e.preventDefault()"
  23. >
  24. 此处最多显示20条,如需更多请点击放大镜查询
  25. </div>
  26. </div>
  27. <a-select-option v-for="item in materialData" :key="item.barCode">
  28. {{ item.materialStr }}
  29. </a-select-option>
  30. </a-select>
  31. <a-button icon="search" @click="onSearch" />
  32. </a-input-group>
  33. <a-input-search
  34. v-if="kind === 'batch' || kind === 'sn' || kind === 'snAdd'"
  35. v-model="names"
  36. placeholder="请点开弹窗"
  37. readOnly
  38. @search="onSearch"
  39. ></a-input-search>
  40. <j-select-material-modal
  41. v-if="kind === 'material'"
  42. ref="selectModal"
  43. :rows="rows"
  44. :multi="multi"
  45. :bar-code="value"
  46. @ok="selectOK"
  47. @initComp="initComp"
  48. />
  49. <j-select-batch-modal
  50. v-if="kind === 'batch'"
  51. ref="selectModal"
  52. :rows="rows"
  53. :multi="multi"
  54. :bar-code="value"
  55. @ok="selectOK"
  56. @initComp="initComp"
  57. />
  58. <j-select-sn-modal
  59. v-if="kind === 'sn'"
  60. ref="selectModal"
  61. :rows="rows"
  62. :multi="multi"
  63. :bar-code="value"
  64. @ok="selectOK"
  65. @initComp="initComp"
  66. />
  67. <j-select-sn-add-modal
  68. v-if="kind === 'snAdd'"
  69. ref="selectModal"
  70. :rows="rows"
  71. :multi="multi"
  72. :bar-code="value"
  73. @ok="selectOK"
  74. @initComp="initComp"
  75. />
  76. </div>
  77. </template>
  78. <script>
  79. import JSelectMaterialModal from './modal/JSelectMaterialModal'
  80. import JSelectBatchModal from './modal/JSelectBatchModal'
  81. import JSelectSnModal from './modal/JSelectSnModal'
  82. import JSelectSnAddModal from './modal/JSelectSnAddModal'
  83. import { getMaterialByParam } from '@/api/api'
  84. export default {
  85. name: 'JSelectList',
  86. components: {
  87. JSelectMaterialModal,
  88. JSelectBatchModal,
  89. JSelectSnModal,
  90. JSelectSnAddModal,
  91. VNodes: {
  92. functional: true,
  93. render: (h, ctx) => ctx.props.vnodes,
  94. },
  95. },
  96. props: {
  97. value: {
  98. type: String,
  99. required: false,
  100. },
  101. disabled: {
  102. type: Boolean,
  103. required: false,
  104. default: false,
  105. },
  106. rows: {
  107. type: String,
  108. required: false,
  109. },
  110. kind: {
  111. type: String,
  112. required: false,
  113. },
  114. multi: {
  115. type: Boolean,
  116. default: true,
  117. required: false,
  118. },
  119. },
  120. data() {
  121. return {
  122. ids: '',
  123. names: '',
  124. materialData: [],
  125. setTimeFlag: null,
  126. searchWidth: '',
  127. }
  128. },
  129. mounted() {
  130. this.ids = this.value
  131. },
  132. watch: {
  133. value(val) {
  134. this.ids = val
  135. },
  136. },
  137. created() {
  138. const currentWidth = window.screen.width
  139. if (currentWidth < 1500) {
  140. this.searchWidth = 'width:75%'
  141. } else {
  142. this.searchWidth = 'width:81%'
  143. }
  144. },
  145. model: {
  146. prop: 'value',
  147. event: 'change',
  148. },
  149. methods: {
  150. initComp(name) {
  151. this.names = name ? name : undefined
  152. },
  153. onSearch() {
  154. this.$refs.selectModal.showModal()
  155. },
  156. handleSearch(value) {
  157. let that = this
  158. if (this.setTimeFlag != null) {
  159. clearTimeout(this.setTimeFlag)
  160. }
  161. this.setTimeFlag = setTimeout(() => {
  162. getMaterialByParam({ q: value }).then((res) => {
  163. if (res && res.code === 200) {
  164. that.materialData = res.data
  165. }
  166. })
  167. }, 500)
  168. },
  169. handleChange(value) {
  170. this.$emit('change', value)
  171. },
  172. selectOK(rows, idstr) {
  173. console.log('选中id', idstr)
  174. if (!rows) {
  175. this.ids = ''
  176. } else {
  177. this.ids = idstr
  178. }
  179. this.$emit('change', this.ids)
  180. },
  181. },
  182. }
  183. </script>
  184. <style scoped></style>