index.vue 3.63 KB
Newer Older
wangdanlei's avatar
wangdanlei committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
<template>
  <div>
    <el-select
      v-model="selVal"
      filterable
      :disabled="disabled"
      remote
      placeholder="请输入"
      :remote-method="remoteMethod"
      :loading="loading"
      @change="changeEvent"
    >
      <el-option
        v-for="(item,i) in requestOp"
        :key="i"
        :label="item.label"
        :value="item.value"
      />
    </el-select>
  </div>
</template>

<script>
import { post } from '@/utils/http'

export default {
  componentName: '产品件号/型号选择',
  name: 'ProductModelSelect',
  components: {},
  props: {
    value: {
      type: Object,
      default: null
    },
    basicData: {
      type: Object,
      default: null
    },
    form: {
      type: Object,
      default: null
    },
    itemObj: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      selVal: '',
      linkageValue: '',
      requestOp: [],
      loading: false,
      com: null
    }
  },
  computed: {
    disabled() {
      let disabled = false
      this.$utils.findByNameVnode(this, 'DeeAsForm').formData.forEach(item => {
        item.data && item.data.forEach(x => {
          if (x.key === this.itemObj.key) {
            disabled = x.component.disabled
          }
        })
      })
      return disabled
    }
  },
  watch: {
    value: {
      handler: function() {
        if (Object.keys(this.basicData).length) {
          this.setData(this.value)
        }
      },
      deep: true
    }
  },
  // 生命周期 - 创建完成(可以访问当前this 实例)
  created() {
  },
  // 生命周期 - 挂载之前
  beforeMount() {
  },
  // 生命周期 - 挂载完成(可以访问 DOM 元素)
  mounted() {
    // 流程里使用
    if (Object.keys(this.basicData).length) {
      this.setData(this.form.extMaterial)
    }
  },
  methods: {
    async setData(value) {
      if (value) {
        await this.getModelNo(value.modelNo)
        this.selVal = JSON.stringify(value)
      }
    },
    async getModelNo(query) {
      const params = {
        'pageFrom': 1,
        'pageSize': 200,
        'searchItems': {
          'operator': 'AND',
          'items': [{
            'fieldName': 'modelNo',
            'operator': 'LIKE',
            'value': query
          }]
        },
        'openProps': [
          {
            'name': 'extUnit'
          }
        ]
      }
      await post(`/ExtDxProcessMaterial/search`, params)
        .then(res => {
          this.loading = false
          if (res.code === 0) {
            this.requestOp = res.items.content.map(item => {
              return {
                label: item.modelNo,
                value: JSON.stringify(item)
              }
            })
          }
        })
    },
    changeEvent(value) {
      const obj = JSON.parse(value)
      this.$set(this.form, 'extMaterial', obj)
jingnan's avatar
jingnan committed
134 135 136 137 138 139 140 141 142 143
      this.$set(this.form, 'sourceSerno', '')
      this.$set(this.form, 'sourceApprovalCert', '')
      this.$set(this.form, 'sourceProductDrawver', '')
      this.$set(this.form, 'sourceElecHardwareNo', '')
      this.$set(this.form, 'sourceSoftConfPieceNo', '')
      this.$set(this.form, 'targetSerno', '')
      this.$set(this.form, 'targetApprovalCert', '')
      this.$set(this.form, 'targetProductDrawver', '')
      this.$set(this.form, 'targetElecHardwareNo', '')
      this.$set(this.form, 'targetSoftConfPieceNo', '')
wangdanlei's avatar
wangdanlei committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
    },
    remoteMethod(query) {
      if (query && query.length >= 2) {
        if (this.time) {
          this.time = null
        }
        this.time = setTimeout(() => {
          this.loading = true
          this.getModelNo(query)
        }, 500)
      }
    }
  }
}
</script>

<style lang='scss' scoped>

</style>