import { Role, TaskStatus } from '@/utils/enums';
import { checkPermi, checkRole } from '@/utils/permission';
import { mapGetters } from 'vuex';
export const $task = {
  computed: {
    ...mapGetters(['userId']),
    // 是否可以提交
    canSubmit() {
      return (row) => {
        return checkPermi(['bst:task:submit']) 
          && TaskStatus.canSubmit().includes(row.status) 
          && row.ownerIds != null
          && row.ownerIds.includes(this.userId);      
      }
    },
    // 是否可以取消
    canCancel() {
      return (row) => {
        return checkPermi(['bst:task:cancel']) 
          && TaskStatus.canCancel().includes(row.status)
          && (checkRole([Role.SYS_ADMIN, Role.ADMIN]) || this.isCreator(row));
      }
    },
    // 是否可以完成
    canPass() {
      return (row) => {
        return checkPermi(['bst:task:pass']) 
          && TaskStatus.canPass().includes(row.status);
      }
    },
    // 是否可以修改
    canEdit() {
      return (row) => {
        return checkPermi(['bst:task:edit']) 
          && (checkRole([Role.SYS_ADMIN, Role.ADMIN]) || this.isCreator(row));
      }
    },
    // 是否可以删除
    canDel() {
      return (row) => {
        return checkPermi(['bst:task:remove']) 
          && (checkRole([Role.SYS_ADMIN, Role.ADMIN]) || this.isCreator(row));
      }
    },
    // 是否是创建者
    isCreator() {
      return (row) => {
        console.log("isCreator", row, this.userId);
        return row.createId === this.userId;
      }
    }
  }
}