create-order.vue 16 KB

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