<template>
  <!-- 交易账号通用详情-->
  <Des :list="desList"></Des>
</template>

<script lang="ts">
import { defineComponent, PropType, watchEffect } from 'vue';
import { ErmcpLoginUserEx, ErmcpTaAccount, ErmcpTaAccountEx } from '@/services/go/ermcp/account/interface';
import { Des, handleDesList } from '@/common/components/commonDes';
import { isPingAnOem } from '@/common/config/projectName';

export default defineComponent({
  name: 'futures-comom-detail',
  components: {
    Des,
  },
  props: {
    selectedData: {
      type: Object as PropType<ErmcpTaAccount>,
      default: {},
    },
    firstSelectedData: {
      default: {},
      type: Object as PropType<ErmcpTaAccountEx>,
    },
    userList: {
      type: Array as PropType<ErmcpLoginUserEx[]>,
      default: [],
    },
  },
  setup(props) {
    const { desList, getDesList } = handleDesList();
    function getRoleName() {
      const item = props.userList.find((e) => e.roleid === props.selectedData?.relateduserid);
      return item ? item.rolename : '--';
    }
    watchEffect(() => {
      if (props.selectedData) {
        const { firstSelectedData, selectedData } = props;
        const data = props.selectedData;
        let list = [];
        if (isPingAnOem()) {
          list = [
            { label: '所属期货账户', value: firstSelectedData.mainAcc?.accountname },
            { label: '账户名称', value: selectedData.accountname },
            { label: '期货保证金', value: selectedData.trademargintmpname },
            { label: '期货手续费', value: selectedData.tradefeetmpname },
          ];
        } else {
          list = [
            { label: '所属期货账户', value: firstSelectedData.mainAcc?.accountname },
            { label: '账户名称', value: selectedData.accountname },
            { label: '期货保证金', value: selectedData.trademargintmpname },
            { label: '期货手续费', value: selectedData.tradefeetmpname },
            { label: '指定交易用户', value: getRoleName() },
          ];
        }
        getDesList(list);
      }
    });
    return {
      desList,
    };
  },
});
</script>
