quickBuy.vue 5.3 KB

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