giveAsPresent.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <view class="container">
  3. <view class="list flex_r flex_ac flex_jb mar_t16">
  4. <view class="list_name">赠送类型:</view>
  5. <view class="list_text">
  6. <div class="option-i" @click="value = 1">
  7. <img src="@/static/img/xuanzhong_icon.png" v-if="value === 1" class="ico" alt="" />
  8. <img src="@/static/img/weixuanzhong_icon.png" v-else class="ico" alt="" />
  9. <span class="txt">茶宝</span>
  10. </div>
  11. <div class="option-i" @click="value = 0">
  12. <img src="@/static/img/xuanzhong_icon.png" v-if="value === 0" class="ico" alt="" />
  13. <img src="@/static/img/weixuanzhong_icon.png" v-else class="ico" alt="" />
  14. <span class="txt">余额</span>
  15. </div>
  16. </view>
  17. </view>
  18. <view class="list flex_r flex_ac flex_jb mar_t16" v-if="value == 0">
  19. <view class="list_name">当前余额:</view>
  20. <view class="list_text"><text>{{ userinfo.user_money }}</text></view>
  21. </view>
  22. <view class="list flex_r flex_ac flex_jb mar_t16" v-else>
  23. <view class="list_name">当前茶宝:</view>
  24. <view class="list_text"><text>{{ userinfo.cha_bao }}</text></view>
  25. </view>
  26. <view class="list flex_r flex_ac flex_jb mar_t16">
  27. <view class="list_name">对方账号:</view>
  28. <view class="list_text">
  29. <input type="text" v-model="id" placeholder="输入对方账号" placeholder-style="color:#ddd;" />
  30. </view>
  31. </view>
  32. <view class="list flex_r flex_ac flex_jb mar_t16">
  33. <view class="list_name">赠送数量:</view>
  34. <view class="list_text">
  35. <input type="text" v-model="give_num" placeholder="自定义赠送数量" placeholder-style="color:#ddd;" />
  36. </view>
  37. </view>
  38. <view class="list flex_r flex_ac flex_jb mar_t16">
  39. <view class="list_name">手续费:</view>
  40. <view class="list_text">{{ list[value].fee * 100 }}%</view>
  41. </view>
  42. <view class="tips">{{ list[value].tips }}</view>
  43. <view class="btn flex_r flex_ac flex_jc" @tap="give">立即赠送</view>
  44. </view>
  45. </template>
  46. <script>
  47. let page = 1;
  48. let app = getApp();
  49. var appEv = app.$vm.$options;
  50. import { post } from "@/request/api.js";
  51. export default {
  52. data() {
  53. return {
  54. id: "",
  55. give_num: "",
  56. userinfo: undefined, // 获取用户信息
  57. pickerShow: false,
  58. value: 1,
  59. list: [],
  60. };
  61. },
  62. components: {},
  63. onLoad() {
  64. this.userinfo = uni.getStorageSync("userinfo");
  65. this.getGiveList();
  66. },
  67. methods: {
  68. getGiveList() {
  69. post("v1/giveRate").then((res) => {
  70. this.list = res.data.data;
  71. });
  72. },
  73. give() {
  74. if (this.give_num == 0) {
  75. appEv.errTips("赠送数量不得为0");
  76. return;
  77. } else if (
  78. this.give_num > Number(this.userinfo.cha_bao) &&
  79. this.value == 1
  80. ) {
  81. appEv.errTips("赠送数量不得超过茶宝余额");
  82. return;
  83. } else if (
  84. this.give_num > Number(this.userinfo.user_money) &&
  85. this.value == 0
  86. ) {
  87. appEv.errTips("赠送数量不得超过余额");
  88. return;
  89. } else if (this.id == "") {
  90. appEv.errTips("请输入赠送账号");
  91. return;
  92. } else {
  93. let content = "";
  94. if (this.value == 0) {
  95. content = `你将赠送给${this.id}余额${
  96. this.give_num
  97. },扣除手续费后对方将收到${
  98. this.$h.Mul(this.give_num, (1 - this.list[this.value].fee))
  99. }余额`;
  100. } else {
  101. content = `你将赠送给${this.id}茶宝${
  102. this.give_num
  103. },扣除手续费后对方将收到${
  104. this.$h.Mul(this.give_num, (1 - this.list[this.value].fee))
  105. }茶宝`;
  106. }
  107. let that = this
  108. uni.showModal({
  109. title: "提示",
  110. content: content,
  111. showCancel: true,
  112. success: function(res) {
  113. if (res.confirm) {
  114. if (that.value == 0) {
  115. that.giveMoney();
  116. } else {
  117. that.giveIntegral();
  118. }
  119. } else {}
  120. },
  121. });
  122. }
  123. },
  124. // 赠送茶宝
  125. giveIntegral() {
  126. let data = {
  127. mobile: this.id,
  128. number: this.give_num,
  129. };
  130. post("v1/my/give", data).then((res) => {
  131. if (res.code === 0) {
  132. this.give_num = 0;
  133. this.id = "";
  134. this.getuserInfo();
  135. appEv.errTips(res.msg);
  136. } else {
  137. appEv.errTips(res.msg);
  138. }
  139. });
  140. },
  141. giveMoney() {
  142. let data = {
  143. mobile: this.id,
  144. number: this.give_num,
  145. };
  146. post("v1/my/moneyGive", data).then((res) => {
  147. if (res.code === 0) {
  148. this.give_num = 0;
  149. this.id = "";
  150. appEv.errTips(res.msg);
  151. this.getuserInfo();
  152. } else {
  153. appEv.errTips(res.msg);
  154. }
  155. });
  156. },
  157. async getuserInfo() {
  158. this.userinfo = await uni.userfun();
  159. },
  160. OnpickerShow() {
  161. this.pickerShow = !this.pickerShow;
  162. },
  163. confirm(da) {
  164. this.value = da[0]
  165. }
  166. },
  167. };
  168. </script>
  169. <style lang="scss">
  170. // 页面配置
  171. page {
  172. background: #f4f4f4;
  173. }
  174. // 页面配置-end
  175. .list {
  176. width: 100%;
  177. height: 86rpx;
  178. padding: 0 30rpx;
  179. box-sizing: border-box;
  180. background: #fff;
  181. }
  182. .list_text {
  183. flex: 1;
  184. font-family: "SourceHanSansCN-Bold";
  185. text-align: right;
  186. .iconfont {
  187. font-size: 28rpx;
  188. margin-left: 12rpx;
  189. }
  190. .option-i {
  191. display: inline-block;
  192. margin-right: 32rpx;
  193. &:last-child {
  194. margin-right: 0;
  195. }
  196. }
  197. .ico {
  198. width: 32rpx;
  199. height: 32rpx;
  200. margin-right: 6rpx;
  201. }
  202. .txt,
  203. .ico {
  204. vertical-align: middle;
  205. }
  206. }
  207. .list_name {
  208. flex: 1;
  209. color: #333333;
  210. font-size: 28rpx;
  211. font-family: "SourceHanSansCN-Medium";
  212. font-weight: 500;
  213. }
  214. .list_text input {
  215. font-size: 30rpx;
  216. color: #333;
  217. text-align: right;
  218. font-weight: bold;
  219. // margin-left: 20rpx;
  220. }
  221. .list_text text {
  222. font-family: "SourceHanSansCN-Medium";
  223. font-size: 36rpx;
  224. font-weight: bold;
  225. color: #17bb87;
  226. }
  227. .tips {
  228. margin-top: 100rpx;
  229. text-align: center;
  230. color: #999;
  231. font-size: 30rpx;
  232. }
  233. .btn {
  234. width: 689rpx;
  235. height: 92rpx;
  236. background: #17bb87;
  237. color: #fff;
  238. font-size: 42rpx;
  239. font-family: "SourceHanSansCN-Medium";
  240. font-weight: 500;
  241. margin: 20rpx auto 0;
  242. border-radius: 10rpx;
  243. }
  244. </style>