contribution.vue 18 KB

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