contribution.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  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">个人满500,单位满2000可打印纸质证书</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. if (this.is_show) {
  333. if (!obj.donate_er) {
  334. this.$api.msg('请填写您的姓名');
  335. return;
  336. }
  337. } else {
  338. if (!obj.donate_er) {
  339. this.$api.msg('请填写您的单位');
  340. return;
  341. }
  342. }
  343. const reg = /^(\+?0?86-?)?1[\d]\d{9}$/;
  344. if (!reg.test(obj.mobile)) {
  345. obj.$api.msg('请填写正确的手机号码');
  346. return;
  347. }
  348. }
  349. if (this.is_receipts) {
  350. if (!obj.address) {
  351. this.$api.msg('请输入联系地址');
  352. return;
  353. }
  354. }
  355. if (!obj.address) {
  356. obj.address = '用户未填写联系地址';
  357. }
  358. uni.showLoading({
  359. title:'提交中...'
  360. })
  361. createOrderkey({
  362. money: obj.money, //捐款金额
  363. intention: obj.intention, //捐款意向
  364. way: obj.way, //捐款方式
  365. is_public: obj.is_public, //是否实名公开
  366. is_receipts: obj.is_receipts, //是否开发票
  367. donate_er: obj.donate_er, //捐款人/单位
  368. mobile: obj.mobile, //手机号
  369. address: obj.address //联系地址
  370. }).then(({ data }) => {
  371. console.log(345, data);
  372. console.log(666, obj);
  373. uni.hideLoading()
  374. let res = data.result.jsConfig;
  375. console.log(res);
  376. // 仅作为示例,非真实参数信息。
  377. obj.weichatObj.chooseWXPay({
  378. timestamp: res.timestamp,
  379. nonceStr: res.nonceStr,
  380. package: res.package,
  381. signType: res.signType,
  382. paySign: res.paySign,
  383. success: function(res) {
  384. // obj.$api.msg('支付成功')
  385. if (obj.is_public) {
  386. uni.navigateTo({
  387. url: '/pages/form/donaSuccess?money=' + obj.money + '&name="' + obj.donate_er + '"'
  388. });
  389. } else {
  390. uni.navigateTo({
  391. url: '/pages/form/donaSuccess?money=' + obj.money
  392. });
  393. }
  394. },
  395. fail: function(res) {
  396. this.$refs.popup1.open();
  397. console.log(res, '失败');
  398. console.log(res.errMsg);
  399. }
  400. });
  401. }).catch((re)=>{
  402. uni.showModal({
  403. title:'申请失败',
  404. content:Object.stringify(re),
  405. showCancel:false
  406. })
  407. });
  408. // 支付中
  409. obj.payLoding = true;
  410. }
  411. }
  412. };
  413. </script>
  414. <style lang="scss">
  415. .content {
  416. }
  417. .top {
  418. display: flex;
  419. align-items: center;
  420. justify-content: center;
  421. background-color: #e63931;
  422. color: #ffffff;
  423. padding: 22rpx 0;
  424. }
  425. .box {
  426. margin-top: 10rpx;
  427. .box-item2 {
  428. background-color: #ffffff;
  429. padding: 18rpx 24rpx;
  430. // display: flex;
  431. border-bottom: 1rpx solid #f2f2f2;
  432. .box-left {
  433. color: #e63931;
  434. }
  435. .box-info {
  436. text-indent: 68rpx;
  437. margin-top: 16rpx;
  438. color: #7b7b7b;
  439. }
  440. .box-phone {
  441. text-indent: 68rpx;
  442. margin-top: 6rpx;
  443. // text-align: center;
  444. color: #7b7b7b;
  445. }
  446. }
  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. position: fixed;
  511. bottom: 0;
  512. left: 0;
  513. right: 0;
  514. width: 750rpx;
  515. height: 100rpx;
  516. background: #f3392c;
  517. color: #ffffff;
  518. display: flex;
  519. align-items: center;
  520. justify-content: center;
  521. }
  522. .popup_row {
  523. height: 500rpx;
  524. width: 100%;
  525. padding: 24rpx;
  526. background-color: #ffffff;
  527. .title {
  528. border-bottom: 2rpx solid #f2f2f2;
  529. color: #e63931;
  530. font-size: 32rpx;
  531. padding-left: 4rpx;
  532. padding-bottom: 16rpx;
  533. display: flex;
  534. justify-content: space-between;
  535. // align-items: center;
  536. .cancel {
  537. width: 36rpx;
  538. height: 36rpx;
  539. image {
  540. width: 36rpx;
  541. height: 36rpx;
  542. }
  543. }
  544. }
  545. .money-btn {
  546. display: flex;
  547. justify-content: space-around;
  548. margin-top: 28rpx;
  549. .btn {
  550. // width: 20%;
  551. // display: flex;
  552. // button{
  553. // background-color: #FFFFFF;
  554. // }
  555. }
  556. }
  557. .pop-main {
  558. margin-top: 32rpx;
  559. font-size: 34rpx;
  560. display: flex;
  561. .money-left {
  562. // width: 100rpx;
  563. padding: 0 6rpx;
  564. flex-shrink: 0;
  565. color: #e63931;
  566. // background-color: #457DBF;
  567. }
  568. .money-iup {
  569. width: 100%;
  570. padding-left: 22rpx;
  571. input {
  572. font-size: 32rpx;
  573. // color: #1B1B1B;
  574. color: #ff9797;
  575. .input-placeholder {
  576. // height: 70rpx;
  577. font-size: 32rpx;
  578. color: #ff9797;
  579. }
  580. }
  581. // background-color: pink;
  582. }
  583. }
  584. .comfirm {
  585. display: flex;
  586. justify-content: flex-end;
  587. margin-top: 54rpx;
  588. .comfirm1 {
  589. padding: 12rpx 24rpx;
  590. border-radius: 12rpx;
  591. color: #ffffff;
  592. background-color: #e63931;
  593. }
  594. }
  595. }
  596. .popup-box {
  597. width: 522rpx;
  598. height: 605rpx;
  599. background-color: #ffffff;
  600. border-radius: 20rpx;
  601. .img {
  602. border-radius: 20rpx 20rpx 0 0;
  603. width: 522rpx;
  604. height: 307rpx;
  605. image {
  606. border-radius: 20rpx 20rpx 0 0;
  607. width: 522rpx;
  608. height: 307rpx;
  609. }
  610. }
  611. .mian {
  612. display: flex;
  613. flex-direction: column;
  614. align-items: center;
  615. padding: 32rpx 32rpx;
  616. background-color: #ffffff;
  617. border-radius: 0 0 20rpx 20rpx;
  618. text-align: center;
  619. .delivery {
  620. font-size: 36rpx;
  621. color: #333333;
  622. // margin-top: 46rpx;
  623. }
  624. .nocancel {
  625. font-size: 30rpx;
  626. color: #999999;
  627. margin-top: 26rpx;
  628. }
  629. .comfirm-box {
  630. margin-top: 52rpx;
  631. display: flex;
  632. // margin-bottom: 32rpx;
  633. // justify-content: space-around;
  634. .cancel {
  635. display: flex;
  636. align-items: center;
  637. justify-content: center;
  638. width: 197rpx;
  639. height: 61rpx;
  640. border: 1px solid #c90f1b;
  641. border-radius: 31rpx;
  642. font-size: 24rpx;
  643. color: #c90f1b;
  644. }
  645. .comfirm {
  646. margin-left: 32rpx;
  647. display: flex;
  648. align-items: center;
  649. justify-content: center;
  650. width: 197rpx;
  651. height: 61rpx;
  652. background: #c90f1b;
  653. border-radius: 31px;
  654. font-size: 24rpx;
  655. color: #ffffff;
  656. }
  657. }
  658. }
  659. }
  660. </style>