<template>
  <div class="CenterRightboxContainer">
    <div class="CenterRightbox">
      <div class="ccenter">
        <div class="cheader">
          <!-- 顶部按钮 -->
          <BtnsTop
            title="外汇即期"
            @handleQuickSearch="handleQuickSearch"
            @handleattachmentVisible="handleattachmentVisible"
            @handleModal="handleModal_ForexSpot"
          />
          <div class="publicFormbox">
            <publicForm
              ref="publicForm"
              :form-arr="zdArr"
              :form-data="formData"
            />
          </div>
        </div>
        <!-- 底部按钮 -->
        <BtnsBottom
          @handleclearForm="handleclearForm_ForexSpot"
          @handlePreSubmit="handlePreSubmit"
        />
      </div>
      <div class="cright">
        <CRight
          :value="handleType"
          @handleModal="handleModal_ForexSpot"
        />
      </div>
    </div>

    <!-- 要复制交易 弹窗 -->
    <QuickSearch
      :value="quickSearchVisible"
      @closeQuickSearch="handleCloseQuickSearch"
      @dblclick="handleQuickSearchdblclick_ForexSpot"
    />

    <!-- 附件管理 弹窗 -->
    <Attachment
      :value="attachmentVisible"
      @closeAttachment="handleCloseAttachment"
      @dblclick="handleAttachmentdblclick_ForexSpot"
    />
  </div>
</template>

<script>
import publicForm from '@/components/formLinkage';
import CRight from '../lineRight/index.vue';
import QuickSearch from '../component/quickSearch.vue';
import Attachment from '../component/attachment';
import BtnsTop from '../component/btnsTop.vue';
import BtnsBottom from '../component/btnsBottom.vue';
import fieldMixin from './fieldMixin';
import './index.scss';

