create-order.vue 17 KB

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