contribution.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  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='#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. saveUrl()
  250. // let token = uni.getStorageSync('token');
  251. console.log(1, this);
  252. // uni.showModal({
  253. // title: '判断hasLogin',
  254. // content: JSON.stringify(this.hasLogin),
  255. // })
  256. if (!this.hasLogin) {
  257. // 登录拦截
  258. // interceptor();
  259. uni.showModal({
  260. title: '登录',
  261. content: '您未登录,是否马上登陆?',
  262. success: e => {
  263. if (e.confirm) {
  264. interceptor();
  265. }
  266. },
  267. fail: e => {
  268. console.log(e);
  269. uni.showModal({
  270. title: 'cuowu',
  271. content: JSON.stringify(e),
  272. })
  273. }
  274. });
  275. } else {
  276. // this.loadData();
  277. }
  278. },
  279. computed: {
  280. ...mapState('user', ['userInfo', 'baseURL', 'hasLogin']),
  281. ...mapState(['weichatObj']),
  282. },
  283. methods: {
  284. // 点击捐赠意向
  285. addType(e) {
  286. chosintention({}).then(({
  287. data
  288. }) => {
  289. console.log(data)
  290. this.chooseDire = data.map(item => item.title)
  291. }).catch()
  292. },
  293. // 选择捐赠意向
  294. PickerDire: function(e) {
  295. console.log(334, this.chooseDire)
  296. this.intention = this.chooseDire[e.target.value];
  297. this.index = e.target.value + 1;
  298. },
  299. // 选择捐款方式
  300. PickerType: function(e) {
  301. this.way = this.chooseType[e.target.value];
  302. this.index = e.target.value + 1;
  303. console.log('选择捐款方式', this.index)
  304. if (this.index == 1) {
  305. this.is_show = true
  306. } else {
  307. this.is_show = false
  308. }
  309. // if ( )
  310. },
  311. // 选择捐款金额
  312. PickerMoney: function(e) {
  313. this.money = this.chooseMoney[e.target.value];
  314. this.index = e.target.value + 1;
  315. console.log('选择金额', this.money)
  316. if (this.money == '其他金额') {
  317. this.isshowMoney = true
  318. } else {
  319. this.isshowMoney = false
  320. this.elsemoney = ''
  321. }
  322. },
  323. // 其他金额 选择
  324. tochooseMoney: function() {
  325. this.$refs.popup.open();
  326. },
  327. addmoney(mon) {
  328. console.log('点击金额按钮', mon.money)
  329. this.popmoney = mon.money
  330. console.log(123, this.popmoney)
  331. },
  332. cancel() {
  333. this.$refs.popup.close();
  334. },
  335. cancel1() {
  336. this.$refs.popup1.close();
  337. },
  338. comfirm1: function() {
  339. let obj = this
  340. if (obj.popmoney.toString().trim() == '') {
  341. console.log('输入框为空')
  342. } else {
  343. console.log('输入框为不为空')
  344. obj.money = obj.popmoney
  345. obj.popmoney = ''
  346. this.$refs.popup.close();
  347. }
  348. },
  349. comfirmExit() {
  350. console.log('点击comfirmExit')
  351. this.$refs.popup1.close()
  352. uni.switchTab({
  353. url: '/pages/home/home'
  354. });
  355. },
  356. // 是否实名公开
  357. switch1Change(e) {
  358. this.is_public = e.detail.value
  359. console.log(this.is_public)
  360. },
  361. //是都寄发票
  362. switch2Change(e) {
  363. this.is_receipts = e.detail.value
  364. console.log('is_receipts', this.is_receipts)
  365. },
  366. // 提交
  367. confirm: async function() {
  368. let obj = this
  369. if (!obj.way) {
  370. this.$api.msg('请选择捐款方式!');
  371. return;
  372. }
  373. if (!obj.money) {
  374. this.$api.msg('请输入捐款金额!');
  375. return;
  376. }
  377. if (this.is_show) {
  378. if (!obj.donate_er) {
  379. this.$api.msg('请填写您的姓名');
  380. return;
  381. }
  382. } else {
  383. if (!obj.donate_er) {
  384. this.$api.msg('请填写您的单位');
  385. return;
  386. }
  387. }
  388. const reg = /^(\+?0?86-?)?1[\d]\d{9}$/;
  389. if (!reg.test(obj.mobile)) {
  390. obj.$api.msg('请填写正确的手机号码');
  391. return;
  392. }
  393. if (this.is_receipts == true) {
  394. obj.address = '用户未填写联系地址'
  395. if (!obj.address) {
  396. this.$api.msg('请输入联系地址');
  397. return;
  398. }
  399. }
  400. if (!obj.address) {
  401. obj.address = '用户未填写联系地址'
  402. }
  403. createOrderkey({
  404. money: obj.money, //捐款金额
  405. intention: obj.intention, //捐款意向
  406. way: obj.way, //捐款方式
  407. is_public: obj.is_public, //是否实名公开
  408. is_receipts: obj.is_receipts, //是否开发票
  409. donate_er: obj.donate_er, //捐款人/单位
  410. mobile: obj.mobile, //手机号
  411. address: obj.address, //联系地址
  412. }).then(({
  413. data
  414. }) => {
  415. console.log(345, data)
  416. // console.log(666, obj)
  417. let res = data.result.jsConfig;
  418. console.log(res)
  419. // 仅作为示例,非真实参数信息。
  420. obj.weichatObj.chooseWXPay({
  421. timestamp: res.timestamp,
  422. nonceStr: res.nonceStr,
  423. package: res.package,
  424. signType: res.signType,
  425. paySign: res.paySign,
  426. success: function(res) {
  427. // obj.$api.msg('支付成功')
  428. if(obj.is_public){
  429. uni.navigateTo({
  430. url: '/pages/form/donaSuccess?money=' + obj.money +'&name="'+ obj.donate_er+'"'
  431. })
  432. } else{
  433. uni.navigateTo({
  434. url: '/pages/form/donaSuccess?money=' + obj.money
  435. })
  436. }
  437. },
  438. fail: function(res) {
  439. this.$refs.popup1.open()
  440. console.log(res, "失败")
  441. console.log(res.errMsg)
  442. }
  443. });
  444. })
  445. // 支付中
  446. obj.payLoding = true;
  447. }
  448. },
  449. }
  450. </script>
  451. <style lang="scss">
  452. .content {}
  453. .top {
  454. display: flex;
  455. align-items: center;
  456. justify-content: center;
  457. background-color: #E63931;
  458. color: #FFFFFF;
  459. padding: 22rpx 0;
  460. }
  461. .box {
  462. margin-top: 10rpx;
  463. .box-item2{
  464. background-color: #FFFFFF;
  465. padding: 18rpx 24rpx;
  466. // display: flex;
  467. border-bottom: 1rpx solid #F2F2F2;
  468. .box-left{
  469. color: #E63931;
  470. }
  471. .box-info{
  472. text-indent: 68rpx;
  473. margin-top: 16rpx;
  474. color: #7b7b7b;
  475. }
  476. .box-phone{
  477. text-indent: 68rpx;
  478. margin-top: 6rpx;
  479. // text-align: center;
  480. color: #7b7b7b;
  481. }
  482. }
  483. .box-item1 {
  484. background-color: #FFFFFF;
  485. padding: 18rpx 24rpx;
  486. // display: flex;
  487. border-bottom: 1rpx solid #F2F2F2;
  488. }
  489. .box-main {
  490. display: flex;
  491. .box-left {
  492. width: 200rpx;
  493. flex-shrink: 0;
  494. // flex: 0;
  495. }
  496. .box-right {
  497. width: 100%;
  498. color: #999999;
  499. text-align: right;
  500. }
  501. }
  502. .box-bottom {
  503. color: #999999;
  504. // padding-left: 12rpx;
  505. padding-top: 12rpx;
  506. font-size: 26rpx;
  507. }
  508. .box-item {
  509. background-color: #FFFFFF;
  510. padding: 24rpx;
  511. display: flex;
  512. border-bottom: 1rpx solid #F2F2F2;
  513. }
  514. .box-left {
  515. width: 200rpx;
  516. flex-shrink: 0;
  517. // flex: 0;
  518. .imp {
  519. color: #E63931;
  520. margin-right: 2rpx;
  521. }
  522. }
  523. .box-right {
  524. width: 100%;
  525. color: #999999;
  526. text-align: right;
  527. }
  528. }
  529. .switch-box {
  530. margin-top: 24rpx;
  531. display: flex;
  532. align-items: center;
  533. padding: 16rpx 24rpx;
  534. color: #7b7b7b;
  535. background-color: #FFFFFF;
  536. border-bottom: 1rpx solid #F2F2F2;
  537. justify-content: space-between;
  538. .switch-right {
  539. // background-color: #E63931;
  540. }
  541. }
  542. .infoOptional {
  543. padding: 20rpx 24rpx;
  544. }
  545. .submit {
  546. position: fixed;
  547. bottom: 0;
  548. left: 0;
  549. right: 0;
  550. width: 750rpx;
  551. height: 100rpx;
  552. background: #F3392C;
  553. color: #FFFFFF;
  554. display: flex;
  555. align-items: center;
  556. justify-content: center;
  557. }
  558. .popup_row {
  559. height: 500rpx;
  560. width: 100%;
  561. padding: 24rpx;
  562. background-color: #FFFFFF;
  563. .title {
  564. border-bottom: 2rpx solid #F2F2F2;
  565. color: #E63931;
  566. font-size: 32rpx;
  567. padding-left: 4rpx;
  568. padding-bottom: 16rpx;
  569. display: flex;
  570. justify-content: space-between;
  571. // align-items: center;
  572. .cancel {
  573. width: 36rpx;
  574. height: 36rpx;
  575. image {
  576. width: 36rpx;
  577. height: 36rpx;
  578. }
  579. }
  580. }
  581. .money-btn {
  582. display: flex;
  583. justify-content: space-around;
  584. margin-top: 28rpx;
  585. .btn {
  586. // width: 20%;
  587. // display: flex;
  588. // button{
  589. // background-color: #FFFFFF;
  590. // }
  591. }
  592. }
  593. .pop-main {
  594. margin-top: 32rpx;
  595. font-size: 34rpx;
  596. display: flex;
  597. .money-left {
  598. // width: 100rpx;
  599. padding: 0 6rpx;
  600. flex-shrink: 0;
  601. color: #E63931;
  602. // background-color: #457DBF;
  603. }
  604. .money-iup {
  605. width: 100%;
  606. padding-left: 22rpx;
  607. input {
  608. font-size: 32rpx;
  609. // color: #1B1B1B;
  610. color: #FF9797;
  611. .input-placeholder {
  612. // height: 70rpx;
  613. font-size: 32rpx;
  614. color: #FF9797;
  615. }
  616. }
  617. // background-color: pink;
  618. }
  619. }
  620. .comfirm {
  621. display: flex;
  622. justify-content: flex-end;
  623. margin-top: 54rpx;
  624. .comfirm1 {
  625. padding: 12rpx 24rpx;
  626. border-radius: 12rpx;
  627. color: #FFFFFF;
  628. background-color: #E63931;
  629. }
  630. }
  631. }
  632. .popup-box {
  633. width: 522rpx;
  634. height: 605rpx;
  635. background-color: #FFFFFF;
  636. border-radius: 20rpx;
  637. .img {
  638. border-radius: 20rpx 20rpx 0 0;
  639. width: 522rpx;
  640. height: 307rpx;
  641. image {
  642. border-radius: 20rpx 20rpx 0 0;
  643. width: 522rpx;
  644. height: 307rpx;
  645. }
  646. }
  647. .mian {
  648. display: flex;
  649. flex-direction: column;
  650. align-items: center;
  651. padding: 32rpx 32rpx;
  652. background-color: #FFFFFF;
  653. border-radius: 0 0 20rpx 20rpx;
  654. text-align: center;
  655. .delivery {
  656. font-size: 36rpx;
  657. color: #333333;
  658. // margin-top: 46rpx;
  659. }
  660. .nocancel {
  661. font-size: 30rpx;
  662. color: #999999;
  663. margin-top: 26rpx;
  664. }
  665. .comfirm-box {
  666. margin-top: 52rpx;
  667. display: flex;
  668. // margin-bottom: 32rpx;
  669. // justify-content: space-around;
  670. .cancel {
  671. display: flex;
  672. align-items: center;
  673. justify-content: center;
  674. width: 197rpx;
  675. height: 61rpx;
  676. border: 1px solid #C90F1B;
  677. border-radius: 31rpx;
  678. font-size: 24rpx;
  679. color: #C90F1B;
  680. }
  681. .comfirm {
  682. margin-left: 32rpx;
  683. display: flex;
  684. align-items: center;
  685. justify-content: center;
  686. width: 197rpx;
  687. height: 61rpx;
  688. background: #C90F1B;
  689. border-radius: 31px;
  690. font-size: 24rpx;
  691. color: #FFFFFF;
  692. }
  693. }
  694. }
  695. }
  696. </style>