<!-- 主页模块 主页一览-->
<template>
  <div>
    <div class="head">
      <span class="headicon">基本信息</span>
    </div>
    <div class="top-buttons">
      <div style="float:right">
        <el-button size="small"
                   v-if="!isOperation"
                   type="primary"
                   @click="submit">提交</el-button>
        <el-button size="small"
                   @click="back">返回</el-button>
      </div>
    </div>
    <div class="form">
      <el-form ref="ruleForm"
               label-width="120px"
               label-position="right"
               :model="ruleForm"
               :rules="rules">
        <el-form-item label="公司名称">
          <span class="content">{{ msg.tenantName | empty }}</span>
        </el-form-item>
        <el-form-item label="联系人">
          <span class="content">{{ msg.linkmanName | empty }}</span>
        </el-form-item>
        <el-form-item label="联系人电话">
          <span class="content">{{ msg.linkmanPhone | empty }}</span>
        </el-form-item>
        <el-form-item label="来源">
          <span class="content">{{ msg.tenantSource | empty }}</span>
        </el-form-item>
        <el-form-item label="责任人"
                      prop="customerServiceStaffId">
          <span class="content"
                v-if="isOperation">{{
            msg.customerServiceStaffName | empty
          }}</span>
          <el-select v-else
                     size="small"
                     v-model="ruleForm.customerServiceStaffId"
                     placeholder="请选择">
            <el-option v-for="item in options"
                       :key="item.operatorId"
                       :label="item.operatorName"
                       :value="item.operatorId" />
          </el-select>
        </el-form-item>
        <el-form-item label="跟踪状态"
                      prop="statusFlag">
          <span class="content"
                v-if="isOperation">{{
            msg.status | empty
          }}</span>
          <el-select v-else
                     size="small"
                     v-model="ruleForm.statusFlag"
                     placeholder="请选择">
            <el-option v-for="item in status"
                       :key="item.value"
                       :label="item.label"
                       :value="item.value"
                       :disabled="item.disabled" />
          </el-select>
        </el-form-item>
        <el-form-item label="试用期限开始"
                      prop="contractStartDate">
          <span class="content"
                v-if="isOperation">{{
            msg.contractStartDate | empty
          }}</span>
          <el-date-picker v-else
                          size="small"
                          :disabled="disabledStartTime"
                          v-model="ruleForm.contractStartDate"
                          value-format="yyyy-MM-dd"
                          type="date"
                          placeholder="选择日期"
                          :picker-options="startTime" />
        </el-form-item>
        <el-form-item label="试用期限结束"
                      prop="contractEndDate">
          <span class="content"
                v-if="isOperation">{{
            msg.contractEndDate | empty
          }}</span>
          <el-date-picker v-else
                          size="small"
                          v-model="ruleForm.contractEndDate"
                          :disabled="!ruleForm.contractStartDate"
                          value-format="yyyy-MM-dd"
                          type="date"
                          placeholder="选择日期"
                          :picker-options="endTime" />
        </el-form-item>
        <!-- <el-form-item label="使用船舶数量"
                      prop="shipNumber">
          <span class="content"
                v-if="isOperation">{{
            msg.shipNumber | empty
          }}</span>
          <el-input v-else
                    size="small"
                    v-model="ruleForm.shipNumber"
                    placeholder="请输入内容"></el-input>
        </el-form-item> -->
      </el-form>
    </div>
    <div style="margin-top: 20px;">
      <div class="head">
        <span class="headicon">附件</span>
      </div>
      <ws-upload ref="upload"
                 oss-key="test"
                 :editable="!isOperation"
                 :appendix-ids="appendixIds" />
    </div>
    <div class="head head2">
      <span class="headicon">开通服务</span>
    </div>
    <div class="top-buttons"
         v-if="!isOperation"
         style="background-color:#fff;padding:0">
      <el-button size="small"
                 type="primary"
                 :disabled="
          msg.statusFlag === '4' || msg.statusFlag === '1' ? true : false
        "
                 @click="addServe"
                 :loading="loading">开通服务</el-button>
    </div>
    <el-dialog title="开通服务"
               :visible.sync="dialogVisible"
               width="50%"
               :close-on-click-modal="false"
               @closed="handleDialogClosed">
      <el-collapse v-if="dialogVisible"
                   v-loading="loading">
        <el-collapse-item v-for="plugin in dialogTreeData"
                          :key="plugin.pluginCode">
          <template slot="title">
            <svg-icon icon-class="ship"
                      class="svg-icon" />
            <div class="plugin-name">{{ plugin.pluginName }}</div>
          </template>
          <div class="collapse-item-content">
            <div class="title">属性设置</div>
            <div class="collapse-item-content-item">
              <template v-for="(radioAttr, idx) in Object.values(plugin.radioAttribute)">
                <el-radio-group v-model="radioAttr.selected"
                                :key="idx">
                  <el-radio v-for="radio in radioAttr.options"
                            :key="radio.attributeCode"
                            :label="radio.attributeCode">{{ radio.attributeName }}</el-radio>
                </el-radio-group>
              </template>
              <div style="margin-left:10px">
                <el-checkbox v-for="attr in plugin.checkboxAttributes"
                             v-model="attr.selected"
                             :key="attr.attributeCode">
                  {{ attr.attributeName }}
                </el-checkbox>
              </div>
            </div>
            <div class="collapse-item-content-item">
              <div class="title">服务设置</div>
              <el-tree :data="plugin.pluginServers"
                       show-checkbox
                       :default-checked-keys="
                  dialogDefaultCheckedKeyObj[plugin.pluginCode]
                "
                       @check-change="
                  checkChange(
                    plugin.pluginCode,
                    'pluginService' + plugin.pluginCode
                  )
                "
                       node-key="serviceCode"
                       :props="{ label: 'serviceName', children: 'children' }"
                       :ref="'pluginService' + plugin.pluginCode" />
            </div>
          </div>
        </el-collapse-item>
      </el-collapse>
      <div slot="footer"
           class="dialog-footer">
        <el-button @click="handleDialogCancel"
                   :disabled="loading">取 消</el-button>
        <el-button type="primary"
                   @click="handleActive"
                   :loading="loading">确 定</el-button>
      </div>
    </el-dialog>
    <div class="activatedServices">
      <el-collapse>
        <el-collapse-item v-for="plugin in pageTreeData"
                          :key="plugin.pluginId">
          <div slot="title"
               class="payedPlugin">
            <div class="basic">
              <svg-icon icon-class="ship"
                        class="svg-icon" />
              <div class="plugin-name">{{ plugin.pluginName }}</div>
            </div>
            <div class="plugin-extra">
              <div>开通时间：{{ plugin.pluginOpenedDate }}</div>
              <div class="plugin-extra-end-date">
                到期时间：{{ plugin.pluginExpiredDate }}
              </div>
              <div class="plugin-extra-seperator"></div>
              <div class="plugin-extra-left-days"
                   :class="
                  leftDays(plugin.pluginOpenedDate, plugin.pluginExpiredDate) <
                    100 &&
                    leftDays(
                      plugin.pluginOpenedDate,
                      plugin.pluginExpiredDate
                    ) >= 0 &&
                    'red'
                ">
                剩余天数：{{
                  {
                    start: plugin.pluginOpenedDate,
                    end: plugin.pluginExpiredDate
                  } | leftDays
                }}天
              </div>
            </div>
          </div>
          <div class="collapse-item-content">
            <el-tree :data="plugin.activatedServices"
                     :props="{ label: 'label', children: 'tenantServiceItems' }"></el-tree>
          </div>
        </el-collapse-item>
      </el-collapse>
    </div>

    <div class="head head2">
      <span class="headicon">操作历史</span>
    </div>
    <div>
      <el-table :data="tableHistoryData"
                style="width: 100%">
        <!-- <el-table-column type="selection" width="30" align="center" /> -->
        <el-table-column prop="roleId"
                         label="序号"
                         width="50"
                         align="center">
          <template slot-scope="scope">{{ scope.$index + 1 }}</template>
        </el-table-column>
        <el-table-column prop="operateUser"
                         label="操作人">
          <template slot-scope="{ row }">
            {{ row.operateUser }}
          </template>
        </el-table-column>
        <el-table-column prop="operateDate"
                         label="操作时间">
          <template slot-scope="{ row }">
            {{ row.operateDate }}
          </template>
        </el-table-column>
        <el-table-column prop="operateContent"
                         label="内容">
          <template slot-scope="{ row }">
            {{ row.operateContent }}
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!--停用盒子-->
    <ws-dialog v-if="dialogRejectBox"
               title="停用"
               width="35%"
               :visible.sync="dialogRejectBox"
               :close-on-click-modal="false">
      <ws-form :rules="disCardCheck"
               :model="stop"
               ref="disCardForm">
        <ws-form-item prop="reason"
                      label="停用原因">
          <ws-input v-model="stop.reason"
                    maxlength="200"
                    :rows="4"
                    type="textarea" />
        </ws-form-item>
      </ws-form>
      <div slot="footer"
           class="dialog-footer">
        <ws-button type="primary"
                   @click="goDiscard">确认</ws-button>
        <ws-button @click="setBlank('discard')">取消</ws-button>
      </div>
    </ws-dialog>
    <!-- 正式用户 -->
    <ws-dialog title="提示信息"
               width="35%"
               :visible.sync="dialogFormal"
               :close-on-click-modal="false">
      <div class="Formal">
        <img src="../../assets/images/common/prompt.png"
             alt="" />
        <span>确定将该租户状态变为"正式租户"？更改后，请到"租户管理"模块，完善该租户的信息</span>
      </div>
      <div class="Formal-footer">
        <ws-button @click="formalPerfect"
                   type="primary">确定并立即完善</ws-button>
        <ws-button @click="formalConfirm"
                   type="primary">确定</ws-button>
        <ws-button @click="formalCancel">取消</ws-button>
      </div>
    </ws-dialog>
  </div>
