<template>
  <div class="fwcs">
    <el-breadcrumb
      v-if="is_map != 0"
      separator="/"
      class="bread_crumb"
    >
      <el-breadcrumb-item :to="{ path: '/workplace' }">在线组件工具</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/intelligent_drawing' }">智能制图</el-breadcrumb-item>
      <el-breadcrumb-item>发布信息填写</el-breadcrumb-item>
    </el-breadcrumb>
    <el-breadcrumb
      v-else-if="process_id != ''"
      separator="/"
      class="bread_crumb"
    >
      <el-breadcrumb-item :to="{ path: '/workplace' }">在线组件工具</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/progress/designer' }">流程设计</el-breadcrumb-item>
      <el-breadcrumb-item>发布信息填写</el-breadcrumb-item>
    </el-breadcrumb>
    <el-breadcrumb
      v-else
      separator="/"
      class="bread_crumb"
    >
      <el-breadcrumb-item :to="{ path: '/fwzc' }">服务注册</el-breadcrumb-item>
      <el-breadcrumb-item v-if="!jcxxtx">服务测试</el-breadcrumb-item>
      <el-breadcrumb-item
        v-else
        :to="{ path: '/fwzc' }"
      >服务测试</el-breadcrumb-item>
      <el-breadcrumb-item v-if="jcxxtx">基础信息填写</el-breadcrumb-item>
    </el-breadcrumb>
    <div>
      <block-radius>
        <div class="fwcs_add">
          <el-form
            ref="form"
            :model="form"
            :rules="process_id == '' ? rules : rules_process"
          >
            <el-form-item prop="name">
              <p class="formname">服务名称：</p>
              <el-input
                v-model="form.name"
                placeholder="请输入服务名称"
                class="form_in"
              ></el-input>
            </el-form-item>
            <el-form-item prop="desc">
              <p class="formname">服务描述：</p>
              <el-input
                type="textarea"
                v-model="form.desc"
                placeholder="请输入服务描述"
                class="form_in"
              ></el-input>
            </el-form-item>
            <el-form-item prop="area">
              <p class="formname">服务领域：</p>
              <el-select
                v-model="form.area"
                placeholder="请选择"
                class="form_in"
              >
                <el-option
                  v-for="item in optionsArea"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item prop="origin">
              <p class="formname">所属组织：</p>
              <el-input
                v-model="form.origin"
                class="form_in"
                :disabled="true"
              ></el-input>
            </el-form-item>
            <el-form-item>
              <p class="formname">服务封面：</p>
              <upload-file
                :multiple="false"
                :max="1"
                type="cropper"
                :readOnly="false"
                :list="cover"
                @getNewList="getNewList"
              ></upload-file>
            </el-form-item>
            <el-form-item>
              <p class="formname">接口编码：</p>
              <el-input
                v-model="form.code"
                class="form_in"
                :disabled="true"
              ></el-input>
            </el-form-item>
            <el-form-item prop="resource">
              <p class="formname">开放程度：</p>
              <el-radio-group v-model="form.resource">
                <el-radio :label="1">共享</el-radio>
                <el-radio :label="2">受限</el-radio>
                <el-radio :label="3">敏感</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item
              v-if="is_map != 0"
              class="btn_footer"
            >
              <el-button
                class="previous"
                @click="goBack('map')"
              >{{ is_map == 1 ? "返回智能制图" : "返回Web应用程序" }}</el-button>
              <el-button
                class="registe"
                @click="registeMap"
              >服务发布</el-button>
            </el-form-item>
          </el-form>
        </div>
      </block-radius>
    </div>
    <apass-dialog
      ref="alertChange"
      :title="dialogInfo.title"
      :msg="dialogInfo.msg"
      :submit="dialogInfo.submit"
      :cancelHide="true"
    ></apass-dialog>
  </div>
</template>

<script>
const gisServiceUrl = window.serviceConfig.gisServiceRoot;
const gisPortalSiteName = window.serviceConfig.gisPortalSiteName
  ? window.serviceConfig.gisPortalSiteName
  : "portal";
