<template>
  <div style="display: none" :style="{ display: 'block' }">
    <el-dialog :title="$t('networkmanagement.management')" :visible.sync="dialogVisible" width="40%">
      <p
        style="
          color: red;
          position: absolute;
          top: 20px;
          left: 110px;
          font-size: 18px;
        "
        v-if="$i18n.locale==='en'"
      >
        {{ $t('networkmanagement.prompt') }}
      </p>
      <p
          style="color: red;margin-bottom: 20px;font-size: 18px;"
          v-if="$i18n.locale==='zh'"
      >
        {{ $t('networkmanagement.prompt') }}
      </p>
      <h3 style="color: #fff">{{ $t('networkmanagement.internalNetworkCard') }}</h3>
      <el-divider></el-divider>
      <el-table :data="tableData" style="width: 100%" border>
        <el-table-column prop="wlgl_nw_name" :label="$t('networkmanagement.networkCardName')">
          <template slot-scope="scope">
            <el-select v-model="scope.row.wlgl_nw_name" placeholder="">
              <el-option
                v-for="(item,index) in options1"
                :key="item.label"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column prop="wlgl_nw_ip" :label="$t('networkmanagement.IPV4Address')">
          <template slot-scope="scope">
            <div class="net_setting">
              <el-row>
                <el-col :span="5">
                  <el-input v-model="wlgl_nw_ip1"></el-input>
                </el-col>
                <el-col :span="1">. </el-col>
                <el-col :span="5">
                  <el-input v-model="wlgl_nw_ip2"></el-input>
                </el-col>
                <el-col :span="1">.</el-col>
                <el-col :span="5">
                  <el-input v-model="wlgl_nw_ip3"></el-input>
                </el-col>
                <el-col :span="1">.</el-col>
                <el-col :span="5">
                  <el-input v-model="wlgl_nw_ip4"></el-input>
                </el-col>
              </el-row>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="wlgl_nw_zwym" :label="$t('networkmanagement.IPV4Mask')">
          <template slot-scope="scope">
            <div class="net_setting">
              <el-row>
                <el-col :span="5">
                  <el-input v-model="wlgl_nw_zwym1"></el-input>
                </el-col>
                <el-col :span="1">. </el-col>
                <el-col :span="5">
                  <el-input v-model="wlgl_nw_zwym2"></el-input>
                </el-col>
                <el-col :span="1">.</el-col>
                <el-col :span="5">
                  <el-input v-model="wlgl_nw_zwym3"></el-input>
                </el-col>
                <el-col :span="1">.</el-col>
                <el-col :span="5">
                  <el-input v-model="wlgl_nw_zwym4"></el-input>
                </el-col>
              </el-row>
            </div> </template
        ></el-table-column>
      </el-table>
      <h3 style="color: #fff">{{ $t('networkmanagement.externalNetworkCard') }}</h3>
      <el-divider></el-divider>
      <el-table :data="tableData1" style="width: 100%" border>
        <el-table-column prop="wlgl_ww_name" :label="$t('networkmanagement.networkCardName')">
          <template slot-scope="scope">
            <el-select v-model="scope.row.wlgl_ww_name" placeholder="">
              <el-option
                v-for="(item,index) in options2"
                :key="item.label"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column prop="wlgl_ww_ip" :label="$t('networkmanagement.IPV4Address')">
          <template slot-scope="scope">
            <div class="net_setting">
              <el-row>
                <el-col :span="5">
                  <el-input v-model="wlgl_ww_ip1"></el-input>
                </el-col>
                <el-col :span="1">. </el-col>
                <el-col :span="5">
                  <el-input v-model="wlgl_ww_ip2"></el-input>
                </el-col>
                <el-col :span="1">.</el-col>
                <el-col :span="5">
                  <el-input v-model="wlgl_ww_ip3"></el-input>
                </el-col>
                <el-col :span="1">.</el-col>
                <el-col :span="5">
                  <el-input v-model="wlgl_ww_ip4"></el-input>
                </el-col>
              </el-row>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="wlgl_ww_zwym" :label="$t('networkmanagement.IPV4Mask')">
          <template slot-scope="scope">
            <div class="net_setting">
              <el-row>
                <el-col :span="5">
                  <el-input v-model="wlgl_ww_zwym1"></el-input>
                </el-col>
                <el-col :span="1">. </el-col>
                <el-col :span="5">
                  <el-input v-model="wlgl_ww_zwym2"></el-input>
                </el-col>
                <el-col :span="1">.</el-col>
                <el-col :span="5">
                  <el-input v-model="wlgl_ww_zwym3"></el-input>
                </el-col>
                <el-col :span="1">.</el-col>
                <el-col :span="5">
                  <el-input v-model="wlgl_ww_zwym4"></el-input>
                </el-col>
              </el-row>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="save">{{$t('save')}}</el-button>
        <el-button @click="dialogVisible = false">{{$t('cancel')}}</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {SaveUserAnswer, GetUserAnswer, getQueryAnswer} from "../api/user";
