<template>
  <div>
    <el-form :model="formData" style="width: 100%;" ref="dataForm" :rules="formRules"
             label-width="auto"
    >
      <el-row :gutter="24" class="el-row">
        <el-col :span="12" class="el-col">
          <el-form-item label="灯组标签:" prop="mac" class="query-form-item">
            <el-input
              v-model="formData.mac" style="width: 80%"
              auto-complete="off"
              placeholder="请输入灯组标签"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12" class="el-col">
          <el-form-item label="灯组备注:" prop="remark" class="query-form-item">
            <el-input
              v-model="formData.remark" style="width: 80%"
              auto-complete="off"
              placeholder="请输入灯组备注"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="24" class="el-row">
        <el-col :span="12" class="el-col">
          <el-form-item label="灭灯时间:" prop="timeout" class="query-form-item">
            <el-input-number :min="0" v-model="formData.timeout" style="width: 80%"
                             placeholder="灭灯时间"
            ></el-input-number>
          </el-form-item>
        </el-col>

        <!--<el-col :span="12" class="el-col">-->
        <!--  <el-form-item label="灯组状态:" prop="monopoly" class="query-form-item">-->
        <!--    <el-select v-model="formData.monopoly" style="width: 80%" placeholder="独占库存"-->
        <!--               :disabled="formData.autoTag == 0">-->
        <!--      <el-option label="否" :value="0"></el-option>-->
        <!--      <el-option label="是" :value="1"></el-option>-->
        <!--    </el-select>-->
        <!--  </el-form-item>-->
        <!--</el-col>-->
      </el-row>
      <!--<el-row :gutter="24" class="el-row">-->
      <!--  <el-col :span="12" class="el-col">-->
      <!--    <el-form-item label="常用业务:" prop="isPopular" class="query-form-item">-->
      <!--      <el-select v-model="formData.isPopular" style="width: 80%" placeholder="业务类型是否常用">-->
      <!--        <el-option label="是" :value="1"></el-option>-->
      <!--        <el-option label="否" :value="0"></el-option>-->
      <!--      </el-select>-->
      <!--    </el-form-item>-->
      <!--  </el-col>-->
      <!--  <el-col :span="12" class="el-col">-->
      <!--    <el-form-item label="顺序号:" prop="number" class="query-form-item">-->

      <!--      <el-input-number :min="0" v-model="formData.number" style="width: 80%"-->
      <!--                       placeholder="顺序号"-->
      <!--      ></el-input-number>-->
      <!--    </el-form-item>-->
      <!--  </el-col>-->
      <!--</el-row>-->




      <!--<el-row :gutter="24" class="el-row">-->
      <!--  <el-col class="el-col">-->
      <!--    <el-form-item label="备注:" prop="remark" class="query-form-item">-->
      <!--      <el-input-->
      <!--        v-model="formData.remark"-->
      <!--        style="width: 91%"-->
      <!--        auto-complete="off"-->
      <!--      ></el-input>-->
      <!--    </el-form-item>-->
      <!--  </el-col>-->
      <!--</el-row>-->


      <el-divider></el-divider>


    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click.native="hideForm">取消</el-button>
      <el-button
        type="primary"
        @click.native="formSubmit()"
      >提交
      </el-button
      >
    </div>
  </div>
</template>

<script>

import { editLed, saveLed } from '@/api/collect/collectLedGroup'

export default {
  props: {
    closeDialog: {
      type: Function,
      required: true
    },
    rowData:{
      type: Object,
      required: true
    }
  },
  data() {
    return {
      formData: {
        timeout:0,
      },
    }
  },
  methods: {
    formSubmit(){
      if (this.rowData != null){
        editLed(this.formData).then(res => {
          if (res.code == 20000){
            this.closeDialog()
            this.$message.success("修改成功")
          }else {
            this.closeDialog()
            this.$message.error(res.message)
          }
        })
      }else {
        saveLed(this.formData).then(res => {
          if (res.code == 20000){
            this.closeDialog()
            this.$message.success("添加成功")
          }else {
            this.closeDialog()
            this.$message.error(res.message)
          }
        })
      }
    },
    hideForm(){
      this.closeDialog()
    }
  },
  created() {
    if (this.rowData != null){
      this.formData = this.rowData
    }
  }

}
</script>

<style scoped>
.dialog-footer {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}
</style>
