<template>
  <!-- 停用现货品种-->
  <a-modal class="commonModal spot-detail"
           title="停用现货品种"
           v-model:visible="visible"
           centered
           :maskClosable="false"
           @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="submit">确认停用</a-button>
    </template>
    <a-form class="inlineForm"
            ref="formRef"
            :model="formState"
            :rules="rules">
      <fieldset class="formFieldSet">
        <legend>基本信息</legend>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="现货品种名称"
                         name="deliverygoodsname">
              <span class="white">{{ formatValue(selectedRow.data.deliverygoodsname) }}</span>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="现货品种代码"
                         name="deliverygoodscode">
              <span class="white">{{ formatValue(selectedRow.data.deliverygoodsname) }}</span>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="单位"
                         name="unitid">
              <span class="white">{{ formatValue(selectedRow.data.enumdicname) }}</span>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="状态"
                         name="unitid">
              <span class="green">{{ getValidName(selectedRow.data.isvalid) }}</span>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="24">
            <a-form-item label="备注"
                         name="remark">
              <span class="white">{{ formatValue(selectedRow.data.remark) }}</span>
            </a-form-item>
          </a-col>
        </a-row>
      </fieldset>
      <fieldset class="formFieldSet">
        <legend>商品信息</legend>
        <a-row :gutter="24"
               class="dialogRowTitle">
          <a-col :span="8">
            <span>
              商品
            </span>
          </a-col>
          <a-col :span="8">
            <span>
              单位
            </span>
          </a-col>
          <a-col :span="8">
            <span>
              标仓系数
            </span>
          </a-col>
          <template v-for="item in selectedRow.gmlist"
                    :key="item.wrstandardid">
            <a-col :span="8"
                   class="bt1">
              <div class="white">{{ item.wrstandardname }}</div>
            </a-col>
            <a-col :span="8">
              <div class="white">{{ item.enumdicname }}</div>
            </a-col>
            <a-col :span="8">
              <div class="white">{{ item.convertfactor }}</div>
            </a-col>
          </template>
        </a-row>
      </fieldset>
      <fieldset class="formFieldSet">
        <legend>品牌信息</legend>
        <a-row :gutter="24"
               class="dialogRowTitle dialogRowTitle2">
          <a-col :span="24">
            <span>
              品牌
            </span>
          </a-col>
          <template v-for="item in selectedRow.gblist"
                    :key="item.brandid">
            <a-col :span="24"
                   class="bt1">
              <div class="white">{{ item.brandname }}</div>
            </a-col>
          </template>
        </a-row>
      </fieldset>
      <fieldset class="formFieldSet">
        <legend>套保品种信息</legend>
        <a-row :gutter="24"
               class="dialogRowTitle">
          <a-col :span="8">
            <span>
              套保品种
            </span>
          </a-col>
          <a-col :span="8">
            <span>
              单位
            </span>
          </a-col>
          <a-col :span="8">
            <span>
              套保系数
            </span>
          </a-col>
          <template v-for="item in selectedRow.mgList"
                    :key="item.mg.middlegoodsid">
            <a-col :span="8"
                   class="bt1">
              <div class="white">{{ item.mg.middlegoodsname }}</div>
            </a-col>
            <a-col :span="8">
              <div class="white">{{ item.mg.enumdicname }}</div>
            </a-col>
            <a-col :span="8">
              <div class="white">{{ item.mg.needhedgeratio }}</div>
            </a-col>
          </template>
        </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 { formatValue } from '@/common/methods';
import { getStatusName, getValidName } from '@/common/constants/enumsName';
import { Modal } from 'ant-design-vue';
import { reqDeliveryGoodsBuilder } from '@/views/information/goods/components/setup';
import { ErmcpDeliveryGoodsDetailEx } from '@/services/go/ermcp/goodsInfo/interface';
import { requestResultLoadingAndInfo } from '@/common/methods/request/resultInfo';
import { addDeliveryGoodsApply, deliveryGoodsCancel } from '@/services/proto/delivery';
import { DeliveryGoodsCancelReq } from '@/services/proto/delivery/interface';

export default defineComponent({
    name: 'custom-disable',
    components: {},
    props: {
        selectedRow: {
            type: Object as PropType<ErmcpDeliveryGoodsDetailEx>,
            default: {},
        },
    },
    setup(props, context) {
        const { visible, cancel } = closeModal('goods_info_spot_normal_disable');
        const maskClosableFlag = ref<boolean>(false);
        const loading = ref<boolean>(false);
        function submit() {
            Modal.confirm({
                title: '是否确认停用客户资料',
                okText: '确认停用',
                cancelText: '取消',
                onOk() {
                    let reqParam: DeliveryGoodsCancelReq = reqDeliveryGoodsBuilder(props.selectedRow.data.deliverygoodsid.toString(), 0);
                    requestResultLoadingAndInfo(deliveryGoodsCancel, reqParam, loading, ['停用现货品种成功', '停用现货品种失败:']).then(() => {
                        cancel();
                        context.emit('refresh');
                    });
                },
                onCancel() {},
            });
        }
        return {
            visible,
            cancel,
            submit,
            loading,
            maskClosableFlag,
            formatValue,
            getStatusName,
            getValidName,
        };
    },
});
</script>

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