<template>
  <!-- 催办 -->
  <a-modal
    :destroy-on-close="true"
    title="催办"
    :body-style="{ overflow: 'auto' }"
    :width="600"
    :visible="showRemindModal"
    :confirm-loading="false"
    @ok="handleOkRemind"
    @cancel="() => (showRemindModal = false)"
  >
    <a-form-model
      ref="remindForm"
      layout="horizontal"
      :model="remindForm"
      :class="$style.remindForm"
      :label-col="{ span: 5 }"
      :wrapper-col="{ span: 18 }"
      :rules="remindRules"
    >
      <a-form-model-item label="当前处理人" prop="users" :class="$style.currentOperator">
        <a-checkbox-group v-model="remindForm.users" name="checkboxgroup">
          <a-checkbox v-for="item in currentOperator" :key="item.account" :value="item">
            {{ item.name }}
          </a-checkbox>
        </a-checkbox-group>
      </a-form-model-item>
      <a-form-model-item label="催办内容">
        <sd-opinion-model
          ref="opinionModel"
          v-model="remindForm.content"
          :hand-write="false"
          :cyy-popup-container="cyyPopupContainer"
        />
      </a-form-model-item>
      <sd-notify-type v-model="notifyType" />
    </a-form-model>
  </a-modal>
</template>

<script>
import { Message } from 'ant-design-vue'
import FlowService from '../flow-service'
import components from './_import-components/sd-workflow-reminder-import'
const duration = 1
export default {
  name: 'SdWorkflowReminder',
  metaInfo: {
    title: 'SdWorkflowReminder',
  },
  components,
  data() {
    return {
      showRemindModal: false,
      confirmLoading: false,
      remindForm: {
        users: [],
        content: '',
      },
      remindRules: {
        users: [{ type: 'array', required: true, message: '请选择催办人员', trigger: 'change' }],
      },
      currentOperator: [],
      notifyType: [],
    }
  },
  methods: {
    run() {
      // 获取催办人员
      const key = Symbol.for()
      FlowService.getReminderUsers(this.webflow.FlowData).then(
        (data) => {
          this.showRemindModal = true
          this.currentOperator = data
          this.remindForm.users = data
        },
        () => {
          Message.error({ content: '获取可催办人员失败', key, duration })
        }
      )
    },
    cyyPopupContainer() {
      return document.body
    },
    handleOkRemind() {
      this.$refs.remindForm.validate((valid) => {
        if (valid) {
          const key = Symbol.for()
          Message.loading({ content: '处理中...', key })
          this.confirmLoading = true
          FlowService.reminder(
            this.webflow.FlowData,
            this.webflow.getFormData(),
            this.remindForm.content,
            this.remindForm.users,
            this.notifyType
          ).then(
            (res) => {
              this.confirmLoading = false
              this.showRemindModal = false
              this.webflow.updateFlow()
              Message.success({ content: '催办成功', key, duration })
            },
            () => {
              this.confirmLoading = false
              Message.error('处理失败')
            }
          )
        }
      })
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
.remind-form {
  :global(textarea.ant-input) {
    margin-bottom: 0;
  }
}
</style>
