quickBuy.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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">{{userInfo.customerType == 2 ? '请输入您想认购的碳汇数' : '请输入购碳数'}}:</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'" v-show="userInfo.customerType == 2">
  18. <view class="conditions-item-til">备注说明:</view>
  19. <view class="remark">
  20. <textarea class="remark-textarea" maxlength="240" v-model="remark" placeholder-style="font-size:30rpx" 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">{{amountBtnText}}</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 { mapState, mapMutations } 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. computed: {
  52. ...mapState(['userInfo'])
  53. },
  54. created() {
  55. let self = this;
  56. uni.getStorage({
  57. key : 'userInfo',
  58. success:function(res){
  59. // console.log('userInfo customerType',res.data.customerType);
  60. if(res.data.customerType =='1'){
  61. // console.log('个人用户');
  62. self.amountBtnText = '立即购买'
  63. }else{
  64. self.amountBtnText = '提交认购申请'
  65. };
  66. }
  67. });
  68. this.thetoken = 'Bearer' + ' ' + this.$store.state.token;
  69. this.shoppingNum = 1;
  70. uni.getStorage({
  71. key:'userInfo',
  72. success: function (res) {
  73. self.customerType = res.data.customerType;
  74. if(!res.data){this.goLogin();};
  75. console.log('userInfo',res);
  76. },
  77. fail:function(err){
  78. this.goLogin();
  79. }
  80. });
  81. console.log('prohelpPeople',this.prohelpPeople);
  82. },
  83. props: {
  84. visible: {
  85. type: Boolean,
  86. default: false
  87. },
  88. productType:{
  89. type: String,
  90. default: 'all'
  91. },
  92. prohelpPeople:{
  93. type: Array,
  94. default: () => []
  95. }
  96. },
  97. data() {
  98. return {
  99. thetoken:'',
  100. $getimg:this.$getimg,
  101. customerType:null,
  102. shoppingNum:'',
  103. remark:'',
  104. totalMoney:0,
  105. price:3,
  106. helpPeople:[],
  107. amountBtnText:'提交认购申请'
  108. // goodsId:'',
  109. // carbonVal:''
  110. }
  111. },
  112. methods: {
  113. ...mapMutations(['addCart']),
  114. getHelpPeople:debounce(function(num){
  115. if(this.productType=='self'){
  116. console.log('this.prohelpPeople',this.prohelpPeople);
  117. this.helpPeople = this.prohelpPeople;
  118. this.helpPeople[0].carbonSkin = this.shoppingNum;
  119. return ;
  120. };
  121. this.helpPeople = [];
  122. this.loading = true;
  123. this.$api.http.get(this.config.apiBaseurl + '/carbon-h5/wap/goodsManage/getGoodsInfoByCarbonNum?carbonNum='+this.shoppingNum,{
  124. header: {
  125. Accept:'application/json',
  126. Authorization: this.thetoken, //注意Bearer后面有一空格
  127. },
  128. }).then(res =>{
  129. // this.loading = false
  130. console.log('getHelpPeople',res);
  131. this.helpPeople = res.data.retBody;
  132. })
  133. },200),
  134. refreshfarmer(){
  135. this.getHelpPeople(this.shoppingNum);
  136. },
  137. goCart(){
  138. console.log('customerType',this.customerType);
  139. if(this.customerType!=1){//不是个人走线下
  140. this.$emit('closeModal',true);
  141. this.offlineBuy();
  142. // this.$api.href('/pages/offlineBuy/offlineBuy');
  143. return;
  144. };
  145. if(this.helpPeople === undefined || this.helpPeople.length == 0){
  146. this.$api.msg("请等待农户数据加载完毕!")
  147. return
  148. }else{
  149. this.helpPeople.remark = this.remark;
  150. this.$refs.randomPop.close()
  151. this.$emit('closeModal',true);
  152. this.addCart(this.helpPeople);
  153. this.$api.href('/pages/confirmOrder/confirmOrder')
  154. }
  155. },
  156. openPop() {
  157. this.$refs.randomPop.open();
  158. if(this.customerType!=1){
  159. return;
  160. };
  161. this.getHelpPeople(this.shoppingNum);
  162. },
  163. closePop() {
  164. Object.assign(this.$data, this.$options.data.call(this))
  165. this.$refs.randomPop.close()
  166. this.$emit('closeModal', true)
  167. },
  168. offlineBuy(){
  169. let self = this;
  170. let offlineparams = {amount:this.shoppingNum,remark:this.remark};
  171. self.$api.http.post(this.config.apiBaseurl + "/carbon-h5/wap/apply",offlineparams,{
  172. header: {
  173. Accept:'application/json',
  174. Authorization: this.thetoken, //注意Bearer后面有一空格
  175. },
  176. }).then(res=>{
  177. console.log('res.data.retBody',res.data.retBody);
  178. self.$api.href('/pages/offlineBuy/offlineBuy?guid=' + res.data.retBody);
  179. // self.$api.href('/pages/usercenter/subscribe/subscribe');
  180. }).catch( err =>{
  181. console.log('err',err)
  182. })
  183. },
  184. goLogin(){
  185. uni.showToast({
  186. title:"没有获取登录信息即将跳转到登录页",
  187. icon:"none",
  188. duration:2000
  189. });
  190. setTimeout(i=>{
  191. uni.navigateTo({
  192. url: '/pages/login/loginType',
  193. fail:function(err){
  194. console.log(err)
  195. }
  196. });
  197. },2000);
  198. }
  199. },
  200. watch: {
  201. //碳汇购入量计算
  202. shoppingNum(n, o) {
  203. if (n > 1000) {
  204. // this.$api.msg("单次购买不得超过1000KG!")
  205. // setTimeout(res => {
  206. // this.shoppingNum = 1000
  207. // }, 200)
  208. }
  209. this.getHelpPeople(n)
  210. this.totalMoney = this.price * n;
  211. }
  212. }
  213. }
  214. </script>
  215. <style>
  216. @import url("./quickBuy.css");
  217. </style>