<template>
  <common-detail :title="`重新发起审批 -${configs.record.name}`" @goBack="configs.visible = false">
    <template #custom_content>
      <el-card>
        <AttributeItem component="div" :current-node="configs.record.variableMap" ref="nodeRef"></AttributeItem>
        <div class="text-center">
          <el-button type="primary" :loading="loading" class="w-md" @click="submit()">提交</el-button>
        </div>
      </el-card>
    </template>
  </common-detail>
</template>

<script>
import { defineComponent, ref } from '@vue/composition-api'
import { Message } from 'element-ui'
import AttributeItem from '../components/attributeItem.vue'
import { applyResource } from 'services/services/product'

export default defineComponent({
  components: { AttributeItem },
  props: {
    configs: {
      type: Object
    }
  },
  setup(props, context) {
    const goBack = () => {
      context.emit('getData')
      props.configs.visible = false
    }
    const loading = ref(false)
    const nodeRef = ref()
    async function submit() {
      const params = nodeRef.value.getPostData()
      if (params === false) return Message.error('审批节点参数缺失')
      loading.value = true
      const res = await applyResource(params)
      if (res.success) {
        Message.success(res.message)
        goBack()
      }
      loading.value = false
    }
    return {
      nodeRef,
      loading,
      submit,
      goBack
    }
  }
})
</script>
