create-order.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  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
  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. let data = {orderID:response.data.orderID}
  318. this.$api.navigateTo(`/pages/user/order/success?data=${JSON.stringify({data:data})}`)
  319. }else{
  320. this.submitState ='confirm'
  321. this.isSubLoading = false;
  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. }
  327. }).catch(error =>{
  328. this.$util.msg(error.msg,3000);
  329. })
  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:570rpx;
  478. height:100%;
  479. float: left;
  480. }
  481. .footer-count{
  482. float: left;
  483. padding-left: 24rpx;
  484. width:180rpx;
  485. box-sizing: border-box;
  486. }
  487. .footer-price{
  488. width:370rpx;
  489. float: right;
  490. text-align: right;
  491. color: $text-color;
  492. padding: 10rpx 20rpx 10rpx 0;
  493. box-sizing: border-box;
  494. .sum-none{
  495. width: 100%;
  496. height: 45rpx;
  497. line-height: 45rpx;
  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:$color-system;
  515. }
  516. }
  517. .sum{
  518. width: 100%;
  519. height: 45rpx;
  520. line-height: 45rpx;
  521. float: left;
  522. &.none{
  523. height: 90rpx;
  524. line-height: 90rpx;
  525. }
  526. .price{
  527. font-size: $font-size-32;
  528. color: #FF2A2A;
  529. }
  530. }
  531. }
  532. .footer-submit{
  533. display:flex;
  534. align-items:center;
  535. justify-content: center;
  536. width: 180rpx;
  537. height: 100%;
  538. box-sizing: border-box;
  539. padding: 15rpx 5rpx;
  540. .btn{
  541. width: 100%;
  542. height: 100%;
  543. color: #FFFFFF;
  544. background:linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%);
  545. font-size: $font-size-26;
  546. text-align: center;
  547. line-height: 80rpx;
  548. border-radius: 40rpx;
  549. &.disabled{
  550. background: #F7F7F7;
  551. color: #999999;
  552. }
  553. }
  554. }
  555. }
  556. </style>