quickBuy.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <uni-popup ref="randomPop" type="bottom" class="randomPop">
  3. <view class="popup-content">
  4. <view class="popup-head">
  5. 线下认购
  6. <text class="close iconfont icon-shense" @click="closePop"></text>
  7. </view>
  8. <view class="popup-body">
  9. <view class="conditions-item input-number">
  10. <view class="conditions-item-til">请输入您想认购的碳汇数:</view>
  11. <view class="num">
  12. <input class="input" type="number" v-model="shoppingNum" placeholder="单次购买不超过1000株" placeholder-style="font-size:20rpx"/>
  13. </view>
  14. </view>
  15. <view class="conditions-item remark-wrap" >
  16. <view class="conditions-item-til">备注说明:</view>
  17. <view class="remark">
  18. <textarea class="remark-textarea" maxlength="240" v-model="remark" placeholder="请输入您对认购的碳汇产品要求" />
  19. </view>
  20. </view>
  21. <view class="amount-wrap">
  22. <view class="amount-flex-wrap">
  23. <view class="amount-til">预估金额:</view>
  24. <view class="amount">
  25. <text class="rmb">¥</text>
  26. <text class="num">{{totalMoney}}</text>
  27. </view>
  28. </view>
  29. <view class="amount-btn" @click="goCart">提交认购申请</view>
  30. </view>
  31. <view class="tip">
  32. 购买{{shoppingNum}}kg,预估金额{{totalMoney}}元,认购期3年
  33. </view>
  34. </view>
  35. </view>
  36. </uni-popup>
  37. </template>
  38. <script>
  39. import {
  40. mapMutations
  41. } from 'vuex';
  42. import {
  43. debounce
  44. } from '@/utils/util.js'
  45. import uniPopup from '@/components/uni-popup/uni-popup.vue'
  46. export default {
  47. name: 'quickBuy',
  48. components: {
  49. uniPopup,
  50. },
  51. created() {
  52. let self = this;
  53. this.shoppingNum = 1;
  54. uni.getStorage({
  55. key:'userInfo',
  56. success: function (res) {
  57. self.customerType = res.data.customerType;
  58. // console.log('userInfo',res);
  59. }
  60. });
  61. },
  62. props: {
  63. visible: {
  64. type: Boolean,
  65. default: false
  66. }
  67. },
  68. data() {
  69. return {
  70. customerType:null,
  71. shoppingNum:'',
  72. remark:'',
  73. totalMoney:0,
  74. price:3,
  75. helpPeople:[],
  76. // goodsId:'',
  77. // carbonVal:''
  78. }
  79. },
  80. methods: {
  81. ...mapMutations(['addCart']),
  82. getHelpPeople:debounce(function(num){
  83. this.helpPeople = []
  84. this.loading = true
  85. this.$api.http.get(this.config.apiBaseurl + '/carbon-h5/wap/goodsManage/getGoodsInfoByCarbonNum?carbonNum='+this.shoppingNum,{
  86. header: {
  87. Accept:'application/json',
  88. Authorization: 'Bearer '+ this.token, //注意Bearer后面有一空格
  89. },
  90. }).then(res =>{
  91. // this.loading = false
  92. console.log('getHelpPeople',res);
  93. this.helpPeople = res.data.retBody;
  94. })
  95. },200),
  96. refreshfarmer(){
  97. this.getHelpPeople(this.shoppingNum);
  98. },
  99. goCart(){
  100. console.log('customerType',this.customerType);
  101. if(this.customerType!=1){
  102. this.$api.href('/pages/offlineBuy/offlineBuy');
  103. return;
  104. };
  105. if(this.helpPeople === undefined || this.helpPeople.length == 0){
  106. this.$api.msg("请等待农户数据加载完毕!")
  107. return
  108. }else{
  109. this.$refs.randomPop.close()
  110. this.$emit('closeModal',true)
  111. this.addCart(this.helpPeople);
  112. this.$api.href('/pages/confirmOrder/confirmOrder')
  113. }
  114. },
  115. openPop() {
  116. this.$refs.randomPop.open();
  117. if(this.customerType!=1){
  118. return;
  119. };
  120. this.getHelpPeople(this.shoppingNum);
  121. },
  122. closePop() {
  123. Object.assign(this.$data, this.$options.data.call(this))
  124. this.$refs.randomPop.close()
  125. this.$emit('closeModal', true)
  126. },
  127. },
  128. watch: {
  129. //碳汇购入量计算
  130. shoppingNum(n, o) {
  131. if (n > 1000) {
  132. this.$api.msg("单次购买不得超过1000KG!")
  133. setTimeout(res => {
  134. this.shoppingNum = 1000
  135. }, 200)
  136. }
  137. this.getHelpPeople(n)
  138. this.totalMoney = this.price * n;
  139. }
  140. }
  141. }
  142. </script>
  143. <style>
  144. @import url("./quickBuy.css");
  145. </style>