create-order.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. <template>
  2. <view class="container order clearfix" :style="{paddingBottom :isIphoneX ? '170rpx' : '134rpx'}">
  3. <!-- 透明模态层 -->
  4. <modal-layer v-if='modallayer'></modal-layer>
  5. <!-- 地址选择 -->
  6. <choice-address ref="choiceAddress" v-if="isAddress" :addressData="addressData"></choice-address>
  7. <!-- 商品 -->
  8. <goods-list ref='goods' v-if="isRequest" :goodsData="goodsData" @handleGoodList="handChangeInputGoodsList"></goods-list>
  9. <!-- 发票信息 -->
  10. <invoice-tent ref="invoice"
  11. v-if="isRequest"
  12. :invoiceDatas="invoiceData"
  13. @handleChoiceaInvoice="handleChoiceaInvoiceData">
  14. </invoice-tent>
  15. <!-- 运费 -->
  16. <freight ref="freight"
  17. v-if="isFreight"
  18. :freightData="freightData"
  19. @confirmFreight="hanldFreightFn">
  20. </freight>
  21. <freight-alert v-if="isfreightTip" ref="csPhone"></freight-alert>
  22. <!-- 余额抵扣 -->
  23. <view class="invoice-balance" v-show="!rechargeGoods">
  24. <view class="balabce-t">
  25. <view class="balabce-t-le">余额抵扣</view>
  26. <view class="balabce-t-ri">
  27. <view class="money">
  28. <text>可用余额:</text>
  29. <text>¥{{userMoney | NumFormat}}</text>
  30. </view>
  31. <view class="checkbox-box">
  32. <button class="checkbox iconfont"
  33. hover-class="btn-hover"
  34. v-if="userMoney!=0"
  35. @click.stop="checkedBalabce"
  36. :class="[ischecked ?'icon-gouxuanl':'icon-weigouxuan']"
  37. >
  38. </button>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="balabce-b" :class="{'balabce-b--hide':!ischecked}">
  43. <view class="balabce-b-text animation" :style="{'transform':ischecked?'translateY(0)':'translateY(-50%)','-webkit-transform':ischecked?'translateY(0)':'translateY(-50%)'}">
  44. <text>当前使用:¥{{deductMoney | NumFormat}},剩余:¥{{surplusMoney | NumFormat}}</text>
  45. </view>
  46. </view>
  47. </view>
  48. <!-- 底部 -->
  49. <view class="footer" :style="{paddingBottom :isIphoneX ? '68rpx' : '0rpx'}">
  50. <view class="footer-le">
  51. <view class="footer-count">
  52. <text>共{{allCount}}件商品</text>
  53. </view>
  54. <view class="footer-price">
  55. <view class="sum-none" v-if="reducedPrice>0">
  56. <text class="money-sign">¥</text>
  57. <text class="money">{{ totalOriginalPrice | NumFormat }}</text>
  58. <text class="money-reduced">减<text>¥{{ reducedPrice | NumFormat}}</text></text>
  59. </view>
  60. <view class="sum" :class="reducedPrice == 0 ? 'none' : ''">总价:<text class="price">¥{{payAllPrice | NumFormat}}</text></view>
  61. </view>
  62. </view>
  63. <view class="footer-submit" @click.stop="orderSubmitMit">
  64. <view class="btn">提交订单</view>
  65. </view>
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. import choiceAddress from '@/components/cm-module/creatOrder/choiceAddress'
  71. import goodsList from '@/components/cm-module/creatOrder/goodsList'
  72. import invoiceTent from '@/components/cm-module/creatOrder/invoiceTent'
  73. import freight from '@/components/cm-module/creatOrder/freight'
  74. import freightAlert from '@/components/cm-module/modelAlert/freightAlert'
  75. import modalLayer from "@/components/modal-layer"
  76. export default {
  77. components:{
  78. choiceAddress,
  79. goodsList,
  80. invoiceTent,
  81. freight,
  82. freightAlert,
  83. modalLayer
  84. },
  85. data() {
  86. return {
  87. modallayer:false,
  88. orderID:0,
  89. productIds:'', //获取上一级页面商品信息
  90. productCount:'', //获取上一级页面商品数量
  91. classifyIDS:'', //获取上一级页面商品分类
  92. userID:'', //用户ID
  93. cartType:'', //购买类型(1购物车提交,2直接购买提交)
  94. submitState:'', //提交状态
  95. balanceDeductionFlag:2, //勾选余额的状态(1使用,2不使用)
  96. allCount:1, //订单提交总数量
  97. totalOriginalPrice:0, //订单总原价(划线部分)
  98. reducedPrice:0, //满减金额
  99. payAllPrice:0.00, //订单提交总金额
  100. allPrice:0.00, //订单总金额
  101. surplusMoney:0.00, //显示勾选后的剩余抵扣
  102. userMoney:0.00, //显示可使用余额
  103. deductMoney:0.00, //显示已使用的余额
  104. addressID:'', //地址ID
  105. townID:'', //区ID
  106. isRequest:false, //是否加载完成渲染子组件
  107. isFreight:false, //是否加载完成渲染子组件
  108. isAddress:false, //是否加载完成地址
  109. isfreightTip:false, //控制邮费弹窗
  110. ischecked:false, //是否勾选余额
  111. hanldFreePostFlag:'', //邮费状态
  112. hanldFreight:'', //邮费
  113. addressData:{}, //初始化地址信息
  114. goodsData:[], //初始化商品信息
  115. invoiceData:{type:0}, //初始化发票信息
  116. freightData:{}, //邮费数据
  117. orderInfo:[], //提交的商品信息
  118. payInfo:{}, //订单信息
  119. rechargeGoods:null, //判断订单里有定金商品或者充值商品时,余额抵扣部分不显示
  120. isIphoneX:this.$store.state.isIphoneX
  121. }
  122. },
  123. onLoad(option){//商品数据
  124. let data = JSON.parse(option.data);
  125. if(option.type =='prodcut'){
  126. this.cartType = 2
  127. this.productCount = data.data.productCount
  128. this.productIds = data.data.productID
  129. }else{
  130. this.cartType = 1
  131. this.productCount = data.data.productCount
  132. this.productIds = data.data.productID
  133. }
  134. this.$api.getStorage().then((resolve) =>{
  135. this.userID = resolve.userID
  136. this.getInitCrearOrder(option);
  137. })
  138. },
  139. filters:{
  140. NumFormat(value) {//处理金额
  141. return Number(value).toFixed(2);
  142. },
  143. },
  144. methods: {
  145. getInitCrearOrder(option){//获取订单商品信息
  146. let params ={userId:this.userID,count:this.productCount,productIds:this.productIds}
  147. this.OrderService.CreateOrderInfo(params).then(response =>{
  148. let resData = response.data
  149. this.isRequest = true
  150. this.goodsData = resData.list
  151. this.userMoney = resData.userMoney
  152. this.reducedPrice = resData.reducedPrice
  153. this.allPrice = this.payAllPrice = resData.totalPrice
  154. this.totalOriginalPrice = resData.totalOriginalPrice
  155. this.rechargeGoods = resData.rechargeGoods
  156. }).catch(error =>{
  157. this.$util.msg(error.msg,2000)
  158. })
  159. },
  160. getFreightData(){//获取邮费信息
  161. let params ={
  162. userId:this.userID,
  163. productIds:this.productIds,
  164. totalPrice:this.allPrice,
  165. townId:this.addressData.townID
  166. }
  167. this.OrderService.GetOrderPostage(params).then(response =>{
  168. this.isFreight = true
  169. this.freightData = response.data
  170. this.hanldFreePostFlag = response.data.freePostFlag
  171. this.hanldFreight = response.data.freight
  172. if(this.hanldFreePostFlag == 1){
  173. this.payAllPrice = this.allPrice + response.data.freight
  174. this.attributePallPrice()
  175. }else{
  176. this.payAllPrice = this.allPrice
  177. this.attributePallPrice()
  178. }
  179. })
  180. },
  181. getAddressData(){//获取地址信息
  182. this.$api.getStorage().then((resolve) => {
  183. this.UserService.QueryAddressList({pageNum:1,pageSize:1,userID:resolve.userID}).then(response =>{
  184. this.isAddress = true
  185. this.addressData = {}
  186. if(response.data.results != ''){
  187. this.addressID = response.data.results[0].addressID;
  188. this.townID = response.data.results[0].townID;
  189. this.addressData = response.data.results[0];
  190. this.getFreightData()
  191. }else{
  192. this.addressData = this.addressData;
  193. }
  194. })
  195. })
  196. },
  197. handChangeInputGoodsList(data){//对应供应商的留言信息
  198. this.goodsData = data;
  199. },
  200. handleChoiceaInvoiceData(data){//获取发票信息
  201. this.invoiceData = data
  202. },
  203. hanldFreightFn(data){//显示邮费弹窗
  204. switch(data){
  205. case 1:
  206. this.hanldFreight = this.freightData.freight
  207. this.hanldFreePostFlag = data
  208. this.payAllPrice =this.allPrice + this.hanldFreight
  209. this.attributePallPrice()
  210. break
  211. case -1:
  212. this.hanldFreight = 0
  213. this.hanldFreePostFlag = data
  214. this.payAllPrice = this.allPrice
  215. this.attributePallPrice()
  216. break
  217. }
  218. },
  219. checkedBalabce(){//勾选使用余额
  220. if(this.userMoney > 0){
  221. this.ischecked = !this.ischecked
  222. if(this.ischecked){
  223. this.balanceDeductionFlag =1
  224. this.attributePallPrice()
  225. }else{
  226. if(this.hanldFreePostFlag == 1 || this.hanldFreePostFlag == '1'){
  227. this.payAllPrice = this.allPrice+parseInt(this.freightData.freight)
  228. }else{
  229. this.payAllPrice = this.allPrice
  230. }
  231. this.balanceDeductionFlag = 2
  232. }
  233. }else{
  234. return
  235. }
  236. },
  237. attributePallPrice(){//计算价格
  238. if(this.hanldFreePostFlag == 1 || this.hanldFreePostFlag == '1'){
  239. this.attributeHashfreight(this.freightData.freight)
  240. }else{
  241. this.attributeNofreight()
  242. }
  243. },
  244. attributeNofreight(){//计算没有邮费的支付价格
  245. if(this.ischecked){
  246. if(this.userMoney>this.payAllPrice){
  247. this.payAllPrice = 0.00
  248. this.deductMoney = this.allPrice //勾选后使用抵余额
  249. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  250. }else{
  251. this.payAllPrice = this.allPrice - this.userMoney //勾选后的总价
  252. this.deductMoney = this.userMoney //勾选后使用抵余额
  253. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  254. }
  255. }else{
  256. this.payAllPrice = this.allPrice;
  257. this.deductMoney = 0.00;
  258. this.surplusMoney = this.userMoney;
  259. }
  260. },
  261. attributeHashfreight(freight){//计算需要邮费的支付价格
  262. this.payAllPrice = this.allPrice+parseInt(freight)//计算不包邮的价格 总价等于商品价格+邮费
  263. if(this.ischecked){
  264. if(this.userMoney>this.payAllPrice){ //余额大于支付金额
  265. this.payAllPrice =0.00
  266. this.deductMoney = this.allPrice+parseInt(freight) //勾选后使用抵余额
  267. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  268. }else{
  269. this.payAllPrice = this.allPrice+parseInt(freight) - this.userMoney //勾选后的总价
  270. this.deductMoney = this.userMoney //勾选后使用抵余额
  271. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  272. }
  273. }else{
  274. this.payAllPrice = this.allPrice+parseInt(freight)
  275. this.deductMoney = 0.00
  276. this.surplusMoney = this.userMoney
  277. }
  278. },
  279. orderSubmitMit(){//提交订单
  280. if(this.addressID == ''){
  281. this.$util.msg('请先添加收货地址~',2000)
  282. return
  283. }
  284. this.orderInfo = this.goodsData.map(el => {
  285. let productInfo = [];
  286. el.cartList.forEach(item => {
  287. productInfo.push({
  288. productId:item.productId,
  289. productNum:item.number,
  290. presentNum:0,
  291. productType:item.productType
  292. })
  293. })
  294. return {shopId:el.id,note:el.note?el.note:'',productInfo:productInfo}
  295. })
  296. //订单信息
  297. this.payInfo = {
  298. clauseId:0,//条款(暂时保留)
  299. orderShouldPayFee:this.payAllPrice.toFixed(2),//提交的总价
  300. balancePayFlag:this.balanceDeductionFlag,//余额抵扣的状态
  301. freight:parseInt(this.hanldFreight).toFixed(2),//邮费
  302. freePostFlag:parseInt(this.hanldFreePostFlag)//运费形式
  303. }
  304. let param = {
  305. orderSource:6,
  306. clubUserId:this.userID,
  307. cartType:this.cartType,
  308. addressId:this.addressID,
  309. orderInfo:this.orderInfo,
  310. payInfo:this.payInfo, //订单信息
  311. orderInvoice:this.invoiceData
  312. }
  313. // console.log(param)
  314. this.modalLayer = true;
  315. this.OrderService.CreatedOrderSubmit({'params':JSON.stringify(param)}).then(response =>{
  316. const data = response.data;
  317. if(data.code === '1'){
  318. this.submitState ='success'
  319. let data = {orderID:response.data.orderID}
  320. this.$api.navigateTo(`/pages/user/order/success?data=${JSON.stringify({data:data})}`)
  321. }else{
  322. this.submitState ='confirm'
  323. this.$util.msg('订单提交成功',3000,true,'success')
  324. setTimeout(()=>{
  325. this.$api.redirectTo(`/pages/user/order/order-payment?type=${this.submitState}&orderID=${response.data.orderID}`)
  326. },3000)
  327. }
  328. }).catch(error =>{
  329. this.$util.msg(error.msg,3000);
  330. })
  331. },
  332. handFreightAlertShow(){//显示邮费弹窗
  333. this.isfreightTip = true;
  334. },
  335. hideFreight(){//关闭邮费弹窗
  336. this.isfreightTip = false;
  337. },
  338. },
  339. onShow() {
  340. // this.addressID = ''
  341. let pages = getCurrentPages();
  342. let currPage = pages[pages.length-1];
  343. if(currPage.data.select =='select'){
  344. this.isAddress = true
  345. let SelectData = uni.getStorageSync('selectAddress');
  346. this.addressID = SelectData.addressID;
  347. this.addressData = SelectData
  348. this.getFreightData()
  349. }else{
  350. this.getAddressData()
  351. }
  352. }
  353. }
  354. </script>
  355. <style lang="scss">
  356. page {
  357. height: auto;
  358. background:#F7F7F7;
  359. }
  360. .btn-hover{
  361. background: #FFFFFF;
  362. }
  363. .animation{
  364. /* transition: transform 0.3s ease;*/
  365. transition-property: transform;
  366. transition-duration: 0.3s;
  367. transition-timing-function: ease;
  368. }
  369. .order{
  370. padding-bottom: 134rpx;
  371. }
  372. .invoice-freight{
  373. width: 702rpx;
  374. padding: 0 24rpx;
  375. height: 86rpx;
  376. line-height: 86rpx;
  377. font-size: $font-size-28;
  378. color: $text-color;
  379. background: #FFFFFF;
  380. float: left;
  381. font-weight: bold;
  382. .freight-left{
  383. float: left;
  384. .icon-yunfeishuoming{
  385. height: 100%;
  386. padding: 0 15rpx;
  387. color: $color-system;
  388. font-weight: normal;
  389. }
  390. }
  391. .freight-right{
  392. float: right;
  393. color: #2A81FF;
  394. }
  395. }
  396. .invoice-balance{
  397. width: 702rpx;
  398. height: auto;
  399. padding:0 24rpx;
  400. background: #FFFFFF;
  401. float: left;
  402. margin-top: 24rpx;
  403. margin-bottom: 24rpx;
  404. .balabce-t{
  405. width: 100%;
  406. height: 86rpx;
  407. line-height: 86rpx;
  408. font-size: $font-size-28;
  409. color: $text-color;
  410. float: left;
  411. .balabce-t-le{
  412. float: left;
  413. font-weight: bold;
  414. }
  415. .balabce-t-ri{
  416. float: right;
  417. display: flex;
  418. align-items: center;
  419. .money{
  420. display: flex;
  421. float: left;
  422. }
  423. .checkbox-box{
  424. display: flex;
  425. width: 60rpx;
  426. float: left;
  427. height: 100%;
  428. font-size: $font-size-24;
  429. .checkbox{
  430. width: 40rpx;
  431. text-align: right;
  432. box-sizing: border-box;
  433. text-align: center;
  434. text-decoration: none;
  435. border-radius: 0;
  436. -webkit-tap-highlight-color: transparent;
  437. overflow: hidden;
  438. color: $color-system;
  439. }
  440. }
  441. }
  442. }
  443. .balabce-b{
  444. width: 100%;
  445. float: left;
  446. overflow: hidden;
  447. .balabce-b-text{
  448. width: 100%;
  449. line-height: 58rpx;
  450. font-size: $font-size-24;
  451. color: #FF2A2A;
  452. text-align: right;
  453. float: right;
  454. }
  455. &.balabce-b--hide {
  456. padding: 0 0;
  457. height: 0px;
  458. line-height: 0px;
  459. }
  460. }
  461. }
  462. .footer{
  463. position: fixed;
  464. left: 0;
  465. bottom: 0;
  466. z-index: 995;
  467. display: flex;
  468. align-items: center;
  469. width: 100%;
  470. height: 110rpx;
  471. line-height: 110rpx;
  472. justify-content: space-between;
  473. font-size: $font-size-28;
  474. background-color: #FFFFFF;
  475. z-index: 998;
  476. color: $text-color;
  477. .footer-le{
  478. width:570rpx;
  479. height:100%;
  480. float: left;
  481. }
  482. .footer-count{
  483. float: left;
  484. padding-left: 24rpx;
  485. width:180rpx;
  486. box-sizing: border-box;
  487. }
  488. .footer-price{
  489. width:370rpx;
  490. float: right;
  491. text-align: right;
  492. color: $text-color;
  493. padding: 10rpx 20rpx 10rpx 0;
  494. box-sizing: border-box;
  495. .sum-none{
  496. width: 100%;
  497. height: 45rpx;
  498. line-height: 45rpx;
  499. color: $text-color;
  500. float: left;
  501. text-align: right;
  502. .money{
  503. font-size: $font-size-26;
  504. color: #999999;
  505. text-decoration: line-through;
  506. }
  507. .money-sign{
  508. font-size: $font-size-26;
  509. color: #999999;
  510. text-decoration: line-through;
  511. }
  512. .money-reduced{
  513. margin-left: 10rpx;
  514. font-size: $font-size-26;
  515. color:$color-system;
  516. }
  517. }
  518. .sum{
  519. width: 100%;
  520. height: 45rpx;
  521. line-height: 45rpx;
  522. float: left;
  523. &.none{
  524. height: 90rpx;
  525. line-height: 90rpx;
  526. }
  527. .price{
  528. font-size: $font-size-32;
  529. color: #FF2A2A;
  530. }
  531. }
  532. }
  533. .footer-submit{
  534. display:flex;
  535. align-items:center;
  536. justify-content: center;
  537. width: 180rpx;
  538. height: 100%;
  539. box-sizing: border-box;
  540. padding: 15rpx 5rpx;
  541. .btn{
  542. width: 100%;
  543. height: 100%;
  544. color: #FFFFFF;
  545. background:linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%);
  546. font-size: $font-size-26;
  547. text-align: center;
  548. line-height: 80rpx;
  549. border-radius: 40rpx;
  550. }
  551. }
  552. }
  553. </style>