import userDialog from "@base/views/user/user/dialog";
import positionDialog from "@base/views/user/position/dialog";
import saleOrgDialog from "@base/views/user/sale_org/dialog";
import roleDialog from "@base/views/user/role/dialog";

let modules = {};
modules = {
  props: {
    _dataId: [String, Number],
    fileObjId: Number,
    treeNodeArr: Array,
    currentRow: Object,
  },
  components: {
    userDialog,
    positionDialog,
    saleOrgDialog,
    roleDialog,
  },
  inject: ["current_prefix", "getFileStoreArea"],
  data() {
    return {
      isEdit: false,
      tabIndex: "first",
      dataId: "",
      showDialog: true,
      fileObjAuth: {
        saleOrgName: null,
        positionName: null,
        roleName: null,
        nickName: null,
        addAuth: 1,
        editAuth: 1,
        viewAuth: 1,
        uploadAuth: 1,
        downloadAuth: 1,
        moveAuth: 1,
        copyAuth: 1,
        replaceAuth: 1,
        deleteAuth: 1,
        deleteDirAuth: 1,
        historyAuth: 1,
        shareAuth: 1,
        downWatermarkAuth: 0,
        authAuth: 1,
      },
      showUserDialog: false,
      showPositionDialog: false,
      showSaleOrgDialog: false,
      showRoleDialog: false,
    };
  },
  created() {
    if (this.currentRow) {
      this.fileObjAuth = this.$baseLodash.cloneDeep(this.currentRow);
    }
  },
  computed: {
    title() {
      let prevTitle = this.currentRow
        ? this.$t2("查看", "system.button.check")
        : this.$t2("新增", "system.button.add");
      let title =
        prevTitle + this.$t2("文件权限", "components.fileLibrary.fileAuth");
      return title;
    },
    fileStoreArea() {
      return this.getFileStoreArea();
    },
  },
  mounted() {},
  methods: {
    saveData() {
      this.$refs.editForm.$baseValidate((valid) => {
        if (valid) {
          this.$emit("confirm", this.fileObjAuth);
          this.handleClose();
        }
      });
    },
    confirmInsertUser(rows) {
      if (rows.length) {
        let row = rows[0];
        this.fileObjAuth.userId = row.id;
        this.fileObjAuth.nickName = row.nickName;
      }
    },
    confirmInsertSaleOrg(rows) {
      if (rows.length) {
        let row = rows[0];
        this.fileObjAuth.saleOrgId = row.id;
        this.fileObjAuth.saleOrgName = row.name;
      }
    },
    confirmInsertPosition(rows) {
      if (rows.length) {
        let row = rows[0];
        this.fileObjAuth.positionId = row.id;
        this.fileObjAuth.positionName = row.name;
      }
    },
    confirmInsertRole(rows) {
      if (rows.length) {
        let row = rows[0];
        this.fileObjAuth.roleId = row.id;
        this.fileObjAuth.roleName = row.name;
      }
    },
    handleClose() {
      this.showDialog = false;
      this.$emit("update:visiable", false);
    },
  },
};
export default modules;