</template>

<script>
import { operators } from "../../api/lessee";
import WsUpload from "@/components/WsUpload";
import {
  getTrialList, //获取试用租户列表
  getTrialDetail, //详情页的数据
  activablePlugins,
  plugins,
  activate,
  postSubmit, //提交
  getTrialHistory //获取历史
} from "../../api/lessee";

export default {
  name: "trialDetail",
  components: {
    WsUpload
  },
  computed: {},
  // 空内容填充‘--’字符
  filters: {
    empty (value) {
      let empt = "";
      if (!value) {
        empt = "--";
      } else {
        empt = value;
      }
      return empt;
    },
    leftDays ({ start, end }) {
      return Math.floor(
        (new Date(end).getTime() - new Date(start).getTime()) /
        (1000 * 3600 * 24)
      );
    }
  },
  data () {
    return {
      disabledStartTime: false,
      isOperation: false,
      status: [
        {
          value: "1",
          label: "待核实",
          disabled: false
        },
        {
          value: "2",
          label: "试用中"
        },
        {
          value: "3",
          label: "使用中"
        },
        {
          value: "4",
          label: "停用"
        }
      ],
      loading: false,
      dialogDefaultCheckedKeyObj: {},
      dialogVisible: false,
      // 开始时间控制
      startTime: {
        disabledDate: time => {
          return time.getTime() < new Date().getTime() - 24 * 3600 * 1000;
        }
      },
      // 结束时间控制
      endTime: {
        disabledDate: time => {
          if (this.ruleForm.contractStartDate) {
            return (
              time.getTime() <
              new Date(this.ruleForm.contractStartDate).getTime() -
              24 * 3600 * 1000 ||
              time.getTime() >=
              new Date(this.ruleForm.contractStartDate).getTime() +
              60 * 24 * 3600 * 1000
            );
          }
        }
      },
      selectedServices: [],
      pluginAttributes: [],
      trialpage: {
        tenantId: this.$route.query.id
      }, // 传的id值
      tableHistoryData: [], //查询历史table
      appendixIds: "", //附件
      options: [], //责任人的Arr
      // tenantId: "",
      // options: "",
      // enabled: "", // 启用或禁用
      // state: "", // 启用禁用状态
      msg: "",
      dialogTreeData: [],
      pageTreeData: [],
      ruleForm: {}, //校验
      rules: {
        customerServiceStaffId: [
          {
            required: true,
            message: "责任人不能为空",
            trigger: "blur"
          }
        ],
        statusFlag: [
          {
            required: true,
            message: "跟踪状态不能为空",
            trigger: "blur"
          }
        ],
        contractStartDate: [
          {
            required: true,
            validator: this.contractStartDate,
            trigger: "blur"
          }
        ],
        contractEndDate: [
          {
            required: true,
            validator: this.contractEndDate,
            trigger: "blur"
          }
        ],
        shipNumber: [
          {
            required: true,
            message: "使用船舶数量不能为空",
            trigger: "blur"
          }
        ]
      },
      disCardCheck: {
        reason: [{ required: true, trigger: "change" }] // 停用校验
      },
      dialogRejectBox: false, // 停用标识
      stop: {
        reason: "" // 停用原因
      },
      dialogFormal: false //正式用户弹出框
    };
  },
  created () {
    this.tenantId = localStorage.getItem("tenantId");
    this.getHistory();
    this.getPayedServices();
    this.checkList();
    this.getTrial();
  },

  methods: {
    leftDays (start, end) {
      return Math.floor(
        (new Date(end).getTime() - new Date(start).getTime()) /
        (1000 * 3600 * 24)
      );
    },
    checkChange (key, ref) {
      const nodes = this.$refs[ref][0].getCheckedNodes(true, false);
      const keys = [];
      nodes.forEach(v => {
        keys.push(v.id);
      });
      this.$set(this.dialogDefaultCheckedKeyObj, key, keys);
    },
    handleDialogCancel () {
      this.dialogVisible = false;
    },
    handleDialogClosed () {
      this.dialogTreeData = [];
    },
    async addServe () {
      await this.getAvailabelServices();
      this.dialogVisible = true;
    },
    // 获取未选择的、可用的插件列表
    async getAvailabelServices () {
      this.loading = true;
      const response = await activablePlugins({ tenantId: this.tenantId });
      // console.info(response, "response----------");
      this.dialogTreeData = this.convertDialogTreeData(response.data);
      await this.getPayedServices();
      this.loading = false;
    },
    // 新增试用租户
    // 使用期限验证
    contractStartDate (rule, value, callback) {
      this.$refs.ruleForm.clearValidate("contractEndDate");
      const end = this.ruleForm.contractEndDate;
      if (!value) {
        callback(new Error("试用期限开始日期不能为空"));
      } else if (end > value) {
        callback();
      } else {
        callback(new Error("试用期限开始日期不能大于试用期限结束日期"));
      }
    },
    contractEndDate (rule, value, callback) {
      this.$refs.ruleForm.clearValidate("contractStartDate");
      const start = this.ruleForm.contractStartDate;
      if (!value) {
        callback(new Error("试用期限结束日期不能为空"));
      } else if (value > start) {
        callback();
      } else {
        callback(new Error("试用期限结束日期不能大于60天"));
      }
    },
    // 停用
    goDiscard () {
      this.$refs.disCardForm.validate(valid => {
        if (valid) {
          this.$confirm("是否确认提交?", "提示", {
            confirmButtonText: "确认",
            cancelButtonText: "取消",
            distinguishCancelAndClose: true,
            type: "warning"
          })
            .then(() => {
              const pastParmas = {
                ...this.msg,
                reason: this.stop.reason
              };
              postSubmit(pastParmas).then(response => {
                this.dialogRejectBox = false;
                this.$router.push({
                  name: "lessee",
                  params: { type: "tryUser" }
                });
                this.$message({
                  type: "success",
                  message: "操作成功!"
                });
              });
            })
            .catch(action => { });
        } else {
          this.$message({
            message: "带星号的为必填项",
            type: "error"
          });
          return false;
        }
      });
    },
    // 取消按钮
    setBlank (val) {
      this.dialogRejectBox = false;
    },
    // 获取table的列表信息
    getTrial () {
      getTrialDetail(this.trialpage).then(res => {
        const { data } = res;
        this.msg = data;
        this.ruleForm = data;
        this.disabledStartTime = data.statusFlag * 1 === 2;
        this.appendixIds = data.appendixPath;
        this.status[0].disabled = data.statusFlag * 1 !== 1;
        this.isOperation = data.statusFlag * 1 === 3;
      });
    },
    //获取操作历史
    getHistory () {
      getTrialHistory(this.trialpage).then(res => {
        const { data } = res;
        this.tableHistoryData = data;
      });
    },
    submitForm (callback) {
      // TODO: 接口需要修改: postSubmit
      // 参数拼接
      const { operatorName = "" } =
        this.options.find(
          item => item.operatorId === this.ruleForm.customerServiceStaffId
        ) || {};
      const { label = "" } =
        this.status.find(item => item.value === this.ruleForm.statusFlag) || {};
      const pastParmas = {
        ...this.msg,
        customerServiceStaffName: operatorName,
        status: label,
        activatedServices: this.selectedServices,
        pluginAttributes: this.pluginAttributes
      };
      this.$refs.upload.handleSaveBill().then(res => {
        postSubmit({ ...pastParmas, appendixPath: res }).then(res => {
          if (res.code * 1 === 200) {
            if (callback) {
              callback(res.data);
              return;
            }
            this.$router.push({
              name: "lessee",
              params: { type: "tryUser" }
            });
          }
        });
      });
      //TODO： 调用后台接口
    },
    // 提交
    submit () {
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          if (
            (this.ruleForm.statusFlag === "2" ||
              this.ruleForm.statusFlag === "3") &&
            this.pageTreeData &&
            this.pageTreeData.length === 0
          ) {
            this.$message({
              type: "warning",
              message: "请至少开通一个服务!"
            });
            return;
          }

          //停用
          if (this.ruleForm.statusFlag === "4") {
            this.dialogRejectBox = true;
            return;
          } else {
            this.dialogRejectBox = false;
          }
          //正式租户
          if (this.ruleForm.statusFlag === "3") {
            this.dialogFormal = true;
            return;
          } else {
            this.dialogFormal = false;
          }
          this.$confirm("是否确认提交?", "提示", {
            confirmButtonText: "确认",
            cancelButtonText: "取消",
            distinguishCancelAndClose: true,
            type: "warning"
          })
            .then(() => {
              this.submitForm();
              this.$message({
                type: "success",
                message: "操作成功!"
              });
            })
            .catch(action => {
              this.$message({
                type: "info",
                message: "操作失败!"
              });
            });
          // }
        } else {
          this.$message({
            message: "带星号的为必填项",
            type: "error",
            showClose: true
          });
          return false;
        }
      });
    },
    // 查询账户
    checkList () {
      operators({
        currentPage: "",
        pageSize: ""
      }).then(response => {
        this.options = response.data.records;
      });
    },
    // 正式用户的dialog弹出层 按钮
    formalPerfect () {
      this.submitForm(res => {
        localStorage.setItem("tenantId", this.tenantId);
        this.$router.push({
          name: "lesseeMsg"
        });
      });
    },
    formalConfirm () {
      this.submitForm();
      this.$router.push({
        name: "lessee"
      });
    },
    formalCancel () {
      this.dialogFormal = false;
    },
    back () {
      this.$router.push({
        name: "lessee",
        params: { type: "tryUser" }
      });
    },
    // 获取租户插件列表
    // 获取租户已购买的插件列表
    getPayedServices (compare = true) {
      plugins({
        tenantId: this.tenantId
      }).then(response => {
        // console.info(response, 'plugins')
        this.pageTreeData = response.data.map(plugin => {
          return {
            ...plugin,
            activatedServices: plugin.activatedServices.map(service => {
              return {
                ...service,
                label: service.serviceName,
                tenantServiceItems: service.tenantServiceItems.map(item => {
                  return { ...item, label: item.serviceItemName };
                })
              };
            })
          };
        });
        // 如果dialog里有值，就对比勾选服务
        if (compare && this.dialogTreeData != '') {
          this.pageTreeData.forEach(plugin => {
            let serviceCodes = [];
            plugin.activatedServices.forEach(service => {
              if (
                !service.tenantServiceItems ||
                service.tenantServiceItems.length === 0
              ) {
                serviceCodes.push(service.serviceCode);
              } else {
                serviceCodes = serviceCodes.concat(
                  service.tenantServiceItems.map(itm => itm.serviceItemCode)
                );
              }
            });
            this.dialogDefaultCheckedKeyObj[plugin.pluginCode] = serviceCodes;
          });
        }
        // console.info(this.dialogDefaultCheckedKeyObj, 'this.dialogDefaultCheckedKeyObj')
        // 只有在服务没有勾选的情况之前  并且是 试用中 或者 使用中的情况下   走默认的勾选 逻辑
        if ((this.ruleForm.statusFlag * 1 === 2 || this.ruleForm.statusFlag * 1 === 3) && Object.keys(this.dialogDefaultCheckedKeyObj).length === 0) {
          this.dialogDefaultCheckedKeyObj = { "map": ["mapManagement"], "configuration": ["Client", "CircularCategory", "CrewJob"], "news": ["NewsManagement"], 'notice': ['NoticeManagement'] }
        }
      });
    },
    handleActive () {

      for (let index = 0; index < this.dialogTreeData.length; index++) {
        const plugin = this.dialogTreeData[index];
        // 填写activatedServices字段
        const tree = this.$refs["pluginService" + plugin.pluginCode][0];
        const treeSelectedServices = tree.getCheckedNodes();
        const halfSelectedServices = tree.getHalfCheckedNodes();
        const tmp = treeSelectedServices.concat(halfSelectedServices);
        treeSelectedServices.forEach(itm => {
          if (itm.parentServiceCode !== "-1") {
            // 这个是serviceitem
            if (
              !this.selectedServices.some(
                item => item.serviceCode === itm.parentServiceCode
              )
            ) {
              // 没重复的service，则添加这个service
              const service = tmp.find(
                item => item.serviceCode === itm.parentServiceCode
              );
              const wantToAddService = {};
              wantToAddService.serviceCode = service.serviceCode;
              wantToAddService.pluginCode = service.pluginCode;
              wantToAddService.serviceExpiredDate =
                this.ruleForm.contractEndDate + " 00:00:00";
              wantToAddService.tenantServiceItems = [
                {
                  serviceItemCode: itm.serviceCode,
                  serviceItemName: itm.serviceName
                }
              ];
              this.selectedServices.push(wantToAddService);
            } else {
              // 有重复的，则直接往service的tenantServiceItems字段塞
              const service = this.selectedServices.find(
                item => item.serviceCode === itm.parentServiceCode
              );
              service.tenantServiceItems.push({
                serviceItemCode: itm.serviceCode,
                serviceItemName: itm.serviceName
              });
            }
          } else if (
            !itm.tenantServiceItems ||
            itm.tenantServiceItems.length === 0
          ) {
            // 只有service级，没有serviceItem级，则这个service也要加上
            this.selectedServices.push({
              serviceCode: itm.serviceCode,
              pluginCode: itm.pluginCode,
              serviceExpiredDate: this.ruleForm.contractEndDate + " 00:00:00",
              tenantServiceItems: []
            });
          }
        });
        // 填写pluginAttributes字段
        const radio = plugin.radioAttribute;
        for (let index = 0; index < Object.values(radio).length; index++) {
          const radioItem = Object.values(radio)[index];
          if (radioItem.selected) {
            this.pluginAttributes.push({
              attributeCode: radioItem.selected,
              pluginCode: radioItem.pluginCode
            });
            // Todo：校验错误需要修改，应该先判断有无服务属性，然后再做检查，而且有的是radio有的是checkbox
            // } else {
            //   this.$message({
            //     message: '请先设置服务属性',
            //     type: 'error',
            //     showClose: true
            //   })
            //   return;
          }
        }
        const checkboxAttributeCode = plugin.checkboxAttributes
          .filter(itm => itm.selected)
          .map(item => {
            return {
              attributeCode: item.attributeCode,
              pluginCode: item.pluginCode
            };
          });
        this.pluginAttributes = this.pluginAttributes.concat(
          checkboxAttributeCode
        );
      }
      this.loading = true;
      activate({
        tenantId: this.tenantId,
        activatedServices: this.selectedServices,
        pluginAttributes: this.pluginAttributes
      })
        .then(() => {
          this.loading = false;
          this.$message({
            type: "success",
            message: "开通成功",
            showClose: true
          });
          this.dialogVisible = false;
          this.getPayedServices(false);
        })
        .catch(() => {
          this.loading = false;
          this.$message({
            type: "error",
            message: "开通失败",
            showClose: true
          });
        });
    },
    convertDialogTreeData (arr) {
      return arr.map(item => {
        const radioAttribute = {};
        const checkboxAttributes = [];
        item.pluginAttributes.forEach(attr => {
          if (attr.multipleChoiceFlag === "1") {
            if (radioAttribute[attr.attributeType]) {
              radioAttribute[attr.attributeType].options.push(attr);
            } else {
              radioAttribute[attr.attributeType] = {
                selected: "",
                options: [attr]
              };
            }
            if (!radioAttribute[attr.attributeType].selected) {
              radioAttribute[attr.attributeType].selected = attr.isOpening
                ? attr.attributeCode
                : "";
            }
            radioAttribute[attr.attributeType].pluginCode = item.pluginCode;
          } else {
            attr.selected = attr.isOpening;
            checkboxAttributes.push(attr);
          }
        });

        let newVar = {
          ...item,
          radioAttribute,
          checkboxAttributes,
          pluginServers: item.pluginServers.map(service => {
            return { ...service, pluginCode: item.pluginCode };
          })
        };
        // // console.info(newVar.pluginServers, "newVar");
        return newVar;
      });
    }
  }
};
</script>

