loveDonate.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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. <text class="imp">*</text>捐款意向
  10. </view>
  11. <view class="box-right">
  12. <picker :value="index" @change="PickerDire" :range="chooseDire" class="box-right" @click="addType">
  13. <text>{{ intention || '请选择捐款意向'}}</text>
  14. </picker>
  15. </view>
  16. </view> -->
  17. <view class="box-item">
  18. <view class="box-left">
  19. <text class="imp">*</text>捐款方式
  20. </view>
  21. <view class="box-right">
  22. <!-- <input type="text" placeholder="请选择捐款方式" /> -->
  23. <picker @change="PickerType" :value="index" :range="chooseType" class="box-right">
  24. <text>{{ way || '请选择捐款方式'}}</text>
  25. </picker>
  26. </view>
  27. </view>
  28. <!-- <view class="box-item">
  29. <view class="box-left">
  30. 捐款金额
  31. </view>
  32. <view class="box-right">
  33. <picker @change="PickerMoney" :value="index" :range="chooseMoney" class="box-right">
  34. <text>{{ money || '请选择捐款金额'}}</text>
  35. </picker>
  36. </view>
  37. </view> -->
  38. <view class="box-item1" @click="tochooseMoney">
  39. <!-- <view class="box-item1" @click="tochooseMoney"> -->
  40. <view class="box-main">
  41. <view class="box-left">
  42. <text class="imp">*</text>捐款金额
  43. </view>
  44. <view class="box-right">
  45. <input type="text" placeholder="请选择金额" v-model="money" disabled />
  46. <!-- <picker @change="PickerMoney" :value="index" :range="chooseMoney" class="box-right">
  47. <text>{{ money || '请选择捐款金额'}}</text>
  48. </picker> -->
  49. </view>
  50. </view>
  51. <view class="box-bottom">
  52. 个人满500,单位满2000可打印纸质证书
  53. </view>
  54. </view>
  55. </view>
  56. <!-- <view class="infoOptional">
  57. 信息(选填)
  58. </view> -->
  59. <view class="box">
  60. <view class="box-item">
  61. <view class="box-left">
  62. <view v-if="is_show">
  63. <text class="imp">*</text>姓名
  64. </view>
  65. <view v-else>
  66. <text class="imp">*</text>单位
  67. </view>
  68. </view>
  69. <view class="box-right">
  70. <input type="text" placeholder="请真实填写" v-model="donate_er" />
  71. </view>
  72. </view>
  73. <view class="box-item">
  74. <view class="box-left">
  75. <text class="imp">*</text>手机号
  76. </view>
  77. <view class="box-right">
  78. <input type="text" placeholder="请填写手机号" v-model="mobile" />
  79. </view>
  80. </view>
  81. </view>
  82. <view class="switch-box">
  83. <view class="switch-left">
  84. 实名公开
  85. </view>
  86. <view class="switch-right">
  87. <switch :checked="is_public" color='#FF727E' style="transform: scale(0.7,0.7)" @change="switch1Change" />
  88. </view>
  89. </view>
  90. <view class="switch-box">
  91. <view class="switch-left">
  92. 寄发票
  93. </view>
  94. <view class="switch-right">
  95. <switch :checked="is_receipts" color='#FF727E' style="transform: scale(0.7,0.7)" @change="switch2Change" />
  96. </view>
  97. </view>
  98. <view class="box">
  99. <view class="box-item">
  100. <view class="box-left">
  101. 联系地址
  102. </view>
  103. <view class="box-right">
  104. <input type="text" placeholder="请输入联系地址" v-model="address" />
  105. </view>
  106. </view>
  107. </view>
  108. <view class="submit" @click="confirm()">
  109. 提交
  110. </view>
  111. <uni-popup ref="popup" type="bottom" @click="close">
  112. <view class="popup_row">
  113. <view class="title">
  114. <view class="title-left">
  115. 一份爱心,一份力量!
  116. </view>
  117. <view class="cancel" @click="cancel">
  118. <image src="../../static/img/取消.png" mode=""></image>
  119. </view>
  120. </view>
  121. <view class="money-btn">
  122. <view class="btn" v-for="item in moneyList" :key="item.id">
  123. <button type="default" @click="addmoney(item)">{{ item.money}}</button>
  124. </view>
  125. </view>
  126. <view class="pop-main">
  127. <view class="money-left">
  128. 金额数
  129. </view>
  130. <view class="money-iup">
  131. <input type="text" value="" v-model="popmoney" placeholder="请选择金额或者自定义金额" />
  132. </view>
  133. <view class="">
  134. </view>
  135. </view>
  136. <view class="comfirm">
  137. <view class="comfirm1" @click="comfirm1()">
  138. 确认
  139. </view>
  140. </view>
  141. </view>
  142. </uni-popup>
  143. </view>
  144. </template>
  145. <script>
  146. import {
  147. chosintention,
  148. joinDona
  149. } from '@/api/ask.js';
  150. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  151. import {
  152. computedOrderkey,
  153. balance,
  154. createOrderkey,
  155. orderPay
  156. } from '@/api/money.js';
  157. import {
  158. saveUrl,
  159. interceptor
  160. } from '@/utils/loginUtils.js';
  161. import {
  162. mapState,
  163. mapMutations
  164. } from 'vuex';
  165. import {
  166. userinfo
  167. } from '@/api/user.js';
  168. export default {
  169. components: {
  170. uniPopup,
  171. // uniLoadMore
  172. },
  173. data() {
  174. return {
  175. id:'',
  176. index: 0,
  177. intention: '', // 捐款意向
  178. way: '', // 捐款方式
  179. money: '', // 捐款金额
  180. elsemoney: '', // 其他金额
  181. popmoney: '', // 按钮金额 弹窗金额
  182. is_show: true,
  183. moneyList: [{
  184. id: 0,
  185. money: 500
  186. },
  187. {
  188. id: 1,
  189. money: 200
  190. },
  191. {
  192. id: 2,
  193. money: 100
  194. },
  195. {
  196. id: 3,
  197. money: 50
  198. },
  199. {
  200. id: 4,
  201. money: 20
  202. },
  203. ],
  204. is_public: true, // 是否实名公开
  205. is_receipts: false, // 是否开发票
  206. donate_er: '', // 捐款人/单位
  207. mobile: '', // 手机号
  208. isshowMoney: false, // 其他金额是否展示
  209. address: '', // 联系地址
  210. // chooseDire: ['请选择捐款意向','疫情防控','其他','红十字人道事业(非定向捐赠)','红十字博爱送万家','AED救护及科普','青少年生命安全教育基地建设项目','关注重度失能老人项目','青少年白血病救护项目','地芯行动-关爱地中海贫血儿童','会费缴纳'],
  211. chooseDire: [],
  212. chooseType: ['个人', '单位'],
  213. chooseMoney: ['5元', '10元', '50元', '其他金额'],
  214. payLoding: false, //判断是否支付中
  215. froms: '', //保存h5中数据来源对象
  216. type: '', //判断是否从订单中进入
  217. payName: 'weixin',
  218. // orderInfo: {},
  219. }
  220. },
  221. onLoad(options) {
  222. console.log(333,options)
  223. this.id = options.id
  224. },
  225. onShow() {
  226. saveUrl()
  227. // let token = uni.getStorageSync('token');
  228. console.log(1, this);
  229. // uni.showModal({
  230. // title: '判断hasLogin',
  231. // content: JSON.stringify(this.hasLogin),
  232. // })
  233. if (!this.hasLogin) {
  234. // 登录拦截
  235. // interceptor();
  236. uni.showModal({
  237. title: '登录',
  238. content: '您未登录,是否马上登陆?',
  239. success: e => {
  240. if (e.confirm) {
  241. interceptor();
  242. }
  243. },
  244. fail: e => {
  245. console.log(e);
  246. uni.showModal({
  247. title: 'cuowu',
  248. content: JSON.stringify(e),
  249. })
  250. }
  251. });
  252. } else {
  253. // this.loadData();
  254. }
  255. },
  256. computed: {
  257. ...mapState('user', ['userInfo', 'baseURL', 'hasLogin']),
  258. ...mapState(['weichatObj']),
  259. },
  260. methods: {
  261. // 点击捐赠意向
  262. addType(e) {
  263. chosintention({}).then(({
  264. data
  265. }) => {
  266. console.log(data)
  267. this.chooseDire = data.map(item => item.title)
  268. }).catch()
  269. },
  270. // 选择捐赠意向
  271. PickerDire: function(e) {
  272. console.log(334, this.chooseDire)
  273. this.intention = this.chooseDire[e.target.value];
  274. this.index = e.target.value + 1;
  275. },
  276. // 选择捐款方式
  277. PickerType: function(e) {
  278. this.way = this.chooseType[e.target.value];
  279. this.index = e.target.value + 1;
  280. console.log('选择捐款方式', this.index)
  281. if (this.index == 1) {
  282. this.is_show = true
  283. } else {
  284. this.is_show = false
  285. }
  286. // if ( )
  287. },
  288. // 选择捐款金额
  289. PickerMoney: function(e) {
  290. this.money = this.chooseMoney[e.target.value];
  291. this.index = e.target.value + 1;
  292. console.log('选择金额', this.money)
  293. if (this.money == '其他金额') {
  294. this.isshowMoney = true
  295. } else {
  296. this.isshowMoney = false
  297. this.elsemoney = ''
  298. }
  299. },
  300. // 其他金额 选择
  301. tochooseMoney: function() {
  302. this.$refs.popup.open();
  303. },
  304. addmoney(mon) {
  305. console.log('点击金额按钮', mon.money)
  306. this.popmoney = mon.money
  307. console.log(123, this.popmoney)
  308. },
  309. cancel() {
  310. this.$refs.popup.close();
  311. },
  312. comfirm1: function() {
  313. let obj = this
  314. if (obj.popmoney.toString().trim() == '') {
  315. console.log('输入框为空')
  316. } else {
  317. console.log('输入框为不为空')
  318. obj.money = obj.popmoney
  319. obj.popmoney = ''
  320. this.$refs.popup.close();
  321. }
  322. },
  323. // 是否实名公开
  324. switch1Change(e) {
  325. this.is_public = e.detail.value
  326. console.log(this.is_public)
  327. },
  328. //是都寄发票
  329. switch2Change(e) {
  330. this.is_receipts = e.detail.value
  331. console.log('is_receipts', this.is_receipts)
  332. },
  333. // 提交
  334. confirm: async function() {
  335. let obj = this
  336. console.log('点击提交')
  337. if (!obj.way) {
  338. this.$api.msg('请选择捐款方式!');
  339. return;
  340. }
  341. if (!obj.money) {
  342. this.$api.msg('请输入捐款金额!');
  343. return;
  344. }
  345. // <text class="imp">*</text>
  346. if (this.is_show) {
  347. if (!obj.donate_er) {
  348. this.$api.msg('请填写您的姓名');
  349. return;
  350. }
  351. } else {
  352. if (!obj.donate_er) {
  353. this.$api.msg('请填写您的单位');
  354. return;
  355. }
  356. }
  357. const reg = /^(\+?0?86-?)?1[\d]\d{9}$/;
  358. if (!reg.test(obj.mobile)) {
  359. obj.$api.msg('请填写正确的手机号码');
  360. return;
  361. }
  362. if (this.is_receipts == true) {
  363. obj.address = '用户未填写联系地址'
  364. if (!obj.address) {
  365. this.$api.msg('请输入联系地址');
  366. return;
  367. }
  368. }
  369. if (!obj.address) {
  370. obj.address = '用户未填写联系地址'
  371. }
  372. console.log('is_receipts', obj.is_receipts)
  373. // uni.showModal({
  374. // title: '暂未开启捐款,请耐心等待',
  375. // })
  376. createOrderkey({
  377. hid:obj.id, // 帮扶id
  378. money: obj.money, //捐款金额
  379. intention: obj.intention, //捐款意向
  380. way: obj.way, //捐款方式
  381. is_public: obj.is_public, //是否实名公开
  382. is_receipts: obj.is_receipts, //是否开发票
  383. donate_er: obj.donate_er, //捐款人/单位
  384. mobile: obj.mobile, //手机号
  385. address: obj.address, //联系地址
  386. }).then(({
  387. data
  388. }) => {
  389. // uni.showModal({
  390. // title: '触发点击',
  391. // content: JSON.stringify(data)
  392. // })
  393. console.log(345, data)
  394. let res = data.result.jsConfig;
  395. console.log(res)
  396. // 仅作为示例,非真实参数信息。
  397. obj.weichatObj.chooseWXPay({
  398. timestamp: res.timestamp,
  399. nonceStr: res.nonceStr,
  400. package: res.package,
  401. signType: res.signType,
  402. paySign: res.paySign,
  403. success: function(res) {
  404. console.log(res)
  405. // obj.$api.msg('支付成功')
  406. uni.navigateTo({
  407. url: '/pages/form/donaSuccess1?money=' + obj.money
  408. })
  409. },
  410. fail: function(res) {
  411. console.log(res, "失败")
  412. console.log(res.errMsg)
  413. }
  414. });
  415. })
  416. // 支付中
  417. obj.payLoding = true;
  418. // uni.requestPayment({
  419. // provider: 'wxpay',
  420. // timeStamp: String(Date.now()),
  421. // nonceStr: 'A1B2C3D4E5',
  422. // package: 'prepay_id=wx20180101abcdefg',
  423. // signType: 'MD5',
  424. // paySign: '',
  425. // success: function(res) {
  426. // console.log('success:' + JSON.stringify(res));
  427. // },
  428. // fail: function(err) {
  429. // console.log('fail:' + JSON.stringify(err));
  430. // }
  431. // });
  432. }
  433. },
  434. }
  435. </script>
  436. <style lang="scss">
  437. .content {}
  438. .top {
  439. display: flex;
  440. align-items: center;
  441. justify-content: center;
  442. background: $motif-color;
  443. color: #FFFFFF;
  444. padding: 22rpx 0;
  445. }
  446. .box {
  447. .box-item1 {
  448. background-color: #FFFFFF;
  449. padding: 18rpx 24rpx;
  450. // display: flex;
  451. border-bottom: 1rpx solid #F2F2F2;
  452. }
  453. .box-main {
  454. display: flex;
  455. .box-left {
  456. width: 200rpx;
  457. flex-shrink: 0;
  458. // flex: 0;
  459. }
  460. .box-right {
  461. width: 100%;
  462. color: #999999;
  463. text-align: right;
  464. }
  465. }
  466. .box-bottom {
  467. color: #999999;
  468. // padding-left: 12rpx;
  469. padding-top: 12rpx;
  470. font-size: 26rpx;
  471. }
  472. .box-item {
  473. background-color: #FFFFFF;
  474. padding: 24rpx;
  475. display: flex;
  476. border-bottom: 1rpx solid #F2F2F2;
  477. }
  478. .box-left {
  479. width: 200rpx;
  480. flex-shrink: 0;
  481. // flex: 0;
  482. .imp {
  483. color: #E63931;
  484. margin-right: 2rpx;
  485. }
  486. }
  487. .box-right {
  488. width: 100%;
  489. color: #999999;
  490. text-align: right;
  491. }
  492. }
  493. .switch-box {
  494. margin-top: 24rpx;
  495. display: flex;
  496. align-items: center;
  497. padding: 16rpx 24rpx;
  498. color: #7b7b7b;
  499. background-color: #FFFFFF;
  500. border-bottom: 1rpx solid #F2F2F2;
  501. justify-content: space-between;
  502. .switch-right {
  503. // background-color: #E63931;
  504. }
  505. }
  506. .infoOptional {
  507. padding: 20rpx 24rpx;
  508. }
  509. .submit {
  510. background-color: #FF727E;
  511. color: #FFFFFF;
  512. padding: 20rpx 0;
  513. display: flex;
  514. align-items: center;
  515. justify-content: center;
  516. border-radius: 12rpx;
  517. margin: 52rpx;
  518. }
  519. .popup_row {
  520. height: 500rpx;
  521. width: 100%;
  522. padding: 24rpx;
  523. background-color: #FFFFFF;
  524. .title {
  525. border-bottom: 2rpx solid #F2F2F2;
  526. color: #E63931;
  527. font-size: 32rpx;
  528. padding-left: 4rpx;
  529. padding-bottom: 16rpx;
  530. display: flex;
  531. justify-content: space-between;
  532. // align-items: center;
  533. .cancel {
  534. width: 36rpx;
  535. height: 36rpx;
  536. image {
  537. width: 36rpx;
  538. height: 36rpx;
  539. }
  540. }
  541. }
  542. .money-btn {
  543. display: flex;
  544. justify-content: space-around;
  545. margin-top: 28rpx;
  546. .btn {
  547. // width: 20%;
  548. // display: flex;
  549. // button{
  550. // background-color: #FFFFFF;
  551. // }
  552. }
  553. }
  554. .pop-main {
  555. margin-top: 32rpx;
  556. font-size: 34rpx;
  557. display: flex;
  558. .money-left {
  559. // width: 100rpx;
  560. padding: 0 6rpx;
  561. flex-shrink: 0;
  562. color: #E63931;
  563. // background-color: #457DBF;
  564. }
  565. .money-iup {
  566. width: 100%;
  567. padding-left: 22rpx;
  568. input {
  569. font-size: 32rpx;
  570. // color: #1B1B1B;
  571. color: #FF9797;
  572. .input-placeholder {
  573. // height: 70rpx;
  574. font-size: 32rpx;
  575. color: #FF9797;
  576. }
  577. }
  578. // background-color: pink;
  579. }
  580. }
  581. .comfirm {
  582. display: flex;
  583. justify-content: flex-end;
  584. margin-top: 54rpx;
  585. .comfirm1 {
  586. padding: 12rpx 24rpx;
  587. border-radius: 12rpx;
  588. color: #FFFFFF;
  589. background-color: #E63931;
  590. }
  591. }
  592. }
  593. </style>