contribution.vue 15 KB

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