create-order.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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.toFixed(2)}}</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.toFixed(2)}},剩余:¥{{surplusMoney.toFixed(2)}}</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 class="iconfont icon-biaoqian"></text>减<text>¥{{ reducedPrice | NumFormat}}</text></text>
  59. </view>
  60. <view class="sum">总价:<text class="price">¥{{payAllPrice | NumFormat}}</text></view>
  61. </view>
  62. </view>
  63. <view class="footer-submit" @click.stop="orderSubmitMit">提交订单</view>
  64. </view>
  65. </view>
  66. </template>
  67. <script>
  68. import choiceAddress from '@/components/cm-module/creatOrder/choiceAddress'
  69. import goodsList from '@/components/cm-module/creatOrder/goodsList'
  70. import invoiceTent from '@/components/cm-module/creatOrder/invoiceTent'
  71. import freight from '@/components/cm-module/creatOrder/freight'
  72. import freightAlert from '@/components/cm-module/modelAlert/freightAlert'
  73. import modalLayer from "@/components/modal-layer"
  74. import { queryAddressList } from "@/api/cart.js"
  75. import { createOrderSubmit,getOrderPostage } from "@/api/order.js"
  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. 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. 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. createOrderSubmit({'params':JSON.stringify(param)}).then(response =>{
  316. if(response.code === 1){
  317. this.submitState ='success'
  318. let data = {orderID:response.data.orderID}
  319. this.$api.navigateTo(`/pages/user/order/success?data=${JSON.stringify({data:data})}`)
  320. }else if(response.code === 2){
  321. this.submitState ='confirm'
  322. this.$util.msg('订单提交成功',3000,true,'success')
  323. setTimeout(()=>{
  324. this.$api.redirectTo(`/pages/user/order/order-payment?type=${this.submitState}&orderID=${response.data.orderID}`)
  325. },3000)
  326. }else{
  327. this.$util.msg(response.msg,3000);
  328. }
  329. }).catch(error =>{})
  330. },
  331. handFreightAlertShow(){//显示邮费弹窗
  332. this.isfreightTip = true;
  333. },
  334. hideFreight(){//关闭邮费弹窗
  335. this.isfreightTip = false;
  336. },
  337. },
  338. onShow() {
  339. // this.addressID = ''
  340. let pages = getCurrentPages();
  341. let currPage = pages[pages.length-1];
  342. if(currPage.data.select =='select'){
  343. this.isAddress = true
  344. let SelectData = uni.getStorageSync('selectAddress');
  345. this.addressID = SelectData.addressID;
  346. this.addressData = SelectData
  347. this.getFreightData()
  348. }else{
  349. this.getAddressData()
  350. }
  351. }
  352. }
  353. </script>
  354. <style lang="scss">
  355. page {
  356. height: auto;
  357. background:#F7F7F7;
  358. }
  359. .btn-hover{
  360. background: #FFFFFF;
  361. }
  362. .animation{
  363. /* transition: transform 0.3s ease;*/
  364. transition-property: transform;
  365. transition-duration: 0.3s;
  366. transition-timing-function: ease;
  367. }
  368. .order{
  369. padding-bottom: 134rpx;
  370. }
  371. .invoice-freight{
  372. width: 702rpx;
  373. padding: 0 24rpx;
  374. height: 86rpx;
  375. line-height: 86rpx;
  376. font-size: $font-size-28;
  377. color: $text-color;
  378. background: #FFFFFF;
  379. float: left;
  380. font-weight: bold;
  381. .freight-left{
  382. float: left;
  383. .icon-yunfeishuoming{
  384. height: 100%;
  385. padding: 0 15rpx;
  386. color: $color-system;
  387. font-weight: normal;
  388. }
  389. }
  390. .freight-right{
  391. float: right;
  392. color: #2A81FF;
  393. }
  394. }
  395. .invoice-balance{
  396. width: 702rpx;
  397. height: auto;
  398. padding:0 24rpx;
  399. background: #FFFFFF;
  400. float: left;
  401. margin-top: 24rpx;
  402. margin-bottom: 24rpx;
  403. .balabce-t{
  404. width: 100%;
  405. height: 86rpx;
  406. line-height: 86rpx;
  407. font-size: $font-size-28;
  408. color: $text-color;
  409. float: left;
  410. .balabce-t-le{
  411. float: left;
  412. font-weight: bold;
  413. }
  414. .balabce-t-ri{
  415. float: right;
  416. display: flex;
  417. align-items: center;
  418. .money{
  419. display: flex;
  420. float: left;
  421. }
  422. .checkbox-box{
  423. display: flex;
  424. width: 60rpx;
  425. float: left;
  426. height: 100%;
  427. font-size: $font-size-24;
  428. .checkbox{
  429. width: 40rpx;
  430. text-align: right;
  431. box-sizing: border-box;
  432. text-align: center;
  433. text-decoration: none;
  434. border-radius: 0;
  435. -webkit-tap-highlight-color: transparent;
  436. overflow: hidden;
  437. color: $color-system;
  438. }
  439. }
  440. }
  441. }
  442. .balabce-b{
  443. width: 100%;
  444. float: left;
  445. overflow: hidden;
  446. .balabce-b-text{
  447. width: 100%;
  448. line-height: 58rpx;
  449. font-size: $font-size-24;
  450. color: #FF2A2A;
  451. text-align: right;
  452. float: right;
  453. }
  454. &.balabce-b--hide {
  455. padding: 0 0;
  456. height: 0px;
  457. line-height: 0px;
  458. }
  459. }
  460. }
  461. .footer{
  462. position: fixed;
  463. left: 0;
  464. bottom: 0;
  465. z-index: 995;
  466. display: flex;
  467. align-items: center;
  468. width: 100%;
  469. height: 110rpx;
  470. line-height: 110rpx;
  471. justify-content: space-between;
  472. font-size: $font-size-28;
  473. background-color: #FFFFFF;
  474. z-index: 998;
  475. color: $text-color;
  476. .footer-le{
  477. width:550rpx;
  478. height:100%;
  479. float: left;
  480. }
  481. .footer-count{
  482. float: left;
  483. padding-left: 24rpx;
  484. width: 200rpx;
  485. box-sizing: border-box;
  486. }
  487. .footer-price{
  488. width: 350rpx;
  489. float: right;
  490. text-align: right;
  491. color: $text-color;
  492. padding-right: 24rpx;
  493. box-sizing: border-box;
  494. .sum-none{
  495. width: 100%;
  496. height: 55rpx;
  497. line-height: 55rpx;
  498. color: $text-color;
  499. float: left;
  500. text-align: right;
  501. .money{
  502. font-size: $font-size-26;
  503. color: #999999;
  504. text-decoration: line-through;
  505. }
  506. .money-sign{
  507. font-size: $font-size-26;
  508. color: #999999;
  509. text-decoration: line-through;
  510. }
  511. .money-reduced{
  512. margin-left: 10rpx;
  513. font-size: $font-size-26;
  514. color: #ff2a2a;
  515. .iconfont{
  516. font-size: $font-size-34;
  517. }
  518. }
  519. }
  520. .sum{
  521. width: 100%;
  522. height: 55rpx;
  523. line-height: 55rpx;
  524. float: left;
  525. .price{
  526. font-size: $font-size-32;
  527. color: #FF2A2A;
  528. }
  529. }
  530. }
  531. .footer-submit{
  532. display:flex;
  533. align-items:center;
  534. justify-content: center;
  535. width: 200rpx;
  536. height: 100%;
  537. color: #FFFFFF;
  538. background:linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%);
  539. }
  540. }
  541. </style>