export default {
  components: {
    publicForm,
    CRight,
    QuickSearch,
    Attachment,
    BtnsTop,
    BtnsBottom,
  },
  mixins: [fieldMixin],
  data() {
    return {
      zdArr: [
        {
          title: '交易信息',
          formArr: [
            {
              type: 'select',
              prop: 'underlying',
              attrs: {
                label: '货币对',
                needStar: true,
              },
              options: [],
              rules: { required: true },
              events: {
                change: (e) => {
                  this.setccy1ccy2_ForexSpot(e);

                  // 获取即期汇率
                  const data = { pairCode: e };
                  this.$apis.getdcsPairInfo(data).then((res) => {
                    const result = res.data.result;
                    this.formData.spotRate = result.spotRate;
                    this.formData.quotationUnit = result.quotationUnit;
                    this.formData.noDecimal1 = result.noDecimal1;
                    this.formData.noDecimal2 = result.noDecimal2;

                    if (this.formData.amount1) {
                      this.getamount2_ForexSpot();
                    }
                  });

                  // 获取起息日
                  const data2 = {
                    tradeDate: this.formData.tradeDate,
                    code: this.formData.underlying,
                    type: 'PAIR',
                  };
                  this.$apis.getdcsValueDate(data2).then((res) => {
                    this.formData.maturityDate = res.data.result.toString();
                  });
                },
              },
            },
            {
              type: 'inputFinance',
              prop: 'amount1',
              attrs: {
                label: `金额()`,
                needStar: true,
                precision: 2,
              },
              rules: { required: true },
              events: {
                focus: () => {
                  if (
                    this.formData.amount2 &&
                    !this.formData.amount1 &&
                    this.formData.spotRate
                  ) {
                    this.getamount1_ForexSpot();
                  }
                },
                blur: () => {
                  if (this.formData.amount1 && this.formData.spotRate) {
                    this.getamount2_ForexSpot();
                  }
                },
              },
            },
            {
              type: 'input',
              prop: 'spotRate',
              attrs: {
                label: '即期汇率',
                needStar: true,
              },
              options: [],
              rules: { required: true },
              events: {
                blur: () => {
                  if (this.formData.amount1 && this.formData.spotRate) {
                    this.getamount2_ForexSpot();
                  }
                },
              },
            },
            {
              type: 'inputFinance',
              prop: 'amount2',
              attrs: {
                label: `金额()`,
                needStar: true,
                precision: 2,
              },
              rules: { required: true },
              events: {
                focus: () => {
                  if (
                    this.formData.amount1 &&
                    !this.formData.amount2 &&
                    this.formData.spotRate
                  ) {
                    this.getamount2_ForexSpot();
                  }
                },
                blur: () => {
                  if (this.formData.amount2 && this.formData.spotRate) {
                    this.getamount1_ForexSpot();
                  }
                },
              },
            },
            {
              type: 'pickerDateSingle',
              prop: 'tradeDate',
              span: 16,
              attrs: {
                label: '交易日期',
                needStar: true,
              },
              rules: { required: true },
            },
            {
              type: 'pickerTimeHHMM',
              prop: 'tradeTime',
              span: 8,
              attrs: {},
              rules: { required: true },
            },
            {
              type: 'pickerDateSingle',
              prop: 'maturityDate',
              attrs: {
                label: '起息日',
                needStar: true,
              },
              rules: { required: true },
            },
          ],
        },
        {
          title: '交易账户',
          formArr: [
            {
              type: 'select',
              prop: 'folder',
              span: 16,
              attrs: {
                label: '账户',
                needStar: true,
                showValueName: 'name',
              },
              rules: { required: true },
              options: [],
              events: {
                focus: () => {
                  const data = {
                    q: '',
                    'queryParam.menuId': '',
                    'queryParam.productConfigGrp': '',
                  };
                  this.$apis.queryFolderQueryAuthList(data).then((res) => {
                    this.zdArr[1].formArr[0].options = res.data.result.map(
                      (item) => {
                        return {
                          label: item.code,
                          value: item.code,
                          name: item.localName,
                        };
                      },
                    );
                  });
                },
                change: (e) => {
                  const arr = this.zdArr[1].formArr[0].options.filter(
                    (item) => {
                      return item.value === e;
                    },
                  );
                  this.formData.folderName = arr[0].name;
                },
              },
            },
            {
              type: 'input',
              prop: 'folderName',
              span: 8,
              attrs: {
                disabled: true,
                placeHolder: '',
              },
            },
            {
              type: 'select',
              prop: 'cpty',
              span: 16,
              attrs: {
                label: '交易对手',
                needStar: true,
              },
              rules: { required: true },
              options: [],
              events: {
                focus: () => {
                  const data = {
                    isInternalTrade: 'N',
                    'queryParam.pageCtrl': 'true',
                    'queryParam.pageLimit': '100',
                    limitResultSet: 'true',
                    menuId: '',
                    productConfigGrp: '',
                    excludeBranch: 'N',
                    'queryParam.pageStart': '1',
                    scrollFlag: '0',
                    startDate: '',
                    q: '',
                  };
                  this.$apis.queryCptyPage(data).then((res) => {
                    this.zdArr[1].formArr[2].options =
                      res.data.result.datals.map((item) => {
                        return {
                          label: item.code,
                          value: item.code,
                          name: item.localName,
                        };
                      });
                  });
                },
                change: (e) => {
                  const arr = this.zdArr[1].formArr[2].options.filter(
                    (item) => {
                      return item.value === e;
                    },
                  );
                  this.formData.cptyName = arr[0].name;
                },
              },
            },
            {
              type: 'input',
              prop: 'cptyName',
              span: 8,
              attrs: {
                disabled: true,
                placeHolder: '',
              },
            },
          ],
        },
        {
          title: '备注',
          formArr: [
            {
              type: 'select',
              prop: 'dealFlag',
              attrs: {
                label: '交易性质',
                needStar: true,
              },
              rules: { required: true },
              options: [],
            },
            {
              type: 'input',
              prop: 'blockNo',
              span: 16,
              attrs: {
                label: '外部流水号',
              },
              options: [],
            },
            {
              type: 'select',
              prop: 'sourceName',
              span: 8,
              options: [],
            },
            {
              type: 'pickerDateSingle',
              prop: 'transactionDate',
              span: 16,
              attrs: {
                label: '交易成交日期',
              },
            },
            {
              type: 'pickerTimeHHMM',
              prop: 'transactionTime',
              span: 8,
            },
            {
              type: 'select',
              prop: 'tacount',
              attrs: {
                label: '项目',
              },
              options: [],
            },
            {
              type: 'select',
              prop: 'tpurpose',
              attrs: {
                label: '交易背景',
              },
              options: [],
            },
            {
              type: 'input',
              prop: 'ext20',
              attrs: {
                label: '交易目的',
              },
              options: [],
            },
            {
              type: 'input',
              prop: 'comments',
              attrs: {
                label: '备注',
              },
              options: [],
            },
          ],
        },
        {
          title: '拓展字段',
          formArr: [
            {
              type: 'select',
              prop: 'ssiCodeOurBuyCcy1',
              attrs: {
                label: `我方收结算路径()`,
              },
              options: [],
              events: {
                focus: () => {
                  const data = {
                    queryId: 'stb.baseQuery.queryAllSsiInfo',
                    'queryParam.pageCtrl': false,
                    'queryParam.isAllCurrenciesCode': 'N',
                    'queryParam.dealsId': 'NULL',
                    'queryParam.sitesCode': 'BANKZB',
                    'queryParam.tradeDate': this.formData.tradeDate,
                    'queryParam.cptyCode': '',
                    'queryParam.instrumentGrpCode': 'FXSPOT',
                    'queryParam.nostroVostro': 'NOSTRO',
                    'queryParam.payDirection': 'REV',
                    'queryParam.currenciesCode': '',
                    'queryParam.deliveryMode': '0',
                    'queryParam.clrMode': '',
                  };
                  this.$apis.querySettle(data).then((res) => {
                    this.zdArr[3].formArr[0].options =
                      res.data.result.datals.map((item) => {
                        return {
                          label: item.ssiName,
                          value: item.ssiCode,
                        };
                      });
                  });
                },
              },
            },
            {
              type: 'select',
              prop: 'ssiCodeCptyBuyCcy1',
              attrs: {
                label: `对手方收结算路径()`,
              },
              options: [],
              events: {
                focus: () => {
                  const data = {
                    queryId: 'stb.baseQuery.queryAllSsiInfo',
                    'queryParam.pageCtrl': false,
                    'queryParam.isAllCurrenciesCode': 'N',
                    'queryParam.dealsId': 'NULL',
                    'queryParam.sitesCode': 'BANKZB',
                    'queryParam.tradeDate': this.formData.tradeDate,
                    'queryParam.cptyCode': '',
                    'queryParam.instrumentGrpCode': 'FXSPOT',
                    'queryParam.nostroVostro': 'VOSTRO',
                    'queryParam.payDirection': 'REV',
                    'queryParam.currenciesCode': '',
                    'queryParam.deliveryMode': '0',
                    'queryParam.clrMode': '',
                  };
                  this.$apis.querySettle(data).then((res) => {
                    this.zdArr[3].formArr[1].options =
                      res.data.result.datals.map((item) => {
                        return {
                          label: item.ssiName,
                          value: item.ssiCode,
                        };
                      });
                  });
                },
              },
            },
            {
              type: 'select',
              prop: 'ssiCodeOurSellCcy2',
              attrs: {
                label: `我方付结算路径(${this.ccy2 ? this.ccy2 : ''})`,
              },
              options: [],
              events: {
                focus: () => {
                  const data = {
                    queryId: 'stb.baseQuery.queryAllSsiInfo',
                    'queryParam.pageCtrl': false,
                    'queryParam.isAllCurrenciesCode': 'N',
                    'queryParam.dealsId': 'NULL',
                    'queryParam.sitesCode': 'BANKZB',
                    'queryParam.tradeDate': this.formData.tradeDate,
                    'queryParam.cptyCode': '',
                    'queryParam.instrumentGrpCode': 'FXSPOT',
                    'queryParam.nostroVostro': 'NOSTRO',
                    'queryParam.payDirection': 'PAY',
                    'queryParam.currenciesCode': '',
                    'queryParam.deliveryMode': '0',
                    'queryParam.clrMode': '',
                  };
                  this.$apis.querySettle(data).then((res) => {
                    this.zdArr[3].formArr[2].options =
                      res.data.result.datals.map((item) => {
                        return {
                          label: item.ssiName,
                          value: item.ssiCode,
                        };
                      });
                  });
                },
              },
            },
            {
              type: 'select',
              prop: 'ssiCodeCptySellCcy2',
              attrs: {
                label: `对手方付结算路径()`,
              },
              options: [],
              events: {
                focus: () => {
                  const data = {
                    queryId: 'stb.baseQuery.queryAllSsiInfo',
                    'queryParam.pageCtrl': false,
                    'queryParam.isAllCurrenciesCode': 'N',
                    'queryParam.dealsId': 'NULL',
                    'queryParam.sitesCode': 'BANKZB',
                    'queryParam.tradeDate': this.formData.tradeDate,
                    'queryParam.cptyCode': '',
                    'queryParam.instrumentGrpCode': 'FXSPOT',
                    'queryParam.nostroVostro': 'VOSTRO',
                    'queryParam.payDirection': 'PAY',
                    'queryParam.currenciesCode': '',
                    'queryParam.deliveryMode': '0',
                    'queryParam.clrMode': '',
                  };
                  this.$apis.querySettle(data).then((res) => {
                    this.zdArr[3].formArr[3].options =
                      res.data.result.datals.map((item) => {
                        return {
                          label: item.ssiName,
                          value: item.ssiCode,
                        };
                      });
                  });
                },
              },
            },
            {
              type: 'select',
              prop: 'ext1',
              attrs: {
                label: '货币1账户行',
              },
              options: [],
            },
            {
              type: 'select',
              prop: 'ext2',
              attrs: {
                label: '货币2账户行',
              },
              options: [],
            },
            {
              type: 'select',
              prop: 'settlementMode',
              attrs: {
                label: '清算方式',
              },
              options: [],
            },
            {
              type: 'input',
              prop: 'ext4',
              attrs: {
                label: '业务员',
              },
              options: [],
            },
          ],
        },
      ],
      // 默认值
      formData: {
        tradeDate: '',
        tradeTime: '',
        transactionDate: '',
        transactionTime: '',
        maturityDate: '',
        folderName: '',
        cptyName: '',
        spotRate: '',
        quotationUnit: 0, // 10的n次方
        noDecimal1: '', // 两个精度参数
        noDecimal2: '',
        amount1: '',
        amount2: '',
        dealFlag: 'INTERBANK',
        sourceName: 'RCS',
      },
      ccy1: '',
      ccy2: '',
      quickSearchVisible: false,
      attachmentVisible: false,
      handleType: '',
    };
  },
  mounted() {
    this.getOptions_ForexSpot();
    this.getSystemDate_ForexSpot();
  },
  methods: {

  },
};
</script>

