create-order.vue 16 KB

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