quickBuy.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <uni-popup ref="randomPop" type="bottom" class="randomPop">
  3. <view class="popup-content">
  4. <view class="popup-head">
  5. <text v-if="customerType==1">购买碳汇</text>
  6. <text v-else>线下认购</text>
  7. <text class="close" @click="closePop">X</text>
  8. </view>
  9. <view class="popup-body">
  10. <view class="conditions-item input-number">
  11. <view class="conditions-item-til">请输入您想认购的碳汇数:</view>
  12. <view class="num">
  13. <input class="input" type="number" v-model="shoppingNum" placeholder="单次购买不超过1000株" placeholder-style="font-size:20rpx"/>
  14. </view>
  15. </view>
  16. <view class="conditions-item remark-wrap" v-if="productType == 'all'">
  17. <view class="conditions-item-til">备注说明:</view>
  18. <view class="remark">
  19. <textarea class="remark-textarea" maxlength="240" v-model="remark" placeholder="请输入您对认购的碳汇产品要求" />
  20. </view>
  21. </view>
  22. <view class="amount-wrap">
  23. <view class="amount-flex-wrap">
  24. <view class="amount-til">预估金额:</view>
  25. <view class="amount">
  26. <text class="rmb">¥</text>
  27. <text class="num">{{totalMoney}}</text>
  28. </view>
  29. </view>
  30. <view class="amount-btn" @click="goCart">提交认购申请</view>
  31. </view>
  32. <view class="tip">
  33. 购买{{shoppingNum}}kg,预估金额{{totalMoney}}元,认购期3年
  34. </view>
  35. </view>
  36. </view>
  37. </uni-popup>
  38. </template>
  39. <script>
  40. import {
  41. mapMutations
  42. } from 'vuex';
  43. import {
  44. debounce
  45. } from '@/utils/util.js'
  46. import uniPopup from '@/components/uni-popup/uni-popup.vue'
  47. export default {
  48. name: 'quickBuy',
  49. components: {
  50. uniPopup,
  51. },
  52. created() {
  53. let self = this;
  54. this.shoppingNum = 1;
  55. uni.getStorage({
  56. key:'userInfo',
  57. success: function (res) {
  58. self.customerType = res.data.customerType;
  59. if(!res.data){this.goLogin();};
  60. console.log('userInfo',res);
  61. },
  62. fail:function(err){
  63. this.goLogin();
  64. }
  65. });
  66. console.log('prohelpPeople',this.prohelpPeople);
  67. },
  68. props: {
  69. visible: {
  70. type: Boolean,
  71. default: false
  72. },
  73. productType:{
  74. type: String,
  75. default: 'all'
  76. },
  77. prohelpPeople:{
  78. type: Array,
  79. default: () => []
  80. }
  81. },
  82. data() {
  83. return {
  84. customerType:null,
  85. shoppingNum:'',
  86. remark:'',
  87. totalMoney:0,
  88. price:3,
  89. helpPeople:[],
  90. // goodsId:'',
  91. // carbonVal:''
  92. }
  93. },
  94. methods: {
  95. ...mapMutations(['addCart']),
  96. getHelpPeople:debounce(function(num){
  97. if(this.productType=='self'){
  98. console.log('this.prohelpPeople',this.prohelpPeople);
  99. this.helpPeople = this.prohelpPeople;
  100. this.helpPeople[0].carbonSkin = this.shoppingNum;
  101. return ;
  102. };
  103. this.helpPeople = []
  104. this.loading = true
  105. this.$api.http.get(this.config.apiBaseurl + '/carbon-h5/wap/goodsManage/getGoodsInfoByCarbonNum?carbonNum='+this.shoppingNum,{
  106. header: {
  107. Accept:'application/json',
  108. Authorization: 'Bearer '+ this.token, //注意Bearer后面有一空格
  109. },
  110. }).then(res =>{
  111. // this.loading = false
  112. console.log('getHelpPeople',res);
  113. this.helpPeople = res.data.retBody;
  114. })
  115. },200),
  116. refreshfarmer(){
  117. this.getHelpPeople(this.shoppingNum);
  118. },
  119. goCart(){
  120. console.log('customerType',this.customerType);
  121. if(this.customerType!=1){
  122. this.$emit('closeModal',true);
  123. this.offlineBuy();
  124. // this.$api.href('/pages/offlineBuy/offlineBuy');
  125. return;
  126. };
  127. if(this.helpPeople === undefined || this.helpPeople.length == 0){
  128. this.$api.msg("请等待农户数据加载完毕!")
  129. return
  130. }else{
  131. this.$refs.randomPop.close()
  132. this.$emit('closeModal',true);
  133. this.addCart(this.helpPeople);
  134. this.$api.href('/pages/confirmOrder/confirmOrder')
  135. }
  136. },
  137. openPop() {
  138. this.$refs.randomPop.open();
  139. if(this.customerType!=1){
  140. return;
  141. };
  142. this.getHelpPeople(this.shoppingNum);
  143. },
  144. closePop() {
  145. Object.assign(this.$data, this.$options.data.call(this))
  146. this.$refs.randomPop.close()
  147. this.$emit('closeModal', true)
  148. },
  149. offlineBuy(){
  150. let self = this;
  151. let offlineparams = {amount:this.shoppingNum,remark:this.remark};
  152. self.$api.http.post(this.config.apiBaseurl + "/carbon-h5/wap/apply",offlineparams,{
  153. header: {
  154. Accept:'application/json',
  155. Authorization: 'Bearer '+ this.token, //注意Bearer后面有一空格
  156. },
  157. }).then(res=>{
  158. self.$api.href('/pages/usercenter/subscribe/subscribe')
  159. }).catch( err =>{
  160. console.log('err',err)
  161. })
  162. },
  163. goLogin(){
  164. uni.showToast({
  165. title:"没有获取登录信息即将跳转到登录页",
  166. icon:"none",
  167. duration:2000
  168. });
  169. setTimeout(i=>{
  170. uni.navigateTo({
  171. url: '/pages/login/loginType',
  172. fail:function(err){
  173. console.log(err)
  174. }
  175. });
  176. },2000);
  177. }
  178. },
  179. watch: {
  180. //碳汇购入量计算
  181. shoppingNum(n, o) {
  182. if (n > 1000) {
  183. // this.$api.msg("单次购买不得超过1000KG!")
  184. // setTimeout(res => {
  185. // this.shoppingNum = 1000
  186. // }, 200)
  187. }
  188. this.getHelpPeople(n)
  189. this.totalMoney = this.price * n;
  190. }
  191. }
  192. }
  193. </script>
  194. <style>
  195. @import url("./quickBuy.css");
  196. </style>