scoreToConsumption.vue 7.7 KB

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