create-order.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. <template>
  2. <view class="container order clearfix">
  3. <!-- 透明模态层 -->
  4. <modal-layer v-if='modallayer'></modal-layer>
  5. <!-- 地址选择 -->
  6. <choice-address ref="choiceAddress" v-if="isAddress" :addressData="addressData"></choice-address>
  7. <!-- 商品 -->
  8. <goods-list ref='goods' v-if="isRequest" :goodsData="goodsData" @handleGoodList="handChangeInputGoodsList"></goods-list>
  9. <!-- 发票信息 -->
  10. <invoice-tent ref="invoice" v-if="isRequest" :invoiceData="invoiceData"></invoice-tent>
  11. <!-- 运费 -->
  12. <freight ref="freight" v-if="isRequest" :freightData="freightData" @showFreightAlert="handFreightAlertShow"></freight>
  13. <freight-alert v-if="isfreightTip" ref="csPhone" :cellPhone ="cellPhone"></freight-alert>
  14. <!-- 余额抵扣 -->
  15. <view class="invoice-balance">
  16. <view class="balabce-t">
  17. <view class="balabce-t-le">余额抵扣</view>
  18. <view class="balabce-t-ri">
  19. <view class="money">
  20. <text>可用余额:</text>
  21. <text>¥{{userMoney.toFixed(2)}}</text>
  22. </view>
  23. <view class="checkbox-box">
  24. <button class="checkbox iconfont"
  25. hover-class="btn-hover"
  26. v-if="userMoney!=0"
  27. @click.stop="checkedBalabce"
  28. :class="[ischecked ?'icon-gouxuanl':'icon-weigouxuan']"
  29. >
  30. </button>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="balabce-b" :class="{'balabce-b--hide':!ischecked}">
  35. <view class="balabce-b-text animation" :style="{'transform':ischecked?'translateY(0)':'translateY(-50%)','-webkit-transform':ischecked?'translateY(0)':'translateY(-50%)'}">
  36. <text>当前使用:¥{{deductMoney.toFixed(2)}},剩余:¥{{surplusMoney.toFixed(2)}}</text>
  37. </view>
  38. </view>
  39. </view>
  40. <!-- 底部 -->
  41. <view class="footer" :style="{paddingBottom :isIphoneX ? '68rpx' : '0rpx'}">
  42. <view class="footer-le">
  43. <view class="footer-count">
  44. <text>共{{allCount}}件商品</text>
  45. </view>
  46. <view class="footer-price">
  47. <text>总价:<text class="price">¥{{payAllPrice.toFixed(2)}}</text></text>
  48. </view>
  49. </view>
  50. <view class="footer-submit" @click.stop="submit">提交订单</view>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. import choiceAddress from '@/components/module/creatOrder/choiceAddress'
  56. import goodsList from '@/components/module/creatOrder/goodsList'
  57. import invoiceTent from '@/components/module/creatOrder/invoiceTent'
  58. import freight from '@/components/module/creatOrder/freight'
  59. import freightAlert from '@/components/module/modelAlert/freightAlert'
  60. import modalLayer from "@/components/modal-layer"
  61. import { queryAddressList } from "@/api/cart.js"
  62. import { createOrderInfo } from "@/api/order.js"
  63. export default {
  64. components:{
  65. choiceAddress,
  66. goodsList,
  67. invoiceTent,
  68. freight,
  69. freightAlert,
  70. modalLayer
  71. },
  72. data() {
  73. return {
  74. modallayer:false,
  75. orderID:0,
  76. productIds:'', //获取上一级页面商品信息
  77. productCount:'', //获取上一级页面商品数量
  78. classifyIDS:'', //获取上一级页面商品分类
  79. cellPhone:'0755-88888888',//默认客服电话
  80. userID:'', //用户ID
  81. cartType:'', //购买类型(1购物车提交,2直接购买提交)
  82. submitState:'', //提交状态
  83. balanceDeductionFlag:2, //勾选余额的状态(1使用,2不使用)
  84. allCount:1, //订单提交总数量
  85. payAllPrice:0.00, //订单提交总金额
  86. allPrice:0.00, //订单总金额
  87. surplusMoney:0.00, //显示勾选后的剩余抵扣
  88. userMoney:0.00, //显示可使用余额
  89. deductMoney:0.00, //显示已使用的余额
  90. addressID:'', //地址ID
  91. isRequest:false, //是否加载完成渲染子组件
  92. isAddress:false, //是否加载完成地址
  93. isfreightTip:false, //控制邮费弹窗
  94. ischecked:false, //是否勾选余额
  95. addressData:{}, //初始化地址信息
  96. goodsData:[], //初始化商品信息
  97. invoiceData:{}, //初始化发票信息
  98. freightData:{}, //邮费数据
  99. orderInfo:[], //提交的商品信息
  100. isIphoneX:this.$store.state.isIphoneX
  101. }
  102. },
  103. onLoad(option){//商品数据
  104. let data = JSON.parse(option.data);
  105. console.log(data)
  106. this.allPrice = data.data.allPrice;
  107. this.allCount = data.data.allCount;
  108. this.payAllPrice = this.allPrice;
  109. // console.log(data)
  110. if(option.type =='prodcut'){
  111. this.cartType = 2
  112. this.productCount = data.data.productCount
  113. this.productIds = data.data.id
  114. this.classifyIDS = data.data.classifyID
  115. }else{
  116. this.cartType = 1
  117. this.productCount = data.data.productCount
  118. this.productIds = data.data.id
  119. this.classifyIDS = data.data.classifyID
  120. }
  121. this.getInitCrearOrder(option);
  122. // this.getAddressData()
  123. },
  124. methods: {
  125. getInitCrearOrder(option){//获取订单商品信息&&邮费信息&&发票信息
  126. this.$api.getStorage().then((resolve) =>{
  127. this.userID = resolve.userID
  128. let params ={userID:this.userID,count:this.productCount,productIds:this.productIds}
  129. createOrderInfo(params).then(response =>{
  130. let resData = response.data
  131. this.isRequest = true
  132. this.goodsData = resData.shopList
  133. this.userMoney = resData.userMoney
  134. this.freightData = {freePostFlag:resData.freight,cellPhone:resData.cellPhone}
  135. this.invoiceData = resData.invoice
  136. this.goodsData = resData.shopList
  137. }).catch(response =>{
  138. this.$util.msg(response.msg,2000)
  139. })
  140. })
  141. },
  142. getAddressData(){//获取地址信息
  143. this.$api.getStorage().then((resolve) =>{
  144. queryAddressList({index:1,pageSize:1,userID:resolve.userID}).then(response =>{
  145. this.isAddress = true
  146. this.addressData = {}
  147. if(response.results != ''){
  148. this.addressID = response.results[0].addressID;
  149. this.addressData = response.results[0];
  150. }else{
  151. this.addressData = this.addressData;
  152. }
  153. })
  154. })
  155. },
  156. handChangeInputGoodsList(data){//对应供应商的留言信息
  157. this.goodsData = data;
  158. // console.log(this.goodsData)
  159. },
  160. submit(){//提交订单
  161. if(this.addressID == ''){
  162. this.$util.msg('请先添加收货地址~',3000)
  163. return
  164. }
  165. this.orderInfo = this.goodsData.map(el => {
  166. let productInfo = [];
  167. el.productsList.forEach(item => {
  168. productInfo.push({
  169. productId:item.id,
  170. productNum:item.productCount
  171. })
  172. })
  173. if(el.note == null){
  174. el.note = ''
  175. }else{
  176. el.note = el.note
  177. }
  178. return {shopId:el.shopID,note:el.note,productInfo:productInfo}
  179. })
  180. let param = {
  181. userId:this.userID,
  182. organizeID:this.userOrganizeID,
  183. cartType:this.cartType,
  184. addressID:this.addressID,
  185. orderInfo:this.orderInfo,
  186. balanceDeductionFlag:this.balanceDeductionFlag,
  187. orderShouldPayFee:this.payAllPrice,
  188. }
  189. this.modalLayer = true;
  190. // console.log(JSON.stringify(param))
  191. this.$api.lodingGet('/order/submitOrder',{'params':JSON.stringify(param)},
  192. response => {
  193. if(response.code === '1'){
  194. this.submitState ='success'
  195. let data = {orderID:response.data.orderID}
  196. this.$api.navigateTo(`/pages/user/order/order-cashier?type=${this.submitState}&data=${JSON.stringify({data:data})}`)
  197. }else if(response.code === '2'){
  198. this.submitState ='nosuccess'
  199. let data = {
  200. orderID:response.data.orderID,
  201. orderNo:response.data.orderNo,
  202. orderMark:response.data.orderMark,
  203. payableAmount:response.data.payableAmount
  204. }
  205. this.$api.navigateTo(`/pages/user/order/order-cashier?type=${this.submitState}&data=${JSON.stringify({data:data})}`)
  206. }else{
  207. this.$util.msg(response.msg,3000);
  208. }
  209. }
  210. )
  211. },
  212. handFreightAlertShow(){//显示邮费弹窗
  213. this.isfreightTip = true;
  214. this.cellPhone = this.freightData.cellPhone;
  215. },
  216. hideFreight(){//关闭邮费弹窗
  217. this.isfreightTip = false;
  218. },
  219. checkedBalabce(){//勾选使用余额
  220. if(this.userMoney == 0){
  221. return
  222. }else{
  223. this.ischecked = !this.ischecked
  224. if(this.ischecked){
  225. this.balanceDeductionFlag =1
  226. if(this.userMoney>this.payAllPrice){
  227. this.payAllPrice =0.00
  228. this.deductMoney = this.allPrice //勾选后使用抵余额
  229. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  230. }else{
  231. this.payAllPrice = this.allPrice - this.userMoney //勾选后的总价
  232. this.deductMoney = this.userMoney //勾选后使用抵余额
  233. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  234. }
  235. }else{
  236. this.payAllPrice = this.allPrice
  237. this.balanceDeductionFlag = 2
  238. }
  239. }
  240. }
  241. },
  242. onShow() {
  243. // this.addressID = ''
  244. let pages = getCurrentPages();
  245. let currPage = pages[pages.length-1];
  246. if(currPage.data.select =='select'){
  247. this.isAddress = true
  248. let SelectData = uni.getStorageSync('selectAddress');
  249. this.addressID = SelectData.addressID;
  250. this.addressData = SelectData
  251. }else{
  252. this.getAddressData()
  253. }
  254. }
  255. }
  256. </script>
  257. <style lang="scss">
  258. page {
  259. height: auto;
  260. background:#F7F7F7;
  261. }
  262. .btn-hover{
  263. background: #FFFFFF;
  264. }
  265. .animation{
  266. /* transition: transform 0.3s ease;*/
  267. transition-property: transform;
  268. transition-duration: 0.3s;
  269. transition-timing-function: ease;
  270. }
  271. .order{
  272. padding-bottom: 134rpx;
  273. }
  274. .invoice-freight{
  275. width: 702rpx;
  276. padding: 0 24rpx;
  277. height: 86rpx;
  278. line-height: 86rpx;
  279. font-size: $font-size-28;
  280. color: $text-color;
  281. background: #FFFFFF;
  282. float: left;
  283. font-weight: bold;
  284. .freight-left{
  285. float: left;
  286. .icon-yunfeishuoming{
  287. height: 100%;
  288. padding: 0 15rpx;
  289. color: $color-system;
  290. font-weight: normal;
  291. }
  292. }
  293. .freight-right{
  294. float: right;
  295. color: #2A81FF;
  296. }
  297. }
  298. .freight-alert{
  299. width: 100%;
  300. height: 100%;
  301. background: rgba(0,0,0,.5);
  302. position: fixed;
  303. top: 0;
  304. left: 0;
  305. z-index: 8888;
  306. transition: all 0.4s;
  307. &.none{
  308. display: none;
  309. }
  310. &.show{
  311. display: block;
  312. }
  313. .content{
  314. width: 518rpx;
  315. height: 420rpx;
  316. position: absolute;
  317. background: $bg-color;
  318. left: 0;
  319. right: 0;
  320. bottom: 0;
  321. top: 0;
  322. margin: auto;
  323. .text-content{
  324. width: 448rpx;
  325. height: 264rpx;
  326. padding: 35rpx;
  327. float: left;
  328. .title{
  329. line-height: 40rpx;
  330. font-size: $font-size-28;
  331. color: $text-color;
  332. text-align: center;
  333. font-weight: bold;
  334. margin-bottom: 32rpx;
  335. }
  336. .text{
  337. line-height: 36rpx;
  338. font-size: $font-size-26;
  339. color: $text-color;
  340. text-align: justify;
  341. margin-top: 22rpx;
  342. }
  343. .tel{
  344. line-height: 36rpx;
  345. font-size: $font-size-26;
  346. color: $text-color;
  347. text-align: justify;
  348. margin-top: 22rpx;
  349. font-weight: bold;
  350. .txt{
  351. margin-left: 10rpx;
  352. }
  353. }
  354. }
  355. .btn{
  356. width: 100%;
  357. height: 88rpx;
  358. float: left;
  359. background: #000000;
  360. line-height: 88rpx;
  361. font-size: $font-size-28;
  362. text-align: center;
  363. color: #FFFFFF;
  364. border-radius: 0;
  365. padding: 0;
  366. }
  367. }
  368. }
  369. .invoice-balance{
  370. width: 702rpx;
  371. height: auto;
  372. padding:0 24rpx;
  373. background: #FFFFFF;
  374. float: left;
  375. margin-top: 24rpx;
  376. margin-bottom: 24rpx;
  377. .balabce-t{
  378. width: 100%;
  379. height: 86rpx;
  380. line-height: 86rpx;
  381. font-size: $font-size-28;
  382. color: $text-color;
  383. float: left;
  384. .balabce-t-le{
  385. float: left;
  386. font-weight: bold;
  387. }
  388. .balabce-t-ri{
  389. float: right;
  390. display: flex;
  391. align-items: center;
  392. .money{
  393. display: flex;
  394. float: left;
  395. }
  396. .checkbox-box{
  397. display: flex;
  398. width: 60rpx;
  399. float: left;
  400. height: 100%;
  401. font-size: $font-size-24;
  402. .checkbox{
  403. width: 40rpx;
  404. text-align: right;
  405. box-sizing: border-box;
  406. text-align: center;
  407. text-decoration: none;
  408. border-radius: 0;
  409. -webkit-tap-highlight-color: transparent;
  410. overflow: hidden;
  411. }
  412. }
  413. }
  414. }
  415. .balabce-b{
  416. width: 100%;
  417. float: left;
  418. overflow: hidden;
  419. .balabce-b-text{
  420. width: 100%;
  421. line-height: 58rpx;
  422. font-size: $font-size-24;
  423. color: #FF2A2A;
  424. text-align: right;
  425. float: right;
  426. }
  427. &.balabce-b--hide {
  428. padding: 0 0;
  429. height: 0px;
  430. line-height: 0px;
  431. }
  432. }
  433. }
  434. .footer{
  435. position: fixed;
  436. left: 0;
  437. bottom: 0;
  438. z-index: 995;
  439. display: flex;
  440. align-items: center;
  441. width: 100%;
  442. height: 110rpx;
  443. line-height: 110rpx;
  444. justify-content: space-between;
  445. font-size: $font-size-28;
  446. background-color: #FFFFFF;
  447. z-index: 998;
  448. color: $text-color;
  449. .footer-le{
  450. width:550rpx;
  451. height:100%;
  452. float: left;
  453. }
  454. .footer-count{
  455. float: left;
  456. padding-left: 24rpx;
  457. font-weight: bold;
  458. }
  459. .footer-price{
  460. float: right;
  461. text-align: right;
  462. color: $text-color;
  463. font-weight: bold;
  464. padding-right: 24rpx;
  465. .price{
  466. font-size: $font-size-32;
  467. color: #FF2A2A;
  468. }
  469. }
  470. .footer-submit{
  471. display:flex;
  472. align-items:center;
  473. justify-content: center;
  474. width: 200rpx;
  475. height: 100%;
  476. color: #FFFFFF;
  477. background:linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%);
  478. }
  479. }
  480. </style>