openAccount.vue 12 KB

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