contribution.vue 16 KB

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