quickBuy.vue 5.9 KB

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