openPammManager.vue 8.2 KB

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