creatOrd.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. <template>
  2. <view class="content">
  3. <navigator url="/pages/user/address/address" class="address dfsb">
  4. <image src="/static/img/pro/malladdress.png" mode=""></image>
  5. <view v-if="addressInfo.shou_name" class="addInfo">
  6. <view class="addInfo-title">
  7. <text>{{ addressInfo.shou_name }}</text>
  8. <text class="textgrey">{{ addressInfo.shou_phone }}</text>
  9. </view>
  10. <view class="addInfo-bot">{{ addressInfo.shou_address }}</view>
  11. </view>
  12. <view v-if="!addressInfo.shou_name" class="addInfo">请选择地址</view>
  13. <u-icon name="arrow-right" color="#999" size="12"></u-icon>
  14. </navigator>
  15. <view class="shopsBox">
  16. <block v-if="flag == 1">
  17. <view v-for="(item, index) in newsInfo.order_goods.goods" :key="index" class="shopshead dfsb">
  18. <image :src="item.imgurl" mode=""></image>
  19. <view class="shopsInfo dffd">
  20. <view class="elli">{{ item.goods_name }}</view>
  21. <view v-if="item.sku_name" class="selAttr">{{ item.sku_name }}</view>
  22. <view class="price dfsb">
  23. <text v-if="flag == 1" class="promain">¥{{ item.price}}</text>
  24. <text class="textgrey">x{{ item.num || 1 }}</text>
  25. </view>
  26. </view>
  27. </view>
  28. </block>
  29. <block v-if="flag !=1">
  30. <view class="shopshead dfsb">
  31. <image :src="newsInfo.order.imgurl" mode=""></image>
  32. <view class="shopsInfo dffd">
  33. <view class="elli">{{ newsInfo.order.goods_name }}</view>
  34. <view v-if="newsInfo.order.sku_name" class="selAttr">{{ newsInfo.order.sku_name }}</view>
  35. <view class="price dfsb">
  36. <text class="promain">¥{{ newsInfo.order.price }}</text>
  37. <text class="textgrey">x{{ newsInfo.order.num || 1 }}</text>
  38. </view>
  39. </view>
  40. </view>
  41. </block>
  42. <view class="other dfsb">
  43. <text>邮费</text>
  44. <text>{{ newsInfo.exp_fee || 0 }}元</text>
  45. </view>
  46. <view class="other dfsb">
  47. <text>订单备注</text>
  48. <input type="text" v-model="beizhu" placeholder="选填,请先和商家协商一致" />
  49. </view>
  50. </view>
  51. <view v-if="flag == 1" class="payInfo dfsb">
  52. <image class="payicon" src="/static/img/pro/payyh.png" mode=""></image>
  53. <view class="dffd flex1">
  54. <text class="blank fontmid">
  55. 使用优惠券
  56. <text class="prosecond fontmid">-{{ coupon.reduce }}</text>
  57. </text>
  58. <view @click.stop="nextTo" class="textgrey fontssm dffs">
  59. 当前有{{ newsInfo.coupon_list.length }}张可使用的优惠券
  60. <u-icon name="arrow-down" color="#999" size="14"></u-icon>
  61. </view>
  62. </view>
  63. </view>
  64. <view v-if="flag == 1" class="payInfo dffs">
  65. <text class="fontsm">共{{ newsInfo.num }}件,合计{{ newsInfo.total }},折扣{{ newsInfo.discount }}折</text>
  66. </view>
  67. <view class="fixBox dffs">
  68. <text class="prosecond fontmid">实际支付{{ newsInfo.payment_price }},</text>
  69. <text v-if="flag == 1" class="flex1 fontsm ">优惠-{{ coupon.reduce }}</text>
  70. <!-- <text v-if="flag == 1" class="prosecond">¥{{ newsInfo.total }}+{{ newsInfo.point }}积分</text> -->
  71. <view @click="handle" class="clickbtn">提交订单</view>
  72. </view>
  73. </view>
  74. </template>
  75. <script>
  76. export default {
  77. data() {
  78. return {
  79. flag: 1, // 1普通 2拼团 3秒杀
  80. goods: {}, //传来的商品信息
  81. newsInfo: {
  82. coupon_list: [],
  83. order_goods: {
  84. goods: []
  85. },
  86. order: {}
  87. },
  88. addressInfo: {},
  89. coupon: { reduce: 0 }, //优惠券
  90. beizhu: '',
  91. showimg: false,
  92. noWeiXin: true, //是不是微信中支付宝不嫩显示
  93. num: 1,
  94. addid: uni.getStorageSync('setAddId'), //收货id
  95. showPaytype: false, //展示付款方式
  96. paytype: '', // 获取付款方式 3 圆宝积分 4 fyt
  97. showPass: '', // 展示密码
  98. orderId: '' //订单id
  99. };
  100. },
  101. onLoad(opt) {
  102. this.flag = opt.flag || 1;
  103. this.goods = JSON.parse(opt.goods);
  104. this.onload();
  105. },
  106. onShow() {},
  107. methods: {
  108. // 选择优惠券
  109. nextTo() {
  110. uni.navigateTo({
  111. url: '/pages/user/coupon/myCoup?money=' + this.newsInfo.payment_price
  112. });
  113. },
  114. onload() {
  115. console.log(this.flag);
  116. let url = '';
  117. let data = {};
  118. if (this.flag == 1) {
  119. url = 'orders/order_view';
  120. let arrList = [];
  121. let arr = {};
  122. arr['id'] = this.goods.id;
  123. arr['sku_id'] = this.goods.sku_id;
  124. arr['num'] = this.goods.num;
  125. arrList.push(arr);
  126. data = {
  127. goods: JSON.stringify(arrList),
  128. address_id: ''
  129. };
  130. } else if (this.flag == 2) {
  131. url = 'grouporder/order_view';
  132. data = {
  133. id: this.goods.id,
  134. num: this.goods.num,
  135. pid: this.goods.pid,
  136. sku_id: this.goods.sku_id,
  137. id: this.goods.id,
  138. address_id: ''
  139. };
  140. } else {
  141. url = 'seckillorder/order_view';
  142. data = {
  143. id: this.goods.id,
  144. num: this.goods.num,
  145. sku_id: this.goods.sku_id,
  146. id: this.goods.id,
  147. address_id: ''
  148. };
  149. }
  150. this.$api.request(url, data).then(data => {
  151. if (data.code == 200) {
  152. if (this.flag == 1) {
  153. this.addressInfo = data.data.order_goods.address;
  154. this.newsInfo = data.data;
  155. } else if (this.flag == 2) {
  156. this.addressInfo = data.data.order.address;
  157. this.newsInfo = data.data;
  158. } else if (this.flag == 3) {
  159. this.addressInfo = data.data.order.address;
  160. this.newsInfo = data.data;
  161. } else {
  162. }
  163. } else {
  164. this.$api.modal('温馨提示', data.msg, true, res => {
  165. if (this.$api.prePage() != undefined) {
  166. uni.navigateBack({
  167. delta: 1
  168. });
  169. return;
  170. }
  171. uni.switchTab({
  172. url: '/pages/index/index'
  173. });
  174. });
  175. }
  176. });
  177. },
  178. //点击提交
  179. handle() {
  180. if (!this.addressInfo.address_id) return this.$api.toast('请选择收货地址');
  181. let url = '';
  182. let data = {};
  183. if (this.flag == 1) {
  184. url = 'orders/order_create';
  185. let arrList = [];
  186. let arr = {};
  187. arr['id'] = this.goods.id;
  188. arr['sku_id'] = this.goods.sku_id;
  189. arr['num'] = this.goods.num;
  190. arrList.push(arr);
  191. data = {
  192. goods: JSON.stringify(arrList),
  193. content: this.beizhu,
  194. coupon_id: this.coupon.id || '',
  195. address_id: this.addressInfo.address_id || ''
  196. };
  197. } else if (this.flag == 2) {
  198. url = 'grouporder/order_create';
  199. data = {
  200. id: this.goods.id,
  201. num: this.goods.num,
  202. sku_id: this.goods.sku_id,
  203. pid: this.goods.pid,
  204. content: this.beizhu,
  205. address_id: this.addressInfo.address_id || ''
  206. };
  207. } else if (this.flag == 3) {
  208. url = 'seckillorder/toSeckill';
  209. data = {
  210. id: this.goods.id,
  211. goods_id: this.goods.goods_id,
  212. num: this.goods.num,
  213. sku_id: this.goods.sku_id,
  214. content: this.beizhu,
  215. address_id: this.addressInfo.address_id || ''
  216. };
  217. }
  218. this.$api.request(url, data).then(data => {
  219. if (data.code == 200) {
  220. this.orderId = data.data;
  221. this.toPay();
  222. } else {
  223. this.$api.toast(data.msg);
  224. }
  225. });
  226. },
  227. // 支付
  228. toPay() {
  229. this.$api
  230. .request('orders/order_pay', {
  231. id: this.orderId,
  232. type: this.flag
  233. })
  234. .then(data => {
  235. console.log(data);
  236. if (data.code && data.code != 200) {
  237. this.$api.toast(data.msg || '获取支付信息失败');
  238. return;
  239. }
  240. console.log(data);
  241. const orderInfo = data;
  242. const { timeStamp, nonceStr, paySign } = orderInfo;
  243. const payParams = {
  244. provider: 'wxpay',
  245. orderInfo: data,
  246. timeStamp,
  247. nonceStr,
  248. package: orderInfo.package,
  249. signType: 'MD5',
  250. paySign,
  251. success: e => {
  252. setTimeout(res => {
  253. uni.redirectTo({
  254. url: '/pagesA/mall/order?flag=' + this.flag
  255. });
  256. }, 600);
  257. },
  258. fail: err => {
  259. if (err.errMsg.indexOf('取消') > -1 || err.errMsg.indexOf('cancel') > 1 || err.errMsg.indexOf('-2') > -1) {
  260. this.$api.toast('取消支付');
  261. } else {
  262. this.$api.toast('支付遇到错误,请稍候重试');
  263. console.log(err);
  264. }
  265. }
  266. };
  267. uni.requestPayment(payParams);
  268. });
  269. }
  270. }
  271. };
  272. </script>
  273. <style lang="scss">
  274. .content {
  275. min-height: 100vh;
  276. padding: 30rpx 30rpx 140rpx;
  277. .payInfo {
  278. margin-top: 30rpx;
  279. background-color: #fff;
  280. padding: 35rpx 30rpx;
  281. .payicon {
  282. width: 68rpx;
  283. height: 68rpx;
  284. }
  285. .flex1 {
  286. margin: 0 15rpx;
  287. }
  288. .fontmid {
  289. flex: 1;
  290. }
  291. .payselicon {
  292. width: 32rpx;
  293. height: 32rpx;
  294. }
  295. }
  296. .warp {
  297. background-color: none;
  298. align-items: center;
  299. .title {
  300. width: 434rpx;
  301. height: 312rpx;
  302. }
  303. .box {
  304. margin-top: -138rpx;
  305. padding: 164rpx 0 0;
  306. width: 564rpx;
  307. min-height: 502rpx;
  308. background: #ffffff;
  309. border-radius: 16rpx;
  310. border: 2rpx solid #979797;
  311. align-items: center;
  312. .errtit {
  313. padding: 0 40rpx;
  314. font-size: 40rpx;
  315. color: #080404;
  316. line-height: 50rpx;
  317. margin: 46rpx 0 30rpx;
  318. }
  319. .subtit {
  320. image {
  321. width: 54rpx;
  322. height: 54rpx;
  323. margin-right: 20rpx;
  324. }
  325. font-size: 36rpx;
  326. color: #ff5302;
  327. line-height: 50rpx;
  328. }
  329. .com {
  330. margin: 110rpx 0 30rpx;
  331. font-size: 28rpx;
  332. font-family: MicrosoftYaHei;
  333. color: #666666;
  334. line-height: 38rpx;
  335. }
  336. }
  337. .close {
  338. width: 64rpx;
  339. height: 64rpx;
  340. margin-top: 30rpx;
  341. }
  342. }
  343. .address {
  344. padding: 30rpx;
  345. background-color: #fff;
  346. margin: 0rpx 0 22rpx;
  347. border-radius: 16rpx;
  348. overflow: hidden;
  349. image {
  350. width: 56rpx;
  351. height: 56rpx;
  352. margin-right: 30rpx;
  353. }
  354. .addInfo {
  355. flex: 1;
  356. &-title {
  357. text {
  358. font-size: 32rpx;
  359. }
  360. text:nth-of-type(2) {
  361. font-size: 28rpx;
  362. margin-left: 12rpx;
  363. }
  364. }
  365. &-bot {
  366. margin-top: 10rpx;
  367. font-size: 28rpx;
  368. line-height: 40rpx;
  369. }
  370. }
  371. }
  372. .shopsBox {
  373. background-color: #fff;
  374. border-radius: 16rpx;
  375. padding: 30rpx 20rpx;
  376. .shopsTit {
  377. font-size: 32rpx;
  378. line-height: 44rpx;
  379. margin-bottom: 30rpx;
  380. image {
  381. width: 40rpx;
  382. height: 40rpx;
  383. margin-right: 10rpx;
  384. }
  385. }
  386. .shopshead {
  387. padding-bottom: 20rpx;
  388. image {
  389. width: 180rpx;
  390. height: 180rpx;
  391. border-radius: 10rpx;
  392. margin-right: 20rpx;
  393. background-color: #ccc;
  394. }
  395. .shopsInfo {
  396. width: 450rpx;
  397. height: 100%;
  398. align-items: flex-start;
  399. justify-content: space-between;
  400. .elli {
  401. height: 80rpx;
  402. line-height: 40rpx;
  403. }
  404. .price {
  405. width: 100%;
  406. text {
  407. font-size: 32rpx;
  408. }
  409. /deep/ .u-number-input {
  410. margin: 0;
  411. }
  412. /deep/ .u-icon-plus,
  413. /deep/ .uni-input-input,
  414. /deep/ .u-icon-minus {
  415. border: 1px solid #ebebeb;
  416. }
  417. }
  418. }
  419. }
  420. .other {
  421. margin: 30rpx 0 0 60rpx;
  422. &:nth-of-type(1) {
  423. margin-top: 50rpx;
  424. }
  425. text {
  426. margin-right: 30rpx;
  427. }
  428. input {
  429. flex: 1;
  430. }
  431. }
  432. }
  433. .fixBox {
  434. justify-content: flex-end;
  435. font-size: 32rpx;
  436. padding-left: 30rpx;
  437. .clickbtn {
  438. margin: 0 0 0 20rpx;
  439. width: 214rpx;
  440. border-radius: 0px;
  441. }
  442. }
  443. }
  444. </style>