waterDetail.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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. uni.reLaunch({
  305. url:'/pages/water/waterList'
  306. })
  307. }
  308. },
  309. fail: () => {},
  310. complete: () => {}
  311. });
  312. that.payLoding = false;
  313. }
  314. }
  315. };
  316. </script>
  317. <style lang="scss">
  318. .good-list {
  319. padding: 20rpx 28rpx;
  320. width: 750rpx;
  321. .good {
  322. background: #FFFFFF;
  323. box-shadow: 0px 0px 20px 0px rgba(50, 50, 52, 0.06);
  324. width: 100%;
  325. border-radius: 14rpx;
  326. margin-bottom: 20rpx;
  327. position: relative;
  328. padding: 20rpx;
  329. .good-image {
  330. width: 180rpx;
  331. height: 180rpx;
  332. background-color: #eee;
  333. border-radius: 10rpx;
  334. flex-shrink: 0;
  335. }
  336. .right {
  337. height: 180rpx;
  338. position: relative;
  339. width: 100%;
  340. flex-shrink: 1;
  341. .good-name {
  342. font-size: 28rpx;
  343. font-weight: bold;
  344. color: #333333;
  345. padding-left: 20rpx;
  346. }
  347. .good-key {
  348. font-size: 22rpx;
  349. font-weight: 500;
  350. color: #999999;
  351. padding-left: 20rpx
  352. }
  353. .good-price {
  354. display: flex;
  355. justify-content: space-between;
  356. align-items: flex-end;
  357. font-size: 28rpx;
  358. font-weight: bold;
  359. color: #FF1A1A;
  360. position: absolute;
  361. bottom: 0rpx;
  362. padding: 0 20rpx;
  363. left: 0;
  364. right: 0rpx;
  365. }
  366. }
  367. }
  368. }
  369. .attr-list {
  370. display: flex;
  371. flex-direction: column;
  372. font-size: $font-base + 2rpx;
  373. color: $font-color-base;
  374. font-weight: bold;
  375. .item-list {
  376. padding: 20rpx 0 0;
  377. display: flex;
  378. flex-wrap: wrap;
  379. justify-content: flex-start;
  380. .tit {
  381. min-width: 200rpx;
  382. display: flex;
  383. align-items: center;
  384. justify-content: center;
  385. background: #eee;
  386. margin-bottom: 20rpx;
  387. margin-right: 16rpx;
  388. border-radius: 5rpx;
  389. height: 60rpx;
  390. padding: 0 20rpx;
  391. font-size: $font-base;
  392. color: $font-color-dark;
  393. }
  394. .selected {
  395. background: #FCEFF1;
  396. color: $color-red;
  397. border: 1px solid $color-red;
  398. }
  399. }
  400. }
  401. .footer {
  402. position: fixed;
  403. left: 0;
  404. bottom: 0;
  405. z-index: 995;
  406. display: flex;
  407. align-items: center;
  408. width: 100%;
  409. height: 90rpx;
  410. justify-content: space-between;
  411. font-size: 30rpx;
  412. background-color: #fff;
  413. z-index: 998;
  414. color: $font-color-base;
  415. box-shadow: 0 -1px 5px rgba(0, 0, 0, 0.1);
  416. .price-content {
  417. padding-left: 30rpx;
  418. }
  419. .price-tip {
  420. color: $font-color-base;
  421. margin-left: 8rpx;
  422. color: $color-red;
  423. }
  424. .price {
  425. font-size: 36rpx;
  426. color: $color-red;
  427. }
  428. .submit {
  429. display: flex;
  430. align-items: center;
  431. justify-content: center;
  432. width: 280rpx;
  433. height: 100%;
  434. color: #fff;
  435. font-size: 32rpx;
  436. background: $bg-gradual;
  437. &.submitNo {
  438. background-color: $font-color-disabled;
  439. }
  440. }
  441. }
  442. .yt-list {
  443. background: #fff;
  444. margin-top: 30rpx;
  445. border-radius: 20rpx;
  446. .yt-list-cell {
  447. display: flex;
  448. align-items: center;
  449. justify-content: space-between;
  450. padding: 10rpx 30rpx 10rpx 40rpx;
  451. line-height: 70rpx;
  452. position: relative;
  453. .checked,
  454. .noChecked {
  455. width: 36rpx;
  456. height: 36rpx;
  457. }
  458. .noChecked {
  459. border: 1px solid $font-color-light;
  460. border-radius: 100rpx;
  461. }
  462. &.cell-hover {
  463. background: #fafafa;
  464. }
  465. &.b-b:after {
  466. left: 30rpx;
  467. }
  468. .cell-icon {
  469. height: 32rpx;
  470. width: 32rpx;
  471. font-size: 22rpx;
  472. color: #fff;
  473. text-align: center;
  474. line-height: 32rpx;
  475. background: #f85e52;
  476. border-radius: 4rpx;
  477. margin-right: 12rpx;
  478. &.hb {
  479. background: #ffaa0e;
  480. }
  481. &.lpk {
  482. background: #3ab54a;
  483. }
  484. }
  485. .cell-more {
  486. align-self: center;
  487. font-size: 24rpx;
  488. color: $font-color-light;
  489. margin-left: 8rpx;
  490. margin-right: -10rpx;
  491. }
  492. .cell-tit {
  493. font-size: 26rpx;
  494. color: $font-color-light;
  495. margin-right: 10rpx;
  496. .orderIcon {
  497. width: 48rpx;
  498. }
  499. }
  500. .cell-tip {
  501. font-size: 26rpx;
  502. color: $font-color-dark;
  503. &.disabled {
  504. color: $font-color-light;
  505. }
  506. &.active {
  507. color: $base-color;
  508. }
  509. &.red {
  510. color: $base-color;
  511. }
  512. }
  513. &.desc-cell {
  514. .cell-tit {
  515. max-width: 90rpx;
  516. }
  517. }
  518. .desc {
  519. text-align: right;
  520. font-size: $font-base;
  521. color: $font-color-light;
  522. }
  523. }
  524. }
  525. </style>