create-order.vue 17 KB

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