// right-key-menu.vue
<template>
  <div ref="rkm" class="right-key-menu">
    <div
      class="rightKeyMenuItem"
      :class="{ disabled: !curRow.markerId }"
      @click="curRow?.markerId && emits('onSetWorkload', unref(curRow))"
    >
      设置工作量
    </div>
    <div
      class="rightKeyMenuItem"
      :class="{ disabled: !curRow.markerId }"
      @click="curRow?.markerId && emits('onSendMessage', unref(curRow))"
    >
      发送消息
    </div>
    <!-- <div
      v-if="!curRow.paused"
      class="rightKeyMenuItem"
      @click="curRow?.markerId && emits('onPauseMark', unref(curRow))"
    >
      暂停评卷
    </div> -->
    <div
      class="rightKeyMenuItem"
      :class="{ disabled: !curRow.markerId }"
      @click="curRow?.markerId && emits('onShowScoreLines', curRow)"
    >
      分数分布曲线
    </div>
    <div
      v-if="curRow.markingStatus === '正评' && mainStore?.myUserInfo?.role !== 'DEPUTY'"
      class="rightKeyMenuItem"
      @click="curRow?.markerId && emits('forceAssessment', unref(curRow))"
    >
      强制考核分发
    </div>
  </div>
</template>
<script setup lang="ts" name="RightKeyMenu">
import { ref, onUnmounted, unref } from 'vue'
import useMainStore from '@/store/main'
const mainStore = useMainStore()
let rkm = ref()
const emits = defineEmits([
  'rightClick',
  'onSetWorkload',
  'onSendMessage',
  'onPauseMark',
  'forceAssessment',
  'onShowScoreLines',
])
const fun = () => {
  emits('rightClick')
}
const curRow: any = ref({})
const onload = (row: any, column: any, event: any) => {
  curRow.value = row

  let betweenHeight = document.body.clientHeight - event.clientY
  if (betweenHeight < 180) {
    rkm.value.style.top = event.clientY - 140 + 'px'
  } else {
    rkm.value.style.top = event.clientY - 40 + 'px'
  }
  rkm.value.style.left = event.clientX + 20 + 'px'
  document.addEventListener('click', fun)
}
onUnmounted(() => {
  document.removeEventListener('click', fun)
})
defineExpose({
  onload,
})
</script>
<style scoped lang="scss">
.right-key-menu {
  display: block;
  line-height: 30px;
  text-align: center;
}
.right-key-menu:not(:last-child) {
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}
.right-key-menu {
  position: fixed;
  left: 0;
  top: 0;
  background-color: #fff;
  width: 90px;
  font-size: 14px;
  color: #666;
  border-radius: 4px;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  border-radius: 3px;
  white-space: nowrap;
  z-index: 1000;

  border: 1px solid #e4e7ed;
  box-shadow: 0px 0px 0.71429vw rgba(0, 0, 0, 0.12);
  min-width: 8.92857vw;
  text-align: justify;
  word-break: break-all;
  padding: 10px 0;
}
.rightKeyMenuItem {
  padding: 5px 20px;
  &.disabled {
    cursor: not-allowed;
    color: #999;
  }
}
.rightKeyMenuItem {
  &:not(.disabled) {
    &:hover {
      cursor: pointer;
      background: #0091ff;
      color: #fff;
    }
  }
}
</style>
