contribution.vue 18 KB

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