contribution.vue 17 KB

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