waterDetail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. <template>
  2. <view class="good-list">
  3. <view class="good flex">
  4. <image :src="item.image" mode="" class="good-image"></image>
  5. <view class="right">
  6. <view class="good-name ">
  7. <view class="clamp2">
  8. {{item.title}}
  9. </view>
  10. </view>
  11. <view class="good-key">
  12. {{item.keyword}}
  13. </view>
  14. <view class="good-price flex" v-if="item.specifications">
  15. <view class="price">
  16. ¥{{item.price}}
  17. </view>
  18. </view>
  19. </view>
  20. </view>
  21. <view class="attr-list" v-if="item.specifications">
  22. <text>选择规格分类</text>
  23. <view class="item-list flex">
  24. <text class="tit " @click="key=ind" :class="{selected:key==ind}"
  25. v-for="(item,ind) in item.specifications">
  26. {{item.attr_name}}
  27. </text>
  28. </view>
  29. </view>
  30. <view class="yt-list">
  31. <view class="yt-list-cell b-b" @click="payType='weixin'">
  32. <view class="cell-tit flex">
  33. <image class="orderIcon" src="../../static/icon/orderWx.png" mode="widthFix"></image>
  34. <text class="margin-l-10">微信支付</text>
  35. </view>
  36. <image class="checked" v-if="payType=='weixin'" src="../../static/icon/addressIconXz.png"
  37. mode="widthFix"></image>
  38. <view v-else class="noChecked"></view>
  39. </view>
  40. <view class="yt-list-cell b-b" @click="payType='yue'">
  41. <view class="cell-tit flex">
  42. <image class="orderIcon" src="../../static/icon/ye.png" mode="widthFix"></image>
  43. <text class="margin-l-10">余额({{now_money}})</text>
  44. </view>
  45. <image class="checked" v-if="payType=='yue'" src="../../static/icon/addressIconXz.png" mode="widthFix">
  46. </image>
  47. <view v-else class="noChecked"></view>
  48. </view>
  49. </view>
  50. <view class="footer">
  51. <view class="price-content">
  52. <text>支付金额</text>
  53. <text class="price-tip">¥</text>
  54. <text class="price" v-if="item.specifications">{{ item.specifications[key].price }}</text>
  55. </view>
  56. <text class="submit" :class="{submitNo:payLoding}" @click="payLoding?'':cardAdd()">提交订单</text>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. import {
  62. waterDetail
  63. } from '@/api/water.js';
  64. import {
  65. cartAdd
  66. } from '@/api/product.js';
  67. import {
  68. confirm,
  69. createOrderkey,
  70. orderPay
  71. } from '@/api/order.js';
  72. import {
  73. getUserInfo
  74. } from '@/api/user.js';
  75. // #ifdef H5
  76. import weixinObj from "@/plugin/jweixin-module/index.js";
  77. // #endif
  78. export default {
  79. data() {
  80. return {
  81. id: '',
  82. //详情
  83. item: {},
  84. key: 0, //选中的数据对象
  85. payLoding: false,
  86. payType: 'weixin',
  87. now_money: '' //微信余额
  88. };
  89. },
  90. onReachBottom() {
  91. this.getGoodList();
  92. },
  93. onLoad: function(option) {
  94. this.id = option.id
  95. this.getGoodList();
  96. this.userinfo();
  97. },
  98. methods: {
  99. // 加载用户基础信息
  100. userinfo() {
  101. getUserInfo({}).then(({
  102. data
  103. }) => {
  104. this.now_money = data.now_money;
  105. });
  106. },
  107. // 加载数据
  108. getGoodList(source) {
  109. const that = this;
  110. waterDetail({
  111. id: this.id
  112. })
  113. .then(({
  114. data
  115. }) => {
  116. that.item = data.storeInfo;
  117. console.log(data);
  118. })
  119. .catch(e => {
  120. console.log(e);
  121. });
  122. },
  123. // 添加到购物车
  124. async cardAdd() {
  125. let obj = this;
  126. // 判断是否余额不足
  127. if (obj.payType == 'yue' && +obj.now_money < obj.payPrice) {
  128. uni.showModal({
  129. title: '提示',
  130. content: '账户余额不足!',
  131. showCancel: false,
  132. });
  133. return;
  134. }
  135. uni.showLoading({
  136. title: '创建订单中',
  137. mask: true
  138. })
  139. // 支付中
  140. obj.payLoding = true;
  141. try {
  142. // 创建购物车传值对象
  143. let cardData = {
  144. cartNum: obj.item.specifications[obj.key].num, //商品数量
  145. productId: obj.item.product_id, //商品编号
  146. certificate_id: obj.item.id, //水票id
  147. new: 1
  148. };
  149. // 加入购物车
  150. const cartDetail = await cartAdd(cardData);
  151. // 获取订单Key
  152. const orderGet = await confirm({
  153. cartId: cartDetail.data.cartId+'',
  154. certificate_id: obj.item.id, //水票id
  155. });
  156. // 创建订单
  157. const {
  158. data,
  159. status,
  160. msg
  161. } = await createOrderkey({
  162. payType: obj.payType, //支付类型 weixin-微信 yue-余额
  163. certificate_id: obj.item.id, //水票id
  164. // #ifdef H5
  165. from: 'weixin', //来源
  166. // #endif
  167. // #ifdef MP-WEIXIN
  168. from: 'routine', //来源
  169. // #endif
  170. // #ifdef APP-PLUS
  171. from: 'app', //来源
  172. // #endif
  173. }, orderGet.data.orderKey)
  174. // 判断是否支付失败
  175. if (data.status == 'ORDER_EXIST') {
  176. uni.showModal({
  177. title: '提示',
  178. content: msg,
  179. showCancel: false
  180. });
  181. uni.hideLoading();
  182. obj.payLoding = false;
  183. return;
  184. }
  185. // 判断是否为余额支付
  186. if (obj.payType == 'yue') {
  187. if (status == 200 && data.status == 'SUCCESS') {
  188. obj.paySuccessTo();
  189. } else {
  190. uni.showModal({
  191. title: '提示',
  192. content: msg,
  193. showCancel: false
  194. });
  195. uni.hideLoading();
  196. obj.payLoding = false;
  197. }
  198. } else {
  199. // 订单支付创建
  200. const order =await orderPay({
  201. uni: data.result.orderId,
  202. // #ifdef H5
  203. from: 'weixin', //来源
  204. // #endif
  205. // #ifdef MP-WEIXIN
  206. from: 'routine', //来源
  207. // #endif
  208. // #ifdef APP-PLUS
  209. from: 'app', //来源
  210. // #endif
  211. paytype: obj.payType //支付类型 weixin-微信 yue-余额
  212. })
  213. console.log(order,'order')
  214. obj.successOrder(order)
  215. }
  216. } catch (e) {
  217. uni.showModal({
  218. title: '提示',
  219. content: e.message||e.msg,
  220. showCancel: false
  221. });
  222. obj.payLoding = false;
  223. uni.hideLoading();
  224. }
  225. },
  226. //订单支付创建成功回调处理
  227. successOrder(e) {
  228. const obj = this;
  229. console.log(e,'eee')
  230. // 判断是否微信小程序支付
  231. if (obj.payType == 'weixin') {
  232. // #ifdef H5 || MP
  233. let da = e.data.result.jsConfig;
  234. let data = {
  235. nonceStr: da.nonceStr,
  236. package: da.package,
  237. signType: da.signType,
  238. paySign: da.paySign,
  239. success: function(res) {
  240. obj.paySuccessTo();
  241. },
  242. fail: () => {
  243. uni.navigateTo({
  244. url: '/pages/order/order?state=0'
  245. });
  246. }
  247. };
  248. // #endif
  249. // #ifdef H5
  250. data.timestamp = da.timestamp;
  251. weixinObj.chooseWXPay(data);
  252. // #endif
  253. // #ifdef MP-WEIXIN
  254. data.timeStamp = da.timestamp;
  255. wx.requestPayment(data);
  256. // #endif
  257. // #ifdef APP
  258. console.log(e.data.result.jsConfig, '返回数值');
  259. uni.requestPayment({
  260. provider: 'wxpay',
  261. orderInfo: e.data.result.jsConfig,
  262. success(e) {
  263. obj.paySuccessTo();
  264. },
  265. fail: (e) => {
  266. console.log(e, '支付失败');
  267. uni.navigateTo({
  268. url: '/pages/order/order?state=0'
  269. });
  270. }
  271. })
  272. // #endif
  273. }
  274. // #ifdef APP
  275. if (obj.payType == 'ali') {
  276. uni.requestPayment({
  277. provider: 'alipay',
  278. orderInfo: e.data.result.jsConfig,
  279. success(e) {
  280. obj.paySuccessTo();
  281. },
  282. fail: (e) => {
  283. console.log(e, '支付失败');
  284. uni.navigateTo({
  285. url: '/pages/order/order?state=0'
  286. });
  287. }
  288. })
  289. }
  290. // #endif
  291. uni.hideLoading();
  292. obj.payLoding = false;
  293. },
  294. //支付成功调用方法
  295. paySuccessTo(){
  296. const that = this;
  297. uni.hideLoading();
  298. uni.showModal({
  299. title: '提示',
  300. content: '购买成功是否继续购买',
  301. cancelText: '返回',
  302. confirmText: '确定',
  303. success: res => {
  304. if(res.cancel){
  305. uni.reLaunch({
  306. url:'/pages/home/index'
  307. })
  308. }else{
  309. uni.reLaunch({
  310. url:'/pages/water/waterList'
  311. })
  312. }
  313. },
  314. fail: () => {},
  315. complete: () => {}
  316. });
  317. that.payLoding = false;
  318. }
  319. }
  320. };
  321. </script>
  322. <style lang="scss">
  323. .good-list {
  324. padding: 20rpx 28rpx;
  325. width: 750rpx;
  326. .good {
  327. background: #FFFFFF;
  328. box-shadow: 0px 0px 20px 0px rgba(50, 50, 52, 0.06);
  329. width: 100%;
  330. border-radius: 14rpx;
  331. margin-bottom: 20rpx;
  332. position: relative;
  333. padding: 20rpx;
  334. .good-image {
  335. width: 180rpx;
  336. height: 180rpx;
  337. background-color: #eee;
  338. border-radius: 10rpx;
  339. flex-shrink: 0;
  340. }
  341. .right {
  342. height: 180rpx;
  343. position: relative;
  344. width: 100%;
  345. flex-shrink: 1;
  346. .good-name {
  347. font-size: 28rpx;
  348. font-weight: bold;
  349. color: #333333;
  350. padding-left: 20rpx;
  351. }
  352. .good-key {
  353. font-size: 22rpx;
  354. font-weight: 500;
  355. color: #999999;
  356. padding-left: 20rpx
  357. }
  358. .good-price {
  359. display: flex;
  360. justify-content: space-between;
  361. align-items: flex-end;
  362. font-size: 28rpx;
  363. font-weight: bold;
  364. color: #FF1A1A;
  365. position: absolute;
  366. bottom: 0rpx;
  367. padding: 0 20rpx;
  368. left: 0;
  369. right: 0rpx;
  370. }
  371. }
  372. }
  373. }
  374. .attr-list {
  375. display: flex;
  376. flex-direction: column;
  377. font-size: $font-base + 2rpx;
  378. color: $font-color-base;
  379. font-weight: bold;
  380. .item-list {
  381. padding: 20rpx 0 0;
  382. display: flex;
  383. flex-wrap: wrap;
  384. justify-content: flex-start;
  385. .tit {
  386. min-width: 200rpx;
  387. display: flex;
  388. align-items: center;
  389. justify-content: center;
  390. background: #eee;
  391. margin-bottom: 20rpx;
  392. margin-right: 16rpx;
  393. border-radius: 5rpx;
  394. height: 60rpx;
  395. padding: 0 20rpx;
  396. font-size: $font-base;
  397. color: $font-color-dark;
  398. }
  399. .selected {
  400. background: #FCEFF1;
  401. color: $color-red;
  402. border: 1px solid $color-red;
  403. }
  404. }
  405. }
  406. .footer {
  407. position: fixed;
  408. left: 0;
  409. bottom: 0;
  410. z-index: 995;
  411. display: flex;
  412. align-items: center;
  413. width: 100%;
  414. height: 90rpx;
  415. justify-content: space-between;
  416. font-size: 30rpx;
  417. background-color: #fff;
  418. z-index: 998;
  419. color: $font-color-base;
  420. box-shadow: 0 -1px 5px rgba(0, 0, 0, 0.1);
  421. .price-content {
  422. padding-left: 30rpx;
  423. }
  424. .price-tip {
  425. color: $font-color-base;
  426. margin-left: 8rpx;
  427. color: $color-red;
  428. }
  429. .price {
  430. font-size: 36rpx;
  431. color: $color-red;
  432. }
  433. .submit {
  434. display: flex;
  435. align-items: center;
  436. justify-content: center;
  437. width: 280rpx;
  438. height: 100%;
  439. color: #fff;
  440. font-size: 32rpx;
  441. background: $bg-gradual;
  442. &.submitNo {
  443. background-color: $font-color-disabled;
  444. }
  445. }
  446. }
  447. .yt-list {
  448. background: #fff;
  449. margin-top: 30rpx;
  450. border-radius: 20rpx;
  451. .yt-list-cell {
  452. display: flex;
  453. align-items: center;
  454. justify-content: space-between;
  455. padding: 10rpx 30rpx 10rpx 40rpx;
  456. line-height: 70rpx;
  457. position: relative;
  458. .checked,
  459. .noChecked {
  460. width: 36rpx;
  461. height: 36rpx;
  462. }
  463. .noChecked {
  464. border: 1px solid $font-color-light;
  465. border-radius: 100rpx;
  466. }
  467. &.cell-hover {
  468. background: #fafafa;
  469. }
  470. &.b-b:after {
  471. left: 30rpx;
  472. }
  473. .cell-icon {
  474. height: 32rpx;
  475. width: 32rpx;
  476. font-size: 22rpx;
  477. color: #fff;
  478. text-align: center;
  479. line-height: 32rpx;
  480. background: #f85e52;
  481. border-radius: 4rpx;
  482. margin-right: 12rpx;
  483. &.hb {
  484. background: #ffaa0e;
  485. }
  486. &.lpk {
  487. background: #3ab54a;
  488. }
  489. }
  490. .cell-more {
  491. align-self: center;
  492. font-size: 24rpx;
  493. color: $font-color-light;
  494. margin-left: 8rpx;
  495. margin-right: -10rpx;
  496. }
  497. .cell-tit {
  498. font-size: 26rpx;
  499. color: $font-color-light;
  500. margin-right: 10rpx;
  501. .orderIcon {
  502. width: 48rpx;
  503. }
  504. }
  505. .cell-tip {
  506. font-size: 26rpx;
  507. color: $font-color-dark;
  508. &.disabled {
  509. color: $font-color-light;
  510. }
  511. &.active {
  512. color: $base-color;
  513. }
  514. &.red {
  515. color: $base-color;
  516. }
  517. }
  518. &.desc-cell {
  519. .cell-tit {
  520. max-width: 90rpx;
  521. }
  522. }
  523. .desc {
  524. text-align: right;
  525. font-size: $font-base;
  526. color: $font-color-light;
  527. }
  528. }
  529. }
  530. </style>