openAccount.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <template>
  2. <cwg-page-wrapper class="create-page" :isHeaderFixed="true">
  3. <cwg-header :title="params.type === 1 ? t('Ib.NewAccount.TitleM') : t('Ib.NewAccount.TitleP')">
  4. <template #right>
  5. <view class="header-btn" @click="backIndex">
  6. <cwg-icon name="icon_back" :size="18" />
  7. <text>{{ t('Ib.Settings.Title') }}</text>
  8. </view>
  9. </template>
  10. </cwg-header>
  11. <view class="main-content account-content" v-if="showPage">
  12. <view class="box" v-if="isAllLoginTypesHidden">
  13. <view style="margin: 20px 0; font-size: 14px; line-height: 1.7;">
  14. <text>{{ t('news_add_field.OpenAccount.Des3') }}</text>
  15. </view>
  16. </view>
  17. <view class="box" v-else>
  18. <view class="tit">
  19. <cwg-icon name="icon_arrow_right" :size="16" />
  20. <text>{{ t('Ib.NewAccount.Title1') }}</text>
  21. </view>
  22. <view class="des">{{ t('Ib.NewAccount.Des1') }}</view>
  23. <view class="b-card">
  24. <uni-forms ref="formRef" :model="params" :rules="rules" label-position="top">
  25. <uni-row :gutter="20">
  26. <uni-col :xs="24" :sm="12" :md="8">
  27. <uni-forms-item :label="t('Ib.NewAccount.Platform')" name="platform" required>
  28. <cwg-combox v-model:value="params.platform" :options="[{ text: 'MT4', value: 'MT4' }]"
  29. :placeholder="t('placeholder.choose')" />
  30. </uni-forms-item>
  31. </uni-col>
  32. <uni-col :xs="24" :sm="12" :md="8">
  33. <uni-forms-item :label="t('Ib.NewAccount.LoginType')" name="accountType" required>
  34. <cwg-combox v-model:value="params.accountType" :options="accountTypeOptions"
  35. :placeholder="t('placeholder.choose')" @change="onAccountTypeChange" />
  36. </uni-forms-item>
  37. </uni-col>
  38. <uni-col :xs="24" :sm="12" :md="8">
  39. <uni-forms-item :label="t('Ib.NewAccount.Lever')" name="leverage" required>
  40. <cwg-combox v-model:value="params.leverage" :options="formatOptions(optionsLev)"
  41. :placeholder="t('placeholder.choose')" />
  42. </uni-forms-item>
  43. </uni-col>
  44. <uni-col :xs="24" :sm="12" :md="8">
  45. <uni-forms-item :label="t('Ib.NewAccount.Currency')" name="currency" required>
  46. <cwg-combox v-model:value="params.currency" :options="formatOptions(optionsCur)"
  47. :placeholder="t('placeholder.choose')" />
  48. </uni-forms-item>
  49. </uni-col>
  50. <uni-col :xs="24" :sm="12" :md="8">
  51. <uni-forms-item :label="t('Ib.NewAccount.Commission')" name="commission" required>
  52. <cwg-combox v-model:value="params.commission" :options="formatOptions(optionsCom)"
  53. :placeholder="t('placeholder.choose')" />
  54. </uni-forms-item>
  55. </uni-col>
  56. <uni-col :span="24">
  57. <button hover-class="" class="s-btn" type="primary" @click="newAccount">{{ t('Ib.NewAccount.Btn')
  58. }}</button>
  59. </uni-col>
  60. </uni-row>
  61. </uni-forms>
  62. </view>
  63. </view>
  64. <view class="box">
  65. <view style="margin: 20px 0; font-size: 14px; line-height: 1.7;">
  66. <template v-if="params.type === 1">
  67. <view style="font-weight: bold; margin-bottom: 5px;">{{ t('Ib.NewAccount.Dec1') }}</view>
  68. <view>{{ t('Ib.NewAccount.Dec2') }}</view>
  69. </template>
  70. <template v-if="params.type === 2">
  71. <view style="font-weight: bold; margin-bottom: 5px;">{{ t('Ib.NewAccount.Dec3') }}</view>
  72. <view>{{ t('Ib.NewAccount.Dec4') }}</view>
  73. </template>
  74. </view>
  75. </view>
  76. <view class="box" v-if="params.accountType === 6">
  77. <view style="margin: 20px 0; font-size: 14px; line-height: 1.7;">
  78. <view>
  79. <text>{{ t('Ib.NewAccount.Dec5') }}</text>
  80. <text class="crm-cursor" style="color: #368FEC;" @click="openLeverageMargin">{{ t('Ib.NewAccount.Dec6')
  81. }}</text>
  82. <text>{{ t('Ib.NewAccount.Dec7') }}</text>
  83. </view>
  84. </view>
  85. </view>
  86. </view>
  87. <!-- 提交结果弹窗 -->
  88. <cwg-popup :visible="dialogCheck" :showClose="false" :showFooters="true" :confirmText="t('Btn.Confirm')"
  89. :cancelText="t('Btn.Cancel')" @confirm="closeDia" @close="closeDia">
  90. <view class="result-dialog">
  91. <view v-if="dialogVisible" class="icon-wrap">
  92. <cwg-icon name="icon_success" :size="50" color="#67C23A" />
  93. <view class="result-text">{{ t('ApplicationDialog.Des1') }}</view>
  94. <view class="result-sub-text">{{ t('ApplicationDialog.Des12') }}</view>
  95. </view>
  96. <view v-else class="icon-wrap">
  97. <cwg-icon name="icon_warning" :size="50" color="#E6A23C" />
  98. <view class="result-text">{{ RES }}</view>
  99. </view>
  100. </view>
  101. </cwg-popup>
  102. </cwg-page-wrapper>
  103. </template>
  104. <script setup lang="ts">
  105. import { ref, reactive, computed, onMounted } from 'vue'
  106. import { onLoad } from '@dcloudio/uni-app'
  107. import { useI18n } from 'vue-i18n'
  108. import { ibApi } from '@/service/ib'
  109. import { isAfterJuly28 } from '@/utils/dateUtils'
  110. import Config from '@/config/index'
  111. const { t, locale } = useI18n()
  112. const { Code } = Config
  113. const pictLoading = ref(false)
  114. const showPage = ref(false)
  115. const showLogin = ref<string[]>([])
  116. const showData = ref<any[]>([])
  117. const flag = ref(false)
  118. const RES = ref('')
  119. const dialogCheck = ref(false)
  120. const dialogVisible = ref(false)
  121. const optionsLev = ref<string[]>([])
  122. const optionsCur = ref<string[]>([])
  123. const optionsCom = ref<string[]>([])
  124. const formRef = ref()
  125. const params = reactive({
  126. type: 1,
  127. currency: '',
  128. commission: '',
  129. leverage: '',
  130. accountType: '' as string | number,
  131. platform: '',
  132. })
  133. const rules = {
  134. currency: { rules: [{ required: true, errorMessage: t('vaildate.select.empty') }] },
  135. commission: { rules: [{ required: true, errorMessage: t('vaildate.select.empty') }] },
  136. leverage: { rules: [{ required: true, errorMessage: t('vaildate.select.empty') }] },
  137. accountType: { rules: [{ required: true, errorMessage: t('vaildate.select.empty') }] },
  138. platform: { rules: [{ required: true, errorMessage: t('vaildate.select.empty') }] },
  139. }
  140. // 是否全部类型被隐藏
  141. const isAllLoginTypesHidden = computed(() => {
  142. const hiddenStr = showLogin.value.join(',')
  143. return hiddenStr.includes('1') && hiddenStr.includes('2') && hiddenStr.includes('3') &&
  144. hiddenStr.includes('6') && hiddenStr.includes('7') && hiddenStr.includes('8')
  145. })
  146. // 动态计算下拉类型选项
  147. const accountTypeOptions = computed(() => {
  148. const list = []
  149. if (!showLogin.value.includes('1')) list.push({ value: 1, text: t('AccountType.ClassicAccount') })
  150. if (!showLogin.value.includes('2')) list.push({ value: 2, text: t('AccountType.SeniorAccount') })
  151. if (!showLogin.value.includes('3') && !isAfterJuly28()) list.push({ value: 3, text: t('AccountType.AgencyAccount') })
  152. if (!showLogin.value.includes('6')) list.push({ value: 6, text: t('AccountType.SpeedAccount') })
  153. if (!showLogin.value.includes('7')) list.push({ value: 7, text: t('AccountType.StandardAccount') })
  154. if (!showLogin.value.includes('8')) list.push({ value: 8, text: t('AccountType.CentAccount') })
  155. return list
  156. })
  157. // 格式化普通数组为 combox 所需的 [{text, value}] 格式
  158. const formatOptions = (arr: string[]) => {
  159. return (arr || []).map(item => ({ text: String(item), value: item }))
  160. }
  161. // 监听账户类型切换以回填下拉框
  162. const onAccountTypeChange = (type: number) => {
  163. params.leverage = ''
  164. params.currency = ''
  165. params.commission = ''
  166. const target = showData.value.find(item => item.type == type)
  167. if (target) {
  168. optionsLev.value = target.leverage || []
  169. optionsCur.value = target.currency || []
  170. optionsCom.value = target.commission || []
  171. }
  172. }
  173. // 获取必填配置项
  174. const getMustData = async () => {
  175. const res = await ibApi.MamApplyData({})
  176. if (res.code === Code.StatusOK) {
  177. showData.value = res.data || []
  178. } else {
  179. uni.showToast({ title: res.msg, icon: 'none' })
  180. }
  181. }
  182. // 获取排除类型
  183. const getExcludeShowLogin = async () => {
  184. pictLoading.value = true
  185. try {
  186. const res = await ibApi.excludeShowLogin({})
  187. if (res.code === Code.StatusOK) {
  188. showLogin.value = res.data?.excludeShowLoginTypes || []
  189. showPage.value = true
  190. } else {
  191. uni.showToast({ title: res.msg, icon: 'none' })
  192. }
  193. } finally {
  194. pictLoading.value = false
  195. }
  196. }
  197. // 提交申请
  198. const newAccount = async () => {
  199. try {
  200. await formRef.value?.validate()
  201. } catch (error) {
  202. return
  203. }
  204. if (flag.value) return
  205. flag.value = true
  206. try {
  207. const res = await ibApi.MamApplyAdd({ ...params })
  208. if (res.code === Code.StatusOK) {
  209. dialogCheck.value = true
  210. dialogVisible.value = true
  211. } else {
  212. RES.value = res.msg
  213. dialogCheck.value = true
  214. dialogVisible.value = false
  215. }
  216. } catch (err) {
  217. RES.value = t('Msg.Fail')
  218. dialogCheck.value = true
  219. dialogVisible.value = false
  220. } finally {
  221. flag.value = false
  222. }
  223. }
  224. // 关闭弹窗
  225. const closeDia = () => {
  226. formRef.value?.clearValidate()
  227. // 也可以选择重置表单:
  228. Object.assign(params, { currency: '', commission: '', leverage: '', accountType: '', platform: '' })
  229. dialogCheck.value = false
  230. dialogVisible.value = false
  231. }
  232. const backIndex = () => {
  233. uni.navigateBack({ delta: 1 })
  234. }
  235. const openLeverageMargin = () => {
  236. const url = ['cn', 'zhHant'].includes(locale.value)
  237. ? 'https://www.cwgvu.com/cn/leveragemargin'
  238. : 'https://www.cwgvu.com/en/leveragemargin'
  239. // #ifdef H5
  240. window.open(url, '_blank')
  241. // #endif
  242. // #ifndef H5
  243. uni.showToast({ title: t('Msg.NotSupportedInApp'), icon: 'none' })
  244. // #endif
  245. }
  246. onLoad((options: any) => {
  247. if (options && options.type) {
  248. params.type = Number(options.type)
  249. } else {
  250. params.type = 1
  251. }
  252. getExcludeShowLogin()
  253. getMustData()
  254. })
  255. </script>
  256. <style lang="scss" scoped>
  257. @import "@/uni.scss";
  258. .header-btn {
  259. display: flex;
  260. align-items: center;
  261. font-size: px2rpx(14);
  262. color: var(--bs-heading-color);
  263. cursor: pointer;
  264. text {
  265. margin-left: px2rpx(5);
  266. }
  267. }
  268. .main-content {
  269. padding: px2rpx(10);
  270. min-height: calc(100vh - 100px);
  271. }
  272. .box {
  273. padding: px2rpx(15) px2rpx(20);
  274. background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
  275. border-radius: px2rpx(4);
  276. margin-bottom: px2rpx(20);
  277. .tit {
  278. display: flex;
  279. align-items: center;
  280. font-size: px2rpx(16);
  281. font-weight: bold;
  282. margin-bottom: px2rpx(10);
  283. text {
  284. margin-left: px2rpx(5);
  285. }
  286. }
  287. .des {
  288. font-size: px2rpx(14);
  289. font-weight: bold;
  290. line-height: 1.5;
  291. margin-bottom: px2rpx(20);
  292. color: var(--bs-heading-color);
  293. }
  294. }
  295. .b-card {
  296. margin-top: px2rpx(15);
  297. }
  298. .s-btn {
  299. margin-top: px2rpx(10);
  300. min-width: px2rpx(120);
  301. }
  302. .crm-cursor {
  303. cursor: pointer;
  304. text-decoration: underline;
  305. }
  306. .result-dialog {
  307. text-align: center;
  308. padding: px2rpx(20);
  309. .icon-wrap {
  310. margin-bottom: px2rpx(20);
  311. }
  312. .result-text {
  313. font-size: px2rpx(16);
  314. font-weight: bold;
  315. margin-top: px2rpx(20);
  316. margin-bottom: px2rpx(10);
  317. }
  318. .result-sub-text {
  319. font-size: px2rpx(12);
  320. color: var(--bs-heading-color);
  321. margin-bottom: px2rpx(20);
  322. }
  323. .dialog-footer {
  324. display: flex;
  325. justify-content: center;
  326. gap: px2rpx(15);
  327. margin-top: px2rpx(30);
  328. button {
  329. min-width: px2rpx(100);
  330. margin: 0;
  331. }
  332. }
  333. }
  334. </style>