<template>
  <a-modal
    :visible="true"
    :width="800"
    :title="$t('role.form.角色配置')"
    @cancel="handcancel(thethis)"
    :maskClosable="false"
    :footer="null"
  >
    <a-spin :spinning="false">
          <RoleForm ref="baseForm"  :data="data" :isMenu="true" :roleList="roleList" :site="site"></RoleForm>
      <!-- 操作 -->
      <div class="button" :style="{ margin: '20px auto', width: '140px' }">
        <a-button type="primary" @click="on_Submit"> {{$t('提交')}} </a-button>
        <a-button style="margin-left: 10px" @click="handcancel(thethis)"> {{$t('关闭')}} </a-button>
      </div>
    </a-spin>
  </a-modal>
</template>
<script>
import { editRole,  } from "@/baseConfigComponents/api/role.js";
import UploadFile from "@/common/components/MyForm/UploadFile.vue";
import RoleForm from "@/baseConfigComponents/components/Role/Modify/components/Form.vue";
import { clearInfo, handcancel } from "@/common/components/MyForm/utils/utils.js";
export default {
  props: ["data", "that","roleList",'site'],
  mounted() {},
  data() {
    this.thethis = this;
    return {
      module: {
        childrenNum1: 0,//模块数量
      },
      imgClear: false, // 图片清空参数

    };
  },
  created() {
    // console.log(this.roleList)
    if(this.data.moduleList) this.module.childrenNum1 = this.data.moduleList.length
      
 
  },

  methods: {
    addModuleList() {
      this.module.childrenNum1+=1;
      // this.$set(this.module,[`childrenNum${Object.keys(this.module).length+1}`],0)
      //  this.module[Object.keys(this.module)[key-1]]++
    },
    submit() {
      // this.handcancel(this);

      // console.log(this.$refs.moduleForm);
      var verify1 = this.$refs.baseForm.verify(); //基础配置验证结果

    //   this.module.childrenNum1
    //     ? this.$refs.moduleForm.forEach((item) => {
    //         if (!item.verify()) {
    //           verify1 = false;
    //         }
    //       })
    //     : ""; //模块配置验证结果

      if (verify1) {
        //表单合并
        // console.log(this.$refs.baseForm.$data.form);
        let postForm = { ...this.$refs.baseForm.$data.form };
       
        // console.log(postForm);

        //发布
        const { id } = postForm;
        this.$set(postForm, ["siteId"], ~~this.site.siteId);
        this.$set(postForm, ["siteCode"], this.site.siteCode);
        // console.log(siteCode, siteId, id);
        editRole(this.site.siteCode, ~~this.site.siteId, id, postForm).then((res) => {
          console.log(res);
          if (res.code == 10000) {
            this.$message.success("成功");
            this.$emit("closePopForm", this.that);
            this.$emit("getRoleList", "");
          }
        }).catch();
      }
    },
    // 重置表单元素
    clearInfo,
    // 关闭
    handcancel,

    // 提交（更改）表单
    on_Submit(type) {
      var that = this;
      // 提示框确认
      this.$confirm({
        title: "确认提交？",
        okText: "提交",
        cancelText: "取消",
        onOk() {
          // 点击确定
          // that.info = { ...that.form };
          that.submit();
        },
        onCancel() {},
      });
    },

  },

  components: {
    RoleForm,
  },
};
</script>
