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