You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

432 lines
8.7 KiB

6 months ago
  1. <template>
  2. <view>
  3. <!-- 收货地址 -->
  4. <!-- <view class="addr" @tap="selectAddress">
  5. <view class="icon">
  6. <image src="../../static/img/addricon.png" mode=""></image>
  7. </view>
  8. <view class="right">
  9. <view class="tel-name">
  10. <view class="name">
  11. {{recinfo.name}}
  12. </view>
  13. <view class="tel">
  14. {{recinfo.tel}}
  15. </view>
  16. </view>
  17. <view class="addres">
  18. {{recinfo.address}}
  19. {{recinfo.detail}}
  20. </view>
  21. </view>
  22. </view> -->
  23. <!-- 购买商品列表 -->
  24. <view class="buy-list">
  25. <view class="row" v-for="(row,index) in buylist" :key="index">
  26. <view class="goods-info">
  27. <view class="img">
  28. <image :src="row.img"></image>
  29. </view>
  30. <view class="info">
  31. <view class="title">{{row.cpmc}}</view>
  32. <view class="spec">选择{{row.gg}} <text style="color: red;margin-left: 15upx;">单价:{{row.price}}</text></view>
  33. <view class="price-number">
  34. <view class="price">{{row.je|toFixed}}</view>
  35. <view class="number">
  36. 数量:{{row.dinghl}}
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. <!-- 提示-备注 -->
  44. <view class="order">
  45. <view class="row">
  46. <view class="left">
  47. 积分 :
  48. </view>
  49. <view class="right">
  50. 已扣除{{int}}积分抵扣{{deduction|toFixed}}
  51. </view>
  52. </view>
  53. <view class="row">
  54. <view class="left">
  55. 备注 :
  56. </view>
  57. <view class="right">
  58. <input placeholder="选填,备注内容" v-model="note" />
  59. </view>
  60. </view>
  61. </view>
  62. <!-- 明细 -->
  63. <view class="detail">
  64. <view class="row">
  65. <view class="nominal">
  66. 商品金额
  67. </view>
  68. <view class="content">
  69. {{goodsPrice|toFixed}}
  70. </view>
  71. </view>
  72. <view class="row" v-if="yid">
  73. <view class="nominal">
  74. 优惠券
  75. </view>
  76. <view class="content">
  77. <span class="noyhq">{{showyhq}}</span>
  78. </view>
  79. </view>
  80. </view>
  81. <view class="blck">
  82. </view>
  83. <view class="footer">
  84. <view class="settlement">
  85. <view class="sum">合计:<view class="money">{{sumPrice|toFixed}}</view></view>
  86. <view class="btn" @tap="toPay">提交订单</view>
  87. </view>
  88. </view>
  89. </view>
  90. </template>
  91. <script>
  92. import {throttle} from '@/common/util';
  93. export default {
  94. data() {
  95. return {
  96. buylist:[], //订单列表
  97. goodsPrice:0.0, //商品合计价格
  98. sumPrice:0.0, //用户付款价格
  99. freight:0.00, //运费
  100. note:'', //备注
  101. int:0, //抵扣积分
  102. deduction:0, //抵扣价格
  103. recinfo:[],
  104. oneprice:0,//单价
  105. cpids:'',
  106. cpnums:'',
  107. dhid:0,
  108. showyhq:'',
  109. yid:0,//优惠券id
  110. };
  111. },
  112. onLoad(option) {
  113. this.dhid=option.dhid;
  114. this.yid=option.yid;
  115. if(option.yhjine>0){
  116. this.showyhq='¥-'+option.yhjine+'';
  117. let t=this;
  118. setTimeout(function(){
  119. t.sumPrice =parseFloat(t.sumPrice-option.yhjine).toFixed(2);
  120. },200)
  121. }else{
  122. this.showyhq='';
  123. }
  124. },
  125. onShow() {
  126. //页面显示时,加载订单信息
  127. uni.getStorage({
  128. key:'buylist',
  129. success: (ret) => {
  130. this.buylist = ret.data;
  131. console.log(this.buylist,'得到列表')
  132. this.goodsPrice=0;
  133. //合计
  134. let len = this.buylist.length;
  135. for(let i=0;i<len;i++){
  136. if(this.buylist[i].dinghl>0){
  137. this.goodsPrice = this.goodsPrice + (this.buylist[i].dinghl*this.buylist[i].price);
  138. this.cpids=this.cpids+','+this.buylist[i].cpid
  139. this.cpnums=this.cpnums+','+this.buylist[i].dinghl
  140. }
  141. }
  142. this.deduction = this.int/100;
  143. this.sumPrice = this.goodsPrice-this.deduction+this.freight;
  144. }
  145. });
  146. uni.getStorage({
  147. key:'userinfo',
  148. success: (e) => {
  149. this.recinfo = e.data;
  150. }
  151. })
  152. this.getbaseinfo('yunf');
  153. },
  154. onHide() {
  155. },
  156. onBackPress() {
  157. //页面后退时候,清除订单信息
  158. this.clearOrder();
  159. },
  160. filters: {
  161. toFixed:function(x) {
  162. return parseFloat(x).toFixed(2);
  163. }
  164. },
  165. methods: {
  166. async getbaseinfo(key){
  167. let getdata= await this.$api.baseinfo({action:'baseinfo',key:key});
  168. if(getdata.data.info!=''){
  169. if(this.goodsPrice<getdata.data.info[0]){
  170. this.freight=getdata.data.info[1];
  171. this.sumPrice = this.goodsPrice-parseFloat(this.deduction)+parseFloat(this.freight);
  172. }
  173. }
  174. },
  175. async postorder(paymentOrder) {
  176. let getuserinfo=uni.getStorageSync('userinfo');
  177. let paymoney=this.freight+this.sumPrice
  178. uni.hideLoading();
  179. uni.redirectTo({
  180. //这里的价格是显示作用,实际支付价格后台计算
  181. url:"/pages/pay/pay?paymoney="+paymoney+'&dhid='+this.dhid
  182. })
  183. },
  184. clearOrder(){
  185. uni.removeStorage({
  186. key: 'buylist',
  187. success: (res)=>{
  188. this.buylist = [];
  189. console.log('remove buylist success');
  190. }
  191. });
  192. },
  193. toPay:throttle(function(){
  194. //商品列表
  195. let paymentOrder = [];
  196. let goodsid=[];
  197. let len = this.buylist.length;
  198. for(let i=0;i<len;i++){
  199. paymentOrder.push(this.buylist[i]);
  200. goodsid.push(this.buylist[i].id);
  201. }
  202. if(paymentOrder.length==0){
  203. uni.showToast({title:'订单信息有误,请重新购买',icon:'none'});
  204. return ;
  205. }
  206. //本地模拟订单提交UI效果
  207. uni.showLoading({
  208. title:'正在提交订单...'
  209. })
  210. //提交订单
  211. this.postorder(paymentOrder)
  212. }),
  213. //选择收货地址
  214. selectAddress(){
  215. let t=this;
  216. uni.setStorage({
  217. key:'address',
  218. data:t.recinfo,
  219. success() {
  220. uni.navigateTo({
  221. url:"../address/edit/edit?type=edit"
  222. })
  223. }
  224. });
  225. }
  226. }
  227. }
  228. </script>
  229. <style lang="scss">
  230. .addr{
  231. width: 86%;
  232. padding: 20upx 3%;
  233. margin: 30upx auto 20upx auto;
  234. box-shadow: 0upx 5upx 20upx rgba(0,0,0,0.1);
  235. border-radius: 20upx;
  236. display: flex;
  237. .icon{
  238. width: 80upx;
  239. height: 80upx;
  240. display: flex;
  241. align-items: center;
  242. image{
  243. width: 60upx;
  244. height: 60upx;
  245. }
  246. }
  247. .tel-name{
  248. width: 100%;
  249. display: flex;
  250. font-size: 32upx;
  251. .tel{
  252. margin-left: 40upx;
  253. }
  254. }
  255. .addres{
  256. width: 100%;
  257. font-size: 26upx;
  258. color: #999;
  259. }
  260. }
  261. .buy-list{
  262. width: 86%;
  263. padding: 10upx 3%;
  264. margin: 30upx auto 20upx auto;
  265. box-shadow: 0upx 5upx 20upx rgba(0,0,0,0.1);
  266. border-radius: 20upx;
  267. .row{
  268. margin: 30upx 0;
  269. .goods-info{
  270. width: 100%;
  271. display: flex;
  272. .img{
  273. width: 22vw;
  274. height: 22vw;
  275. border-radius: 10upx;
  276. overflow: hidden;
  277. flex-shrink: 0;
  278. margin-right: 10upx;
  279. image{
  280. width: 22vw;
  281. height: 22vw;
  282. }
  283. }
  284. .info{
  285. width: 100%;
  286. height: 22vw;
  287. overflow: hidden;
  288. display: flex;
  289. flex-wrap: wrap;
  290. position: relative;
  291. .title{
  292. width: 100%;
  293. font-size: 28upx;
  294. display: -webkit-box;
  295. -webkit-box-orient: vertical;
  296. -webkit-line-clamp: 2;
  297. // text-align: justify;
  298. overflow: hidden;
  299. }
  300. .spec{
  301. font-size: 22upx;
  302. background-color: #f3f3f3;
  303. color: #a7a7a7;
  304. height: 40upx;
  305. display: flex;
  306. align-items: center;
  307. padding: 0 10upx;
  308. border-radius: 20upx;
  309. margin-bottom: 20vw;
  310. }
  311. .price-number{
  312. position: absolute;
  313. width: 100%;
  314. bottom: 0upx;
  315. display: flex;
  316. justify-content: space-between;
  317. align-items: flex-end;
  318. font-size: 28upx;
  319. height: 40upx;
  320. .price{
  321. color: #f06c7a;
  322. }
  323. .number{
  324. display: flex;
  325. justify-content: center;
  326. align-items: center;
  327. }
  328. }
  329. }
  330. }
  331. }
  332. }
  333. .order{
  334. width: 86%;
  335. padding: 10upx 3%;
  336. margin: 30upx auto 20upx auto;
  337. box-shadow: 0upx 5upx 20upx rgba(0,0,0,0.1);
  338. border-radius: 20upx;
  339. .row{
  340. margin: 20upx 0;
  341. height: 40upx;
  342. display: flex;
  343. .left{
  344. font-size: 28upx;
  345. }
  346. .right{
  347. margin-left: 40upx;
  348. font-size: 26upx;
  349. color: #999;
  350. input{
  351. font-size: 26upx;
  352. color: #999;
  353. }
  354. }
  355. }
  356. }
  357. .blck{
  358. width: 100%;
  359. height: 100upx;
  360. }
  361. .footer{
  362. width: 100%;
  363. padding: 0 4%;
  364. background-color: #fbfbfb;
  365. height: 100upx;
  366. display: flex;
  367. justify-content: flex-end;
  368. align-items: center;
  369. font-size: 28upx;
  370. position: fixed;
  371. bottom: 0upx;
  372. z-index: 5;
  373. .settlement{
  374. width: 80%;
  375. display: flex;
  376. justify-content: flex-end;
  377. align-items: center;
  378. .sum{
  379. width: 50%;
  380. font-size: 28upx;
  381. margin-right: 10upx;
  382. display: flex;
  383. justify-content: flex-end;
  384. .money{
  385. font-weight: 600;
  386. }
  387. }
  388. .btn{
  389. padding: 0 30upx;
  390. height: 60upx;
  391. background-color: #f06c7a;
  392. color: #fff;
  393. display: flex;
  394. justify-content: center;
  395. align-items: center;
  396. font-size: 30upx;
  397. border-radius: 40upx;
  398. }
  399. }
  400. }
  401. .detail{
  402. width: 86%;
  403. padding: 10upx 3%;
  404. margin: 30upx auto 20upx auto;
  405. box-shadow: 0upx 5upx 20upx rgba(0,0,0,0.1);
  406. border-radius: 20upx;
  407. .row{
  408. height: 60upx;
  409. display: flex;
  410. justify-content: space-between;
  411. align-items: center;
  412. .nominal{
  413. font-size: 28upx;
  414. }
  415. .content{
  416. font-size: 26upx;
  417. color: #f06c7a;
  418. }
  419. }
  420. }
  421. </style>