import store from '@/store'
import { getPayResponse } from '@/utils/posUtils'
import softPos from '@/utils/posUtils/softPos'
import misPos from '@/utils/posUtils/misPos'
import tjzyPos from '@/utils/posUtils/tjzyPos'
import dflzPos from '@/utils/posUtils/dflzPos'
import fxsPos from '@/utils/posUtils/fxsPos'

import lbyPos_nh from '@/utils/posUtils/lbyPos_nh' // 银联
import lbyPos_yl from '@/utils/posUtils/lbyPos_yl' // 银联
import lbyPos_jh from '@/utils/posUtils/lbyPos_jh' // 建行

const Store = require('electron-store')
const localStore = new Store()
const posName = localStore.get('posName')

export default function choosePay (type, params, vue) {
  const scenicName = localStore.get('scenicName') || store.state.user.scenicName
  try {
    switch (scenicName) {
      case '西宁景区':
        if (type === 'pay') {
          return softPos('C', params, vue)
        } else {
          return softPos('R', params, vue)
        }
      case '':
      case '东方绿舟':
        return dflzPos(type === 'pay' ? 'C' : 'R', params, vue)
      case '绿博园':
        if (posName === 'nonghang') {
          return lbyPos_nh(type === 'pay' ? 'C' : 'R', params, vue)
        } else if (posName === 'yinlian') {
          return lbyPos_yl(type === 'pay' ? 'C' : 'R', params, vue)
        } else {
          return lbyPos_jh(type === 'pay' ? 'C' : 'R', params, vue)
        }
      case '天津之眼':
        if (type === 'pay') {
          return tjzyPos('C', params, vue)
        } else {
          return tjzyPos('R', params, vue)
        }
      case '伏羲山景区':
        if (type === 'pay') {
          return fxsPos('C', params, vue)
        } else {
          return fxsPos('R', params, vue)
        }
      case '狼山景区':
      case '军山景区':
        if (type === 'pay') {
          return misPos('00', params, vue)
        } else {
          return misPos('02', params, vue)
        }
    }
  } catch (e) {
    console.log(e)
  }
}

export function getPosPayChannel (res) {
  let result
  let code
  let channelMap

  const scenicName = localStore.get('scenicName') || store.state.user.scenicName

  console.log(scenicName)
  switch (scenicName) {
    case '西宁景区':
      code = getPayResponse(res, 'bankNo')
      channelMap = {
        '908': '银联扫码',
        '906': '支付宝',
        '907': '微信'
      }
      break
    case '':
    case '东方绿舟':
      code = getPayResponse(res)?.payWay
      channelMap = {
        '0': '支付宝',
        '1': '微信',
        '2': '银联钱包',
        '3': '其他'
      }
      break
    case '绿博园':
      if (posName === 'nonghang') {
        code = getPayResponse(res)?.payWay
        channelMap = {
          '0': '支付宝',
          '1': '微信',
          '2': '银联钱包',
          '3': '其他'
        }
      } else if (posName === 'yinlian') {
        code = getPayResponse(res)?.bankNo
        channelMap = {
          '0ZFB': '支付宝',
          'WXZF': '微信',
          'YLSM': '银联钱包',
          ' ': '其他'
        }
      } else {
        code = getPayResponse(res)?.tradeCode
        channelMap = {
          '0 ': '银联二维码',
          '1 ': '微信',
          '2 ': '支付宝',
          '3 ': '龙支付'
        }
      }

      break
    case '伏羲山景区':
      code = getPayResponse(res)?.tradeType
      channelMap = {
        S1: '银行卡',
        S2: '支付宝',
        S3: '微信',
        S4: '银联二维码'
      }
      break
    case '天津之眼':
      result = getPayResponse(res)
      code = result.payChannel
      channelMap = {
        'CHANNEL_UNIONPAY': '银行卡',
        'CHANNEL_UNIONCODEPAY': '银联扫码',
        'CHANNEL_ALIPAY': '支付宝',
        'CHANNEL_WEPAY': '微信'
      }
      break
    case '军山景区':
    case '狼山景区':
      result = getPayResponse(res)
      code = result.zffs
      console.log(result)
      channelMap = {
        '01': '银行卡',
        '02': '银联扫码',
        '03': '支付宝',
        '04': '微信'
      }
      break
  }
  console.log(channelMap[code] || '银行卡')
  return channelMap[code] || '银行卡'
}