import BlockRadius from "@/components/general/block-radius";
import CesTable from "@/components/table/table-um";
import Codes from "@/components/general/codes";
import uploadFile from "@/components/general/upload_file";
import helper from "@/services/helper";
import apassDialog from "@/components/apass-dialog";
export default {
  components: {
    BlockRadius,
    CesTable,
    apassDialog,
    "v-apaas-code": Codes,
    uploadFile
  },
  data() {
    return {
      addPortalItemUrl:
        gisServiceUrl +
        "/" +
        gisPortalSiteName +
        "/apaasplat/viewer/addPortalItem.html",
      btnList: [],
      activeBtn: null,
      serviceUrl: "",
      select: "GET",
      optionType: [
        { label: "GET", value: "GET" },
        { label: "POST", value: "POST" },
        { label: "PUT", value: "PUT" },
        { label: "DELETE", value: "DELETE" }
      ],
      optionType1: [{ label: "GET", value: "GET" }],
      activeName: 0,
      activeZh: 0,
      sjfwQqcs: [
        {
          label: "请求字段编码",
          prop: "requestEncoding",
          type: "input",
          align: "left"
        },
        { label: "请求值", prop: "requestValue", type: "input", align: "left" }
      ],
      sjfwQqcstx: [
        { label: "字段编码", prop: "name", type: "", align: "left" },
        { label: "示例值", prop: "example", type: "input", align: "left" },
        {
          label: "字段类型",
          prop: "show_type",
          type: "",
          align: "left",
          width: "140"
        },
        {
          label: "字段名称*",
          prop: "label",
          type: "input",
          align: "left"
        },
        {
          label: "是否必须*",
          prop: "is_must",
          type: "select",
          align: "left",
          width: 100,
          selectArr: [
            { label: "是", value: 1 },
            { label: "否", value: 0 }
          ],
          hasDefault: true
        },
        { label: "字段说明", prop: "descript", type: "input", align: "left" }
      ],
      sjfwFhcstx: [
        { label: "字段编码", prop: "name", type: "", align: "left" },
        { label: "示例值", prop: "example", type: "input", align: "left" },
        { label: "字段类型", prop: "show_type", type: "", align: "left" },
        {
          label: "字段名称*",
          prop: "label",
          type: "input",
          align: "left"
        },
        { label: "字段说明", prop: "descript", type: "input", align: "left" }
      ],
      zhfwQqcsForm: [
        { label: "请求字段编码", prop: "key", type: "input", align: "left" },
        {
          label: "参数类型",
          prop: "field_type",
          type: "select",
          align: "center",
          width: 100,
          selectArr: [
            { label: "text", value: "text" },
            { label: "file", value: "file" }
          ]
        },
        {
          label: "请求值",
          prop: "val",
          type: "upload",
          align: "center",
          uploadKey: "field_type"
        },
        {
          label: "操作",
          type: "Button",
          align: "center",
          width: 100,
          btnList: [
            {
              type: "primary-del",
              label: "删除"
            }
          ]
        }
      ],
      datasZhForm: [],
      datasZhwww: [],
      emptyText: "暂无数据",
      resultShow: false,
      resSuccess: false,
      optionsSq: [{ label: "Bearer Token", value: "Bearer" }],
      sqfsVal: "",
      tokenVal: "",
      sjfwQqt: "JSON",
      zhfwQqt: "JSON",
      skfwQqt: "",
      skfwRadios: [],
      optionsZhyy: [],
      zhyyVal: 22,
      jcxxtx: false,
      form: {
        name: "",
        desc: "",
        area: "",
        origin: "",
        code: "自动生成",
        resource: 1
      },
      rules: {
        name: [
          { required: true, message: "请输入服务名称", trigger: "blur" },
          { min: 0, max: 15, message: "服务名称不超过15个字", trigger: "blur" }
        ],
        desc: [
          { required: true, message: "请输入服务描述", trigger: "blur" },
          {
            min: 0,
            max: 200,
            message: "服务描述不超过200个字",
            trigger: "blur"
          }
        ],
        area: [
          { required: true, message: "请选择服务领域", trigger: "change" }
        ],
        origin: [
          { required: true, message: "请选择所属组织", trigger: "blur" }
        ],
        resource: [
          { required: true, message: "请选择开放程度", trigger: "blur" }
        ]
      },
      rules_process: {
        name: [
          { required: true, message: "请输入服务名称", trigger: "blur" },
          {
            min: 0,
            max: 100,
            message: "服务名称不超过100个字",
            trigger: "blur"
          }
        ],
        desc: [
          { required: true, message: "请输入服务描述", trigger: "blur" },
          {
            min: 0,
            max: 400,
            message: "服务描述不超过400个字",
            trigger: "blur"
          }
        ],
        area: [{ required: true, message: "请选择服务领域", trigger: "blur" }],
        origin: [
          { required: true, message: "请选择所属组织", trigger: "blur" }
        ],
        resource: [
          { required: true, message: "请选择开放程度", trigger: "blur" }
        ]
      },
      cover: [],
      optionsArea: [],
      datasSj: [],
      datasZh: [],
      datasQqcs: [],
      datasFhcs: [],
      request_fields: [],
      response_fields: [],
      noSearchUrl: "",
      requestRules: 0,
      responseRules: 0,
      is_map: 0,
      process_id: "",
      param_fields: [],
      body_fields: [],
      dialogInfo: {
        title: "时空服务参数已修改",
        msg: "",
        submit: null
      },
      is_portal: false,
      portal_id: "",
      dataType: ""
    };
  },
  computed: {},
  watch: {},
  methods: {
    clickBtn(val) {
      this.resultShow = false;
      this.activeBtn = val;
      this.select = "GET";
      this.serviceUrl = "";
      this.noSearchUrl = "";
    },
    getUrl(enUrl) {
      let url = decodeURI(enUrl);
      let arr = [];
      if (url.indexOf("?") != -1) {
        this.noSearchUrl = url.substring(0, url.indexOf("?"));
        let search = url.substring(url.indexOf("?") + 1);
        let vars = search.split("&");
        for (let i = 0; i < vars.length; i++) {
          if (vars[i] != "") {
            let pair = vars[i].split("=");
            arr[i] = {};
            arr[i].requestEncoding = pair[0] ? pair[0] : "";
            arr[i].requestValue = pair[1] ? pair[1] : "";
          }
        }
      } else {
        this.noSearchUrl = enUrl;
      }
      this.serviceUrl = url;
      if (this.activeBtn == 0) {
        this.datasSj = arr;
      } else if (this.activeBtn == 4) {
        this.datasZh = arr;
      }
    },
    clickFwcs() {
      let headers = {};
      let requestData = {};
      if (this.activeBtn == 0) {
        if (this.sqfsVal != "") {
          headers.Authorization = [];
          headers.Authorization[0] = this.sqfsVal + " " + this.tokenVal;
        }
        let request = this.$refs.fwcs_sjfw_qq.getTableData();
        for (let i = 0; i < request.length; i++) {
          if (
            request[i] &&
            request[i].requestEncoding &&
            request[i].requestValue &&
            request[i].requestEncoding != "" &&
            request[i].requestValue != ""
          ) {
            if (
              Object.keys(requestData).indexOf(request[i].requestEncoding) == -1
            ) {
              requestData[request[i].requestEncoding] = [];
              requestData[request[i].requestEncoding][0] =
                request[i].requestValue;
            } else {
              requestData[request[i].requestEncoding].push(
                request[i].requestValue
              );
            }
          }
        }
      } else if (this.activeBtn == 1) {
      } else if (this.activeBtn == 4 && this.zhyyVal != 34) {
        let request = this.$refs.fwcs_zhfw_qq.getTableData();
        for (let i = 0; i < request.length; i++) {
          if (
            request[i] &&
            request[i].requestEncoding &&
            request[i].requestValue &&
            request[i].requestEncoding != "" &&
            request[i].requestValue != ""
          ) {
            if (
              Object.keys(requestData).indexOf(request[i].requestEncoding) == -1
            ) {
              requestData[request[i].requestEncoding] = [];
              requestData[request[i].requestEncoding][0] =
                request[i].requestValue;
            } else {
              requestData[request[i].requestEncoding].push(
                request[i].requestValue
              );
            }
          }
        }
      }
      let bodys = "";
      let contentType = "";
      if (this.activeBtn == 0) {
        bodys = this.$refs.jsonCodes ? this.$refs.jsonCodes.getCodesVal() : "";
        contentType = this.sjfwQqt;
      } else if (this.activeBtn == 4) {
        if (this.activeZh == 1) {
          contentType = this.zhfwQqt;
          if (this.zhfwQqt == "JSON") {
            bodys = this.$refs.zhfwJsonCodes
              ? this.$refs.zhfwJsonCodes.getCodesVal()
              : "";
          } else if (this.zhfwQqt == "form-data") {
            let request = this.$refs.fwcs_zhfw_qq_form.getTableData().concat();
            request.pop();
            bodys = JSON.stringify(request);
          } else if (this.zhfwQqt == "x-www-form-urlencoded") {
            let request = this.$refs.fwcs_zhfw_www.getTableData().concat();
            request.pop();
            bodys = JSON.stringify(request);
          }
        }
      }
      let query = {
        method: this.select,
        url: this.serviceUrl,
        headers: headers,
        params: requestData,
        body: bodys,
        content_type: contentType,
        data_service_type1: this.btnList[this.activeBtn].id,
        data_service_type2:
          this.activeBtn == 0
            ? 12
            : this.activeBtn == 1
            ? this.skfwQqt
            : this.activeBtn == 4
            ? this.zhyyVal
            : 0
      };
      this.$api.workbench.fwzcFwcs(query).then(response => {
        if (response.data.success == 1) {
          let data = response.data.data;
          this.body_fields = data.body_fields;
          this.param_fields = data.param_fields;
          if (data.body_fields && data.body_fields.length != 0) {
            this.datasQqcs = data.body_fields;
            this.dataType = "body";
          } else {
            this.datasQqcs = data.param_fields;
            this.dataType = "param";
          }
          this.datasFhcs = data.response_fields;
          this.resSuccess = true;
          this.resultShow = true;
        } else {
          this.resSuccess = false;
          this.resultShow = true;
          console.log(response.data.errMsg);
        }
      });
    },
    clickTab() {},
    resetSjfw() {
      this.clickFwcs();
    },
    nextJcxx() {
      if (
        this.activeBtn == 0 ||
        (this.activeBtn == 4 && (this.zhyyVal == 22 || this.zhyyVal == 23))
      ) {
        let requestData = this.$refs.fwcs_sjfw_qqcs.getTableData();
        let responseData = this.$refs.fwcs_sjfw_fhcs.getTableData();
        this.requestRules = 0;
        this.responseRules = 0;
        this.checkTable(requestData, 0);
        this.checkTable(responseData, 1);
        if (this.requestRules == 0 && this.responseRules == 0) {
          this.request_fields = requestData;
          this.response_fields = responseData;
          this.jcxxtx = true;
          this.getOrganization();
        } else if (this.requestRules != 0) {
          this.$message.error("请完善请求参数信息中的字段名称");
        } else if (this.responseRules != 0) {
          this.$message.error("请完善返回参数信息中的字段名称");
        }
      } else if (this.activeBtn == 1) {
        let value = helper.getQueryString("id", this.serviceUrl);
        console.log(value);
        if (value && value != "") {
          this.getItemInfo(value);
        } else {
          this.form.name = "";
          this.form.desc = "";
          this.form.area = "";
          this.cover = [];
        }
        this.request_fields = [];
        this.response_fields = [];
        this.jcxxtx = true;
        this.getOrganization();
      } else {
        this.request_fields = [];
        this.response_fields = [];
        this.jcxxtx = true;
        this.getOrganization();
      }
    },
    checkTable(arr, rule) {
      let self = this;
      for (let i = 0; i < arr.length; i++) {
        if (arr[i].name && arr[i].name != "") {
          if (!arr[i].label || arr[i].label == "") {
            if (rule == 0) {
              this.requestRules = 1;
            } else if (rule == 1) {
              this.responseRules = 1;
            }
            return false;
          }
        }
        if (arr[i].children && arr[i].children.length != 0) {
          self.checkTable(arr[i].children, rule);
        }
      }
    },
    // edit form
    getNewList(val) {
      this.cover[0] = val[0].url;
    },
    previous() {
      this.datasQqcs = this.request_fields;
      this.datasFhcs = this.response_fields;
      this.jcxxtx = false;
    },
    getOrganization() {
      let query = {
        id: this.$store.state.userInfo.user_id
      };
      this.$api.user.getUserDetail(query).then(request => {
        if (request.data.success == 1) {
          this.form.origin = request.data.data.department;
          this.oid = request.data.data.department_id;
        } else {
          console.log(response.data.errMsg);
        }
      });
    },
    registeMap() {
      this.$refs.form.validate(valid => {
        if (valid) {
          if (this.cover.length != 0) {
            let query = {};
            if (this.is_map == 1) {
              query = {
                name: this.form.name,
                sectors: this.form.area,
                organization: this.form.origin,
                cover: this.cover[0],
                openness: this.form.resource,
                descript: this.form.desc,
                data_service_type1: 6,
                data_service_type2: this.skfwQqt,
                encode_method: this.form.code,
                method: "GET",
                url: this.serviceUrl,
                request_fields: [],
                request_query_fields: [],
                response_fields: [],
                content_type: "json",
                portal_id: this.portal_id
              };
            } else if (this.is_map == 4) {
              query = {
                name: this.form.name,
                sectors: this.form.area,
                organization: this.form.origin,
                cover: this.cover[0],
                openness: this.form.resource,
                descript: this.form.desc,
                data_service_type1: 21,
                data_service_type2: 34,
                encode_method: this.form.code,
                method: "GET",
                url: this.serviceUrl,
                request_fields: [],
                request_query_fields: [],
                response_fields: [],
                content_type: "json",
                portal_id: this.portal_id
              };
            }
            this.$api.workbench.serviceAdd(query).then(response => {
              if (response.data.success == 1) {
                this.$message.success("服务发布成功");
                this.$router.push("/fwgl/" + this.$store.getters.level);
              } else {
                console.log(response.data.errMsg);
                this.$message.error(response.data.errMsg);
              }
            });
          } else {
            this.$message.error("请上传服务封面");
          }
        } else {
          this.$message.error("请完善服务基本信息");
        }
      });
    },
    registeProcess() {
      this.$refs.form.validate(valid => {
        if (valid) {
          if (this.cover.length != 0) {
            let query = {
              workflows_id: Number(this.process_id), // 服务流程id
              service_name: this.form.name, // 服务名称
              describe: this.form.desc, // 服务描述
              sector: this.form.area, // 服务领域id
              oid: this.oid, // 组织id
              encode_method: this.form.code, // 接口编码
              cover: this.cover[0], // 服务封面
              openness: this.form.resource // 开放程度，1共享/2受限/3敏感
            };
            this.$api.workbench.releaseProcess(query).then(response => {
              if (response.data.success == 1) {
                this.$message.success("服务发布成功");
                this.$router.push("/fwgl/" + this.$store.getters.level);
              } else {
                console.log(response.data.errMsg);
                this.$message.error(response.data.errMsg);
              }
            });
          } else {
            this.$message.error("请上传服务封面");
          }
        } else {
          this.$message.error("请完善服务基本信息");
        }
      });
    },
    registe() {
      this.$refs.form.validate(valid => {
        if (valid) {
          if (this.cover.length != 0) {
            let contentType = "";
            if (this.activeBtn == 1 && !this.is_portal) {
              this.addPortalItem();
            } else {
              if (this.activeBtn == 0) {
                contentType = this.sjfwQqt;
              } else if (this.activeBtn == 4) {
                if (this.activeZh == 1) {
                  contentType = this.zhfwQqt;
                }
              }
              let query = {
                name: this.form.name,
                sectors: this.form.area,
                organization: this.form.origin,
                cover: this.cover[0],
                openness: this.form.resource,
                descript: this.form.desc,
                data_service_type1: this.btnList[this.activeBtn].id,
                data_service_type2:
                  this.activeBtn == 0
                    ? 12
                    : this.activeBtn == 1
                    ? this.skfwQqt
                    : this.activeBtn == 4
                    ? this.zhyyVal
                    : 0,
                encode_method: this.form.code,
                method: this.select,
                url: this.serviceUrl,
                request_fields:
                  this.dataType == "body"
                    ? this.request_fields
                    : this.body_fields,
                request_query_fields:
                  this.dataType == "param"
                    ? this.request_fields
                    : this.param_fields,
                response_fields: this.response_fields,
                content_type: contentType,
                portal_id: this.portal_id
              };
              this.$api.workbench.serviceAdd(query).then(response => {
                if (response.data.success == 1) {
                  this.$message.success("服务注册成功");
                  this.$router.push("/fwgl/" + this.$store.getters.level);
                } else {
                  console.log(response.data.errMsg);
                  this.$message.error(response.data.errMsg);
                }
              });
            }
          } else {
            this.$message.error("请上传服务封面");
          }
        } else {
          this.$message.error("请完善服务基本信息");
        }
      });
    },
    changeTable(val) {
      let search = "?";
      for (let i = 0; i < val.length; i++) {
        if (val[i].requestEncoding != "") {
          search =
            search +
            val[i].requestEncoding +
            "=" +
            (val[i].requestValue ? val[i].requestValue : "") +
            "&";
        }
      }
      let searchDel = search.substring(0, search.length - 1);
      this.serviceUrl = this.noSearchUrl + searchDel;
    },
    delItemQq(val) {
      let arr = this.$refs.fwcs_zhfw_qq_form.getTableData();
      this.delById(arr, val.id);
    },
    delById(arr, id) {
      let self = this;
      for (let i = 0; i < arr.length; i++) {
        if (arr[i].id == id) {
          arr.splice(i, 1);
          return false;
        }
        if (arr[i].children && arr[i].children.length != 0) {
          self.delById(arr[i].children, id);
        }
      }
    },
    changeZhType(val) {
      this.resultShow = false;
      this.resSuccess = false;
    },
    changeZhfwQqt() {},
    getArea() {
      this.$api.workbench.getServiceAreaList().then(response => {
        if (response.data.success == 1) {
          this.optionsArea = response.data.data;
        } else {
          console.log(response.data.errMsg);
        }
      });
    },
    getServiceType1() {
      this.$api.workbench.getServiceTypeList().then(response => {
        if (response.data.success == 1) {
          this.btnList = response.data.data;
          this.btnList.forEach(item => {
            switch (item.id) {
              case 5:
                item.default = "nav_ic_shujufw";
                item.active = "nav_ic_shujufw_sel";
                break;
              case 6:
                item.default = "nav_ic_shikongfw";
                item.active = "nav_ic_shikongfw_sel";
                break;
              case 7:
                item.default = "nav_ic_shipinfw";
                item.active = "nav_ic_shipinfw_sel";
                break;
              case 10:
                item.default = "nav_ic_ganzhifw";
                item.active = "nav_ic_ganzhifw_sel";
                break;
              case 21:
                item.default = "nav_ic_zonghefw";
                item.active = "nav_ic_zonghefw_sel";
                break;
              default:
                break;
            }
          });
          let skfwRadios = this.btnList[1].childDomains;
          skfwRadios.splice(2, 1);
          this.skfwRadios = skfwRadios;
          this.skfwQqt = this.skfwRadios[0].id;
          this.optionsZhyy = this.btnList[4].childDomains;
          this.activeBtn = 0;
        } else {
          console.log(response.data.errMsg);
        }
      });
    },
    judgeMap() {
      let self = this;
      if (self.$route.query.map && self.$route.query.map != 0) {
        self.is_map = self.$route.query.map;
        self.jcxxtx = true;
        // let msg = {
        //   cover: "",
        //   data_service_type2: "20",
        //   descript: "环保资源",
        //   name: "贵州省环保资源地图服务",
        //   portalid: "0303d7b773c5459f83abf95ef93ffb86",
        //   sectors: "1",
        //   url: "https://apaasgis.wodcloud.com/portal/apaasplat/viewer/mapViewer.html?webmap=0303d7b773c5459f83abf95ef93ffb86"
        // };
        // sessionStorage.setItem('shareWebMapParam',JSON.stringify(msg));
        let map_data = JSON.parse(sessionStorage.getItem("shareWebMapParam"));
        if (map_data) {
          let data = map_data;
          self.form.name = data.name;
          self.form.desc = data.descript;
          self.form.area = Number(data.sectors);
          self.serviceUrl = data.url;
          self.skfwQqt = Number(data.data_service_type2);
          self.cover[0] = data.cover;
          self.portal_id = data.portalid;
          self.is_portal = true;
        } else if (self.$store.state.appBuilderParams) {
          let data = this.$store.state.appBuilderParams;
          self.form.name = data.name;
          self.form.desc = data.descript;
          self.form.area = Number(data.sectors);
          self.serviceUrl = data.url;
          self.skfwQqt = Number(data.data_service_type2);
          self.cover[0] = data.cover;
          self.portal_id = data.portalid;
          self.is_portal = true;
        }
        this.getOrganization();
      } else if (self.$route.query.process) {
        self.process_id = self.$route.query.process;
        self.jcxxtx = true;
        this.getProcessDetail();
        this.getOrganization();
      } else {
        self.is_map = 0;
        self.getServiceType1();
      }
    },
    goBack(type) {
      let self = this;
      if (type == "map") {
        window.location.href = "/vmap/#/map";
      } else if (type == "process") {
        this.$router.push("/progress/designer");
      }
    },
    addPortalItem() {
      console.log("添加portal");
      let self = this;
      document.getElementById("listener").contentWindow.postMessage(
        {
          cmd: "addPortalItem",
          params: {
            name: self.form.name,
            url: self.serviceUrl,
            sectors: self.form.area,
            data_service_type2: self.skfwQqt,
            descript: self.form.desc
          }
        },
        "*"
      );
    },
    getItemInfo(itemid) {
      console.log(`获取portal参数${itemid}`);
      document.getElementById("listener").contentWindow.postMessage(
        {
          cmd: "getPortalItemInfo",
          params: itemid
        },
        "*"
      );
    },
    listeners(event) {
      let self = this;
      if (event && event.origin == gisServiceUrl && event.data) {
        if (event.data.cmd == "getPortalItemInfo") {
          console.log(event.data.params);
          let data = event.data.params;
          self.form.name = data.name;
          self.form.desc = data.descript;
          self.form.area = Number(data.sectors);
          self.portal_id = data.portalid;
          self.cover[0] = data.cover;
          if (
            self.serviceUrl != data.url ||
            self.skfwQqt != Number(data.data_service_type2)
          ) {
            self.serviceUrl = data.url;
            self.skfwQqt = Number(data.data_service_type2);
            self.dialogInfo.msg = `您的时空服务地址已更新为${
              self.serviceUrl
            }，服务类型更新为${
              self.skfwRadios.find(item => {
                return item.id == self.skfwQqt;
              }).name
            }。`;
            self.dialogInfo.submit = () => {
              self.$refs.alertChange.hide();
            };
            self.$refs.alertChange.show();
          }
          self.is_portal = true;
        } else if (event.data.cmd == "getPortalItemInfoError") {
          console.log(event.data.params);
          self.is_portal = false;
        } else if (event.data.cmd == "addPortalItem") {
          console.log(event.data.params);
          self.portal_id = event.data.params;
          self.is_portal = true;
          self.registe();
        } else if (event.data.cmd == "addPortalItemError") {
          console.log(event.data.params);
          self.is_portal = false;
        }
      }
    },
    getProcessDetail() {
      this.$api.workbench
        .getProcessDetail({ id: this.process_id })
        .then(response => {
          if (response.data.success == 1) {
            let data = response.data.data;
            this.form.name = data.name;
            this.form.desc = data.describe;
            this.cover.push(
              "/apaas/static/docs/image/image/blob_75dc5c77-754c-440d-8320-92ba68d239d5.blob"
            );
          }
        });
    }
  },
  mounted() {
    let self = this;
    window.addEventListener("message", self.listeners, false);
    self.judgeMap();
    self.getArea();
  }
};
</script>

