contribution.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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" v-if="is_public">
  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(obj.is_public) {
  392. if (this.is_show) {
  393. if (!obj.donate_er) {
  394. this.$api.msg('请填写您的姓名');
  395. return;
  396. }
  397. } else {
  398. if (!obj.donate_er) {
  399. this.$api.msg('请填写您的单位');
  400. return;
  401. }
  402. }
  403. const reg = /^(\+?0?86-?)?1[\d]\d{9}$/;
  404. if (!reg.test(obj.mobile)) {
  405. obj.$api.msg('请填写正确的手机号码');
  406. return;
  407. }
  408. }
  409. if (this.is_receipts == true) {
  410. // obj.address = '用户未填写联系地址'
  411. if (!obj.address) {
  412. this.$api.msg('请输入联系地址');
  413. return;
  414. }
  415. }
  416. if (!obj.address) {
  417. obj.address = '用户未填写联系地址'
  418. }
  419. createOrderkey({
  420. money: obj.money, //捐款金额
  421. intention: obj.intention == '其他' ? obj.jkyx : obj.intention, //捐款意向
  422. way: obj.way, //捐款方式
  423. is_public: obj.is_public, //是否实名公开
  424. is_receipts: obj.is_receipts, //是否开发票
  425. donate_er: obj.donate_er, //捐款人/单位
  426. mobile: obj.mobile, //手机号
  427. address: obj.address, //联系地址
  428. }).then(({
  429. data
  430. }) => {
  431. console.log(345, data)
  432. console.log(666, obj)
  433. let res = data.result.jsConfig;
  434. console.log(res)
  435. // 仅作为示例,非真实参数信息。
  436. obj.weichatObj.chooseWXPay({
  437. timestamp: res.timestamp,
  438. nonceStr: res.nonceStr,
  439. package: res.package,
  440. signType: res.signType,
  441. paySign: res.paySign,
  442. success: function(res) {
  443. // obj.$api.msg('支付成功')
  444. let date = new Date()
  445. let year = date.getFullYear()
  446. let month = date.getMonth() >= 9 ? date.getMonth() + 1 : '0' + (date
  447. .getMonth() + 1)
  448. let day = date.getDate() >= 10 ? date.getDate() : '0' + date.getDate()
  449. uni.navigateTo({
  450. url: '/pages/form/donaSuccess?money=' + obj.money +
  451. '&name=' + obj.donate_er + '&time=' + year + '年' +
  452. month + '月' + day + '日'
  453. })
  454. },
  455. fail: function(res) {
  456. this.$refs.popup1.open()
  457. console.log(res, "失败")
  458. console.log(res.errMsg)
  459. }
  460. });
  461. })
  462. // 支付中
  463. obj.payLoding = true;
  464. }
  465. },
  466. }
  467. </script>
  468. <style lang="scss">
  469. .content {}
  470. .top {
  471. display: flex;
  472. align-items: center;
  473. justify-content: center;
  474. background-color: #E63931;
  475. color: #FFFFFF;
  476. padding: 22rpx 0;
  477. }
  478. .box {
  479. margin-top: 10rpx;
  480. .box-item2 {
  481. background-color: #FFFFFF;
  482. padding: 18rpx 24rpx;
  483. // display: flex;
  484. border-bottom: 1rpx solid #F2F2F2;
  485. .box-left {
  486. color: #E63931;
  487. }
  488. .box-info {
  489. text-indent: 68rpx;
  490. margin-top: 16rpx;
  491. color: #7b7b7b;
  492. }
  493. .box-phone {
  494. text-indent: 68rpx;
  495. margin-top: 6rpx;
  496. // text-align: center;
  497. color: #7b7b7b;
  498. }
  499. }
  500. .box-item1 {
  501. background-color: #FFFFFF;
  502. padding: 18rpx 24rpx;
  503. // display: flex;
  504. border-bottom: 1rpx solid #F2F2F2;
  505. }
  506. .box-main {
  507. display: flex;
  508. .box-left {
  509. width: 200rpx;
  510. flex-shrink: 0;
  511. // flex: 0;
  512. }
  513. .box-right {
  514. width: 100%;
  515. color: #999999;
  516. text-align: right;
  517. }
  518. }
  519. .box-bottom {
  520. color: #999999;
  521. // padding-left: 12rpx;
  522. padding-top: 12rpx;
  523. font-size: 26rpx;
  524. }
  525. .box-item {
  526. background-color: #FFFFFF;
  527. padding: 24rpx;
  528. display: flex;
  529. border-bottom: 1rpx solid #F2F2F2;
  530. }
  531. .box-left {
  532. width: 200rpx;
  533. flex-shrink: 0;
  534. // flex: 0;
  535. .imp {
  536. color: #E63931;
  537. margin-right: 2rpx;
  538. }
  539. }
  540. .box-right {
  541. width: 100%;
  542. color: #999999;
  543. text-align: right;
  544. }
  545. }
  546. .switch-box {
  547. margin-top: 24rpx;
  548. display: flex;
  549. align-items: center;
  550. padding: 16rpx 24rpx;
  551. color: #7b7b7b;
  552. background-color: #FFFFFF;
  553. border-bottom: 1rpx solid #F2F2F2;
  554. justify-content: space-between;
  555. .switch-right {
  556. // background-color: #E63931;
  557. }
  558. }
  559. .infoOptional {
  560. padding: 20rpx 24rpx;
  561. }
  562. .submit {
  563. position: fixed;
  564. bottom: 0;
  565. left: 0;
  566. right: 0;
  567. width: 750rpx;
  568. height: 100rpx;
  569. background: #FA7E67;
  570. color: #FFFFFF;
  571. display: flex;
  572. align-items: center;
  573. justify-content: center;
  574. }
  575. .popup_row {
  576. height: 500rpx;
  577. width: 100%;
  578. padding: 24rpx;
  579. background-color: #FFFFFF;
  580. .title {
  581. border-bottom: 2rpx solid #F2F2F2;
  582. color: #E63931;
  583. font-size: 32rpx;
  584. padding-left: 4rpx;
  585. padding-bottom: 16rpx;
  586. display: flex;
  587. justify-content: space-between;
  588. // align-items: center;
  589. .cancel {
  590. width: 36rpx;
  591. height: 36rpx;
  592. image {
  593. width: 36rpx;
  594. height: 36rpx;
  595. }
  596. }
  597. }
  598. .money-btn {
  599. display: flex;
  600. justify-content: space-around;
  601. margin-top: 28rpx;
  602. .btn {
  603. // width: 20%;
  604. // display: flex;
  605. // button{
  606. // background-color: #FFFFFF;
  607. // }
  608. }
  609. }
  610. .pop-main {
  611. margin-top: 32rpx;
  612. font-size: 34rpx;
  613. display: flex;
  614. .money-left {
  615. // width: 100rpx;
  616. padding: 0 6rpx;
  617. flex-shrink: 0;
  618. color: #E63931;
  619. // background-color: #457DBF;
  620. }
  621. .money-iup {
  622. width: 100%;
  623. padding-left: 22rpx;
  624. input {
  625. font-size: 32rpx;
  626. // color: #1B1B1B;
  627. color: #FF9797;
  628. .input-placeholder {
  629. // height: 70rpx;
  630. font-size: 32rpx;
  631. color: #FF9797;
  632. }
  633. }
  634. // background-color: pink;
  635. }
  636. }
  637. .comfirm {
  638. display: flex;
  639. justify-content: flex-end;
  640. margin-top: 54rpx;
  641. .comfirm1 {
  642. padding: 12rpx 24rpx;
  643. border-radius: 12rpx;
  644. color: #FFFFFF;
  645. background-color: #E63931;
  646. }
  647. }
  648. }
  649. .popup-box {
  650. width: 522rpx;
  651. height: 605rpx;
  652. background-color: #FFFFFF;
  653. border-radius: 20rpx;
  654. .img {
  655. border-radius: 20rpx 20rpx 0 0;
  656. width: 522rpx;
  657. height: 307rpx;
  658. image {
  659. border-radius: 20rpx 20rpx 0 0;
  660. width: 522rpx;
  661. height: 307rpx;
  662. }
  663. }
  664. .mian {
  665. display: flex;
  666. flex-direction: column;
  667. align-items: center;
  668. padding: 32rpx 32rpx;
  669. background-color: #FFFFFF;
  670. border-radius: 0 0 20rpx 20rpx;
  671. text-align: center;
  672. .delivery {
  673. font-size: 36rpx;
  674. color: #333333;
  675. // margin-top: 46rpx;
  676. }
  677. .nocancel {
  678. font-size: 30rpx;
  679. color: #999999;
  680. margin-top: 26rpx;
  681. }
  682. .comfirm-box {
  683. margin-top: 52rpx;
  684. display: flex;
  685. // margin-bottom: 32rpx;
  686. // justify-content: space-around;
  687. .cancel {
  688. display: flex;
  689. align-items: center;
  690. justify-content: center;
  691. width: 197rpx;
  692. height: 61rpx;
  693. border: 1px solid #C90F1B;
  694. border-radius: 31rpx;
  695. font-size: 24rpx;
  696. color: #C90F1B;
  697. }
  698. .comfirm {
  699. margin-left: 32rpx;
  700. display: flex;
  701. align-items: center;
  702. justify-content: center;
  703. width: 197rpx;
  704. height: 61rpx;
  705. background: #FA7E67;
  706. border-radius: 31px;
  707. font-size: 24rpx;
  708. color: #FFFFFF;
  709. }
  710. }
  711. }
  712. }
  713. </style>