waterDetail.vue 11 KB

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