openPammManager.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <cwg-page-wrapper class="create-page" :isHeaderFixed="true">
  3. <cwg-header :title="t('Ib.PammManager.title')">
  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">
  12. <view class="box">
  13. <view class="tit"></view>
  14. <view class="des">{{ t('Ib.PammManager.tips4') }}</view>
  15. <view class="b-card">
  16. <uni-forms ref="formRef" label-width="120" :model="params" :rules="rules" label-position="top">
  17. <uni-row :gutter="20">
  18. <uni-col :xs="24" :sm="12">
  19. <uni-forms-item :label="t('Ib.PammManager.accountId')" name="accountId" required>
  20. <cwg-combox v-model:value="params.accountId" :options="accountIdOptions"
  21. :placeholder="t('placeholder.choose')" />
  22. </uni-forms-item>
  23. </uni-col>
  24. <uni-col :xs="24" :sm="12">
  25. <uni-forms-item :label="t('Ib.PammManager.ownerId')" name="ownerId" required>
  26. <cwg-combox v-model:value="params.ownerId" :options="ownerIdOptions"
  27. :placeholder="t('placeholder.choose')" />
  28. </uni-forms-item>
  29. </uni-col>
  30. <uni-col :xs="24" :sm="12">
  31. <uni-forms-item :label="t('Ib.PammManager.percent')" name="percent" required>
  32. <uni-easyinput v-model.trim="params.percent" :placeholder="t('placeholder.input')" />
  33. </uni-forms-item>
  34. </uni-col>
  35. <uni-col :span="24">
  36. <button class="s-btn" type="primary" @click="newAccount">{{ t('Ib.PammManager.btn') }}</button>
  37. </uni-col>
  38. </uni-row>
  39. </uni-forms>
  40. </view>
  41. </view>
  42. <view class="box">
  43. <view style="margin: 10px 0; font-size: 14px; line-height: 1.5;">
  44. <view style="margin-bottom: 5px;">{{ t('Ib.PammManager.tips2') }}</view>
  45. </view>
  46. </view>
  47. </view>
  48. <!-- 提交结果弹窗 -->
  49. <cwg-popup :visible="dialogCheck" :showClose="false" :showFooters="true" :confirmText="t('Btn.Confirm')"
  50. :cancelText="t('Btn.Cancel')" @confirm="handleDialogAction" @close="handleDialogAction">
  51. <view class="result-dialog">
  52. <view v-if="dialogVisible" class="icon-wrap">
  53. <cwg-icon name="icon_success" :size="50" color="#67C23A" />
  54. <view class="result-text">{{ t('ApplicationDialog.Des1') }}</view>
  55. <view class="result-sub-text">{{ t('ApplicationDialog.Des12') }}</view>
  56. </view>
  57. <view v-else class="icon-wrap">
  58. <cwg-icon name="icon_warning" :size="50" color="#E6A23C" />
  59. <view class="result-text">{{ t('ApplicationDialog.Des43') }}</view>
  60. <view class="result-text" style="color: #e6a23c; margin: 10px 0;">{{ RES }}</view>
  61. <view class="result-sub-text">{{ t('ApplicationDialog.Des45') }}</view>
  62. </view>
  63. </view>
  64. </cwg-popup>
  65. </cwg-page-wrapper>
  66. </template>
  67. <script setup lang="ts">
  68. import { ref, reactive, computed, onMounted } from 'vue'
  69. import { onLoad } from '@dcloudio/uni-app'
  70. import { useI18n } from 'vue-i18n'
  71. import { ibApi } from '@/service/ib'
  72. import Config from '@/config/index'
  73. const { t } = useI18n()
  74. const { Code } = Config
  75. const pictLoading = ref(false)
  76. const showData = ref<any[]>([])
  77. const flag = ref(false)
  78. const RES = ref('')
  79. const dialogCheck = ref(false)
  80. const dialogVisible = ref(false)
  81. const formRef = ref()
  82. const params = reactive({
  83. type: null as number | null,
  84. ownerId: null as string | null,
  85. accountId: null as string | null,
  86. percent: '',
  87. })
  88. // 验证规则
  89. const rules = {
  90. ownerId: { rules: [{ required: true, errorMessage: t('vaildate.select.empty') }] },
  91. accountId: { rules: [{ required: true, errorMessage: t('vaildate.select.empty') }] },
  92. percent: {
  93. rules: [
  94. { required: true, errorMessage: t('vaildate.input.empty') },
  95. {
  96. validateFunction: (rule: any, value: any, data: any, callback: any) => {
  97. if (!value && value !== 0) {
  98. callback(t('vaildate.input.empty'))
  99. } else if (!/^[0-9]+([.]{1}[0-9]{1,2})?$/.test(String(value))) {
  100. callback('0.00-100.00')
  101. } else {
  102. return true
  103. }
  104. }
  105. }
  106. ]
  107. },
  108. }
  109. // 动态计算下拉选项 (处理 disabled 逻辑)
  110. const accountIdOptions = computed(() => {
  111. return showData.value.map(item => {
  112. // disabled="(item.login == params.ownerId) || item.equity!=0"
  113. const isDisabled = (item.login === params.ownerId) || (Number(item.equity) !== 0)
  114. return {
  115. text: item.login,
  116. value: item.login,
  117. disable: isDisabled
  118. }
  119. })
  120. })
  121. const ownerIdOptions = computed(() => {
  122. return showData.value.map(item => {
  123. // disabled="item.login == params.accountId"
  124. const isDisabled = item.login === params.accountId
  125. return {
  126. text: item.login,
  127. value: item.login,
  128. disable: isDisabled
  129. }
  130. })
  131. })
  132. // 获取账号集合
  133. const getMustData = async () => {
  134. pictLoading.value = true
  135. try {
  136. const res = await ibApi.mamApplyPammManagerLogins({})
  137. if (res.code === Code.StatusOK) {
  138. showData.value = res.data || []
  139. } else {
  140. uni.showToast({ title: res.msg, icon: 'none' })
  141. }
  142. } finally {
  143. pictLoading.value = false
  144. }
  145. }
  146. // 提交申请
  147. const newAccount = async () => {
  148. try {
  149. await formRef.value?.validate()
  150. } catch (error) {
  151. return
  152. }
  153. if (flag.value) return
  154. flag.value = true
  155. try {
  156. const res = await ibApi.mamApplyPammManagerAdd({ ...params })
  157. if (res.code === Code.StatusOK) {
  158. dialogCheck.value = true
  159. dialogVisible.value = true
  160. } else {
  161. RES.value = res.msg
  162. dialogCheck.value = true
  163. dialogVisible.value = false
  164. }
  165. } catch (err) {
  166. RES.value = t('Msg.Fail')
  167. dialogCheck.value = true
  168. dialogVisible.value = false
  169. } finally {
  170. flag.value = false
  171. }
  172. }
  173. // 关闭弹窗
  174. const closeDia = () => {
  175. formRef.value?.clearValidate()
  176. dialogCheck.value = false
  177. dialogVisible.value = false
  178. }
  179. // 成功后返回
  180. const backIndex = () => {
  181. formRef.value?.clearValidate()
  182. dialogCheck.value = false
  183. dialogVisible.value = false
  184. uni.navigateBack({ delta: 1 })
  185. }
  186. // 统一处理弹窗操作
  187. const handleDialogAction = () => {
  188. if (dialogVisible.value) {
  189. backIndex()
  190. } else {
  191. closeDia()
  192. }
  193. }
  194. onLoad((options: any) => {
  195. if (options && options.type) {
  196. params.type = Number(options.type)
  197. } else {
  198. params.type = 1
  199. }
  200. getMustData()
  201. })
  202. </script>
  203. <style lang="scss" scoped>
  204. @import "@/uni.scss";
  205. .header-btn {
  206. display: flex;
  207. align-items: center;
  208. font-size: px2rpx(14);
  209. color: var(--bs-heading-color);
  210. cursor: pointer;
  211. text {
  212. margin-left: px2rpx(5);
  213. }
  214. }
  215. .main-content {
  216. padding: px2rpx(10);
  217. min-height: calc(100vh - 100px);
  218. }
  219. .box {
  220. padding: px2rpx(10) px2rpx(20);
  221. background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
  222. border-radius: px2rpx(4);
  223. margin-bottom: px2rpx(20);
  224. .tit {
  225. display: flex;
  226. align-items: center;
  227. font-size: px2rpx(16);
  228. font-weight: bold;
  229. margin-bottom: px2rpx(10);
  230. text {
  231. margin-left: px2rpx(5);
  232. }
  233. }
  234. .des {
  235. font-size: px2rpx(14);
  236. font-weight: bold;
  237. line-height: 1.5;
  238. margin-bottom: px2rpx(20);
  239. color: var(--bs-heading-color);
  240. }
  241. }
  242. .b-card {
  243. margin-top: px2rpx(15);
  244. }
  245. .s-btn {
  246. margin-top: px2rpx(10);
  247. min-width: px2rpx(120);
  248. }
  249. .result-dialog {
  250. text-align: center;
  251. padding: px2rpx(20);
  252. .icon-wrap {
  253. margin-bottom: px2rpx(20);
  254. }
  255. .result-text {
  256. font-size: px2rpx(16);
  257. font-weight: bold;
  258. margin-top: px2rpx(20);
  259. margin-bottom: px2rpx(10);
  260. }
  261. .result-sub-text {
  262. font-size: px2rpx(12);
  263. color: var(--bs-heading-color);
  264. margin-bottom: px2rpx(20);
  265. }
  266. .dialog-footer {
  267. display: flex;
  268. justify-content: center;
  269. gap: px2rpx(15);
  270. margin-top: px2rpx(30);
  271. button {
  272. min-width: px2rpx(100);
  273. margin: 0;
  274. }
  275. }
  276. }
  277. </style>