<template>
  <!-- 审核计划-->
  <a-modal class="commonModal fieldsetDialog warehouse-disable"
           title="审核计划"
           v-model:visible="visible"
           centered
           @cancel="cancel"
           width="890px">
    <template #footer>
      <a-button key="submit"
                class="cancelBtn"
                @click="cancel">取消</a-button>
      <a-button key="submit"
                type="primary"
                :loading="loading"
                @click="pass">审核通过</a-button>
      <a-button key="submit"
                type="primary"
                :loading="loading"
                @click="refuse">审核拒绝</a-button>
    </template>
    <a-form class="inlineForm"
            :form="form"
            @submit="handleSearch">
      <fieldset class="formFieldSet">
        <legend>套保计划</legend>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="计划类型">
              <span class="white">{{ getPlanContractType(selectedRow.contracttype) }}</span>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="计划名称">
              <span class="white">{{ formatValue(selectedRow.hedgeplanno) }}</span>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="现货品种">
              <span class="white">{{ formatValue(selectedRow.deliverygoodsname) }}</span>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="商品">
              <span class="white">{{ formatValue(selectedRow.wrstandardname) }}</span>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="计划量">
              <span class="white">{{ formatValue(selectedRow.planqty) }}</span>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="标仓系数">
              <span class="white">{{ formatValue(selectedRow.convertfactor) }}</span>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="交易用户">
              <span class="white">{{ formatValue(selectedRow.tradeusername) }}</span>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="结算币种">
              <span class="white">{{ formatValue(selectedRow.currencyname) }}</span>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="状态">
              <span
                    class="white">{{ formatValue(getPlanStatusName(selectedRow.hedgeplanstatus)) }}</span>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="备注">
              <span class="white">{{ formatValue(selectedRow.remark) }}</span>
            </a-form-item>
          </a-col>
        </a-row>
      </fieldset>
    </a-form>
  </a-modal>
</template>

<script lang="ts">
import { defineComponent, PropType, ref } from 'vue';
import { closeModal } from '@/common/setup/modal/index';
import { Modal } from 'ant-design-vue';
import { ErmcpHedgePlanReq } from '@/services/proto/hedgeplan/interface';
import Long from 'long';
import { Ermcp3HedgePlan } from '@/services/go/ermcp/plan/interface';
import { getPlanContractType, getPlanStatusName } from '@/views/business/plan/setup';
import { formatValue } from '@/common/methods';
import { requestResultLoadingAndInfo } from '@/common/methods/request/resultInfo';
import { hedgePlanReq } from '@/services/proto/hedgeplan';
import { getPayCurrencyTypeEnumList } from '@/common/constants/enumsList';
import { getUserId } from '@/services/bus/account';
import { getLongTypeLoginID } from '@/services/bus/login';
import { _closeModal } from '@/common/setup/modal/modal';
export default defineComponent({
    name: 'plan_audit_audit',
    emits: ['cancel', 'update'],
    props: {
        selectedRow: {
            type: Object as PropType<Ermcp3HedgePlan>,
            default: {},
        },
    },
    setup(props, context) {
        const { visible, cancel } = _closeModal(context);
        const loading = ref<boolean>(false);
        // 审核通过
        function pass() {
            Modal.confirm({
                title: '是否确认审核通过',
                okText: '审核通过',
                cancelText: '取消',
                onOk() {
                    const params: ErmcpHedgePlanReq = {
                        HedgePlanID: Long.fromString(props.selectedRow.hedgeplanid),
                        OperateType: 4,
                        auditremark: '通过',
                        Currencyid: props.selectedRow.currencyid, // 结算币种id
                        Tradeuserid: props.selectedRow.tradeuserid, // 交易用户id
                        auditid: Number(getLongTypeLoginID()),
                    };
                    requestResultLoadingAndInfo(hedgePlanReq, params, loading, ['审核通过', '审核失败:']).then(() => {
                        cancel(true);
                    });
                },
                onCancel() {},
            });
        }
        // 审核拒绝
        function refuse() {
            Modal.confirm({
                title: '是否确认审核拒绝',
                okText: '审核拒绝',
                cancelText: '取消',
                onOk() {
                    const params: ErmcpHedgePlanReq = {
                        HedgePlanID: Long.fromString(props.selectedRow.hedgeplanid),
                        OperateType: 5,
                    };
                    requestResultLoadingAndInfo(hedgePlanReq, params, loading, ['审核拒绝通过', '审核拒绝失败:']).then(() => {
                        cancel(true);
                    });
                },
                onCancel() {},
            });
        }
        return {
            visible,
            cancel,
            refuse,
            loading,
            pass,
            getPlanContractType,
            formatValue,
            getPayCurrencyTypeEnumList,
            getPlanStatusName,
        };
    },
});
</script>

<style lang="less">
.warehouse-disable {
}
</style>
