contribution1.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. <template>
  2. <view class="content">
  3. <view class="top">
  4. 爱心捐款
  5. </view>
  6. <view class="box">
  7. <view class="box-item">
  8. <view class="box-left">
  9. <text class="imp">*</text>捐款意向
  10. </view>
  11. <view class="box-right">
  12. <!-- <input type="text" placeholder="请选择捐款意向" @click="addType"/> -->
  13. <picker :value="index" @change="PickerDire" :range="chooseDire" class="box-right" @click="addType">
  14. <text>{{ intention || '请选择捐款意向'}}</text>
  15. </picker>
  16. </view>
  17. </view>
  18. <view class="box-item">
  19. <view class="box-left">
  20. <text class="imp">*</text>捐款方式
  21. </view>
  22. <view class="box-right">
  23. <!-- <input type="text" placeholder="请选择捐款方式" /> -->
  24. <picker @change="PickerType" :value="index" :range="chooseType" class="box-right">
  25. <text>{{ way || '请选择捐款方式'}}</text>
  26. </picker>
  27. </view>
  28. </view>
  29. <!-- <view class="box-item">
  30. <view class="box-left">
  31. 捐款金额
  32. </view>
  33. <view class="box-right">
  34. <picker @change="PickerMoney" :value="index" :range="chooseMoney" class="box-right">
  35. <text>{{ money || '请选择捐款金额'}}</text>
  36. </picker>
  37. </view>
  38. </view> -->
  39. <view class="box-item1" @click="tochooseMoney">
  40. <!-- <view class="box-item1" @click="tochooseMoney"> -->
  41. <view class="box-main">
  42. <view class="box-left">
  43. <text class="imp">*</text>捐款金额
  44. </view>
  45. <view class="box-right">
  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" v-if="is_public">
  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="is_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="is_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. </view>
  145. </template>
  146. <script>
  147. import {
  148. chosintention,
  149. joinDona
  150. } from '@/api/ask.js';
  151. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  152. import {
  153. computedOrderkey,
  154. balance,
  155. createOrderkey,
  156. orderPay
  157. } from '@/api/money.js';
  158. import {
  159. saveUrl,
  160. interceptor
  161. } from '@/utils/loginUtils.js';
  162. import {
  163. mapState,
  164. mapMutations
  165. } from 'vuex';
  166. import {
  167. userinfo
  168. } from '@/api/user.js';
  169. export default {
  170. components: {
  171. uniPopup,
  172. // uniLoadMore
  173. },
  174. data() {
  175. return {
  176. index: 0,
  177. intention: '', // 捐款意向
  178. way: '', // 捐款方式
  179. money: '', // 捐款金额
  180. elsemoney: '', // 其他金额
  181. popmoney: '', // 按钮金额 弹窗金额
  182. is_show: true,
  183. moneyList: [{
  184. id: 0,
  185. money: 500
  186. },
  187. {
  188. id: 1,
  189. money: 200
  190. },
  191. {
  192. id: 2,
  193. money: 100
  194. },
  195. {
  196. id: 3,
  197. money: 50
  198. },
  199. {
  200. id: 4,
  201. money: 20
  202. },
  203. ],
  204. is_public: true, // 是否实名公开
  205. is_receipts: false, // 是否开发票
  206. donate_er: '', // 捐款人/单位
  207. mobile: '', // 手机号
  208. isshowMoney: false, // 其他金额是否展示
  209. address: '', // 联系地址
  210. // chooseDire: ['请选择捐款意向','疫情防控','其他','红十字人道事业(非定向捐赠)','红十字博爱送万家','AED救护及科普','青少年生命安全教育基地建设项目','关注重度失能老人项目','青少年白血病救护项目','地芯行动-关爱地中海贫血儿童','会费缴纳'],
  211. chooseDire: [],
  212. chooseType: ['个人', '单位'],
  213. chooseMoney: ['5元', '10元', '50元', '其他金额'],
  214. payLoding: false, //判断是否支付中
  215. froms: '', //保存h5中数据来源对象
  216. type: '', //判断是否从订单中进入
  217. payName: 'weixin',
  218. // orderInfo: {},
  219. }
  220. },
  221. onLoad(options) {
  222. // console.log(333,options)
  223. },
  224. onShow() {
  225. saveUrl()
  226. // let token = uni.getStorageSync('token');
  227. console.log(1, this);
  228. // uni.showModal({
  229. // title: '判断hasLogin',
  230. // content: JSON.stringify(this.hasLogin),
  231. // })
  232. if (!this.hasLogin) {
  233. // 登录拦截
  234. // interceptor();
  235. uni.showModal({
  236. title: '登录',
  237. content: '您未登录,是否马上登陆?',
  238. success: e => {
  239. if (e.confirm) {
  240. interceptor();
  241. }
  242. },
  243. fail: e => {
  244. console.log(e);
  245. uni.showModal({
  246. title: 'cuowu',
  247. content: JSON.stringify(e),
  248. })
  249. }
  250. });
  251. } else {
  252. // this.loadData();
  253. }
  254. },
  255. computed: {
  256. ...mapState('user', ['userInfo', 'baseURL', 'hasLogin']),
  257. ...mapState(['weichatObj']),
  258. },
  259. methods: {
  260. // 点击捐赠意向
  261. addType(e) {
  262. chosintention({}).then(({
  263. data
  264. }) => {
  265. console.log(data)
  266. this.chooseDire = data.map(item => item.title)
  267. }).catch()
  268. },
  269. // 选择捐赠意向
  270. PickerDire: function(e) {
  271. console.log(334, this.chooseDire)
  272. this.intention = this.chooseDire[e.target.value];
  273. this.index = e.target.value + 1;
  274. },
  275. // 选择捐款方式
  276. PickerType: function(e) {
  277. this.way = this.chooseType[e.target.value];
  278. this.index = e.target.value + 1;
  279. console.log('选择捐款方式', this.index)
  280. if (this.index == 1) {
  281. this.is_show = true
  282. } else {
  283. this.is_show = false
  284. }
  285. // if ( )
  286. },
  287. // 选择捐款金额
  288. PickerMoney: function(e) {
  289. this.money = this.chooseMoney[e.target.value];
  290. this.index = e.target.value + 1;
  291. console.log('选择金额', this.money)
  292. if (this.money == '其他金额') {
  293. this.isshowMoney = true
  294. } else {
  295. this.isshowMoney = false
  296. this.elsemoney = ''
  297. }
  298. },
  299. // 其他金额 选择
  300. tochooseMoney: function() {
  301. this.$refs.popup.open();
  302. },
  303. addmoney(mon) {
  304. console.log('点击金额按钮', mon.money)
  305. this.popmoney = mon.money
  306. console.log(123, this.popmoney)
  307. },
  308. cancel() {
  309. this.$refs.popup.close();
  310. },
  311. comfirm1: function() {
  312. let obj = this
  313. if (obj.popmoney.toString().trim() == '') {
  314. console.log('输入框为空')
  315. } else {
  316. console.log('输入框为不为空')
  317. obj.money = obj.popmoney
  318. obj.popmoney = ''
  319. this.$refs.popup.close();
  320. }
  321. },
  322. // 是否实名公开
  323. switch1Change(e) {
  324. this.is_public = e.detail.value
  325. console.log(this.is_public)
  326. },
  327. //是都寄发票
  328. switch2Change(e) {
  329. this.is_receipts = e.detail.value
  330. console.log('is_receipts', this.is_receipts)
  331. },
  332. // 提交
  333. confirm: async function() {
  334. let obj = this
  335. console.log('点击提交')
  336. if (!obj.intention) {
  337. this.$api.msg('请选择捐款意向!');
  338. return;
  339. }
  340. if (!obj.way) {
  341. this.$api.msg('请选择捐款方式!');
  342. return;
  343. }
  344. if (!obj.money) {
  345. this.$api.msg('请输入捐款金额!');
  346. return;
  347. }
  348. // <text class="imp">*</text>
  349. if(obj.is_public) {
  350. if (this.is_show) {
  351. if (!obj.donate_er) {
  352. this.$api.msg('请填写您的姓名');
  353. return;
  354. }
  355. } else {
  356. if (!obj.donate_er) {
  357. this.$api.msg('请填写您的单位');
  358. return;
  359. }
  360. }
  361. const reg = /^(\+?0?86-?)?1[\d]\d{9}$/;
  362. if (!reg.test(obj.mobile)) {
  363. obj.$api.msg('请填写正确的手机号码');
  364. return;
  365. }
  366. }
  367. if (this.is_receipts == true) {
  368. obj.address = '用户未填写联系地址'
  369. if (!obj.address) {
  370. this.$api.msg('请输入联系地址');
  371. return;
  372. }
  373. }
  374. if (!obj.address) {
  375. obj.address = '用户未填写联系地址'
  376. }
  377. console.log('is_receipts', obj.is_receipts)
  378. // uni.showModal({
  379. // title: '暂未开启捐款,请耐心等待',
  380. // })
  381. createOrderkey({
  382. money: obj.money, //捐款金额
  383. intention: obj.intention, //捐款意向
  384. way: obj.way, //捐款方式
  385. is_public: obj.is_public, //是否实名公开
  386. is_receipts: obj.is_receipts, //是否开发票
  387. donate_er: obj.donate_er, //捐款人/单位
  388. mobile: obj.mobile, //手机号
  389. address: obj.address, //联系地址
  390. }).then(({
  391. data
  392. }) => {
  393. // uni.showModal({
  394. // title: '触发点击',
  395. // content: JSON.stringify(data)
  396. // })
  397. console.log(345, data)
  398. let res = data.result.jsConfig;
  399. console.log(res)
  400. // 仅作为示例,非真实参数信息。
  401. obj.weichatObj.chooseWXPay({
  402. timestamp: res.timestamp,
  403. nonceStr: res.nonceStr,
  404. package: res.package,
  405. signType: res.signType,
  406. paySign: res.paySign,
  407. success: function(res) {
  408. console.log(res)
  409. // obj.$api.msg('支付成功')
  410. uni.navigateTo({
  411. url: '/pages/form/donaSuccess1?money=' + obj.money
  412. })
  413. },
  414. fail: function(res) {
  415. console.log(res, "失败")
  416. console.log(res.errMsg)
  417. }
  418. });
  419. })
  420. // 支付中
  421. obj.payLoding = true;
  422. // uni.requestPayment({
  423. // provider: 'wxpay',
  424. // timeStamp: String(Date.now()),
  425. // nonceStr: 'A1B2C3D4E5',
  426. // package: 'prepay_id=wx20180101abcdefg',
  427. // signType: 'MD5',
  428. // paySign: '',
  429. // success: function(res) {
  430. // console.log('success:' + JSON.stringify(res));
  431. // },
  432. // fail: function(err) {
  433. // console.log('fail:' + JSON.stringify(err));
  434. // }
  435. // });
  436. }
  437. },
  438. }
  439. </script>
  440. <style lang="scss">
  441. .content {}
  442. .top {
  443. display: flex;
  444. align-items: center;
  445. justify-content: center;
  446. background-color: #E63931;
  447. color: #FFFFFF;
  448. padding: 22rpx 0;
  449. }
  450. .box {
  451. .box-item1 {
  452. background-color: #FFFFFF;
  453. padding: 18rpx 24rpx;
  454. // display: flex;
  455. border-bottom: 1rpx solid #F2F2F2;
  456. }
  457. .box-main {
  458. display: flex;
  459. .box-left {
  460. width: 200rpx;
  461. flex-shrink: 0;
  462. // flex: 0;
  463. }
  464. .box-right {
  465. width: 100%;
  466. color: #999999;
  467. text-align: right;
  468. }
  469. }
  470. .box-bottom {
  471. color: #999999;
  472. // padding-left: 12rpx;
  473. padding-top: 12rpx;
  474. font-size: 26rpx;
  475. }
  476. .box-item {
  477. background-color: #FFFFFF;
  478. padding: 24rpx;
  479. display: flex;
  480. border-bottom: 1rpx solid #F2F2F2;
  481. }
  482. .box-left {
  483. width: 200rpx;
  484. flex-shrink: 0;
  485. // flex: 0;
  486. .imp {
  487. color: #E63931;
  488. margin-right: 2rpx;
  489. }
  490. }
  491. .box-right {
  492. width: 100%;
  493. color: #999999;
  494. text-align: right;
  495. }
  496. }
  497. .switch-box {
  498. margin-top: 24rpx;
  499. display: flex;
  500. align-items: center;
  501. padding: 16rpx 24rpx;
  502. color: #7b7b7b;
  503. background-color: #FFFFFF;
  504. border-bottom: 1rpx solid #F2F2F2;
  505. justify-content: space-between;
  506. .switch-right {
  507. // background-color: #E63931;
  508. }
  509. }
  510. .infoOptional {
  511. padding: 20rpx 24rpx;
  512. }
  513. .submit {
  514. background-color: #E63931;
  515. color: #FFFFFF;
  516. padding: 20rpx 0;
  517. display: flex;
  518. align-items: center;
  519. justify-content: center;
  520. border-radius: 12rpx;
  521. margin: 52rpx;
  522. }
  523. .popup_row {
  524. height: 500rpx;
  525. width: 100%;
  526. padding: 24rpx;
  527. background-color: #FFFFFF;
  528. .title {
  529. border-bottom: 2rpx solid #F2F2F2;
  530. color: #E63931;
  531. font-size: 32rpx;
  532. padding-left: 4rpx;
  533. padding-bottom: 16rpx;
  534. display: flex;
  535. justify-content: space-between;
  536. // align-items: center;
  537. .cancel {
  538. width: 36rpx;
  539. height: 36rpx;
  540. image {
  541. width: 36rpx;
  542. height: 36rpx;
  543. }
  544. }
  545. }
  546. .money-btn {
  547. display: flex;
  548. justify-content: space-around;
  549. margin-top: 28rpx;
  550. .btn {
  551. // width: 20%;
  552. // display: flex;
  553. // button{
  554. // background-color: #FFFFFF;
  555. // }
  556. }
  557. }
  558. .pop-main {
  559. margin-top: 32rpx;
  560. font-size: 34rpx;
  561. display: flex;
  562. .money-left {
  563. // width: 100rpx;
  564. padding: 0 6rpx;
  565. flex-shrink: 0;
  566. color: #E63931;
  567. // background-color: #457DBF;
  568. }
  569. .money-iup {
  570. width: 100%;
  571. padding-left: 22rpx;
  572. input {
  573. font-size: 32rpx;
  574. // color: #1B1B1B;
  575. color: #FF9797;
  576. .input-placeholder {
  577. // height: 70rpx;
  578. font-size: 32rpx;
  579. color: #FF9797;
  580. }
  581. }
  582. // background-color: pink;
  583. }
  584. }
  585. .comfirm {
  586. display: flex;
  587. justify-content: flex-end;
  588. margin-top: 54rpx;
  589. .comfirm1 {
  590. padding: 12rpx 24rpx;
  591. border-radius: 12rpx;
  592. color: #FFFFFF;
  593. background-color: #E63931;
  594. }
  595. }
  596. }
  597. </style>