<template>
  <div>
    <el-button size="mini" @click="addRowClick">行权限配置</el-button>
    <el-dialog title="配置行权限信息" :visible.sync="dialogVisible" width="400px" append-to-body>
      <el-form ref="form" :model="form" label-width="125px">
        <el-form-item>
          <template slot="label">
            <span>私密属性字段</span>
            <el-tooltip style="cursor: pointer" effect="dark" :content="'权限数据集字段id（私密属性字段）'" placement="top">
              <i class="el-icon-question" />
            </el-tooltip>
          </template>
          <el-select v-model="form.permissionCubeColumnId" placeholder="请选择权限数据集字段" style="width: 100%">
            <el-option :label="item.__config__.label" :value="item.__vModel__" v-for="(item, i) in drawList" :key="i"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <template slot="label">
            <span>公开权限值</span>
            <el-tooltip style="cursor: pointer" effect="dark" :content="'在录入权限数据集字段时，填写哪些值属于公开权限'" placement="top">
              <i class="el-icon-question" />
            </el-tooltip>
          </template>
          <el-input v-model="form.publicPermission" placeholder="请填写公开权限的值"></el-input>
        </el-form-item>
        <el-form-item>
          <template slot="label">
            <span>私有权限值</span>
            <el-tooltip style="cursor: pointer" effect="dark" :content="'在录入权限数据集字段时，填写哪些值属于私有权限'" placement="top">
              <i class="el-icon-question" />
            </el-tooltip>
          </template>
          <el-input v-model="form.privatePermission" placeholder="请填写私有权限的值"></el-input>
        </el-form-item>
        <el-divider></el-divider>
        <el-form-item>
          <template slot="label">
            <span>内部参与部门</span>
            <el-tooltip style="cursor: pointer" effect="dark" :content="'权限部门集合的数据集id,行权限多部门只支持第一个'" placement="top">
              <i class="el-icon-question" />
            </el-tooltip>
          </template>
          <el-select v-model="form.deptIdsCubeColumnId" placeholder="请选择内部参与部门" style="width: 100%">
            <el-option :label="item.__config__.label" :value="item.__vModel__" v-for="(item, i) in drawList" :key="i"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <template slot="label">
            <span>内部参与人字段</span>
            <el-tooltip style="cursor: pointer" effect="dark" :content="'权限用户集合的数据集id'" placement="top">
              <i class="el-icon-question" />
            </el-tooltip>
          </template>
          <el-select v-model="form.userIdsCubeColumnId" placeholder="请选择内部参与人字段" style="width: 100%">
            <el-option :label="item.__config__.label" :value="item.__vModel__" v-for="(item, i) in drawList" :key="i"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <template slot="label">
            <span>分隔符</span>
            <el-tooltip style="cursor: pointer" effect="dark" :content="'选择多个参与人时，需分隔符隔开'" placement="top">
              <i class="el-icon-question" />
            </el-tooltip>
          </template>
          <el-select v-model="form.userIdDelimiter" placeholder="请选择分隔符" style="width: 100%">
            <el-option label="分号符" value=";"></el-option>
            <el-option label="逗号符" value=","></el-option>
          </el-select>
        </el-form-item>
        <el-divider></el-divider>
        <el-form-item>
          <template slot="label">
            <span>参与人权限字段</span>
            <el-tooltip style="cursor: pointer" effect="dark" :content="'将权限选择存储在某个字段上'" placement="top">
              <i class="el-icon-question" />
            </el-tooltip>
          </template>
          <el-select v-model="form.rowPermissionCubecolumnId" placeholder="请选择存储权限字段" style="width: 100%">
            <el-option :label="item.__config__.label" :value="item.__vModel__" v-for="(item, i) in drawList" :key="i"></el-option>
          </el-select>
        </el-form-item>
        <el-divider></el-divider>
        <el-form-item>
          <template slot="label">
            <span>创建人字段</span>
            <el-tooltip style="cursor: pointer" effect="dark" :content="'当前行权限归属谁创建，不受权限影响'" placement="top">
              <i class="el-icon-question" />
            </el-tooltip>
          </template>
          <el-select v-model="form.creatorUserCubeColumnId" placeholder="请选择创建人字段" style="width: 100%">
            <el-option :label="item.__config__.label" :value="item.__vModel__" v-for="(item, i) in drawList" :key="i"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="formClick">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: ['rowPerJson','drawList'],
  name: "rowPermission",
  data(){
    return {
      dialogVisible:false,
      form:{
        userIdsCubeColumnId: '', //权限用户集合的数据集id 当前表的某个字段
        deptIdsCubeColumnId: '', //权限部门集合的数据集id 当前表的某个字段
        userIdDelimiter: ";", //分隔符
        permissionCubeColumnId: '',//权限数据集字段id 私密属性字段（当前表的某个字段）
        publicPermission: "",//公开权限 私密属性字段的值
        privatePermission: "",//私有权限 私密属性字段的值
        rowPermissionCubecolumnId: '', //具体哪个字段存权限
        creatorUserCubeColumnId: '', //当前行权限归属谁创建，不受权限影响
      }
    }
  },
  methods:{
    addRowClick(){
      this.dialogVisible = true
      this.$nextTick(() => {
        try {
          let rowPerJson = JSON.parse(this.rowPerJson);
          if (Object.prototype.toString.call(rowPerJson) === "[object Object]"){
            this.form = Object.assign({}, rowPerJson);
          }
        }catch {

        }
      })
    },
    formClick(){
      this.dialogVisible = false
      this.$emit("setColumnRowPerJson",JSON.stringify(this.form));
    },
  }
}
</script>

<style scoped lang="scss">

</style>
