
<style scoped>
.user-panel {
  margin: 10px auto;
}
</style>
<template>
  <el-dialog
    :visible.sync="showDialog"
    :title="title"
    :modal-append-to-body="false"
    style="text-align:left;"
    @close="closeDialog"
    :close-on-click-modal="false"
  >
    <div class="user-panel" v-loading="loading">
      <el-form ref="form" :model="formModel" :rules="ruleValidate" :label-width="'150px'">
        <el-row>
          <el-col :span="12">
            <el-form-item label="显示抓拍图片" prop="deviceNo">
              <el-switch
                v-model="formModel.showCapPic"
                active-color="#13ce66"
                active-text="是"
                inactive-color="#ff4949"
                inactive-text="否"
                ></el-switch>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="显示用户信息" prop="deviceNo">
              <el-switch
                v-model="formModel.showUserInfo"
                active-color="#13ce66"
                active-text="是"
                inactive-color="#ff4949"
                inactive-text="否"
                ></el-switch>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="叠加用户信息" prop="deviceNo">
              <el-switch
                v-model="formModel.overlayUserInfo"
                active-color="#13ce66"
                active-text="是"
                inactive-color="#ff4949"
                inactive-text="否"
                ></el-switch>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="启用语音提示" prop="deviceNo">
              <el-switch
                v-model="formModel.voicePrompt"
                active-color="#13ce66"
                active-text="是"
                inactive-color="#ff4949"
                inactive-text="否"
                ></el-switch>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="保存抓拍图片" prop="deviceNo">
              <el-switch
                v-model="formModel.saveCapPic"
                active-color="#13ce66"
                active-text="是"
                inactive-color="#ff4949"
                inactive-text="否"
                ></el-switch>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="测温开关使能" prop="deviceNo">
              <el-switch
                v-model="formModel.thermalEnabled"
                active-color="#13ce66"
                active-text="开"
                inactive-color="#ff4949"
                inactive-text="关"
                ></el-switch>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="温度阈值上限" prop="deviceNo">
                <el-input
                    v-model.number="formModel.highestThermalThreshold"
                    style="width: 100px"
                >
                <template slot="append">度</template>
                </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="温度阈值下限" prop="deviceNo">
                <el-input
                    v-model.number="formModel.lowestThermalThreshold"
                    style="width: 100px"
                >
                <template slot="append">度</template>
                </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="体温超标允许开门" prop="deviceNo">
                <el-switch
                    v-model="formModel.thermalDoorEnabled"
                    active-color="#13ce66"
                    active-text="是"
                    inactive-color="#ff4949"
                    inactive-text="否"
                ></el-switch>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button type="primary" @click="handleSubmit" :loading="submitting">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import Constant from "@/constant";
import ehomeApi from "@/api/base/ehome";

export default {
  props: ["deviceNo", "title", "companyResult"],
  data() {
    return {
      formModel: {},
      ruleValidate: {},
      showDialog: true,
      loading: false,
      submitting: false,
      cfgUrl: "/ISAPI/AccessControl/AcsCfg?format=json"
    }
  },
  methods: {
    closeDialog() {
      this.$emit("close", false);
    },
    handleSubmit() {
      var self = this;

      this.$refs["form"].validate(valid => {
        ehomeApi.putXMLConfig(
            self.deviceNo,self.cfgUrl,{
                "AcsCfg": self.formModel
            },
        ).then(function(response) {
            self.loading = false;
            var jsonData = response.data;

            if (jsonData.success) {
              self.$message({
                message: "保存成功!",
                type: "success"
              });

              self.$emit("close", true);
            } else {
              self.$message({
                message: jsonData.message + "",
                type: "warning"
              });
            }
          });
        });
    },
  },
  mounted: function() {
    var self = this;
    
    self.loading = true;

    ehomeApi.getXMLConfig(self.deviceNo,self.cfgUrl)
    .then(response => {
        var jsonData = response.data;
        self.loading = false;

        if (jsonData.success) {
            var data = eval('(' + jsonData.data + ')');

            self.formModel = data.AcsCfg;
        } else {
            self.$message.error(jsonData.message + "");
        }
    })
    .catch(error => {
        self.$message.error(error + "");
    });
  }
};
</script>