create-order.vue 16 KB

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