openPammManager.vue 8.1 KB

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