scoreToConsumption.vue 6.7 KB

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