<template>
  <!-- 商品合约 议价单 撤单 -->
  <a-modal class="commonModal reasonModal" title="原因" v-model:visible="visible" centered @click="cancel" :maskClosable="false">
    <template #footer>
      <a-button key="submit" @click="cancel" class="cancelBtn">取消</a-button>
      <a-button key="submit" type="primary" @click="submit">提交</a-button>
    </template>
    <a-form class="inlineForm" ref="formRef" :model="formState" :rules="rules">
      <a-row :gutter="24">
        <a-col :span="24">
          <a-form-item label="原因" class="relative" name="AuditRemark">
            <a-textarea class="dialogInput" style="width: 100%" placeholder="请输入原因" v-model:value="formState.AuditRemark" readonly :autosize="{ minRows: 8, maxRows: 24 }" />
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
  </a-modal>
</template>

<script lang="ts">
import Drawer from '@/common/components/drawer/index.vue';
import { requestResultLoadingAndInfo } from '@/common/methods/request/resultInfo';
import { validateAction } from '@/common/setup/form/validateAction';
import { _closeModal } from '@/common/setup/modal/modal';
import { geLoginID_number } from '@/services/bus/login';
import { QueryTjmdTransferApplyRsp } from '@/services/go/Tjmd/interface';
import { tradeHoldTransferApplyAuditReq } from '@/services/proto/warehousetrade';
import { TradeHoldTransferApplyAuditReqType } from '@/services/proto/warehousetrade/interface';
import { defineComponent, PropType, ref } from 'vue';
import { FormState } from './interface';
import { handleForm } from './setup';

export default defineComponent({
  name: 'commodity_contract_bargain_refuse_order',
  components: { Drawer },
  emits: ['cancel', 'update'],
  props: {
    selectedRow: {
      type: Object as PropType<QueryTjmdTransferApplyRsp>,
      default: {},
    },
  },
  setup(props, context) {
    const { visible, cancel } = _closeModal(context);
    const loading = ref<boolean>(false);
    const { rules, formState, formRef } = handleForm();
    function submit() {
      validateAction<FormState>(formRef, formState).then((res) => {
        const param: TradeHoldTransferApplyAuditReqType = {
          ApplyID: props.selectedRow.applyid,
          ApplyStatus: 2, // 1:撤销2:拒绝3:通过
          AuditSrc: 2,
          AuditorID: geLoginID_number()!.toString(),
          AuditRemark: res.AuditRemark,
        };
        requestResultLoadingAndInfo(tradeHoldTransferApplyAuditReq, param, loading, ['撤单成功', '撤单失败:']).then(() => {
          // Bus.$emit('spotTrade', true);
          cancel(true);
        });
      });
    }

    return {
      visible,
      cancel,
      submit,
      rules,
      formState,
      formRef,
    };
  },
});
</script>