<style scoped>
.fwcs {
  width: 1200px;
  margin: 0 auto;
  margin-top: -157px;
  margin-bottom: 20px;
}
.fwcs_btn_act {
  background-color: #e56600;
  color: #ffffff;
}
.fwcs_btn_dis {
  background-color: #e3e5ef;
  color: #8890a7;
}
.fwcs_btn_img {
  position: relative;
  top: 2px;
  margin-right: 4px;
}
.gray_line {
  width: 100%;
  margin: 20px auto;
  height: 1px;
  background-color: #dcdfe6;
}
.fwcs_fwdz {
  color: #58617a;
  margin: 20px 15px 15px;
  font-size: 14px;
}
.input-with-select {
  width: 70%;
}
.fwcs_btn_fwcs {
  background-color: #0f2683;
  color: #ffffff;
  margin-left: 10px;
}
.sjfw_qqcstx {
  color: #58617a;
  margin: 10px 15px;
  font-size: 14px;
}
.skfw_csfwxx {
  color: #58617a;
  margin: 10px 15px;
  font-size: 14px;
}
.sjfw_fhcstx {
  color: #58617a;
  margin: 40px 15px 10px;
  font-size: 14px;
}
.btn_footer {
  display: flex;
  justify-content: flex-end;
  margin: 40px 20px 10px;
}
.btn_footer .reset {
  width: 100px;
  background-color: #c3caf8;
  color: #0f2683;
}
.btn_footer .next {
  width: 100px;
  background-color: #0f2683;
  color: #f8f9fd;
}
.btn_footer .previous {
  background-color: #c3caf8;
  color: #0f2683;
}
.btn_footer .registe {
  width: 100px;
  background-color: #0f2683;
  color: #f8f9fd;
}
.sqxx_row {
  padding: 0 20px;
}
.sqxx_title {
  color: #58617a;
  font-size: 14px;
  margin: 10px 15px;
}
.sqxx_select {
  width: 100%;
}
.center_line_c {
  margin: 0 auto;
}
.center_line {
  background-color: #f4f7fc;
  width: 2px;
  height: 400px;
  position: relative;
  left: 50%;
}
.sjfw_qqt {
  margin: 0 20px 15px;
}
.skfw_fwlx {
  margin: 20px 15px;
  color: #58617a;
  font-size: 14px;
}
.skfw_fwlx_radios {
  margin: 10px 0 0;
}
.test_succ {
  width: 100%;
  margin: 0 auto;
}
.skcs_jg {
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #0f2683;
  font-size: 20px;
}
.skcs_jg_img {
  position: relative;
  top: 3px;
}
.zhyy_select {
  width: 70%;
}
.fwcs_add .formname {
  color: #58617a;
  font-size: 14px;
  margin-left: 10px;
}
.form_in {
  width: 1000px;
}
</style>
<style>
.fwcs_fwdz_inner .el-select .el-input {
  width: 130px;
  background-color: #0f2683;
  color: #ffffff;
  border-radius: 8px 0px 0px 8px;
}
.fwcs_tabs .el-tabs__header {
  margin: 20px 0;
}
.zhyy_select .el-input__prefix,
.el-input__suffix {
  position: absolute;
  top: 0;
  right: 10px;
  -webkit-transition: all 0.3s;
  height: 100%;
  color: #c0c4cc;
  text-align: right;
}
</style>
