contribution.vue 17 KB

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