energy-transfer.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <view>
  3. <hua-page-head :pageTitle="pageTitle"></hua-page-head>
  4. <view class="container">
  5. <view class="" v-if="type == 1">
  6. <view class="int-item">
  7. <view class="tips">请输入您转让的用户ID</view>
  8. <view class="input d-flex align-items-center"><input type="text" placeholder="请输入ID"
  9. v-model="userId" @blur="fxname()" /></view>
  10. </view>
  11. <view class="int-item" v-if="nickname != ''">
  12. <view class="tips">该用户的昵称为</view>
  13. <view class="input d-flex align-items-center">{{ nickname }}</view>
  14. </view>
  15. <view class="int-item">
  16. <view class="tips">请输入您的密码</view>
  17. <view class="input d-flex align-items-center"><input type="password" placeholder="请输入密码"
  18. v-model="pwd" /></view>
  19. </view>
  20. <view class="int-item">
  21. <view class="input d-flex align-items-center">
  22. <image src="../../static/nl.png" mode="heightFix"></image>
  23. <input type="text" placeholder="请输入抵用券数量" v-model="number" />
  24. </view>
  25. </view>
  26. <button class="btn" @tap="transfer"><text>转出</text></button>
  27. </view>
  28. <view class="" v-else>
  29. <view class="number-bar">
  30. <view class="price item">
  31. <view class="num">{{ appConfig.energyprice }}</view>
  32. <view class="tit">抵用券价格</view>
  33. </view>
  34. <view class="power item">
  35. <view class="num">{{ userInfo.energy }}</view>
  36. <view class="tit">抵用券余额</view>
  37. </view>
  38. </view>
  39. <view class="int-item">
  40. <view class="tips">请输入您转让的用户ID</view>
  41. <view class="input d-flex align-items-center"><input type="text" placeholder="请输入ID"
  42. v-model="userId" @blur="fxname()" /></view>
  43. </view>
  44. <view class="int-item" v-if="nickname != ''">
  45. <view class="tips">该用户的昵称为</view>
  46. <view class="input d-flex align-items-center">{{ nickname }}</view>
  47. </view>
  48. <view class="int-item">
  49. <view class="tips">请输入您的密码</view>
  50. <view class="input d-flex align-items-center"><input type="password" placeholder="请输入密码"
  51. v-model="pwd" /></view>
  52. </view>
  53. <view class="int-item">
  54. <view class="tips">请输入让利金额</view>
  55. <view class="input d-flex align-items-center"><input type="text" placeholder="请输入让利金额"
  56. v-model="price" @input="changeInt" /></view>
  57. <view class="price-tips">
  58. 折合抵用券:
  59. <text class="num">{{ eNumber ? eNumber.toFixed(6) : 0 }}</text>
  60. </view>
  61. </view>
  62. <button class="btn" @tap="kTransfer"><text>馈赠</text></button>
  63. </view>
  64. </view>
  65. </view>
  66. </template>
  67. <script>
  68. import {
  69. transferEnergy,
  70. giftEnergy
  71. } from '@/api/shop.js';
  72. import {
  73. nickname
  74. } from '@/api/user.js';
  75. import {
  76. mapGetters,
  77. mapActions
  78. } from 'vuex';
  79. export default {
  80. data() {
  81. return {
  82. pageTitle: '抵用券转让',
  83. userId: '',
  84. number: '',
  85. type: null,
  86. price: '',
  87. eNumber: '',
  88. pwd: '',
  89. nickname: ''
  90. };
  91. },
  92. onLoad(option) {
  93. console.log(option);
  94. this.type = option.type;
  95. if (this.type == 1) {
  96. this.pageTitle = '抵用券转让';
  97. } else {
  98. this.pageTitle = '抵用券馈赠';
  99. }
  100. },
  101. methods: {
  102. async transfer() {
  103. const obj = this;
  104. let num = this.number;
  105. if (this.userId == '') {
  106. uni.showToast({
  107. title: '请输入用户ID',
  108. icon: 'none'
  109. });
  110. return;
  111. }
  112. if (this.pwd == '') {
  113. uni.showToast({
  114. title: '请输入密码',
  115. icon: 'none'
  116. });
  117. return;
  118. }
  119. if (num == '') {
  120. uni.showToast({
  121. title: '请输入抵用券数量',
  122. icon: 'none'
  123. });
  124. return;
  125. }
  126. // if (this.userInfo.is_energy == 0) {
  127. // uni.showToast({
  128. // title: '请先激活抵用券',
  129. // icon: 'none'
  130. // });
  131. // } else {
  132. uni.showModal({
  133. title: '提示',
  134. cancelText: '取消',
  135. confirmText: '确定',
  136. content: '确定要将' + num + '个抵用券转出?',
  137. success: res => {
  138. if (res.confirm) {
  139. transferEnergy({
  140. uid: this.userId,
  141. num: num,
  142. password: obj.password
  143. }).then(res => {
  144. console.log(res);
  145. uni.showToast({
  146. title: res.msg,
  147. icon: 'none'
  148. });
  149. });
  150. } else if (res.cancel) {
  151. console.log('用户点击取消');
  152. }
  153. }
  154. });
  155. // }
  156. },
  157. changeInt(e) {
  158. console.log(e.detail.value);
  159. this.eNumber = e.detail.value / this.appConfig.energyprice;
  160. },
  161. fxname() {
  162. nickname({
  163. sn: this.userId
  164. }).then(e => {
  165. console.log(e.data.nickname);
  166. this.nickname = e.data.nickname;
  167. });
  168. },
  169. async kTransfer() {
  170. const obj = this;
  171. let num = this.eNumber.toFixed(6);
  172. let total = parseFloat(this.userInfo.energy);
  173. console.log(num, total);
  174. if (this.userId == '') {
  175. uni.showToast({
  176. title: '请输入用户ID',
  177. icon: 'none'
  178. });
  179. return;
  180. }
  181. if (this.pwd == '') {
  182. uni.showToast({
  183. title: '请输入密码',
  184. icon: 'none'
  185. });
  186. return;
  187. }
  188. if (this.price == '') {
  189. uni.showToast({
  190. title: '请输入让利金额',
  191. icon: 'none'
  192. });
  193. return;
  194. }
  195. if (this.userInfo.is_energy == 0) {
  196. uni.showToast({
  197. title: '请先激活抵用券',
  198. icon: 'none'
  199. });
  200. return;
  201. }
  202. if (num > total) {
  203. uni.showToast({
  204. title: '抵用券余额不足',
  205. icon: 'none'
  206. });
  207. return;
  208. }
  209. uni.showModal({
  210. title: '提示',
  211. cancelText: '取消',
  212. confirmText: '确定',
  213. content: '确定要将' + num + '个抵用券馈赠?',
  214. success: res => {
  215. if (res.confirm) {
  216. console.log(obj.pwd, '密码');
  217. giftEnergy({
  218. gift_user_sn: this.userId,
  219. gift_energy_number: num,
  220. password: obj.pwd
  221. }).then(res => {
  222. console.log(res);
  223. uni.showToast({
  224. title: res.msg,
  225. icon: 'none'
  226. });
  227. });
  228. } else if (res.cancel) {
  229. console.log('用户点击取消');
  230. }
  231. }
  232. });
  233. }
  234. },
  235. computed: {
  236. ...mapGetters(['userInfo', 'appConfig'])
  237. }
  238. };
  239. </script>
  240. <style lang="scss">
  241. .container {
  242. padding: 0 24rpx;
  243. height: calc(100vh - var(--status-bar-height));
  244. }
  245. .int-item {
  246. box-sizing: border-box;
  247. margin: 40rpx auto;
  248. .tips {
  249. font-size: 24rpx;
  250. color: #616161;
  251. margin-bottom: 10rpx;
  252. }
  253. .input {
  254. padding: 0 24rpx;
  255. height: 80rpx;
  256. background-color: #fff;
  257. border-radius: 20rpx;
  258. image {
  259. height: 32rpx;
  260. margin-right: 20rpx;
  261. }
  262. input {
  263. flex: 1;
  264. }
  265. }
  266. }
  267. .btn {
  268. background: #f73e33;
  269. border-radius: 50rpx;
  270. color: #fff;
  271. }
  272. .number-bar {
  273. display: flex;
  274. justify-content: space-between;
  275. align-items: center;
  276. .item {
  277. flex-basis: 100%;
  278. text-align: center;
  279. .num {
  280. font-weight: bold;
  281. font-size: 36rpx;
  282. line-height: 60rpx;
  283. }
  284. .tit {
  285. color: #999;
  286. }
  287. }
  288. }
  289. .price-tips {
  290. line-height: 60rpx;
  291. text {
  292. color: #f73e33;
  293. font-weight: bold;
  294. }
  295. }
  296. </style>