<template>
  <!-- 撤销交收登记-->
  <a-modal class="add-custom custom-detail"
           title="撤销交收登记"
           v-model:visible="visible"
           centered
           :maskClosable="false"
           @cancel="cancel"
           width="890px">
    <template #footer>
      <a-button key="submit"
                type="primary"
                :loading="loading"
                @click="submit">关闭
      </a-button>
      <a-button key="submit"
                type="primary"
                :loading="loading"
                @click="back">撤销
      </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">{{
                  getContractTypeName(selectedRow.contracttype) + '/' + formatValue(selectedRow.contractno)
                }}</span>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="点价类型">
              <span class="white">{{ getPriceTypeName(selectedRow.pricetype) }}</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.sellusername) }}</span>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="现货品种">
              <span class="white">{{ formatValue(selectedRow.deliverygoodsname) }}</span>
            </a-form-item>
          </a-col>
        </a-row>
      </fieldset>
      <fieldset class="formFieldSet">
        <legend>待审核登记信息</legend>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="交收量">
              <span class="white">{{ formatValue(selectedRow.reckonrealqty) }}</span>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="其它费用">
              <span class="white">{{ formatValue(selectedRow.reckonotheramount) }}</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.addmargin !== 0 && selectedRow.addmargin !== undefined ?
                  "+" + formatValue(selectedRow.addmargin) : (selectedRow.decmargin === 0 ? 0.0 : "-" + formatValue(selectedRow.decmargin)))
                              }}</span>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="调整金额">
              <span class="white">{{ formatValue(selectedRow.reckonadjustamount) }}</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.applytime) }}</span>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="登记人">
              <span class="white">{{ formatValue(selectedRow.applyname) }}</span>
            </a-form-item>
          </a-col>
        </a-row>
      </fieldset>
    </a-form>
  </a-modal>
</template>

<script lang="ts">
import { defineComponent, PropType, reactive, ref, watchEffect } from 'vue';
import { closeModal } from '@/common/setup/modal/index';
import { QueryCustomInfoType } from '@/services/go/ermcp/customInfo/interface';
import { mergeObj } from '@/utils/objHandle';
import { getStatusName } from '@/common/constants/enumsName';
import { formatValue, formatTime } from '@/common/methods';
import { QryBussinessJsRsp } from '@/services/go/ermcp/business-review/interface';
import { getContractTypeName, getPriceTypeName } from '@/common/constants/enumsName';
import { Modal } from 'ant-design-vue';
import { ContractOperateApplyReq } from '@/services/proto/contract/interface';
import Long from 'long';
import { somePriceControl } from '@/views/manage/business-review/components/setup';
import { _closeModal } from '@/common/setup/modal/modal';

export default defineComponent({
    name: 'business_review_settlement_cancel',
    emits: ['cancel', 'update'],
    props: {
        selectedRow: {
            type: Object as PropType<QryBussinessJsRsp>,
            default: {},
        },
    },
    setup(props, context) {
        const { visible, cancel } = _closeModal(context);
        const loading = ref<boolean>(false);
        const maskClosableFlag = ref<boolean>(false);

        function back() {
            Modal.confirm({
                title: '是否确认撤销',
                okText: '确认撤销',
                cancelText: '取消',
                onOk() {
                    const param: ContractOperateApplyReq = {
                        OperateApplyID: Long.fromString(props.selectedRow.operateapplyid),
                        OperateType: 4,
                    };
                    somePriceControl(param, loading)
                        .then((res) => {
                            cancel(true);
                        })
                        .catch((err) => {});
                },
                onCancel() {},
            });
        }

        return {
            visible,
            cancel,
            loading,
            formatValue,
            getStatusName,
            maskClosableFlag,
            getContractTypeName,
            getPriceTypeName,
            back,
        };
    },
});
</script>

<style lang="less">
.business_review_settlement_cancel {
    .ant-form.inlineForm {
        margin-top: 20px;
    }
}
</style>;
