contribution.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  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" v-if="public">
  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. {
  211. id: 1,
  212. money: 200
  213. },
  214. {
  215. id: 2,
  216. money: 100
  217. },
  218. {
  219. id: 3,
  220. money: 50
  221. },
  222. {
  223. id: 4,
  224. money: 20
  225. },
  226. {
  227. id: 5,
  228. money: 10
  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 => item.name)
  297. this.chooseList = data
  298. }).catch()
  299. },
  300. // 选择捐赠意向
  301. PickerDire: function(e) {
  302. console.log(334, e)
  303. this.intention = this.chooseDire[e.target.value];
  304. this.category_id = this.chooseList[e.target.value].id;
  305. },
  306. // 选择捐款方式
  307. PickerType: function(e) {
  308. this.way = this.chooseType[e.target.value];
  309. this.way_id = e.target.value;
  310. this.index = e.target.value;
  311. console.log('选择捐款方式', this.way_id)
  312. if (this.index == 1) {
  313. this.is_show = true
  314. } else {
  315. this.is_show = false
  316. }
  317. // if ( )
  318. },
  319. // 选择捐款金额
  320. PickerMoney: function(e) {
  321. this.money = this.chooseMoney[e.target.value];
  322. this.index = e.target.value + 1;
  323. console.log('选择金额', this.money)
  324. if (this.money == '其他金额') {
  325. this.isshowMoney = true
  326. } else {
  327. this.isshowMoney = false
  328. this.elsemoney = ''
  329. }
  330. },
  331. // 其他金额 选择
  332. tochooseMoney: function() {
  333. this.$refs.popup.open();
  334. },
  335. addmoney(mon) {
  336. console.log('点击金额按钮', mon.money)
  337. this.popmoney = mon.money
  338. console.log(123, this.popmoney)
  339. },
  340. cancel() {
  341. this.$refs.popup.close();
  342. },
  343. cancel1() {
  344. this.$refs.popup1.close();
  345. },
  346. comfirm1: function() {
  347. let obj = this
  348. if (obj.popmoney.toString().trim() == '') {
  349. console.log('输入框为空')
  350. } else {
  351. console.log('输入框为不为空')
  352. obj.money = obj.popmoney
  353. obj.popmoney = ''
  354. this.$refs.popup.close();
  355. }
  356. },
  357. comfirmExit() {
  358. console.log('点击comfirmExit')
  359. this.$refs.popup1.close()
  360. uni.switchTab({
  361. url: '/pages/home/home'
  362. });
  363. },
  364. // 是否实名公开
  365. switch1Change(e) {
  366. console.log(e)
  367. this.public = e.detail.value
  368. if (e.detail.value) {
  369. this.is_public = '0'
  370. } else {
  371. this.is_public = '1'
  372. }
  373. console.log(this.is_public)
  374. },
  375. //是都寄发票
  376. switch2Change(e) {
  377. this.is_receipts = e.detail.value
  378. if (e.detail.value) {
  379. this.is_receipts = '0'
  380. } else {
  381. this.is_receipts = '1'
  382. }
  383. console.log('is_receipts', this.is_receipts)
  384. },
  385. // 提交
  386. confirm: async function() {
  387. let obj = this
  388. if (!obj.way) {
  389. this.$api.msg('请选择捐款方式!');
  390. return;
  391. }
  392. if (!obj.money) {
  393. this.$api.msg('请输入捐款金额!');
  394. return;
  395. }
  396. if(obj.public) {
  397. if (this.is_show) {
  398. if (!obj.donate_er) {
  399. this.$api.msg('请填写您的姓名');
  400. return;
  401. }
  402. } else {
  403. if (!obj.donate_er) {
  404. this.$api.msg('请填写您的单位');
  405. return;
  406. }
  407. }
  408. const reg = /^(\+?0?86-?)?1[\d]\d{9}$/;
  409. if (!reg.test(obj.mobile)) {
  410. obj.$api.msg('请填写正确的手机号码');
  411. return;
  412. }
  413. }
  414. if (this.is_receipts == '0') {
  415. // obj.address = '用户未填写联系地址'
  416. if (!obj.address) {
  417. this.$api.msg('请输入联系地址');
  418. return;
  419. }
  420. }
  421. if (!obj.address) {
  422. obj.address = '用户未填写联系地址'
  423. }
  424. if(!obj.isHelp) {
  425. if (!obj.intention) {
  426. this.$api.msg('请选择捐款意向');
  427. return;
  428. }
  429. }
  430. let updata = {
  431. // category_id: obj.category_id, //捐款意向id
  432. amount: obj.money, //捐款金额
  433. name: obj.donate_er, //捐款人/单位
  434. // contact: obj, //单位联系人(企业有效)
  435. tel: obj.mobile, //手机号
  436. address: obj.address, //联系地址
  437. is_open: obj.is_public == '0'?1:0, //是否实名公开
  438. is_ticket: obj.is_receipts == '0'?1:0, //是否开发票
  439. pay_type: 0, //支付方式0微信1支付宝
  440. type: obj.way_id,
  441. }
  442. if (obj.isHelp) {
  443. updata.help_id = obj.help_id
  444. updata.order_name = obj.order_name
  445. } else {
  446. updata.order_name = obj.intention //捐款意向
  447. updata.category_id = obj.category_id //捐款意向id
  448. }
  449. createOrderkey(updata).then(({
  450. data
  451. }) => {
  452. console.log(345, data)
  453. console.log(666, obj)
  454. let res = data.jsConfig;
  455. console.log(res)
  456. // 仅作为示例,非真实参数信息。
  457. obj.weichatObj.chooseWXPay({
  458. timestamp: res.timestamp,
  459. nonceStr: res.nonceStr,
  460. package: res.package,
  461. signType: res.signType,
  462. paySign: res.paySign,
  463. success: function(res) {
  464. // obj.$api.msg('支付成功')
  465. let date = new Date()
  466. let year = date.getFullYear()
  467. let month = date.getMonth() >= 9 ? date.getMonth() + 1 : '0' + (date
  468. .getMonth() + 1)
  469. let day = date.getDate() >= 10 ? date.getDate() : '0' + date.getDate()
  470. uni.navigateTo({
  471. url: '/pages/form/donaSuccess?money=' + obj.money +
  472. '&name=' + obj.donate_er + '&time=' + year + '年' +
  473. month + '月' + day + '日' + '&intention=' + obj.intention
  474. })
  475. },
  476. fail: function(res) {
  477. this.$refs.popup1.open()
  478. console.log(res, "失败")
  479. console.log(res.errMsg)
  480. }
  481. });
  482. })
  483. // 支付中
  484. obj.payLoding = true;
  485. }
  486. },
  487. }
  488. </script>
  489. <style lang="scss">
  490. .content {}
  491. .top {
  492. display: flex;
  493. align-items: center;
  494. justify-content: center;
  495. background-color: #E63931;
  496. color: #FFFFFF;
  497. padding: 22rpx 0;
  498. }
  499. .box {
  500. margin-top: 10rpx;
  501. .box-item2 {
  502. background-color: #FFFFFF;
  503. padding: 18rpx 24rpx;
  504. // display: flex;
  505. border-bottom: 1rpx solid #F2F2F2;
  506. .box-left {
  507. color: #E63931;
  508. }
  509. .box-info {
  510. text-indent: 68rpx;
  511. margin-top: 16rpx;
  512. color: #7b7b7b;
  513. }
  514. .box-phone {
  515. text-indent: 68rpx;
  516. margin-top: 6rpx;
  517. // text-align: center;
  518. color: #7b7b7b;
  519. }
  520. }
  521. .box-item1 {
  522. background-color: #FFFFFF;
  523. padding: 18rpx 24rpx;
  524. // display: flex;
  525. border-bottom: 1rpx solid #F2F2F2;
  526. }
  527. .box-main {
  528. display: flex;
  529. .box-left {
  530. width: 200rpx;
  531. flex-shrink: 0;
  532. // flex: 0;
  533. }
  534. .box-right {
  535. width: 100%;
  536. color: #999999;
  537. text-align: right;
  538. }
  539. }
  540. .box-bottom {
  541. color: #999999;
  542. // padding-left: 12rpx;
  543. padding-top: 12rpx;
  544. font-size: 26rpx;
  545. }
  546. .box-item {
  547. background-color: #FFFFFF;
  548. padding: 24rpx;
  549. display: flex;
  550. border-bottom: 1rpx solid #F2F2F2;
  551. }
  552. .box-left {
  553. width: 200rpx;
  554. flex-shrink: 0;
  555. // flex: 0;
  556. .imp {
  557. color: #E63931;
  558. margin-right: 2rpx;
  559. }
  560. }
  561. .box-right {
  562. width: 100%;
  563. color: #999999;
  564. text-align: right;
  565. }
  566. }
  567. .switch-box {
  568. margin-top: 24rpx;
  569. display: flex;
  570. align-items: center;
  571. padding: 16rpx 24rpx;
  572. color: #7b7b7b;
  573. background-color: #FFFFFF;
  574. border-bottom: 1rpx solid #F2F2F2;
  575. justify-content: space-between;
  576. .switch-right {
  577. // background-color: #E63931;
  578. }
  579. }
  580. .infoOptional {
  581. padding: 20rpx 24rpx;
  582. }
  583. .submit {
  584. position: fixed;
  585. bottom: 0;
  586. left: 0;
  587. right: 0;
  588. width: 750rpx;
  589. height: 100rpx;
  590. background: #E63931;
  591. color: #FFFFFF;
  592. display: flex;
  593. align-items: center;
  594. justify-content: center;
  595. }
  596. .popup_row {
  597. height: 500rpx;
  598. width: 100%;
  599. padding: 24rpx;
  600. background-color: #FFFFFF;
  601. .title {
  602. border-bottom: 2rpx solid #F2F2F2;
  603. color: #E63931;
  604. font-size: 32rpx;
  605. padding-left: 4rpx;
  606. padding-bottom: 16rpx;
  607. display: flex;
  608. justify-content: space-between;
  609. // align-items: center;
  610. .cancel {
  611. width: 36rpx;
  612. height: 36rpx;
  613. image {
  614. width: 36rpx;
  615. height: 36rpx;
  616. }
  617. }
  618. }
  619. .money-btn {
  620. display: flex;
  621. justify-content: space-around;
  622. margin-top: 28rpx;
  623. .btn {
  624. // width: 20%;
  625. // display: flex;
  626. // button{
  627. // background-color: #FFFFFF;
  628. // }
  629. }
  630. }
  631. .pop-main {
  632. margin-top: 32rpx;
  633. font-size: 34rpx;
  634. display: flex;
  635. .money-left {
  636. // width: 100rpx;
  637. padding: 0 6rpx;
  638. flex-shrink: 0;
  639. color: #E63931;
  640. // background-color: #457DBF;
  641. }
  642. .money-iup {
  643. width: 100%;
  644. padding-left: 22rpx;
  645. input {
  646. font-size: 32rpx;
  647. // color: #1B1B1B;
  648. color: #FF9797;
  649. .input-placeholder {
  650. // height: 70rpx;
  651. font-size: 32rpx;
  652. color: #FF9797;
  653. }
  654. }
  655. // background-color: pink;
  656. }
  657. }
  658. .comfirm {
  659. display: flex;
  660. justify-content: flex-end;
  661. margin-top: 54rpx;
  662. .comfirm1 {
  663. padding: 12rpx 24rpx;
  664. border-radius: 12rpx;
  665. color: #FFFFFF;
  666. background-color: #E63931;
  667. }
  668. }
  669. }
  670. .popup-box {
  671. width: 522rpx;
  672. height: 605rpx;
  673. background-color: #FFFFFF;
  674. border-radius: 20rpx;
  675. .img {
  676. border-radius: 20rpx 20rpx 0 0;
  677. width: 522rpx;
  678. height: 307rpx;
  679. image {
  680. border-radius: 20rpx 20rpx 0 0;
  681. width: 522rpx;
  682. height: 307rpx;
  683. }
  684. }
  685. .mian {
  686. display: flex;
  687. flex-direction: column;
  688. align-items: center;
  689. padding: 32rpx 32rpx;
  690. background-color: #FFFFFF;
  691. border-radius: 0 0 20rpx 20rpx;
  692. text-align: center;
  693. .delivery {
  694. font-size: 36rpx;
  695. color: #333333;
  696. // margin-top: 46rpx;
  697. }
  698. .nocancel {
  699. font-size: 30rpx;
  700. color: #999999;
  701. margin-top: 26rpx;
  702. }
  703. .comfirm-box {
  704. margin-top: 52rpx;
  705. display: flex;
  706. // margin-bottom: 32rpx;
  707. // justify-content: space-around;
  708. .cancel {
  709. display: flex;
  710. align-items: center;
  711. justify-content: center;
  712. width: 197rpx;
  713. height: 61rpx;
  714. border: 1px solid #C90F1B;
  715. border-radius: 31rpx;
  716. font-size: 24rpx;
  717. color: #C90F1B;
  718. }
  719. .comfirm {
  720. margin-left: 32rpx;
  721. display: flex;
  722. align-items: center;
  723. justify-content: center;
  724. width: 197rpx;
  725. height: 61rpx;
  726. background: #FA7E67;
  727. border-radius: 31px;
  728. font-size: 24rpx;
  729. color: #FFFFFF;
  730. }
  731. }
  732. }
  733. }
  734. </style>