scoreToConsumption.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <template>
  2. <s-layout class="set-wrap" :title="t('wallet.commission_to_points')" :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="quota" :label="t('wallet.consumption_points')" :required="true">
  7. <uni-easyinput v-model="state.model.quota" type="number"
  8. :placeholder="t('wallet.enter_transfer_amount')" :inputBorder="false" :clearable="false" @input="validateInput" />
  9. </uni-forms-item>
  10. </view>
  11. </uni-forms>
  12. <view class="ss-flex ss-row-center ss-col-center ss-m-t-30">
  13. {{t('wallet.current_commission_available')}}:<text class="text-red">{{currentQuota}}</text>
  14. <!-- <button class="ss-m-l-10 all-btn " @click="useAllPonints">全部</button> -->
  15. </view>
  16. <su-fixed bottom placeholder bg="none">
  17. <view class="footer-box ss-p-20 ss-flex">
  18. <button class="ss-rest-button btn" @tap="onSubmit">{{ t('common.confirm') }}</button>
  19. </view>
  20. </su-fixed>
  21. </s-layout>
  22. </template>
  23. <script setup>
  24. import {
  25. computed,
  26. reactive,
  27. onBeforeMount,
  28. ref,
  29. unref,
  30. watch,
  31. nextTick
  32. } from 'vue';
  33. import sheep from '@/sheep';
  34. import {
  35. clone
  36. } from 'lodash';
  37. import {
  38. onLoad
  39. } from '@dcloudio/uni-app';
  40. import {
  41. points2point
  42. } from '@/sheep/hooks/useGoods';
  43. import {
  44. email
  45. } from '@/sheep/validate/form';
  46. import AuthUtil from '@/sheep/api/member/auth';
  47. import ConsumptionApi from '@/sheep/api/distri/consumption';
  48. import {
  49. showAuthModal,
  50. } from '@/sheep/hooks/useModal';
  51. import { t } from '@/locale'
  52. const userInfo = computed(() => sheep.$store('user').userInfo);
  53. const userWallet = computed(() => sheep.$store('user').userWallet);
  54. const state = reactive({
  55. model: {
  56. quota: undefined,
  57. },
  58. rules: {
  59. quota: {
  60. rules: [{
  61. required: true,
  62. errorMessage: t('wallet.transfer_amount_cannot_be_empty'),
  63. },
  64. {
  65. validateFunction: function (rule, value, data, callback) {
  66. if (value<=0) {
  67. callback(t('wallet.transfer_amount_cannot_be_zero'));
  68. }
  69. return true;
  70. },
  71. },
  72. ],
  73. },
  74. }
  75. });
  76. const currentQuota = computed(() => points2point(userWallet.value.integralDO.currentQuota));
  77. async function validateInput(value) {
  78. // 确保输入是整数
  79. const intValue = parseInt(value);
  80. const strPoints = value.toString()
  81. const [integerPart, decimalPart] = strPoints.split('.')
  82. if (decimalPart) {
  83. nextTick(() => {
  84. state.model.quota = integerPart;
  85. });
  86. }
  87. if (intValue > parseInt(currentQuota.value)) {
  88. nextTick(() => {
  89. state.model.quota = parseInt(currentQuota.value);
  90. });
  91. } else {
  92. nextTick(() => {
  93. state.model.quota = intValue;
  94. });
  95. }
  96. }
  97. // 提交审核
  98. const FormRef = ref(null);
  99. const onSubmit = async () => {
  100. // 参数校验
  101. const validate = await unref(FormRef)
  102. .validate()
  103. .catch((error) => {
  104. console.log('error: ', error);
  105. });
  106. if (!validate) {
  107. return;
  108. }
  109. uni.showModal({
  110. title: t('setting.prompt'),
  111. content: t('wallet.commission_to_points_irreversible'),
  112. success: async function(res) {
  113. if (!res.confirm) {
  114. return;
  115. }
  116. const {
  117. data,
  118. code
  119. } = await ConsumptionApi.quotaTransition(state.model.quota);
  120. if (code === 0) {
  121. uni.showToast({
  122. title: t('wallet.conversion_successful'),
  123. icon: 'none',
  124. duration: 2000
  125. });
  126. uni.$emit('consumptionTransfersComplete');
  127. sheep.$router.redirect('/pages/user/wallet/score')
  128. }
  129. },
  130. });
  131. }
  132. const isLogin = computed(() => sheep.$store('user').isLogin);
  133. // 监听到在这个页面登陆,并刷新页面
  134. watch(
  135. () => isLogin.value,
  136. (newVal) => {
  137. if (newVal) {
  138. window.location.reload()
  139. }
  140. }, {
  141. deep: true, // 深度监听
  142. },
  143. );
  144. onLoad(async (options) => {
  145. if (!isLogin.value) {
  146. showAuthModal();
  147. }
  148. });
  149. </script>
  150. <style lang="scss" scoped>
  151. .code-btn-start {
  152. width: 158rpx;
  153. height: 56rpx;
  154. line-height: normal;
  155. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  156. border-radius: 28rpx;
  157. font-size: 26rpx;
  158. font-weight: 500;
  159. color: #fff;
  160. }
  161. .disabled {
  162. border: 1px solid #f7f7f7;
  163. }
  164. .icon {
  165. display: flex;
  166. align-items: center;
  167. margin-right: 7rpx
  168. }
  169. .icon image {
  170. width: 35rpx;
  171. height: 35rpx;
  172. }
  173. :deep() {
  174. .file-picker__progress {
  175. height: 0 !important;
  176. }
  177. .uni-list-item__content-title {
  178. font-size: 28rpx !important;
  179. color: #333333 !important;
  180. line-height: normal !important;
  181. }
  182. .uni-icons {
  183. font-size: 40rpx !important;
  184. }
  185. .is-disabled {
  186. color: #333333;
  187. }
  188. }
  189. :deep(.disabled) {
  190. opacity: 1;
  191. }
  192. .gender-name {
  193. font-size: 28rpx;
  194. font-weight: 500;
  195. line-height: normal;
  196. color: #333333;
  197. }
  198. .title-box {
  199. font-size: 28rpx;
  200. font-weight: 500;
  201. color: #666666;
  202. line-height: 100rpx;
  203. }
  204. .btn {
  205. width: 710rpx;
  206. height: 80rpx;
  207. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  208. border-radius: 40rpx;
  209. font-size: 30rpx;
  210. font-weight: 500;
  211. color: $white;
  212. }
  213. .btn-two {
  214. width: 310rpx;
  215. height: 80rpx;
  216. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  217. border-radius: 40rpx;
  218. font-size: 30rpx;
  219. font-weight: 500;
  220. color: $white;
  221. }
  222. .radio-dark {
  223. filter: grayscale(100%);
  224. filter: gray;
  225. opacity: 0.4;
  226. }
  227. .content-img {
  228. border-radius: 50%;
  229. }
  230. .header-box-content {
  231. position: relative;
  232. width: 160rpx;
  233. height: 160rpx;
  234. overflow: hidden;
  235. border-radius: 50%;
  236. }
  237. .avatar-action {
  238. position: absolute;
  239. left: 50%;
  240. transform: translateX(-50%);
  241. bottom: 0;
  242. z-index: 1;
  243. width: 160rpx;
  244. height: 46rpx;
  245. background: rgba(#000000, 0.3);
  246. .avatar-action-btn {
  247. width: 160rpx;
  248. height: 46rpx;
  249. font-weight: 500;
  250. font-size: 24rpx;
  251. color: #ffffff;
  252. }
  253. }
  254. // 绑定项
  255. .account-list {
  256. background-color: $white;
  257. height: 100rpx;
  258. padding: 0 20rpx;
  259. .list-img {
  260. width: 40rpx;
  261. height: 40rpx;
  262. margin-right: 10rpx;
  263. }
  264. .list-name {
  265. font-size: 28rpx;
  266. color: #333333;
  267. }
  268. .info {
  269. .avatar {
  270. width: 38rpx;
  271. height: 38rpx;
  272. border-radius: 50%;
  273. overflow: hidden;
  274. }
  275. .name {
  276. font-size: 28rpx;
  277. font-weight: 400;
  278. color: $dark-9;
  279. }
  280. }
  281. .bind-box {
  282. width: 100rpx;
  283. height: 50rpx;
  284. line-height: normal;
  285. display: flex;
  286. justify-content: center;
  287. align-items: center;
  288. font-size: 24rpx;
  289. .bind-btn {
  290. width: 100%;
  291. height: 100%;
  292. border-radius: 25rpx;
  293. background: #f4f4f4;
  294. color: #999999;
  295. }
  296. .relieve-btn {
  297. width: 100%;
  298. height: 100%;
  299. border-radius: 25rpx;
  300. background: var(--ui-BG-Main-opacity-1);
  301. color: var(--ui-BG-Main);
  302. }
  303. }
  304. }
  305. .list-border {
  306. font-size: 28rpx;
  307. font-weight: 400;
  308. color: #333333;
  309. border-bottom: 2rpx solid #eeeeee;
  310. }
  311. image {
  312. width: 100%;
  313. height: 100%;
  314. }
  315. </style>