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