<style scoped lang="scss">
@import "../../styles/variables.scss";
::v-deep .el-message-box__title {
  font-size: 16px !important;
  font-weight: 600 !important;
}
::v-deep .el-form-item__label {
  font-weight: 500 !important;
}
::v-deep .el-dialog__title {
  font-size: 14px !important;
  font-weight: 600 !important;
}
::v-deep .el-dialog__footer {
  text-align: center;
}
::v-deep .el-collapse {
  border: none;
}
::v-deep .el-textarea__inner {
  width: 80% !important;
}
::v-deep .el-input {
  width: 220px;
}
::v-deep .el-form-item {
  margin-bottom: 12px !important;
}
::v-deep .el-form-item__error {
  padding: 0 !important;
}
.detail-item {
  margin-bottom: 20px;
}
.name {
  width: 120px;
  text-align: right;
  display: inline-block;
  color: #666666;
}
.content {
  margin-left: 20px;
  display: inline-block;
  color: #333333;
}
.head2 {
  margin-top: 40px;
}
.activatedServices {
  margin-top: 20px;
}
.first-level-tree-node {
  .property {
    display: flex;
  }
}
.collapse-item-content {
  padding-left: 32px;
}
.collapse-item-content-item {
  line-height: 2;
  display: flex;
  .title {
    margin-right: 8px;
  }
}
.svg-icon,
.plugin-name {
  margin-left: 8px;
}
.payedPlugin {
  width: 100%;
  display: flex;
  justify-content: space-between;
  .basic {
    display: flex;
    align-items: center;
  }
}
.plugin-extra {
  display: flex;
  align-items: center;
  .plugin-extra-end-date {
    margin-left: 16px;
  }
  .plugin-extra-seperator {
    margin-left: 8px;
    height: 14px;
    background-color: #999;
    width: 1px;
  }
  .plugin-extra-left-days {
    margin-left: 8px;
  }
  .red {
    color: $red;
  }
}
//正式租户
.Formal {
  display: flex;
  align-items: center;
  img {
    width: 26px;
    height: 26px;
    display: block;
  }
  span {
    line-height: 26px;
    padding-left: 10px;
  }
}
.Formal-footer {
  margin-top: 20px;
  display: flex;
  justify-content: center;
}

//新增
.el-radio {
  line-height: 28px !important;
}
</style>