export default {
  data() {
    return {
      user_id: "",
      type: "",
      wlgl_nw_ip1: "",
      wlgl_nw_ip2: "",
      wlgl_nw_ip3: "",
      wlgl_nw_ip4: "",
      wlgl_nw_zwym1: "",
      wlgl_nw_zwym2: "",
      wlgl_nw_zwym3: "",
      wlgl_nw_zwym4: "",
      wlgl_ww_ip1: "",
      wlgl_ww_ip2: "",
      wlgl_ww_ip3: "",
      wlgl_ww_ip4: "",
      wlgl_ww_zwym1: "",
      wlgl_ww_zwym2: "",
      wlgl_ww_zwym3: "",
      wlgl_ww_zwym4: "",
      dxgl: [],
      clgl_name: "",
      clgl_xy: "",
      clgl_gzms: "",
      clgl_ydx: "",
      clgl_ydk: "",
      clgl_mddx: "",
      clgl_mddk: "",
      clgl_rkwg: "",
      clgl_rkwk: "",
      clgl_rkip: "",
      clgl_ckwg: "",
      clgl_ckwk: "",
      clgl_ckip: "",
      clgl_wdyml: "",
      cmdlist_ml: "",
      cmdlist_sbid: "",
      cmdlist_qsdz: "",
      cmdlist_dzcd: "",
      cmdlist_ms: "",
      cmdlist_dz: "",
      options1: this.$t('networkmanagement.options1'),
      // [
      //   {
      //     label: "有线区网闸（内网）",
      //     value: "有线区网闸（内网）",
      //   },
      //   {
      //     label: "无线区网闸（内网）",
      //     value: "无线区网闸（内网）",
      //   },
      // ]
      options2: this.$t('networkmanagement.options2'),
      // [
      //   {
      //     label: "有线区网闸（外网）",
      //     value: "有线区网闸（外网）",
      //   },
      //   {
      //     label: "无线区网闸（外网）",
      //     value: "无线区网闸（外网）",
      //   },
      // ],
      dialogVisible: true,
      tableData: [
        {
          wlgl_nw_name: "",
          wlgl_nw_ip: "",
          wlgl_nw_zwym: "",
        },
      ],
      tableData1: [
        {
          wlgl_ww_name: "",
          wlgl_ww_ip: "",
          wlgl_ww_zwym: "",
        },
      ],
    };
  },
  mounted() {
    this.dialogVisible = true;
    let str = window.location.href.split("?")[1];
    this.user_id = decodeURIComponent(str).split("|")[0];
    let type = decodeURIComponent(str).split("|")[1];
    if (type == 1) {
      this.$store.commit("setType", "GYWZ_yx");
    } else {
      this.$store.commit("setType", "GYWZ_wx");
    }
    // alert(this.user_id, this.$store.state.type);
    console.log(this.user_id, this.$store.state.type);
    this.GetUserAnswer();
  },
  methods: {
    async save() {
      var obj = {
        wlgl_nw_name: this.tableData[0].wlgl_nw_name,
        wlgl_nw_ip:
          this.wlgl_nw_ip1 +
          "." +
          this.wlgl_nw_ip2 +
          "." +
          this.wlgl_nw_ip3 +
          "." +
          this.wlgl_nw_ip4,
        wlgl_nw_zwym:
          this.wlgl_nw_zwym1 +
          "." +
          this.wlgl_nw_zwym2 +
          "." +
          this.wlgl_nw_zwym3 +
          "." +
          this.wlgl_nw_zwym4,
        wlgl_ww_name: this.tableData1[0].wlgl_ww_name,
        wlgl_ww_ip:
          this.wlgl_ww_ip1 +
          "." +
          this.wlgl_ww_ip2 +
          "." +
          this.wlgl_ww_ip3 +
          "." +
          this.wlgl_ww_ip4,
        wlgl_ww_zwym:
          this.wlgl_ww_zwym1 +
          "." +
          this.wlgl_ww_zwym2 +
          "." +
          this.wlgl_ww_zwym3 +
          "." +
          this.wlgl_ww_zwym4,
        dxgl: this.dxgl,
        clgl_name: this.clgl_name,
        clgl_xy: this.clgl_xy,
        clgl_gzms: this.clgl_gzms,
        clgl_ydx: this.clgl_ydx,
        clgl_ydk: this.clgl_ydk,
        clgl_mddx: this.clgl_mddx,
        clgl_mddk: this.clgl_mddk,
        clgl_rkwg: this.clgl_rkwg,
        clgl_rkwk: this.clgl_rkwk,
        clgl_rkip: this.clgl_rkip,
        clgl_ckwg: this.clgl_ckwg,
        clgl_ckwk: this.clgl_ckwk,
        clgl_ckip: this.clgl_ckip,
        clgl_wdyml: this.clgl_wdyml,
        cmdlist_ml: this.cmdlist_ml,
        cmdlist_sbid: this.cmdlist_sbid,
        cmdlist_qsdz: this.cmdlist_qsdz,
        cmdlist_dzcd: this.cmdlist_dzcd,
        cmdlist_ms: this.cmdlist_ms,
        cmdlist_dz: this.cmdlist_dz,
      };
      let { data } = await SaveUserAnswer({
        mark: this.$store.state.type,
        user_id: this.user_id,
        // mark: "GYWZ_wx",
        // user_id: "USER202307301109254198",
        mark_value: JSON.stringify(obj),
      });
      if (data.state) {
        this.$message({
          message: this.$t('success'),
          type: "success",
        });
      } else {
        this.$message.error(this.$t('fail'));
      }
    },
    //拿缓存
    async GetUserAnswer() {
      var { data } = await GetUserAnswer({
        mark: this.$store.state.type,
        user_id: this.user_id,
        // mark: "GYWZ_wx",
        // user_id: "USER202307301109254198",
      });
      // console.log(data.data.mark_value);
      if (data.state && data.data && data.data.mark_value) {
        let res = JSON.parse(data.data.mark_value);
        console.log(res)
        this.tableData[0].wlgl_nw_name = res.wlgl_nw_name;
        if(res.wlgl_nw_ip&&res.wlgl_nw_ip!==''){
          this.wlgl_nw_ip1 = res.wlgl_nw_ip.split(".")[0];
          this.wlgl_nw_ip2 = res.wlgl_nw_ip.split(".")[1];
          this.wlgl_nw_ip3 = res.wlgl_nw_ip.split(".")[2];
          this.wlgl_nw_ip4 = res.wlgl_nw_ip.split(".")[3];
        }
      if(res.wlgl_nw_zwym&&res.wlgl_nw_zwym!==''){
        this.wlgl_nw_zwym1 = res.wlgl_nw_zwym.split(".")[0];
        this.wlgl_nw_zwym2 = res.wlgl_nw_zwym.split(".")[1];
        this.wlgl_nw_zwym3 = res.wlgl_nw_zwym.split(".")[2];
        this.wlgl_nw_zwym4 = res.wlgl_nw_zwym.split(".")[3];
      }

        this.tableData1[0].wlgl_ww_name = res.wlgl_ww_name;
      if(res.wlgl_ww_ip&&res.wlgl_ww_ip!==''){
        this.wlgl_ww_ip1 = res.wlgl_ww_ip.split(".")[0];
        this.wlgl_ww_ip2 = res.wlgl_ww_ip.split(".")[1];
        this.wlgl_ww_ip3 = res.wlgl_ww_ip.split(".")[2];
        this.wlgl_ww_ip4 = res.wlgl_ww_ip.split(".")[3];
      }
        if(res.wlgl_ww_zwym&&res.wlgl_ww_zwym!==''){
          this.wlgl_ww_zwym1 = res.wlgl_ww_zwym.split(".")[0];
          this.wlgl_ww_zwym2 = res.wlgl_ww_zwym.split(".")[1];
          this.wlgl_ww_zwym3 = res.wlgl_ww_zwym.split(".")[2];
          this.wlgl_ww_zwym4 = res.wlgl_ww_zwym.split(".")[3];
        }

        this.dxgl = res.dxgl;
        this.clgl_name = res.clgl_name;
        this.clgl_xy = res.clgl_xy;
        this.clgl_gzms = res.clgl_gzms;
        this.clgl_ydx = res.clgl_ydx;
        this.clgl_ydk = res.clgl_ydk;
        this.clgl_mddx = res.clgl_mddx;
        this.clgl_mddk = res.clgl_mddk;
        this.clgl_rkwg = res.clgl_rkwg;
        this.clgl_rkwk = res.clgl_rkwk;
        this.clgl_rkip = res.clgl_rkip;
        this.clgl_ckwg = res.clgl_ckwg;
        this.clgl_ckwk = res.clgl_ckwk;
        this.clgl_ckip = res.clgl_ckip;
        this.clgl_wdyml = res.clgl_wdyml;
        this.cmdlist_ml = res.cmdlist_ml;
        this.cmdlist_sbid = res.cmdlist_sbid;
        this.cmdlist_qsdz = res.cmdlist_qsdz;
        this.cmdlist_dzcd = res.cmdlist_dzcd;
        this.cmdlist_ms = res.cmdlist_ms;
        this.cmdlist_dz = res.cmdlist_dz;
      }else{
        getQueryAnswer({
          mark: this.$store.state.type,
          user_id: this.user_id
        }).then(data => {
          let res = JSON.parse(data.data.data.r3);
          this.tableData[0].wlgl_nw_name = res.wlgl_nw_name;
          if(res.wlgl_nw_ip&&res.wlgl_nw_ip!==''){
            this.wlgl_nw_ip1 = res.wlgl_nw_ip.split(".")[0];
            this.wlgl_nw_ip2 = res.wlgl_nw_ip.split(".")[1];
            this.wlgl_nw_ip3 = res.wlgl_nw_ip.split(".")[2];
            this.wlgl_nw_ip4 = res.wlgl_nw_ip.split(".")[3];
          }
          if(res.wlgl_nw_zwym&&res.wlgl_nw_zwym!==''){
            this.wlgl_nw_zwym1 = res.wlgl_nw_zwym.split(".")[0];
            this.wlgl_nw_zwym2 = res.wlgl_nw_zwym.split(".")[1];
            this.wlgl_nw_zwym3 = res.wlgl_nw_zwym.split(".")[2];
            this.wlgl_nw_zwym4 = res.wlgl_nw_zwym.split(".")[3];
          }

          this.tableData1[0].wlgl_ww_name = res.wlgl_ww_name;
          if(res.wlgl_ww_ip&&res.wlgl_ww_ip!==''){
            this.wlgl_ww_ip1 = res.wlgl_ww_ip.split(".")[0];
            this.wlgl_ww_ip2 = res.wlgl_ww_ip.split(".")[1];
            this.wlgl_ww_ip3 = res.wlgl_ww_ip.split(".")[2];
            this.wlgl_ww_ip4 = res.wlgl_ww_ip.split(".")[3];
          }
          if(res.wlgl_ww_zwym&&res.wlgl_ww_zwym!==''){
            this.wlgl_ww_zwym1 = res.wlgl_ww_zwym.split(".")[0];
            this.wlgl_ww_zwym2 = res.wlgl_ww_zwym.split(".")[1];
            this.wlgl_ww_zwym3 = res.wlgl_ww_zwym.split(".")[2];
            this.wlgl_ww_zwym4 = res.wlgl_ww_zwym.split(".")[3];
          }
          this.dxgl = res.dxgl;
          this.clgl_name = res.clgl_name;
          this.clgl_xy = res.clgl_xy;
          this.clgl_gzms = res.clgl_gzms;
          this.clgl_ydx = res.clgl_ydx;
          this.clgl_ydk = res.clgl_ydk;
          this.clgl_mddx = res.clgl_mddx;
          this.clgl_mddk = res.clgl_mddk;
          this.clgl_rkwg = res.clgl_rkwg;
          this.clgl_rkwk = res.clgl_rkwk;
          this.clgl_rkip = res.clgl_rkip;
          this.clgl_ckwg = res.clgl_ckwg;
          this.clgl_ckwk = res.clgl_ckwk;
          this.clgl_ckip = res.clgl_ckip;
          this.clgl_wdyml = res.clgl_wdyml;
          this.cmdlist_ml = res.cmdlist_ml;
          this.cmdlist_sbid = res.cmdlist_sbid;
          this.cmdlist_qsdz = res.cmdlist_qsdz;
          this.cmdlist_dzcd = res.cmdlist_dzcd;
          this.cmdlist_ms = res.cmdlist_ms;
          this.cmdlist_dz = res.cmdlist_dz;
        })
      }
    },
  },
};
</script>
<style scoped lang="less">
/deep/ .net_setting {
  .el-input__inner {
    height: 30px;
    text-align: center;
    padding: 0;
  }

  .el-col-1 {
    padding: 0px 2px;
    color: black;
    text-align: left;
    line-height: 45px;
    height: 20px;
  }

  .el-col-5 {
    width: 43px;
    height: 30px;
  }

  .el-col-24 {
    padding-right: 152px;
  }
}
</style>
