information.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. <template>
  2. <view style="background-color: #fff;height: 100vh;">
  3. <view class="address flexB " @click="goaddress">
  4. <view class="flexV">
  5. <view class="address_tip red">
  6. 收货人
  7. </view>
  8. <view v-if="!showEdit">
  9. <view>
  10. <text>{{ form.user_name }}</text>
  11. <text style="margin-left: 24rpx;">{{ form.mobile }}</text>
  12. </view>
  13. <view class="gray">
  14. {{ form.province + form.city + form.area + form.address }}
  15. </view>
  16. </view>
  17. <view class="address_title" v-if="showEdit">
  18. 收货人信息
  19. </view>
  20. </view>
  21. <view style="width: 48rpx;height: 48rpx;">
  22. <image src="../../static/Buy_soap_tape/arrow.png" style="width: 48rpx;height: 48rpx;margin-left: 10rpx;"></image>
  23. </view>
  24. </view>
  25. <view class="detail flexV">
  26. <view style="width: 200rpx;height: 160rpx;">
  27. <image :src="type ? image[0] : image[1]" style="width: 200rpx;height: 160rpx;" />
  28. </view>
  29. <view class="detail_flex">
  30. <view class="title">
  31. {{ type ? '【大卫博士健康内裤】专用洗涤皂' : '【大卫博士健康内裤】专用打包胶带' }}
  32. </view>
  33. <view class="dan">
  34. <text>
  35. <text style="font-size: 28rpx;">¥</text>{{ type ? 8 : 20 }}
  36. </text>
  37. <view class="num-input">
  38. <view class="i l" style="font-size: 40rpx;" @tap.stop="red">-</view>
  39. <view class="i c" @tap.stop="inputNum = num, showInput = true">{{ num }}</view>
  40. <view class="i r" style="font-size: 40rpx;" @tap.stop="add">+</view>
  41. <view v-if="showInput" class="inputModelWrapper">
  42. <view class="inputModel">
  43. <view class="t">请输入数量</view>
  44. <view class="m">
  45. <input ref="input" focus type="number" maxlength="6" v-model="inputNum" />
  46. </view>
  47. <view class="b">
  48. <text style="color: #333333;" @tap.stop="showInput = false">取消</text>
  49. <text class="r basecolor" @tap.stop="comfirmNum">确定</text>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. <view class="tip">
  56. 本件商品10{{ type ? '块' : '卷' }}起订
  57. </view>
  58. </view>
  59. </view>
  60. <view class="remark">
  61. <text>备注(选填)</text>
  62. <view class="remark_bg">
  63. <textarea type="text" placeholder="在这里写备注" v-model="remark" placeholder-class="placetext" auto-height />
  64. </view>
  65. </view>
  66. <view class="bottom">
  67. <view class="bottom_top">
  68. <text class="text1">共{{ `${num + (type ? '块' : '卷')}` }},</text>
  69. <text>合计;</text>
  70. <text class="text2">¥</text>
  71. <text class="text3">{{ total }}</text>
  72. </view>
  73. <view class="bottom_btn" @click="$noMultipleClicks(save)">
  74. 立即支付
  75. </view>
  76. </view>
  77. </view>
  78. </template>
  79. <script>
  80. // import NumInput from '@/components/public/num-input.vue'
  81. import { _API_Getpays } from '@/api/Buy_soap_tape.js'
  82. import { location } from '@/api/index.js'
  83. const jweixin = require('jweixin-module');
  84. export default {
  85. data() {
  86. return {
  87. ads: {
  88. location: '',
  89. province: '',
  90. city: '',
  91. area: ''
  92. }, //文字地址
  93. allForm: {},
  94. type: '',
  95. noClick: true,
  96. showEdit: true,
  97. showInput: false,
  98. inputNum: '',
  99. remark: '',
  100. image: [
  101. require('../../static/Buy_soap_tape/soap-s.png'),
  102. require('../../static/Buy_soap_tape/tape-s.png')
  103. ],
  104. num: 10,
  105. openid: '',
  106. m_mi: '',
  107. location: '',
  108. form: {
  109. user_name: '',
  110. mobile: '',
  111. province: '',
  112. city: '',
  113. area: '',
  114. address: '',
  115. area_code: '+86' // 手机号地区代码
  116. // user_name: '张先生',
  117. // mobile: '13523102256',
  118. // province: '河南省',
  119. // city: '郑州市',
  120. // area: '管城回族区',
  121. // address: '七里河小区1号楼1单元 5楼A508',
  122. },
  123. }
  124. },
  125. computed: {
  126. address() {
  127. return this.$store.state.list[this.$store.getters['usingAddressIndex']]
  128. },
  129. total() {
  130. return this.type ? this.num * 8 : this.num * 20
  131. }
  132. },
  133. onLoad: function(option) {
  134. this.type = uni.getStorageSync('type')
  135. if (option.num) {
  136. this.num = Number(option.num)
  137. }
  138. },
  139. onShow() {
  140. if (this.address) {
  141. this.showEdit = false
  142. const { con_name, con_mobile, provice, city, area, address, area_code } = this.address
  143. this.form = {
  144. user_name: con_name,
  145. mobile: con_mobile,
  146. province: provice,
  147. city: city,
  148. area: area,
  149. address: address,
  150. area_code: area_code
  151. }
  152. }
  153. },
  154. mounted() {
  155. this.getAddress()
  156. },
  157. methods: {
  158. //通过后端获取wx.config的配置,再通过微信的js-sdk获取经纬度
  159. getAddress() {
  160. const _this = this;
  161. let link = window.location.href;
  162. location({
  163. url: link
  164. }).then(res => {
  165. if (res.code == 200) {
  166. let data = JSON.parse(res.data);
  167. console.log('后端返回的wx.config的配置:', JSON.parse(res.data));
  168. _this.getLocation(data);
  169. } else {
  170. console.log('获取位置失败');
  171. }
  172. });
  173. },
  174. getLocation(params) {
  175. const _this = this;
  176. // 判断是否支持获取定位
  177. jweixin.config({
  178. debug: false, //开启debug模式.正式环境设置为false,测试环境设置为true
  179. appId: params.appId,
  180. timestamp: params.timestamp,
  181. nonceStr: params.nonceStr,
  182. signature: params.signature,
  183. jsApiList: ['getLocation'] //根据需要看需要哪些SDK的功能
  184. });
  185. // sdk加载完成后执行
  186. jweixin.ready(() => {
  187. jweixin.checkJsApi({
  188. jsApiList: ['getLocation'],
  189. success: res => {
  190. if (res.checkResult.getLocation == false) {
  191. alert('你的微信版本太低,不支持微信JS接口,请升级到最新的微信版本!');
  192. return;
  193. }
  194. }
  195. });
  196. jweixin.error(res => {
  197. console.log( 'err错误', res.errMsg,);
  198. });
  199. // 获取位置
  200. jweixin.getLocation({
  201. type: 'gcj02',
  202. success: res => {
  203. this.location = `${res.longitude},${res.latitude}`;
  204. console.log('location', this.location, res)
  205. },
  206. cancel: res => {
  207. uni.showToast({
  208. title: '您已禁止获取位置信息',
  209. icon: 'none'
  210. });
  211. },
  212. fail: err => {
  213. uni.showModal({
  214. title: '提示',
  215. content: '获取位置信息失败,请关闭网页重新打开,否则会导致无法支付',
  216. showCancel: false,
  217. })
  218. }
  219. });
  220. });
  221. },
  222. //WeixinJSBridge判断
  223. wxJsPay(data, callback_succ_func, callback_error_func) {
  224. if (typeof WeixinJSBridge == 'undefined') {
  225. if (document.addEventListener) {
  226. document.addEventListener('WeixinJSBridgeReady', this.jsApiCall, false);
  227. } else if (document.attachEvent) {
  228. document.attachEvent('WeixinJSBridgeReady', this.jsApiCall);
  229. document.attachEvent('onWeixinJSBridgeReady', this.jsApiCall);
  230. }
  231. } else {
  232. this.jsApiCall(data, callback_succ_func, callback_error_func);
  233. }
  234. },
  235. //调起支付
  236. jsApiCall(data, callback_succ_func, callback_error_func) {
  237. //使用原生的,避免初始化appid问题
  238. WeixinJSBridge.invoke(
  239. 'getBrandWCPayRequest', {
  240. appId: data.appId,
  241. timeStamp: data.timeStamp,
  242. nonceStr: data.nonceStr,
  243. package: data.package,
  244. signType: data.signType,
  245. paySign: data.paySign
  246. },
  247. function(res) {
  248. var msg = res.err_msg ? res.err_msg : res.errMsg;
  249. switch (msg) {
  250. //支付成功时
  251. case 'get_brand_wcpay_request:ok':
  252. if (callback_succ_func) {
  253. uni.showModal({
  254. content: '支付成功!',
  255. showCancel: false
  256. });
  257. callback_succ_func(res);
  258. }
  259. break;
  260. default:
  261. //支付失败时
  262. WeixinJSBridge.log('支付失败!' + msg + ',请返回重试.');
  263. if (callback_error_func) {
  264. callback_error_func({
  265. msg: msg
  266. });
  267. }
  268. break;
  269. // //支付成功时
  270. // case 'get_brand_wcpay_request:ok':
  271. // // if (callback_succ_func) {
  272. // uni.showModal({
  273. // content: '购买成功',
  274. // showCancel: false,
  275. // success: function(res) {
  276. // uni.redirectTo({
  277. // url: "/pages/soap/index"
  278. // })
  279. // },
  280. // // complete: function() {
  281. // // that.SearchStatus()
  282. // // }
  283. // });
  284. // // }
  285. // break;
  286. // default:
  287. // //支付失败时
  288. // WeixinJSBridge.log('支付失败!' + msg + ',请返回重试.');
  289. // if (callback_error_func) {
  290. // callback_error_func({
  291. // msg: msg
  292. // });
  293. // }
  294. // break;
  295. }
  296. }
  297. );
  298. },
  299. // 提交
  300. save() {
  301. let _this = this
  302. this.form.cost = this.total
  303. this.form.price = this.type ? 8 : 20
  304. this.form.num = this.num
  305. this.form.remark = this.remark
  306. this.form.goods_type = this.type ? 1 : 2
  307. this.form.location = this.location
  308. if (!this.form.user_name || !this.form.province) {
  309. uni.toast('未填写收货人信息');
  310. return
  311. }
  312. this.allForm = this.form
  313. _API_Getpays(this.form).then(res => {
  314. if (res.code === 200) {
  315. this.allForm.order_no = res.data.order_num
  316. this.allForm.created_at = res.data.created_at
  317. let that = this
  318. let callback_succ_func = function() {
  319. uni.showModal({
  320. content: '支付成功!',
  321. showCancel: false,
  322. success: function(res) {
  323. uni.reLaunch({
  324. url: '../pay-status/pay-status?order_no=' + that.allForm.order_no + '&total=' +that.total + '&data=' + encodeURIComponent(JSON.stringify(that.allForm)).replace(/%/g, '%25')
  325. })
  326. },
  327. })
  328. };
  329. let callback_error_func = res => {
  330. uni.showModal({
  331. content: '支付失败!',
  332. showCancel: false
  333. });
  334. };
  335. // let callback_succ_func = res => {
  336. // uni.showToast({
  337. // title: '支付成功'
  338. // })
  339. // }
  340. // let callback_error_func = res => {
  341. // uni.showModal({
  342. // content: '支付失败!',
  343. // showCancel: false
  344. // })
  345. // }
  346. let info = res.data.data.pay_info
  347. this.wxJsPay(info, callback_succ_func, callback_error_func)
  348. } else {
  349. uni.showToast({
  350. title: res.message || '失败',
  351. icon: 'none'
  352. })
  353. return false;
  354. }
  355. })
  356. .catch(err => {})
  357. .finally(() => {
  358. setTimeout(() => {}, 3000)
  359. })
  360. },
  361. red() {
  362. if (this.num - 1 === 9) {
  363. uni.showModal({
  364. content: `数量不能再少了`,
  365. showCancel: false
  366. })
  367. } else {
  368. this.num -= 1
  369. }
  370. },
  371. add() {
  372. this.num += 1
  373. },
  374. comfirmNum() {
  375. //限制下单数量
  376. // if (this.inputNum % 10 != 0) {
  377. // uni.showModal({
  378. // content: `请输入10的倍数`,
  379. // showCancel: false
  380. // })
  381. // return
  382. // } else if (this.inputNum == 0) {
  383. // uni.showModal({
  384. // content: `数量不能为0`,
  385. // showCancel: false
  386. // })
  387. // return
  388. // }
  389. if (this.inputNum < 10) {
  390. uni.showModal({
  391. content: `购买数量不能小于10`,
  392. showCancel: false
  393. })
  394. return
  395. }
  396. this.num = Number(this.inputNum)
  397. this.showInput = false
  398. },
  399. // 收货人
  400. goaddress() {
  401. uni.navigateTo({
  402. url: './address-manage'
  403. })
  404. // const url = this.showEdit ? './address' : './address?data=' + encodeURIComponent(JSON.stringify(this.form))
  405. // uni.navigateTo({
  406. // url
  407. // })
  408. }
  409. }
  410. }
  411. </script>
  412. <style>
  413. .placetext {
  414. font-size: 28rpx;
  415. font-weight: 400;
  416. color: #999999;
  417. }
  418. </style>
  419. <style lang="scss" scoped>
  420. .num-input {
  421. @include flex();
  422. width: 228rpx;
  423. height: 64rpx;
  424. overflow: hidden;
  425. font-size: 32rpx;
  426. background: #F9F9FB;
  427. // border-radius: 64rpx;
  428. .i {
  429. flex: 1;
  430. height: 100%;
  431. @include flex();
  432. // &.c {
  433. // border-left: 4rpx solid #FFFFFF;
  434. // border-right: 4rpx solid #FFFFFF;
  435. // }
  436. }
  437. .l {
  438. color: #CCCCCC;
  439. }
  440. .r {
  441. color: #FB231F;
  442. }
  443. .inputModelWrapper {
  444. @include flex();
  445. top: 0;
  446. left: 0;
  447. z-index: 2;
  448. width: 100vw;
  449. height: 100vh;
  450. position: fixed;
  451. background: rgba(0, 0, 0, 0.3);
  452. .inputModel {
  453. width: 600rpx;
  454. height: 400rpx;
  455. background: #FFFFFF;
  456. border-radius: 8rpx;
  457. @include flex(column);
  458. .t {
  459. @include flex();
  460. width: 100%;
  461. height: 100rpx;
  462. border-bottom: 1rpx solid #CCCCCC;
  463. }
  464. .m {
  465. width: 100%;
  466. flex: 1;
  467. @include flex();
  468. input {
  469. width: 240rpx;
  470. height: 120rpx;
  471. text-align: center;
  472. font-size: 88rpx;
  473. border-radius: 8rpx;
  474. border: 1rpx solid #CCCCCC;
  475. }
  476. }
  477. .b {
  478. @include flex();
  479. width: 100%;
  480. height: 100rpx;
  481. border-top: 1rpx solid #CCCCCC;
  482. text {
  483. font-size: 32rpx;
  484. font-weight: 400;
  485. height: 100%;
  486. flex: 1;
  487. @include flex();
  488. &.basecolor {
  489. border-left: 1rpx solid #CCCCCC;
  490. }
  491. }
  492. }
  493. }
  494. }
  495. }
  496. .address {
  497. padding: 40rpx 0;
  498. margin: 0 24rpx;
  499. background-color: #fff;
  500. &_tip {
  501. width: 92rpx;
  502. color: #fff;
  503. font-size: 24rpx;
  504. font-weight: bold;
  505. line-height: 50rpx;
  506. text-align: center;
  507. border-radius: 8rpx 8rpx 8rpx 8rpx;
  508. margin-right: 20rpx;
  509. }
  510. .green {
  511. background: linear-gradient(180deg, #46DBA1 0%, #19D16E 100%);
  512. }
  513. .red {
  514. background: linear-gradient(180deg, #FF232C 0%, #FF571B 100%);
  515. }
  516. &_title {
  517. font-size: 28rpx;
  518. font-weight: 400;
  519. color: $uni-text-color;
  520. }
  521. text {
  522. font-size: 34rpx;
  523. font-weight: bold;
  524. }
  525. .gray {
  526. width: 518rpx;
  527. font-size: 28rpx;
  528. color: #999999;
  529. margin-top: 8rpx;
  530. text-overflow: -o-ellipsis-lastline;
  531. overflow: hidden; //溢出内容隐藏
  532. text-overflow: ellipsis; //文本溢出部分用省略号表示
  533. display: -webkit-box; //特别显示模式
  534. line-clamp: 2;
  535. -webkit-line-clamp: 2; //行数
  536. -webkit-box-orient: vertical;
  537. }
  538. }
  539. .bottom {
  540. position: fixed;
  541. left: 0;
  542. bottom: 0;
  543. width: 100%;
  544. padding: 8rpx 24rpx 8rpx 24rpx;
  545. box-shadow: 0px -4rpx 24rpx 2rpx rgba(0, 0, 0, 0.1);
  546. background-color: #fff;
  547. &_top {
  548. font-weight: bold;
  549. font-size: 28rpx;
  550. .text1 {
  551. color: #999;
  552. }
  553. .text2 {
  554. color: #FB231F;
  555. }
  556. .text3 {
  557. font-size: 60rpx;
  558. color: #FB231F;
  559. }
  560. }
  561. &_btn {
  562. width: 702rpx;
  563. height: 88rpx;
  564. background: linear-gradient(91deg, #F30000 0%, #FE4815 100%);
  565. border-radius: 44rpx 44rpx 44rpx 44rpx;
  566. text-align: center;
  567. line-height: 88rpx;
  568. font-size: 32rpx;
  569. font-weight: bold;
  570. color: #FFFFFF;
  571. margin-top: 12rpx;
  572. }
  573. }
  574. .remark {
  575. padding: 80rpx 24rpx 210rpx 24rpx;
  576. text {
  577. font-size: 34rpx;
  578. font-weight: bold;
  579. }
  580. &_bg {
  581. margin-top: 22rpx;
  582. background-color: #F9F9FB;
  583. padding: 32rpx 24rpx;
  584. border-radius: 16rpx 16rpx 16rpx 16rpx;
  585. .placetext {
  586. font-size: 28rpx;
  587. font-weight: 400;
  588. color: #999999;
  589. }
  590. }
  591. }
  592. .detail {
  593. padding: 56rpx 24rpx 24rpx 24rpx;
  594. background-color: #fff;
  595. border-top: 24rpx solid #F5F5F5;
  596. &_flex {
  597. // height: 160rpx;
  598. display: flex;
  599. justify-content: space-between;
  600. flex-direction: column;
  601. .title {
  602. font-size: 30rpx;
  603. font-weight: bold;
  604. color: #333333;
  605. }
  606. .dan {
  607. display: flex;
  608. justify-content: space-between;
  609. width: 500rpx;
  610. margin: 16rpx 0 6rpx 0;
  611. text {
  612. font-size: 44rpx;
  613. color: #FB231F;
  614. font-weight: bold;
  615. }
  616. }
  617. .tip {
  618. width: 212rpx;
  619. height: 32rpx;
  620. line-height: 30rpx;
  621. border-radius: 0px 0px 0px 0px;
  622. opacity: 1;
  623. border: 1rpx solid #FB231F;
  624. font-size: 24rpx;
  625. color: #FB231F;
  626. text-align: center;
  627. }
  628. }
  629. }
  630. </style>