contribution.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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" v-if="is_public">
  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='#E63931' 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='#E63931' 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. <uni-popup ref="popup1" type="center">
  144. <view class="popup-box">
  145. <!-- <view class="img">
  146. <image src="../../static/img/WechatIMG662.png" mode=""></image>
  147. </view> -->
  148. <view class="mian">
  149. <view class="delivery">
  150. 支付失败
  151. <!-- {{ i18n.qrhwsdm }} -->
  152. </view>
  153. <view class="nocancel">
  154. 请退出页面,重新登录
  155. <!-- {{ i18n.wfcx }} -->
  156. </view>
  157. <view class="comfirm-box">
  158. <view class="cancel" @click="cancel1">
  159. 取消
  160. </view>
  161. <view class="comfirm" @click="comfirmExit()">
  162. 确认
  163. </view>
  164. </view>
  165. </view>
  166. </view>
  167. </uni-popup>
  168. </view>
  169. </template>
  170. <script>
  171. import {
  172. chosintention,
  173. joinDona
  174. } from '@/api/ask.js';
  175. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  176. import {
  177. computedOrderkey,
  178. balance,
  179. createOrderkey,
  180. orderPay
  181. } from '@/api/money.js';
  182. import {
  183. saveUrl,
  184. interceptor
  185. } from '@/utils/loginUtils.js';
  186. import {
  187. mapState,
  188. mapMutations
  189. } from 'vuex';
  190. import {
  191. userinfo
  192. } from '@/api/user.js';
  193. export default {
  194. components: {
  195. uniPopup,
  196. // uniLoadMore
  197. },
  198. data() {
  199. return {
  200. index: 0,
  201. intention: '', // 捐款意向
  202. way: '', // 捐款方式
  203. money: '', // 捐款金额
  204. // elsemoney: '', // 其他金额
  205. popmoney: '', // 按钮金额 弹窗金额
  206. is_show: true,
  207. moneyList: [{
  208. id: 0,
  209. money: 500
  210. },
  211. {
  212. id: 1,
  213. money: 200
  214. },
  215. {
  216. id: 2,
  217. money: 100
  218. },
  219. {
  220. id: 3,
  221. money: 50
  222. },
  223. {
  224. id: 4,
  225. money: 20
  226. },
  227. ],
  228. is_public: true, // 是否实名公开
  229. is_receipts: false, // 是否开发票
  230. donate_er: '', // 捐款人/单位
  231. mobile: '', // 手机号
  232. isshowMoney: false, // 其他金额是否展示
  233. address: '', // 联系地址
  234. // chooseDire: ['请选择捐款意向','红十字人道事业(非定向捐赠)','疫情防控','其他','红十字博爱送万家','AED救护及科普','青少年生命安全教育基地建设项目','关注重度失能老人项目','青少年白血病救护项目','地芯行动-关爱地中海贫血儿童','会费缴纳'],
  235. chooseDire: [],
  236. chooseType: ['个人', '单位'],
  237. chooseMoney: ['5元', '10元', '50元', '其他金额'],
  238. payLoding: false, //判断是否支付中
  239. froms: '', //保存h5中数据来源对象
  240. type: '', //判断是否从订单中进入
  241. payName: 'weixin',
  242. // orderInfo: {},
  243. }
  244. },
  245. onLoad(options) {
  246. // console.log(333,options)
  247. },
  248. onShow() {
  249. if (!this.hasLogin) {
  250. // 登录拦截
  251. uni.showModal({
  252. title: '登录',
  253. content: '您未登录,是否马上登陆?',
  254. success: e => {
  255. if (e.confirm) {
  256. saveUrl()
  257. interceptor();
  258. }
  259. },
  260. fail: e => {
  261. console.log(e);
  262. uni.showModal({
  263. title: '错误',
  264. content: JSON.stringify(e),
  265. })
  266. }
  267. });
  268. } else {
  269. // this.loadData();
  270. }
  271. },
  272. computed: {
  273. ...mapState('user', ['userInfo', 'baseURL', 'hasLogin']),
  274. ...mapState(['weichatObj']),
  275. },
  276. methods: {
  277. // 点击捐赠意向
  278. addType(e) {
  279. chosintention({}).then(({
  280. data
  281. }) => {
  282. console.log(data)
  283. this.chooseDire = data.map(item => item.title)
  284. }).catch()
  285. },
  286. // 选择捐赠意向
  287. PickerDire: function(e) {
  288. console.log(334, this.chooseDire)
  289. this.intention = this.chooseDire[e.target.value];
  290. this.index = e.target.value + 1;
  291. },
  292. // 选择捐款方式
  293. PickerType: function(e) {
  294. this.way = this.chooseType[e.target.value];
  295. this.index = e.target.value + 1;
  296. console.log('选择捐款方式', this.index)
  297. if (this.index == 1) {
  298. this.is_show = true
  299. } else {
  300. this.is_show = false
  301. }
  302. // if ( )
  303. },
  304. // 选择捐款金额
  305. PickerMoney: function(e) {
  306. this.money = this.chooseMoney[e.target.value];
  307. this.index = e.target.value + 1;
  308. console.log('选择金额', this.money)
  309. if (this.money == '其他金额') {
  310. this.isshowMoney = true
  311. } else {
  312. this.isshowMoney = false
  313. this.elsemoney = ''
  314. }
  315. },
  316. // 其他金额 选择
  317. tochooseMoney: function() {
  318. this.$refs.popup.open();
  319. },
  320. addmoney(mon) {
  321. console.log('点击金额按钮', mon.money)
  322. this.popmoney = mon.money
  323. console.log(123, this.popmoney)
  324. },
  325. cancel() {
  326. this.$refs.popup.close();
  327. },
  328. cancel1() {
  329. this.$refs.popup1.close();
  330. },
  331. comfirm1: function() {
  332. let obj = this
  333. if (obj.popmoney.toString().trim() == '') {
  334. console.log('输入框为空')
  335. } else {
  336. console.log('输入框为不为空')
  337. obj.money = obj.popmoney
  338. obj.popmoney = ''
  339. this.$refs.popup.close();
  340. }
  341. },
  342. comfirmExit() {
  343. console.log('点击comfirmExit')
  344. this.$refs.popup1.close()
  345. uni.switchTab({
  346. url: '/pages/home/home'
  347. });
  348. },
  349. // 是否实名公开
  350. switch1Change(e) {
  351. this.is_public = e.detail.value
  352. console.log(this.is_public)
  353. },
  354. //是都寄发票
  355. switch2Change(e) {
  356. this.is_receipts = e.detail.value
  357. console.log('is_receipts', this.is_receipts)
  358. },
  359. // 提交
  360. confirm: async function() {
  361. let obj = this
  362. if (!obj.way) {
  363. this.$api.msg('请选择捐款方式!');
  364. return;
  365. }
  366. if (!obj.money) {
  367. this.$api.msg('请输入捐款金额!');
  368. return;
  369. }
  370. if(obj.is_public) {
  371. if (this.is_show) {
  372. if (!obj.donate_er) {
  373. this.$api.msg('请填写您的姓名');
  374. return;
  375. }
  376. } else {
  377. if (!obj.donate_er) {
  378. this.$api.msg('请填写您的单位');
  379. return;
  380. }
  381. }
  382. const reg = /^(\+?0?86-?)?1[\d]\d{9}$/;
  383. if (!reg.test(obj.mobile)) {
  384. obj.$api.msg('请填写正确的手机号码');
  385. return;
  386. }
  387. }
  388. if (this.is_receipts == true) {
  389. // obj.address = '用户未填写联系地址'
  390. if (!obj.address) {
  391. this.$api.msg('请输入联系地址');
  392. return;
  393. }
  394. }
  395. if (!obj.address) {
  396. obj.address = '用户未填写联系地址'
  397. }
  398. createOrderkey({
  399. money: obj.money, //捐款金额
  400. intention: obj.intention, //捐款意向
  401. way: obj.way, //捐款方式
  402. is_public: obj.is_public, //是否实名公开
  403. is_receipts: obj.is_receipts, //是否开发票
  404. donate_er: obj.donate_er, //捐款人/单位
  405. mobile: obj.mobile, //手机号
  406. address: obj.address, //联系地址
  407. }).then(({
  408. data
  409. }) => {
  410. console.log(345, data)
  411. console.log(666, obj)
  412. let res = data.result.jsConfig;
  413. console.log(res)
  414. // 仅作为示例,非真实参数信息。
  415. obj.weichatObj.chooseWXPay({
  416. timestamp: res.timestamp,
  417. nonceStr: res.nonceStr,
  418. package: res.package,
  419. signType: res.signType,
  420. paySign: res.paySign,
  421. success: function(res) {
  422. // obj.$api.msg('支付成功')
  423. let date = new Date()
  424. let year = date.getFullYear()
  425. let month = date.getMonth() >= 9 ? date.getMonth() + 1 : '0'+(date.getMonth() +1 )
  426. let day = date.getDate() >= 10 ? date.getDate() : '0' + date.getDate()
  427. uni.navigateTo({
  428. url: '/pages/form/donaSuccess?money=' + obj.money + '&name=' + obj.donate_er + '&time=' + year + '年' + month + '月' + day +'日'
  429. })
  430. },
  431. fail: function(res) {
  432. this.$refs.popup1.open()
  433. console.log(res, "失败")
  434. console.log(res.errMsg)
  435. }
  436. });
  437. })
  438. // 支付中
  439. obj.payLoding = true;
  440. }
  441. },
  442. }
  443. </script>
  444. <style lang="scss">
  445. .content {}
  446. .top {
  447. display: flex;
  448. align-items: center;
  449. justify-content: center;
  450. background-color: #E63931;
  451. color: #FFFFFF;
  452. padding: 22rpx 0;
  453. }
  454. .box {
  455. margin-top: 10rpx;
  456. .box-item2{
  457. background-color: #FFFFFF;
  458. padding: 18rpx 24rpx;
  459. // display: flex;
  460. border-bottom: 1rpx solid #F2F2F2;
  461. .box-left{
  462. color: #E63931;
  463. }
  464. .box-info{
  465. text-indent: 68rpx;
  466. margin-top: 16rpx;
  467. color: #7b7b7b;
  468. }
  469. .box-phone{
  470. text-indent: 68rpx;
  471. margin-top: 6rpx;
  472. // text-align: center;
  473. color: #7b7b7b;
  474. }
  475. }
  476. .box-item1 {
  477. background-color: #FFFFFF;
  478. padding: 18rpx 24rpx;
  479. // display: flex;
  480. border-bottom: 1rpx solid #F2F2F2;
  481. }
  482. .box-main {
  483. display: flex;
  484. .box-left {
  485. width: 200rpx;
  486. flex-shrink: 0;
  487. // flex: 0;
  488. }
  489. .box-right {
  490. width: 100%;
  491. color: #999999;
  492. text-align: right;
  493. }
  494. }
  495. .box-bottom {
  496. color: #999999;
  497. // padding-left: 12rpx;
  498. padding-top: 12rpx;
  499. font-size: 26rpx;
  500. }
  501. .box-item {
  502. background-color: #FFFFFF;
  503. padding: 24rpx;
  504. display: flex;
  505. border-bottom: 1rpx solid #F2F2F2;
  506. }
  507. .box-left {
  508. width: 200rpx;
  509. flex-shrink: 0;
  510. // flex: 0;
  511. .imp {
  512. color: #E63931;
  513. margin-right: 2rpx;
  514. }
  515. }
  516. .box-right {
  517. width: 100%;
  518. color: #999999;
  519. text-align: right;
  520. }
  521. }
  522. .switch-box {
  523. margin-top: 24rpx;
  524. display: flex;
  525. align-items: center;
  526. padding: 16rpx 24rpx;
  527. color: #7b7b7b;
  528. background-color: #FFFFFF;
  529. border-bottom: 1rpx solid #F2F2F2;
  530. justify-content: space-between;
  531. .switch-right {
  532. // background-color: #E63931;
  533. }
  534. }
  535. .infoOptional {
  536. padding: 20rpx 24rpx;
  537. }
  538. .submit {
  539. position: fixed;
  540. bottom: 0;
  541. left: 0;
  542. right: 0;
  543. width: 750rpx;
  544. height: 100rpx;
  545. background: #FA7E67;
  546. color: #FFFFFF;
  547. display: flex;
  548. align-items: center;
  549. justify-content: center;
  550. }
  551. .popup_row {
  552. height: 500rpx;
  553. width: 100%;
  554. padding: 24rpx;
  555. background-color: #FFFFFF;
  556. .title {
  557. border-bottom: 2rpx solid #F2F2F2;
  558. color: #E63931;
  559. font-size: 32rpx;
  560. padding-left: 4rpx;
  561. padding-bottom: 16rpx;
  562. display: flex;
  563. justify-content: space-between;
  564. // align-items: center;
  565. .cancel {
  566. width: 36rpx;
  567. height: 36rpx;
  568. image {
  569. width: 36rpx;
  570. height: 36rpx;
  571. }
  572. }
  573. }
  574. .money-btn {
  575. display: flex;
  576. justify-content: space-around;
  577. margin-top: 28rpx;
  578. .btn {
  579. // width: 20%;
  580. // display: flex;
  581. // button{
  582. // background-color: #FFFFFF;
  583. // }
  584. }
  585. }
  586. .pop-main {
  587. margin-top: 32rpx;
  588. font-size: 34rpx;
  589. display: flex;
  590. .money-left {
  591. // width: 100rpx;
  592. padding: 0 6rpx;
  593. flex-shrink: 0;
  594. color: #E63931;
  595. // background-color: #457DBF;
  596. }
  597. .money-iup {
  598. width: 100%;
  599. padding-left: 22rpx;
  600. input {
  601. font-size: 32rpx;
  602. // color: #1B1B1B;
  603. color: #FF9797;
  604. .input-placeholder {
  605. // height: 70rpx;
  606. font-size: 32rpx;
  607. color: #FF9797;
  608. }
  609. }
  610. // background-color: pink;
  611. }
  612. }
  613. .comfirm {
  614. display: flex;
  615. justify-content: flex-end;
  616. margin-top: 54rpx;
  617. .comfirm1 {
  618. padding: 12rpx 24rpx;
  619. border-radius: 12rpx;
  620. color: #FFFFFF;
  621. background-color: #E63931;
  622. }
  623. }
  624. }
  625. .popup-box {
  626. width: 522rpx;
  627. height: 605rpx;
  628. background-color: #FFFFFF;
  629. border-radius: 20rpx;
  630. .img {
  631. border-radius: 20rpx 20rpx 0 0;
  632. width: 522rpx;
  633. height: 307rpx;
  634. image {
  635. border-radius: 20rpx 20rpx 0 0;
  636. width: 522rpx;
  637. height: 307rpx;
  638. }
  639. }
  640. .mian {
  641. display: flex;
  642. flex-direction: column;
  643. align-items: center;
  644. padding: 32rpx 32rpx;
  645. background-color: #FFFFFF;
  646. border-radius: 0 0 20rpx 20rpx;
  647. text-align: center;
  648. .delivery {
  649. font-size: 36rpx;
  650. color: #333333;
  651. // margin-top: 46rpx;
  652. }
  653. .nocancel {
  654. font-size: 30rpx;
  655. color: #999999;
  656. margin-top: 26rpx;
  657. }
  658. .comfirm-box {
  659. margin-top: 52rpx;
  660. display: flex;
  661. // margin-bottom: 32rpx;
  662. // justify-content: space-around;
  663. .cancel {
  664. display: flex;
  665. align-items: center;
  666. justify-content: center;
  667. width: 197rpx;
  668. height: 61rpx;
  669. border: 1px solid #C90F1B;
  670. border-radius: 31rpx;
  671. font-size: 24rpx;
  672. color: #C90F1B;
  673. }
  674. .comfirm {
  675. margin-left: 32rpx;
  676. display: flex;
  677. align-items: center;
  678. justify-content: center;
  679. width: 197rpx;
  680. height: 61rpx;
  681. background: #FA7E67;
  682. border-radius: 31px;
  683. font-size: 24rpx;
  684. color: #FFFFFF;
  685. }
  686. }
  687. }
  688. }
  689. </style>