consumptionTransfers.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. <template>
  2. <s-layout class="set-wrap" :title="t('wallet.积分转让')" :bgStyle="{ color: '#FFF' }">
  3. <uni-forms :model="state.model" :rules="state.rules" validateTrigger="bind" labelPosition="left" border
  4. class="form-box" labelWidth='200' ref="FormRef">
  5. <view class="bg-white ss-p-x-30">
  6. <uni-forms-item name="integralType" :label="t('wallet.转让积分类型')" :required="true">
  7. <uni-data-picker v-model="state.model.integralType"
  8. :localdata="[{ value: 1, text: t('wallet.红积分') }, { value: 2, text: t('wallet.黄积分') }, { value: 3, text: t('wallet.绿积分') }]"
  9. placeholder="请选择类型" style="width: 100%;" />
  10. </uni-forms-item>
  11. <template v-if="state.model.integralType">
  12. <uni-forms-item name="recipientUserName" :label="t('wallet.recipient')" :required="true"
  13. :error-message="state.usernameErrorMsg">
  14. <uni-easyinput v-model="state.model.recipientUserName" type="recipientUserName"
  15. :placeholder="t('wallet.enter_recipient_username')" :inputBorder="false" :clearable="false"
  16. @blur="verifyUsername">
  17. <template v-slot:right>
  18. <view v-if="state.verifyUsername" class="icon">
  19. <image style :src="sheep.$url.static('/static/images/shibai.png')" />
  20. </view>
  21. <view v-else class="icon">
  22. <image :src="sheep.$url.static('/static/images/chenggong.png')" />
  23. </view>
  24. </template>
  25. </uni-easyinput>
  26. </uni-forms-item>
  27. <uni-forms-item name="recipientUserPhone" :label="t('wallet.recipient_phone')" :required="true"
  28. :error-message="state.mobileErrorMsg">
  29. <uni-easyinput v-model="state.model.recipientUserPhone" type="number"
  30. :placeholder="t('wallet.enter_recipient_phone')" :inputBorder="false" :clearable="false"
  31. @blur="verifyPhone">
  32. <template v-slot:right>
  33. <view v-if="state.verifyMobile" class="icon">
  34. <image style :src="sheep.$url.static('/static/images/shibai.png')" />
  35. </view>
  36. <view v-else class="icon">
  37. <image :src="sheep.$url.static('/static/images/chenggong.png')" />
  38. </view>
  39. </template>
  40. </uni-easyinput>
  41. </uni-forms-item>
  42. <uni-forms-item name="consumptionPoints" :label="t('wallet.transfer_amount')" :required="true">
  43. <uni-easyinput v-model="state.model.consumptionPoints" type="number"
  44. :placeholder="t('wallet.enter_transfer_amount')" :inputBorder="false" :clearable="false"
  45. @input="validateInput" />
  46. </uni-forms-item>
  47. </template>
  48. </view>
  49. </uni-forms>
  50. <view class="ss-flex ss-row-center ss-col-center ss-m-t-30">
  51. <template v-if="state.model.integralType">
  52. {{ t('wallet.current_transferable_amount') }}<text class="text-red">{{ canUseConsumptionPoints }}</text>
  53. </template>
  54. <!-- <button class="ss-m-l-10 all-btn " @click="useAllPonints">{{t('common.all')}}</button> -->
  55. </view>
  56. <su-fixed bottom placeholder bg="none" v-if="state.model.integralType">
  57. <view class="footer-box ss-p-20 ss-flex">
  58. <button class="ss-rest-button btn" @tap="onSubmit">{{ t('common.confirm') }}</button>
  59. </view>
  60. </su-fixed>
  61. </s-layout>
  62. </template>
  63. <script setup>
  64. import {
  65. computed,
  66. reactive,
  67. onBeforeMount,
  68. ref,
  69. unref,
  70. watch,
  71. nextTick
  72. } from 'vue';
  73. import sheep from '@/sheep';
  74. import {
  75. clone
  76. } from 'lodash';
  77. import {
  78. onLoad
  79. } from '@dcloudio/uni-app';
  80. import {
  81. points2point
  82. } from '@/sheep/hooks/useGoods';
  83. import {
  84. email
  85. } from '@/sheep/validate/form';
  86. import { showInputPayPassword } from '@/sheep/hooks/useModal'
  87. import AuthUtil from '@/sheep/api/member/auth';
  88. import ConsumptionApi from '@/sheep/api/distri/consumption';
  89. import {
  90. showAuthModal,
  91. closeAuthModal,
  92. getSmsCode,
  93. getSmsTimer,
  94. showWalletModal,
  95. colseWalletModal
  96. } from '@/sheep/hooks/useModal';
  97. import { t } from '@/locale'
  98. const userInfo = computed(() => sheep.$store('user').userInfo);
  99. const userWallet = computed(() => sheep.$store('user').userWallet);
  100. const state = reactive({
  101. verifyUsername: true,
  102. verifyMobile: true,
  103. usernameErrorMsg: '',
  104. mobileErrorMsg: '',
  105. model: {
  106. recipientUserName: undefined,
  107. recipientUserId: undefined,
  108. recipientUserPhone: undefined,
  109. consumptionPoints: undefined,
  110. integralType: undefined,
  111. // smsCodeUseReqDTO: {
  112. // mobile: undefined,
  113. // scene: 11,
  114. // code: undefined
  115. // }
  116. },
  117. rules: {
  118. recipientUserName: {
  119. rules: [{
  120. required: true,
  121. errorMessage: t('wallet.recipient_cannot_be_empty'),
  122. },],
  123. },
  124. recipientUserPhone: {
  125. rules: [{
  126. required: true,
  127. errorMessage: t('wallet.recipient_phone_cannot_be_empty'),
  128. },],
  129. },
  130. "smsCodeUseReqDTO.code": {
  131. rules: [{
  132. required: true,
  133. errorMessage: t('wallet.verification_code_cannot_be_empty'),
  134. },],
  135. },
  136. consumptionPoints: {
  137. rules: [{
  138. required: true,
  139. errorMessage: t('wallet.transfer_amount_cannot_be_empty'),
  140. },
  141. {
  142. validateFunction: function (rule, value, data, callback) {
  143. if (value <= 0) {
  144. callback(t('wallet.transfer_amount_less_than_zero'));
  145. }
  146. return true;
  147. },
  148. },
  149. ],
  150. },
  151. }
  152. });
  153. const canUseConsumptionPoints = computed(() => {
  154. if (state.model.integralType == 1) {
  155. return points2point(userWallet.value.integralDO.redCurrentQuota);
  156. } else if (state.model.integralType == 2) {
  157. return points2point(userWallet.value.integralDO.yellowCurrentQuota);
  158. } else if (state.model.integralType == 3) {
  159. return points2point(userWallet.value.integralDO.greenCurrentQuota);
  160. }
  161. return 0;
  162. });
  163. let lastUsername = ref('')
  164. async function verifyUsername(e) {
  165. const username = e.detail.value;
  166. if (username == lastUsername.value) return;
  167. if (username == '') {
  168. state.verifyUsername = true
  169. return false;
  170. } else if (username === userInfo.value.username) {
  171. state.usernameErrorMsg = t('wallet.recipient_cannot_be_self')
  172. return false;
  173. }
  174. lastUsername.value = username
  175. // 提交数据
  176. const {
  177. data
  178. } = await AuthUtil.verifyUsername(username);
  179. if (data) {
  180. state.usernameErrorMsg = t('wallet.user_does_not_exist')
  181. } else {
  182. state.usernameErrorMsg = ''
  183. }
  184. state.verifyUsername = data
  185. }
  186. async function verifyPhone(e) {
  187. const phone = e.detail.value;
  188. if (phone == '' || !state.model.recipientUserName) {
  189. // 为空或者没输入用户名,不调校验
  190. state.verifyMobile = true
  191. return false;
  192. }
  193. // 提交数据
  194. const {
  195. data
  196. } = await AuthUtil.verifyPhone(state.model.recipientUserName, phone);
  197. // false就是已经有这个用户名,可以登录,true是没有,不可以登录
  198. if (!data || data.mobile !== phone) {
  199. state.mobileErrorMsg = t('wallet.username_phone_mismatch')
  200. state.verifyMobile = true
  201. } else {
  202. state.mobileErrorMsg = ''
  203. state.model.recipientUserId = data.id
  204. state.verifyMobile = false
  205. }
  206. }
  207. async function validateInput(value) {
  208. // 确保输入是整数
  209. const intValue = parseInt(value);
  210. const strPoints = value.toString()
  211. const [integerPart, decimalPart] = strPoints.split('.')
  212. if (decimalPart) {
  213. const points = parseFloat(`${integerPart}.${decimalPart.slice(0, 2)}`);
  214. // 使用 nextTick 确保 DOM 更新
  215. nextTick(() => {
  216. state.model.consumptionPoints = integerPart;
  217. });
  218. }
  219. if (intValue > parseInt(canUseConsumptionPoints.value)) {
  220. nextTick(() => {
  221. state.model.consumptionPoints = parseInt(canUseConsumptionPoints.value);
  222. });
  223. } else {
  224. nextTick(() => {
  225. state.model.consumptionPoints = intValue;
  226. });
  227. }
  228. }
  229. // 提交审核
  230. const FormRef = ref(null);
  231. const onSubmit = async () => {
  232. if (state.model.recipientUserName === userInfo.value.username) {
  233. uni.showToast({
  234. title: t('wallet.cannot_transfer_to_self'),
  235. icon: 'none',
  236. duration: 2000
  237. })
  238. return;
  239. } else if (state.verifyUsername) {
  240. return;
  241. } else if (state.verifyMobile) {
  242. return;
  243. }
  244. // 参数校验
  245. const validate = await unref(FormRef)
  246. .validate()
  247. .catch((error) => {
  248. console.log('error: ', error);
  249. });
  250. if (!validate) {
  251. return;
  252. }
  253. showInputPayPassword(async (password) => {
  254. state.model.payPassword = password
  255. const {
  256. data,
  257. code
  258. } = await ConsumptionApi.createConsumptionLog(state.model);
  259. if (code === 0) {
  260. sheep.$helper.toast(t('wallet.transfer_successful'))
  261. uni.$emit('consumptionTransfersComplete');
  262. sheep.$router.redirect('/pages/user/wallet/score')
  263. }
  264. })
  265. }
  266. const isLogin = computed(() => sheep.$store('user').isLogin);
  267. // 监听到在这个页面登陆,并刷新页面
  268. watch(
  269. () => isLogin.value,
  270. (newVal) => {
  271. if (newVal) {
  272. window.location.reload()
  273. }
  274. }, {
  275. deep: true, // 深度监听
  276. },
  277. );
  278. onLoad(async (options) => {
  279. if (!isLogin.value) {
  280. showAuthModal();
  281. }
  282. });
  283. </script>
  284. <style lang="scss" scoped>
  285. :deep(.uni-forms-item__content) {
  286. display: flex;
  287. align-items: center;
  288. flex: 1;
  289. }
  290. .code-btn-start {
  291. width: 158rpx;
  292. height: 56rpx;
  293. line-height: normal;
  294. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  295. border-radius: 28rpx;
  296. font-size: 26rpx;
  297. font-weight: 500;
  298. color: #fff;
  299. }
  300. .disabled {
  301. border: 1px solid #f7f7f7;
  302. background: gainsboro !important;
  303. }
  304. .icon {
  305. display: flex;
  306. align-items: center;
  307. margin-right: 7rpx
  308. }
  309. .icon image {
  310. width: 35rpx;
  311. height: 35rpx;
  312. }
  313. :deep() {
  314. .file-picker__progress {
  315. height: 0 !important;
  316. }
  317. .uni-list-item__content-title {
  318. font-size: 28rpx !important;
  319. color: #333333 !important;
  320. line-height: normal !important;
  321. }
  322. .uni-icons {
  323. font-size: 40rpx !important;
  324. }
  325. .is-disabled {
  326. color: #333333;
  327. }
  328. }
  329. :deep(.disabled) {
  330. opacity: 1;
  331. }
  332. .gender-name {
  333. font-size: 28rpx;
  334. font-weight: 500;
  335. line-height: normal;
  336. color: #333333;
  337. }
  338. .title-box {
  339. font-size: 28rpx;
  340. font-weight: 500;
  341. color: #666666;
  342. line-height: 100rpx;
  343. }
  344. .btn {
  345. width: 710rpx;
  346. height: 80rpx;
  347. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  348. border-radius: 40rpx;
  349. font-size: 30rpx;
  350. font-weight: 500;
  351. color: $white;
  352. }
  353. .btn-two {
  354. width: 310rpx;
  355. height: 80rpx;
  356. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  357. border-radius: 40rpx;
  358. font-size: 30rpx;
  359. font-weight: 500;
  360. color: $white;
  361. }
  362. .radio-dark {
  363. filter: grayscale(100%);
  364. filter: gray;
  365. opacity: 0.4;
  366. }
  367. .content-img {
  368. border-radius: 50%;
  369. }
  370. .header-box-content {
  371. position: relative;
  372. width: 160rpx;
  373. height: 160rpx;
  374. overflow: hidden;
  375. border-radius: 50%;
  376. }
  377. .avatar-action {
  378. position: absolute;
  379. left: 50%;
  380. transform: translateX(-50%);
  381. bottom: 0;
  382. z-index: 1;
  383. width: 160rpx;
  384. height: 46rpx;
  385. background: rgba(#000000, 0.3);
  386. .avatar-action-btn {
  387. width: 160rpx;
  388. height: 46rpx;
  389. font-weight: 500;
  390. font-size: 24rpx;
  391. color: #ffffff;
  392. }
  393. }
  394. // 绑定项
  395. .account-list {
  396. background-color: $white;
  397. height: 100rpx;
  398. padding: 0 20rpx;
  399. .list-img {
  400. width: 40rpx;
  401. height: 40rpx;
  402. margin-right: 10rpx;
  403. }
  404. .list-name {
  405. font-size: 28rpx;
  406. color: #333333;
  407. }
  408. .info {
  409. .avatar {
  410. width: 38rpx;
  411. height: 38rpx;
  412. border-radius: 50%;
  413. overflow: hidden;
  414. }
  415. .name {
  416. font-size: 28rpx;
  417. font-weight: 400;
  418. color: $dark-9;
  419. }
  420. }
  421. .bind-box {
  422. width: 100rpx;
  423. height: 50rpx;
  424. line-height: normal;
  425. display: flex;
  426. justify-content: center;
  427. align-items: center;
  428. font-size: 24rpx;
  429. .bind-btn {
  430. width: 100%;
  431. height: 100%;
  432. border-radius: 25rpx;
  433. background: #f4f4f4;
  434. color: #999999;
  435. }
  436. .relieve-btn {
  437. width: 100%;
  438. height: 100%;
  439. border-radius: 25rpx;
  440. background: var(--ui-BG-Main-opacity-1);
  441. color: var(--ui-BG-Main);
  442. }
  443. }
  444. }
  445. .list-border {
  446. font-size: 28rpx;
  447. font-weight: 400;
  448. color: #333333;
  449. border-bottom: 2rpx solid #eeeeee;
  450. }
  451. image {
  452. width: 100%;
  453. height: 100%;
  454. }
  455. </style>