<!-- 斥候无线数据采集——网关配置 -->
<template>
  <div>
    <!-- <el-button type="info" plain @click="getShow">斥候数据采集网关配置</el-button> -->
    <div class="gateway" v-show="isShow" v-loading="loading">
      <div class="title">
        <p class="title_l">新建网关</p>
        <i class="el-icon-close title_r" @click="isShow = false"></i>
      </div>
      <el-divider></el-divider>
      <div class="content">
        <el-form
          :model="formData"
          :label-position="labelPosition"
          :rules="rules"
          ref="ruleForm"
        >
          <el-row>
            <el-col :span="24">
              <el-form-item
                label="网关名称:"
                :label-width="formLabelWidth"
                prop="wgpz_wgmc"
              >
                <el-select
                  v-model="formData.wgpz_wgmc"
                  placeholder="请选择"
                  style="width: 200px"
                >
                  <el-option
                    v-for="item in options1"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item
                label="网关ID:"
                :label-width="formLabelWidth"
                prop="wgpz_wgid"
              >
                <el-select
                  v-model="formData.wgpz_wgid"
                  placeholder="请选择"
                  style="width: 200px"
                >
                  <el-option
                    v-for="item in options2"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <div class="footer">
            <el-button type="primary" @click="innerVisible = true"
              >保 存</el-button
            >

            <el-button @click="isShow = false">取 消</el-button>
          </div>
        </el-form>
      </div>
    </div>
    <div>
      <el-dialog
        title="系统提示"
        :visible.sync="innerVisible"
        append-to-body
        width="382px"
      >
        <p class="inner_content" style="color: #fff">
          请确认选择的网关类型与网关实体一致:否则该工程无法下载至实体网关
        </p>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="saveGate">确定</el-button>
          <el-button @click="innerVisible = false">取 消</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { SaveUserAnswer, GetUserAnswer } from "@/api/user";
export default {
  name: "TestChiGate",

  data() {
    return {
      loading: false,
      user_id: "",
      options1: [
        {
          value: "有线区网关2",
          label: "有线区网关2",
        },
        {
          value: "无线区网关2",
          label: "无线区网关2",
        },
      ],
      options2: [
        {
          value: "LAN-BOX2",
          label: "LAN-BOX2",
        },
        {
          value: "WLAN-BOX2",
          label: "WLAN-BOX2",
        },
      ],
      formData: {
        wgpz_wgmc: "有线区网关2",
        wgpz_wgid: "LAN-BOX2",
      },
      innerVisible: false,
      labelPosition: "left",
      formLabelWidth: "96px",
      count: 0,
      isShow: true,
      options: [
        {
          value: "选项1",
          label: "测试1",
        },
        {
          value: "选项2",
          label: "测试2",
        },
        {
          value: "选项3",
          label: "测试3",
        },
        {
          value: "选项4",
          label: "测试4",
        },
        {
          value: "选项5",
          label: "测试5",
        },
      ],
      rules: {
        gateway_id: [
          { required: true, message: "请输入网关ID", trigger: "blur" },
        ],
        gateway_name: [
          { required: true, message: "请输入网关名称", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    let that = this;
    window.getParameter = that.getParameter;
  },
  methods: {
    getParameter(data) {
      this.user_id = data;
    },
    async saveGate() {
      let datas = sessionStorage.getItem("CHGYWG_wx");
      this.formData = { ...JSON.parse(datas), ...this.formData };
      let res = await SaveUserAnswer({
        mark: "CHGYWG_wx",
        user_id: "USER202307301114011710",
        mark_value: JSON.stringify(this.formData),
      });
      if (res.status == 200) {
        this.$message({
          message: "保存成功",
          type: "success",
        });
      }
      console.log(res);
      sessionStorage.setItem("CHGYWG_wx", JSON.stringify(this.formData));
      this.$router.push("/chiwifidevice");
    },
    async GetUserAnswer() {
      this.loading = true;
      let { data } = await GetUserAnswer({
        mark: "CHGYWG_wx",
        user_id: "USER202307301114011710",
      });
      this.loading = false;
      if (data.data && data.state) {
        console.log(JSON.parse(data.data.mark_value));
        let obj = JSON.parse(data.data.mark_value);
        if (obj.wgpz_wgid) {
          this.formData.wgpz_wgid = obj.wgpz_wgid;
          this.formData.wgpz_wgmc = obj.wgpz_wgmc;
        }
      }
    },
  },
  mounted() {
    this.GetUserAnswer();
  },
};
</script>

<style lang="less" scoped>
/deep/ .gateway {
  position: absolute;
  left: 694px;
  top: 188px;
  width: 382px;
  height: 309px;
  line-height: 20px;
  // background-color: rgba(255, 255, 255, 1);
  background: url(../assets/image/bg.png);
  background-size: 100% 100%;
  text-align: center;
  border: 1px solid rgba(187, 187, 187, 1);

  .el-divider--horizontal {
    margin: 8px 0;
  }

  .title {
    margin: 13px 11px 0px 21px;
    display: flex;
    justify-content: space-between;

    .title_l {
      width: 72px;
      height: 26px;
      color: rgba(16, 16, 16, 1);
      font-size: 18px;
      text-align: left;
    }

    .title_r {
      width: 24px;
      height: 24px;
      cursor: pointer;
      color: rgba(111, 103, 103, 1);
    }
  }

  .content {
    margin-left: 50px;
    margin-right: 50px;

    .el-input__inner {
      width: 200px;
      height: 30px;
    }
  }

  /deep/ .footer {
    .el-button {
      width: 80px;
      height: 30px;
      line-height: 0.5;
    }
  }
}
</style>
