contribution.vue 17 KB

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