donateLove.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <view class="content">
  3. <view class="top">
  4. 爱心捐赠
  5. </view>
  6. <view class="box">
  7. <view class="box-item">
  8. <view class="box-left">
  9. 捐款意向
  10. </view>
  11. <view class="box-right">
  12. <!-- <input type="text" placeholder="请选择捐款意向" @click="addType"/> -->
  13. <picker :value="index" @change="PickerDire" :range="chooseDire" class="box-right" @click="addType">
  14. <text>{{ intention || '请选择捐款意向'}}</text>
  15. </picker>
  16. </view>
  17. </view>
  18. <view class="box-item">
  19. <view class="box-left">
  20. 捐款方式
  21. </view>
  22. <view class="box-right">
  23. <!-- <input type="text" placeholder="请选择捐款方式" /> -->
  24. <picker @change="PickerType" :value="index" :range="chooseType" class="box-right">
  25. <text>{{ way || '请选择捐款方式'}}</text>
  26. </picker>
  27. </view>
  28. </view>
  29. <view class="box-item">
  30. <view class="box-left">
  31. 捐款金额
  32. </view>
  33. <view class="box-right">
  34. <input type="text" placeholder="单位(元)" v-model="money"/>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="switch-box">
  39. <view class="switch-left">
  40. 是否实名公开
  41. </view>
  42. <view class="switch-right">
  43. <switch :checked="is_public" color='#E63931' style="transform: scale(0.7,0.7)" @change="switch1Change"/>
  44. </view>
  45. </view>
  46. <view class="switch-box">
  47. <view class="switch-left">
  48. 寄发票
  49. </view>
  50. <view class="switch-right">
  51. <switch :checked="is_receiptsL" color='#E63931' style="transform: scale(0.7,0.7)" @change="switch2Change"/>
  52. </view>
  53. </view>
  54. <view class="infoOptional">
  55. 信息(选填)
  56. </view>
  57. <view class="box">
  58. <view class="box-item">
  59. <view class="box-left">
  60. 捐款人/单位
  61. </view>
  62. <view class="box-right">
  63. <input type="text" placeholder="请选择捐款人/单位" v-model="donate_er"/>
  64. </view>
  65. </view>
  66. <view class="box-item">
  67. <view class="box-left">
  68. 手机号
  69. </view>
  70. <view class="box-right">
  71. <input type="text" placeholder="请填写手机号" v-model="mobile"/>
  72. </view>
  73. </view>
  74. <view class="box-item">
  75. <view class="box-left">
  76. 联系地址
  77. </view>
  78. <view class="box-right">
  79. <input type="text" placeholder="请输入联系地址(用于寄发票)" v-model="address"/>
  80. </view>
  81. </view>
  82. </view>
  83. <view class="submit" @click="!payLoding ? confirm() : ''">
  84. 提交
  85. </view>
  86. </view>
  87. </template>
  88. <script>
  89. import {
  90. chosintention,
  91. joinDona
  92. } from '@/api/ask.js';
  93. import { computedOrderkey, balance, createOrderkey, orderPay } from '@/api/money.js';
  94. export default{
  95. data(){
  96. return{
  97. index: 0,
  98. intention:'', //捐款意向
  99. way:'', //捐款方式
  100. money:'', //捐款金额
  101. is_public: false, //是否实名公开
  102. is_receiptsL: false, //是否开发票
  103. donate_er: '', //捐款人/单位
  104. mobile: '', //手机号
  105. address:'', // 联系地址
  106. // chooseDire: ['请选择捐款意向','疫情防控','其他','红十字人道事业(非定向捐赠)','红十字博爱送万家','AED救护及科普','青少年生命安全教育基地建设项目','关注重度失能老人项目','青少年白血病救护项目','地芯行动-关爱地中海贫血儿童','会费缴纳'],
  107. chooseDire:[],
  108. chooseType:['个人','单位'],
  109. payLoding: false, //判断是否支付中
  110. froms: '', //保存h5中数据来源对象
  111. type: '', //判断是否从订单中进入
  112. }
  113. },
  114. onLoad(options) {
  115. console.log(333,options)
  116. },
  117. methods:{
  118. // 点击捐赠意向
  119. addType(e){
  120. chosintention({}).then(({ data })=>{
  121. console.log(data)
  122. this.chooseDire = data.map(item => item.title)
  123. }).catch()
  124. },
  125. // 选择捐赠意向
  126. PickerDire:function(e) {
  127. console.log(334,this.chooseDire)
  128. this.intention = this.chooseDire[e.target.value];
  129. this.index = e.target.value + 1;
  130. },
  131. // 选择捐款方式
  132. PickerType:function(e) {
  133. this.way = this.chooseType[e.target.value];
  134. this.index = e.target.value + 1;
  135. },
  136. // 是否实名公开
  137. switch1Change(e){
  138. this.is_public = e.detail.value
  139. console.log(this.is_public )
  140. },
  141. //是都寄发票
  142. switch2Change(e){
  143. this.is_receiptsL = e.detail.value
  144. console.log(this.is_receiptsL )
  145. },
  146. // 提交,
  147. //确认支付
  148. confirm: async function() {
  149. let obj = this;
  150. // 支付中
  151. obj.payLoding = true;
  152. // #ifdef H5
  153. // 获取当前是否为微信浏览器
  154. obj.froms = uni.getStorageSync('weichatBrowser') || '';
  155. // #endif
  156. // 判断是否为未支付订单中跳转进入
  157. if (obj.type != 1) {
  158. // 初次生成订单
  159. obj.firstCreateOrder();
  160. } else {
  161. // 已经生成订单未支付
  162. obj.orderMoneyPay();
  163. }
  164. },
  165. // 初次订单创建
  166. firstCreateOrder() {
  167. let obj = this;
  168. // 获取下单页面数据
  169. let prepage = obj.$api.prePage();
  170. let data = {
  171. use_integral_pink: obj.use_integral_pink,
  172. real_name: prepage.addressData.real_name, //联系人名称
  173. phone: prepage.addressData.phone, //联系人号码
  174. couponId: prepage.couponChecked.id, //优惠券编号
  175. addressId: prepage.addressData.id, //支付地址id
  176. useIntegral: prepage.checkedPoints ? 1 : 0, //是否积分抵扣1为是0为否
  177. useShopping_card: prepage.shoppingPoints ? 1 : 0, //是否使用购物卡
  178. payType: obj.payName, //支付类型 weixin-微信 yue-余额
  179. mark: prepage.idcardName+prepage.idcardNum, //备注
  180. // #ifdef H5
  181. from: obj.froms ? 'weixin' : 'H5', //来源
  182. // #endif
  183. // #ifdef MP-WEIXIN
  184. from: 'routine', //来源
  185. // #endif
  186. // #ifdef APP-PLUS
  187. from: 'app', //来源
  188. // #endif
  189. shipping_type: 1, //提货方式 1 快递 2自提
  190. };
  191. // 判断是否拼团商品
  192. if (obj.typegoods == 6) {
  193. data.level = obj.level;
  194. }else{
  195. data.pinkId = obj.pinkid;
  196. }
  197. // 生成订单
  198. createOrderkey(data, obj.orderKey)
  199. .then(({ data, status, msg }) => {
  200. // 保存订单号
  201. obj.orderId = data.result.orderId;
  202. // 允许支付
  203. obj.payLoding = false;
  204. if (data.status == 'ORDER_EXIST') {
  205. obj.$api.msg(msg);
  206. return;
  207. }
  208. // 判断是否为余额支付
  209. if (obj.payName == 'yue') {
  210. if (status == 200&&data.status == 'SUCCESS') {
  211. obj.paySuccessTo();
  212. } else {
  213. alert(msg);
  214. obj.$api.msg(msg)
  215. }
  216. } else {
  217. // 立即支付
  218. obj.orderMoneyPay();
  219. }
  220. })
  221. .catch(e => {
  222. alert(e.message);
  223. console.log(e);
  224. });
  225. }
  226. // add() {
  227. // console.log('点击提交按钮')
  228. // let obj = this
  229. // if (obj.intention == '') {
  230. // obj.$api.msg('请输入捐款意向');
  231. // return;
  232. // };
  233. // if (obj.way == '') {
  234. // obj.$api.msg('请输入捐款方式');
  235. // return;
  236. // };
  237. // if (obj.money == '') {
  238. // obj.$api.msg('请输入捐款金额');
  239. // return;
  240. // };
  241. // orderPay({
  242. // uni: obj.orderId,
  243. // // #ifdef H5
  244. // from: obj.froms ? 'weixin' : 'H5', //来源
  245. // // #endif
  246. // // #ifdef MP-WEIXIN
  247. // from: 'routine', //来源
  248. // // #endif
  249. // // #ifdef APP-PLUS
  250. // from: 'app', //来源
  251. // // #endif
  252. // paytype: obj.payName //支付类型 weixin-微信 yue-余额
  253. // }).then(e =>{
  254. // console.log(e)
  255. // })
  256. // joinDona({
  257. // intention:obj.intention, //捐款意向
  258. // way:obj.way, //捐款方式
  259. // money:obj.money, //捐款金额
  260. // is_public: obj.is_public, //是否实名公开
  261. // is_receiptsL: obj.is_receiptsL, //是否开发票
  262. // donate_er: obj.donate_er, //捐款人/单位
  263. // mobile: obj.mobile, //手机号
  264. // address:obj.address, // 联系地址
  265. // }).then(({data})=>{
  266. // console.log(data)
  267. // console.log('登录成功')
  268. // // uni.navigateTo({
  269. // // url: "/pages/form/donaSuccess"
  270. // // })
  271. // }).catch((err)=>{
  272. // console.log(err)
  273. // })
  274. // }
  275. },
  276. }
  277. </script>
  278. <style lang="scss">
  279. .content{
  280. }
  281. .top{
  282. display: flex;
  283. align-items: center;
  284. justify-content: center;
  285. background-color: #E63931;
  286. color: #FFFFFF;
  287. padding: 22rpx 0;
  288. }
  289. .box{
  290. .box-item{
  291. background-color: #FFFFFF;
  292. padding: 24rpx;
  293. display: flex;
  294. border-bottom: 1rpx solid #F2F2F2;
  295. }
  296. .box-left{
  297. width: 200rpx;
  298. flex-shrink: 0;
  299. // flex: 0;
  300. }
  301. .box-right{
  302. width: 100%;
  303. color: #999999;
  304. }
  305. }
  306. .switch-box{
  307. margin-top: 24rpx;
  308. display: flex;
  309. align-items: center;
  310. padding: 16rpx 24rpx;
  311. color: #7b7b7b;
  312. background-color: #FFFFFF;
  313. border-bottom: 1rpx solid #F2F2F2;
  314. justify-content: space-between;
  315. .switch-right{
  316. // background-color: #E63931;
  317. }
  318. }
  319. .infoOptional{
  320. padding: 20rpx 24rpx;
  321. }
  322. .submit{
  323. background-color: #E63931;
  324. color: #FFFFFF;
  325. padding: 20rpx 0;
  326. display: flex;
  327. align-items: center;
  328. justify-content: center;
  329. border-radius: 12rpx;
  330. margin: 32rpx;
  331. }
  332. </style>