warehouse.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <el-select
  3. v-model="value"
  4. :placeholder="attrs.placeholder?attrs.placeholder:'请选择'"
  5. :disabled="attrs.disabled"
  6. :size="attrs.size"
  7. :clearable="attrs.clearable"
  8. @clear="onChange"
  9. @change="onChange"
  10. filterable
  11. >
  12. <el-option
  13. v-for="item in options"
  14. :key="item.id"
  15. :label="item.name"
  16. :value="item.id">
  17. </el-option>
  18. </el-select>
  19. </template>
  20. <script lang="ts">
  21. /*
  22. 配置说明
  23. config:{
  24. attrs:{
  25. retConfig:{
  26. retLabel:'name' //返回的值(示例)
  27. retValue:'id' //返回的值(示例)
  28. }
  29. disabled:true/false //是否禁用
  30. size:medium/small/mini //尺寸
  31. clearable:true/false //是否清空
  32. placeholder:'' //占位符
  33. },
  34. request:{}
  35. }
  36. */
  37. import { Component, Prop, Vue, Watch } from "vue-property-decorator";
  38. import VueViews from '@/benyun/compVue/VueViews'
  39. @Component
  40. export default class Warehouse extends VueViews {
  41. value:any='';
  42. options:Array<any>=[]
  43. @Watch('propValue')
  44. propValueChange(v:any){
  45. this.setValue(v);
  46. }
  47. created(){
  48. if(this.propConfig){
  49. this.setConfig(this.propConfig)
  50. }
  51. if(this.propValue){
  52. this.setValue(this.propValue)
  53. }
  54. }
  55. mounted(){
  56. this.request();
  57. }
  58. setValue(data:any){
  59. if(data){
  60. this.value = (this as any).$lodash.cloneDeep(data);
  61. }else{
  62. this.value = '';
  63. }
  64. }
  65. getValue(){
  66. return (this as any).$lodash.cloneDeep(this.value);
  67. }
  68. setOptions(data:Array<any>){
  69. this.options = data;
  70. if(!this.value && this.attrs.defaultIndex >= 0 && this.options[this.attrs.defaultIndex]){
  71. this.value = this.options[this.attrs.defaultIndex].id;
  72. this.onChange();
  73. }
  74. }
  75. onChange(){
  76. let currentItem:any=null;
  77. for(const item of this.options){
  78. if(item.id == this.value){
  79. currentItem = item
  80. }
  81. }
  82. if(this.attrs.retConfig){
  83. let obj:any={};
  84. if(currentItem){
  85. for(const key in this.attrs.retConfig){
  86. obj[key] = currentItem[this.attrs.retConfig[key]]
  87. }
  88. }
  89. this.$emit('onChange',obj);
  90. }else{
  91. this.$emit('onChange',this.value);
  92. }
  93. (this.$root as any).eventHub.$emit('warehouseChange',currentItem)
  94. }
  95. // 清空数据
  96. clearValue(){
  97. this.value = ''
  98. }
  99. //请求url
  100. request(){
  101. let parame:any = {
  102. url:'/maindata/maindataStorehouse/page',
  103. method: 'GET',
  104. params: {
  105. pageNo:1,
  106. pageSize:1000
  107. }
  108. };
  109. parame.success = (res:any) => {
  110. if(res.data && res.data.records){
  111. this.setOptions(res.data.records);
  112. }
  113. }
  114. parame.fail = (err:any) => {}
  115. this.requestHandle(parame);
  116. }
  117. }
  118. </script>
  119. <style lang="scss" scoped>
  120. </style>