addDevice.vue 3.7 KB
<template>
  <div class="addorder_page">
    <glsx-dialog :show="show" width="30%">
      <el-form ref="addForm" :model="form" :rules="formRules" label-width="110px">
        <el-form-item label="设备名称" prop="deviceName">
          <el-input v-model="form.deviceName" maxlength="10" show-word-limit />
        </el-form-item>
        <el-form-item label="设备类型" prop="typeId">
          <el-select v-model="form.typeId" placeholder="请选择" class="el_select">
            <el-option v-for="item in deviceType" :key="item.id" :value="item.id" :label="item.name">{{ item.name }}</el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="品牌定制商" prop="merchantId">
          <el-select v-model="form.merchantId" placeholder="请选择" class="el_select">
            <el-option v-for="item in merchantList" :key="item.merchantId" :value="item.merchantId" :label="item.merchantId + '/' + item.merchantName">{{ item.merchantId }}/{{ item.merchantName }}</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="设备介绍">
          <el-input v-model="form.remark" type="textarea" rows="5"  maxlength="200" show-word-limit />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="saveInfo">提交</el-button>
          <el-button @click="cancel">取消</el-button>
        </el-form-item>
      </el-form>
    </glsx-dialog>
  </div>
</template>
<script>
import {
  FINDSENDMERCHANTNO,
  INSERTANDUPDATEDEVICE
} from '@/http/interface'
import {
  Validator
} from '@/common/validator'
import GlsxDialog from '@/components/dialog/index'
export default {
  name: 'AddDevice',
  components: {
    'glsx-dialog': GlsxDialog
  },
  props: {
    deviceType: {
      type: Array,
      default: function() {
        return []
      }
    },
    id: {
      type: [String, Number],
      default: ''
    },
    show: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      form: {
        typeId: ''
      },
      deviceList: [],
      radio: '',
      loading: false,
      merchantList: [],
      tableLoading: false,
      formRules: {
        deviceName: [{
          required: true,
          message: '请输入设备名称',
          trigger: 'blur'
        }],
        typeId: [{
          required: true,
          message: '请选择设备类型',
          trigger: 'blur'
        }],
        merchantId: [{
          required: true,
          message: '请输入品牌定制商',
          trigger: 'blur'
        }]
      }
    }
  },
  created() {

  },

  mounted: function() {
    this.init()
  },
  methods: {

    /**
       * 初始化函数
       */
    init: function() {
      const o = this.$props || {}
      this.getMerchant()
    },

    /**
       * 保存数据
       */
    saveInfo: function() {
      const _this = this
      const m = _this.form
      const oParams = JSON.parse(JSON.stringify(m))
      console.log(oParams)
      _this.$refs.addForm.validate((valid) => {
        if (!valid) {
          return false
        }
        INSERTANDUPDATEDEVICE(oParams).then(res => {
          if (res.returnCode == 0) {
            _this.$emit('closed', true)
          }
        })
      })
    },

    /**
       * 关闭弹框
       */
    cancel: function() {
      this.$emit('closed')
    },

    /**
     * 获取品牌定制商
     */
    getMerchant: function() {
      const _this = this
      FINDSENDMERCHANTNO().then(res => {
        console.log(res)
        const { data } = res
        _this.merchantList = data || []
      })
    }

  }

}
</script>
<style lang="scss" scoped>
  .addorder_page {
    padding: 20px;
    position: relative;
  }
  .el_select {
    width: 100%;
  }
</style>