<!--
  分账关系类型的封装 

  @author terrfly
  @site https://www.jeequan.com
  @date 2022/05/09 17:14
-->
<template>
  <div>
    <a-select labelInValue placeholder="分账关系类型" style="width: 100px;" @change="changeRelationType($event)">
      <a-select-option v-for="item in vdata.relationList" :key="item.value">{{ item.text }}</a-select-option>

<!--      <a-select-option key="PARTNER">合作伙伴</a-select-option>
      <a-select-option key="SERVICE_PROVIDER">服务商</a-select-option>
      <a-select-option key="STORE">门店</a-select-option>
      <a-select-option key="STAFF">员工</a-select-option>
      <a-select-option key="STORE_OWNER">店主</a-select-option>
      <a-select-option key="HEADQUARTER">总部</a-select-option>
      <a-select-option key="BRAND">品牌方</a-select-option>
      <a-select-option key="DISTRIBUTOR">分销商</a-select-option>
      <a-select-option key="USER">用户</a-select-option>
      <a-select-option key="SUPPLIER">供应商</a-select-option>
      <a-select-option key="CUSTOM">自定义</a-select-option>-->
    </a-select>
  </div>
</template>
<script lang="ts" setup>
import {reactive, onMounted, inject} from 'vue'

// 默认分账关系类型
const defaultRelationList = [{value: 'PARTNER', text: '合作伙伴'}, {value: 'SERVICE_PROVIDER', text: '服务商'}, {value: 'STORE', text: '门店'}, {value: 'STAFF', text: '员工'},
    {value: 'STORE_OWNER', text: '店主'}, {value: 'HEADQUARTER', text: '总部'}, {value: 'BRAND', text: '品牌方'}, {value: 'DISTRIBUTOR', text: '分销商'}, {value: 'USER', text: '用户'},
    {value: 'SUPPLIER', text: '供应商'}, {value:'PLAT_RED', text:'平台红包'}, {value: 'CUSTOM', text: '自定义'}]

// 收付通分账关系类型
const sftRelationList = [{value: 'SUPPLIER', text: '供应商'}, {value: 'DISTRIBUTOR', text: '分销商'}, {value: 'SERVICE_PROVIDER', text: '服务商'}, {value: 'PLATFORM', text: '平台'},
  {value: 'OTHERS', text: '其他'}]

// 河马付分账关系类型
const hmRelationList = [{value: 'PARTNER', text: '合作伙伴'}, {value: 'SERVICE_PROVIDER', text: '服务商'}, {value: 'STORE', text: '门店'}, {value: 'HEAD_QUARTERS', text: '总部'},
 {value: 'BRAND_PARTY', text: '品牌方'}, {value: 'DISTRIBUTOR', text: '分销商'}, {value: 'SUPPLIER', text: '供应商'}, {value: 'OTHER', text: '其他'}]

// 参数注入： 当前选择的数据对象信息（包含 ifCode, mchNo, appId 等参数 ）
let selectedMchAndIfcodeInfoRef : any = inject('selectedMchAndIfcodeInfo')
let selectedMchAndIfcodeInfo : any = selectedMchAndIfcodeInfoRef.value

// 定义组件的传入参数 
const props = defineProps({
    relationType: { type: String, default: '' },
    relationTypeName: { type: String, default: '' },
})

const vdata:any = reactive({
  relationList: []
})

onMounted(() => {
  vdata.relationList = []
  if (selectedMchAndIfcodeInfo.ifCode == 'sftpay') {
    vdata.relationList = sftRelationList
  }if (selectedMchAndIfcodeInfo.ifCode == 'hmpay') {
    vdata.relationList = hmRelationList
  }else {
    vdata.relationList = defaultRelationList
  }
})

// emit： 向父组件进行通讯。 
const emit = defineEmits(['update:relationType', 'update:relationTypeName'])


// 切换 账号关系
function changeRelationType (value) {
  emit('update:relationType', value.key)

  if (value.key !== 'CUSTOM') {
      emit('update:relationTypeName', value.label[0].children)

  } else {
     emit('update:relationTypeName', '')
  }
}


</script>
