create-order.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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. this.OrderService.CreateOrderInfo({
  143. userId:this.userID,
  144. count:this.productCount,
  145. productIds:this.productIds,
  146. unionId:uni.getStorageSync('unionId')
  147. })
  148. .then(response =>{
  149. let resData = response.data
  150. this.isRequest = true
  151. this.goodsData = resData.list
  152. this.userMoney = resData.userMoney
  153. this.reducedPrice = resData.reducedPrice
  154. this.allPrice = this.payAllPrice = resData.totalPrice
  155. this.totalOriginalPrice = resData.totalOriginalPrice
  156. this.rechargeGoods = resData.rechargeGoods
  157. }).catch(error =>{
  158. this.$util.msg(error.msg,2000)
  159. })
  160. },
  161. getFreightData(){//获取邮费信息
  162. let params ={
  163. userId:this.userID,
  164. productIds:this.productIds,
  165. totalPrice:this.allPrice,
  166. townId:this.addressData.townID
  167. }
  168. this.OrderService.GetOrderPostage(params).then(response =>{
  169. this.isFreight = true
  170. this.freightData = response.data
  171. this.hanldFreePostFlag = response.data.freePostFlag
  172. this.hanldFreight = response.data.freight
  173. if(this.hanldFreePostFlag == 1){
  174. this.payAllPrice = this.allPrice + response.data.freight
  175. this.attributePallPrice()
  176. }else{
  177. this.payAllPrice = this.allPrice
  178. this.attributePallPrice()
  179. }
  180. })
  181. },
  182. getAddressData(){//获取地址信息
  183. this.$api.getStorage().then((resolve) => {
  184. this.UserService.QueryAddressList({pageNum:1,pageSize:1,userID:resolve.userId}).then(response =>{
  185. this.isAddress = true
  186. this.addressData = {}
  187. if(response.data.results != ''){
  188. this.addressID = response.data.results[0].addressID;
  189. this.townID = response.data.results[0].townID;
  190. this.addressData = response.data.results[0];
  191. this.getFreightData()
  192. }else{
  193. this.addressData = this.addressData;
  194. }
  195. })
  196. })
  197. },
  198. handChangeInputGoodsList(data){//对应供应商的留言信息
  199. this.goodsData = data;
  200. },
  201. handleChoiceaInvoiceData(data){//获取发票信息
  202. this.invoiceData = data
  203. },
  204. hanldFreightFn(data){//显示邮费弹窗
  205. switch(data){
  206. case 1:
  207. this.hanldFreight = this.freightData.freight
  208. this.hanldFreePostFlag = data
  209. this.payAllPrice =this.allPrice + this.hanldFreight
  210. this.attributePallPrice()
  211. break
  212. case -1:
  213. this.hanldFreight = 0
  214. this.hanldFreePostFlag = data
  215. this.payAllPrice = this.allPrice
  216. this.attributePallPrice()
  217. break
  218. }
  219. },
  220. checkedBalabce(){//勾选使用余额
  221. if(this.userMoney > 0){
  222. this.ischecked = !this.ischecked
  223. if(this.ischecked){
  224. this.balanceDeductionFlag =1
  225. this.attributePallPrice()
  226. }else{
  227. if(this.hanldFreePostFlag == 1 || this.hanldFreePostFlag == '1'){
  228. this.payAllPrice = this.allPrice+parseInt(this.freightData.freight)
  229. }else{
  230. this.payAllPrice = this.allPrice
  231. }
  232. this.balanceDeductionFlag = 2
  233. }
  234. }else{
  235. return
  236. }
  237. },
  238. attributePallPrice(){//计算价格
  239. if(this.hanldFreePostFlag == 1 || this.hanldFreePostFlag == '1'){
  240. this.attributeHashfreight(this.freightData.freight)
  241. }else{
  242. this.attributeNofreight()
  243. }
  244. },
  245. attributeNofreight(){//计算没有邮费的支付价格
  246. if(this.ischecked){
  247. if(this.userMoney>this.payAllPrice){
  248. this.payAllPrice = 0.00
  249. this.deductMoney = this.allPrice //勾选后使用抵余额
  250. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  251. }else{
  252. this.payAllPrice = this.allPrice - this.userMoney //勾选后的总价
  253. this.deductMoney = this.userMoney //勾选后使用抵余额
  254. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  255. }
  256. }else{
  257. this.payAllPrice = this.allPrice;
  258. this.deductMoney = 0.00;
  259. this.surplusMoney = this.userMoney;
  260. }
  261. },
  262. attributeHashfreight(freight){//计算需要邮费的支付价格
  263. this.payAllPrice = this.allPrice+parseInt(freight)//计算不包邮的价格 总价等于商品价格+邮费
  264. if(this.ischecked){
  265. if(this.userMoney>this.payAllPrice){ //余额大于支付金额
  266. this.payAllPrice =0.00
  267. this.deductMoney = this.allPrice+parseInt(freight) //勾选后使用抵余额
  268. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  269. }else{
  270. this.payAllPrice = this.allPrice+parseInt(freight) - this.userMoney //勾选后的总价
  271. this.deductMoney = this.userMoney //勾选后使用抵余额
  272. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  273. }
  274. }else{
  275. this.payAllPrice = this.allPrice+parseInt(freight)
  276. this.deductMoney = 0.00
  277. this.surplusMoney = this.userMoney
  278. }
  279. },
  280. orderSubmitMit(){//提交订单
  281. if(this.isSubLoading){ return; }
  282. if(this.addressID == ''){
  283. this.$util.msg('请先添加收货地址~',2000)
  284. return
  285. }
  286. this.orderInfo = this.goodsData.map(el => {
  287. let productInfo = [];
  288. el.cartList.forEach(item => {
  289. productInfo.push({
  290. productId:item.productId,
  291. productNum:item.number,
  292. presentNum:0,
  293. productType:item.productType
  294. })
  295. })
  296. return {shopId:el.id,note:el.note?el.note:'',productInfo:productInfo}
  297. })
  298. //订单信息
  299. this.payInfo = {
  300. clauseId:0,//条款(暂时保留)
  301. orderShouldPayFee:this.payAllPrice.toFixed(2),//提交的总价
  302. balancePayFlag:this.balanceDeductionFlag,//余额抵扣的状态
  303. freight:parseInt(this.hanldFreight).toFixed(2),//邮费
  304. freePostFlag:parseInt(this.hanldFreePostFlag)//运费形式
  305. }
  306. let param = {
  307. orderSource:6,
  308. clubUserId:this.userID,
  309. cartType:this.cartType,
  310. addressId:this.addressID,
  311. orderInfo:this.orderInfo,
  312. payInfo:this.payInfo, //订单信息
  313. orderInvoice:this.invoiceData
  314. }
  315. // console.log(param)
  316. this.isSubLoading = true;
  317. this.OrderService.CreatedOrderSubmit({'params':JSON.stringify(param)}).then(response =>{
  318. const data = response.data;
  319. if(data.code === '1'){
  320. this.submitState ='success'
  321. this.isSubLoading = false;
  322. setTimeout(()=>{
  323. this.isSubLoading = false;
  324. },2000)
  325. let data = {orderID:response.data.orderID}
  326. this.$api.navigateTo(`/pages/user/order/success?data=${JSON.stringify({data:data})}`)
  327. }else{
  328. this.submitState ='confirm'
  329. this.$util.msg('订单提交成功',3000,true,'success')
  330. setTimeout(()=>{
  331. this.isSubLoading = false;
  332. },2000)
  333. setTimeout(()=>{
  334. this.$api.redirectTo(`/pages/user/order/order-payment?type=${this.submitState}&orderID=${response.data.orderID}`)
  335. },3000)
  336. }
  337. }).catch(error =>{
  338. this.$util.msg(error.msg,3000);
  339. })
  340. },
  341. handFreightAlertShow(){//显示邮费弹窗
  342. this.isfreightTip = true;
  343. },
  344. hideFreight(){//关闭邮费弹窗
  345. this.isfreightTip = false;
  346. },
  347. },
  348. onShow() {
  349. // this.addressID = ''
  350. let pages = getCurrentPages();
  351. let currPage = pages[pages.length-1];
  352. if(currPage.data.select =='select'){
  353. this.isAddress = true
  354. let SelectData = uni.getStorageSync('selectAddress');
  355. this.addressID = SelectData.addressID;
  356. this.addressData = SelectData
  357. this.getFreightData()
  358. }else{
  359. this.getAddressData()
  360. }
  361. }
  362. }
  363. </script>
  364. <style lang="scss">
  365. page {
  366. height: auto;
  367. background:#F7F7F7;
  368. }
  369. .btn-hover{
  370. background: #FFFFFF;
  371. }
  372. .animation{
  373. /* transition: transform 0.3s ease;*/
  374. transition-property: transform;
  375. transition-duration: 0.3s;
  376. transition-timing-function: ease;
  377. }
  378. .order{
  379. padding-bottom: 134rpx;
  380. }
  381. .invoice-freight{
  382. width: 702rpx;
  383. padding: 0 24rpx;
  384. height: 86rpx;
  385. line-height: 86rpx;
  386. font-size: $font-size-28;
  387. color: $text-color;
  388. background: #FFFFFF;
  389. float: left;
  390. font-weight: bold;
  391. .freight-left{
  392. float: left;
  393. .icon-yunfeishuoming{
  394. height: 100%;
  395. padding: 0 15rpx;
  396. color: $color-system;
  397. font-weight: normal;
  398. }
  399. }
  400. .freight-right{
  401. float: right;
  402. color: #2A81FF;
  403. }
  404. }
  405. .invoice-balance{
  406. width: 702rpx;
  407. height: auto;
  408. padding:0 24rpx;
  409. background: #FFFFFF;
  410. float: left;
  411. margin-top: 24rpx;
  412. margin-bottom: 24rpx;
  413. .balabce-t{
  414. width: 100%;
  415. height: 86rpx;
  416. line-height: 86rpx;
  417. font-size: $font-size-28;
  418. color: $text-color;
  419. float: left;
  420. .balabce-t-le{
  421. float: left;
  422. font-weight: bold;
  423. }
  424. .balabce-t-ri{
  425. float: right;
  426. display: flex;
  427. align-items: center;
  428. .money{
  429. display: flex;
  430. float: left;
  431. }
  432. .checkbox-box{
  433. display: flex;
  434. width: 60rpx;
  435. float: left;
  436. height: 100%;
  437. font-size: $font-size-24;
  438. .checkbox{
  439. width: 40rpx;
  440. text-align: right;
  441. box-sizing: border-box;
  442. text-align: center;
  443. text-decoration: none;
  444. border-radius: 0;
  445. -webkit-tap-highlight-color: transparent;
  446. overflow: hidden;
  447. color: $color-system;
  448. }
  449. }
  450. }
  451. }
  452. .balabce-b{
  453. width: 100%;
  454. float: left;
  455. overflow: hidden;
  456. .balabce-b-text{
  457. width: 100%;
  458. line-height: 58rpx;
  459. font-size: $font-size-24;
  460. color: #FF2A2A;
  461. text-align: right;
  462. float: right;
  463. }
  464. &.balabce-b--hide {
  465. padding: 0 0;
  466. height: 0px;
  467. line-height: 0px;
  468. }
  469. }
  470. }
  471. .footer{
  472. position: fixed;
  473. left: 0;
  474. bottom: 0;
  475. z-index: 995;
  476. display: flex;
  477. align-items: center;
  478. width: 100%;
  479. height: 110rpx;
  480. line-height: 110rpx;
  481. justify-content: space-between;
  482. font-size: $font-size-28;
  483. background-color: #FFFFFF;
  484. z-index: 998;
  485. color: $text-color;
  486. .footer-le{
  487. width:570rpx;
  488. height:100%;
  489. float: left;
  490. }
  491. .footer-count{
  492. float: left;
  493. padding-left: 24rpx;
  494. width:180rpx;
  495. box-sizing: border-box;
  496. }
  497. .footer-price{
  498. width:370rpx;
  499. float: right;
  500. text-align: right;
  501. color: $text-color;
  502. padding: 10rpx 20rpx 10rpx 0;
  503. box-sizing: border-box;
  504. .sum-none{
  505. width: 100%;
  506. height: 45rpx;
  507. line-height: 45rpx;
  508. color: $text-color;
  509. float: left;
  510. text-align: right;
  511. .money{
  512. font-size: $font-size-26;
  513. color: #999999;
  514. text-decoration: line-through;
  515. }
  516. .money-sign{
  517. font-size: $font-size-26;
  518. color: #999999;
  519. text-decoration: line-through;
  520. }
  521. .money-reduced{
  522. margin-left: 10rpx;
  523. font-size: $font-size-26;
  524. color:$color-system;
  525. }
  526. }
  527. .sum{
  528. width: 100%;
  529. height: 45rpx;
  530. line-height: 45rpx;
  531. float: left;
  532. &.none{
  533. height: 90rpx;
  534. line-height: 90rpx;
  535. }
  536. .price{
  537. font-size: $font-size-32;
  538. color: #FF2A2A;
  539. }
  540. }
  541. }
  542. .footer-submit{
  543. display:flex;
  544. align-items:center;
  545. justify-content: center;
  546. width: 180rpx;
  547. height: 100%;
  548. box-sizing: border-box;
  549. padding: 15rpx 5rpx;
  550. .btn{
  551. width: 100%;
  552. height: 100%;
  553. color: #FFFFFF;
  554. background:linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%);
  555. font-size: $font-size-26;
  556. text-align: center;
  557. line-height: 80rpx;
  558. border-radius: 40rpx;
  559. &.disabled{
  560. background: #e4e8eb;
  561. color: #999999;
  562. }
  563. }
  564. }
  565. }
  566. </style>