create-order.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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"></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,createOrderSubmit,getOrderPostage } 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. userID:'', //用户ID
  80. cartType:'', //购买类型(1购物车提交,2直接购买提交)
  81. submitState:'', //提交状态
  82. balanceDeductionFlag:2, //勾选余额的状态(1使用,2不使用)
  83. allCount:1, //订单提交总数量
  84. payAllPrice:0.00, //订单提交总金额
  85. allPrice:0.00, //订单总金额
  86. surplusMoney:0.00, //显示勾选后的剩余抵扣
  87. userMoney:0.00, //显示可使用余额
  88. deductMoney:0.00, //显示已使用的余额
  89. addressID:'', //地址ID
  90. townID:'', //区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.productID
  114. // this.classifyIDS = data.data.classifyID
  115. }else{
  116. this.cartType = 1
  117. this.productCount = data.data.productCount
  118. this.productIds = data.data.productID
  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}
  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({pageNum:1,pageSize:1,userID:resolve.userID}).then(response =>{
  145. this.isAddress = true
  146. this.addressData = {}
  147. if(response.data.results != ''){
  148. this.addressID = response.data.results[0].addressID;
  149. this.townID = response.data.results[0].townID;
  150. this.addressData = response.data.results[0];
  151. }else{
  152. this.addressData = this.addressData;
  153. }
  154. })
  155. })
  156. },
  157. handChangeInputGoodsList(data){//对应供应商的留言信息
  158. this.goodsData = data;
  159. // console.log(this.goodsData)
  160. },
  161. submit(){//提交订单
  162. if(this.addressID == ''){
  163. this.$util.msg('请先添加收货地址~',2000)
  164. return
  165. }
  166. this.orderInfo = this.goodsData.map(el => {
  167. let productInfo = [];
  168. el.productsList.forEach(item => {
  169. productInfo.push({
  170. productId:item.productID,
  171. productNum:item.productCount
  172. })
  173. })
  174. if(el.note == null){
  175. el.note = ''
  176. }else{
  177. el.note = el.note
  178. }
  179. return {shopId:el.shopID,note:el.note,productInfo:productInfo}
  180. })
  181. let orderInvoice = Object.assign(this.invoiceData,'',{type:0})
  182. let param = {
  183. orderSource:6,
  184. userId:this.userID,
  185. cartType:this.cartType,
  186. addressId:this.addressID,
  187. orderInfo:this.orderInfo,
  188. balanceDeductionFlag:this.balanceDeductionFlag,
  189. orderShouldPayFee:this.payAllPrice,
  190. orderInvoice:orderInvoice
  191. }
  192. this.modalLayer = true;
  193. // console.log(JSON.stringify(param))
  194. createOrderSubmit({'params':JSON.stringify(param)}).then(response =>{
  195. if(response.code === 1){
  196. this.submitState ='success'
  197. let data = {orderID:response.data.orderID}
  198. this.$api.navigateTo(`/pages/user/order/order-cashier?type=${this.submitState}&data=${JSON.stringify({data:data})}`)
  199. }else if(response.code === 2){
  200. this.submitState ='nosuccess'
  201. let data = {
  202. orderID:response.data.orderID,
  203. orderNo:response.data.orderNo,
  204. orderMark:response.data.orderMark,
  205. payableAmount:response.data.payableAmount
  206. }
  207. this.$api.navigateTo(`/pages/user/order/order-cashier?type=${this.submitState}&data=${JSON.stringify({data:data})}`)
  208. }else{
  209. this.$util.msg(response.msg,2000);
  210. }
  211. }).catch(response =>{
  212. })
  213. },
  214. getPostage(){
  215. this.$api.getStorage().then((resolve) =>{
  216. let params ={
  217. userId:resolve.userID,
  218. productIds:this.productIds,
  219. totalPrice:this.payAllPrice,
  220. townID:this.addressData.townID
  221. }
  222. getOrderPostage(params).then(response =>{
  223. console.log(response)
  224. })
  225. })
  226. },
  227. handFreightAlertShow(){//显示邮费弹窗
  228. this.isfreightTip = true;
  229. },
  230. hideFreight(){//关闭邮费弹窗
  231. this.isfreightTip = false;
  232. },
  233. checkedBalabce(){//勾选使用余额
  234. if(this.userMoney == 0){
  235. return
  236. }else{
  237. this.ischecked = !this.ischecked
  238. if(this.ischecked){
  239. this.balanceDeductionFlag =1
  240. if(this.userMoney>this.payAllPrice){
  241. this.payAllPrice =0.00
  242. this.deductMoney = this.allPrice //勾选后使用抵余额
  243. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  244. }else{
  245. this.payAllPrice = this.allPrice - this.userMoney //勾选后的总价
  246. this.deductMoney = this.userMoney //勾选后使用抵余额
  247. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  248. }
  249. }else{
  250. this.payAllPrice = this.allPrice
  251. this.balanceDeductionFlag = 2
  252. }
  253. }
  254. }
  255. },
  256. onShow() {
  257. // this.addressID = ''
  258. let pages = getCurrentPages();
  259. let currPage = pages[pages.length-1];
  260. if(currPage.data.select =='select'){
  261. this.isAddress = true
  262. let SelectData = uni.getStorageSync('selectAddress');
  263. this.addressID = SelectData.addressID;
  264. this.addressData = SelectData
  265. }else{
  266. this.getAddressData()
  267. }
  268. }
  269. }
  270. </script>
  271. <style lang="scss">
  272. page {
  273. height: auto;
  274. background:#F7F7F7;
  275. }
  276. .btn-hover{
  277. background: #FFFFFF;
  278. }
  279. .animation{
  280. /* transition: transform 0.3s ease;*/
  281. transition-property: transform;
  282. transition-duration: 0.3s;
  283. transition-timing-function: ease;
  284. }
  285. .order{
  286. padding-bottom: 134rpx;
  287. }
  288. .invoice-freight{
  289. width: 702rpx;
  290. padding: 0 24rpx;
  291. height: 86rpx;
  292. line-height: 86rpx;
  293. font-size: $font-size-28;
  294. color: $text-color;
  295. background: #FFFFFF;
  296. float: left;
  297. font-weight: bold;
  298. .freight-left{
  299. float: left;
  300. .icon-yunfeishuoming{
  301. height: 100%;
  302. padding: 0 15rpx;
  303. color: $color-system;
  304. font-weight: normal;
  305. }
  306. }
  307. .freight-right{
  308. float: right;
  309. color: #2A81FF;
  310. }
  311. }
  312. .invoice-balance{
  313. width: 702rpx;
  314. height: auto;
  315. padding:0 24rpx;
  316. background: #FFFFFF;
  317. float: left;
  318. margin-top: 24rpx;
  319. margin-bottom: 24rpx;
  320. .balabce-t{
  321. width: 100%;
  322. height: 86rpx;
  323. line-height: 86rpx;
  324. font-size: $font-size-28;
  325. color: $text-color;
  326. float: left;
  327. .balabce-t-le{
  328. float: left;
  329. font-weight: bold;
  330. }
  331. .balabce-t-ri{
  332. float: right;
  333. display: flex;
  334. align-items: center;
  335. .money{
  336. display: flex;
  337. float: left;
  338. }
  339. .checkbox-box{
  340. display: flex;
  341. width: 60rpx;
  342. float: left;
  343. height: 100%;
  344. font-size: $font-size-24;
  345. .checkbox{
  346. width: 40rpx;
  347. text-align: right;
  348. box-sizing: border-box;
  349. text-align: center;
  350. text-decoration: none;
  351. border-radius: 0;
  352. -webkit-tap-highlight-color: transparent;
  353. overflow: hidden;
  354. color: $color-system;
  355. }
  356. }
  357. }
  358. }
  359. .balabce-b{
  360. width: 100%;
  361. float: left;
  362. overflow: hidden;
  363. .balabce-b-text{
  364. width: 100%;
  365. line-height: 58rpx;
  366. font-size: $font-size-24;
  367. color: #FF2A2A;
  368. text-align: right;
  369. float: right;
  370. }
  371. &.balabce-b--hide {
  372. padding: 0 0;
  373. height: 0px;
  374. line-height: 0px;
  375. }
  376. }
  377. }
  378. .footer{
  379. position: fixed;
  380. left: 0;
  381. bottom: 0;
  382. z-index: 995;
  383. display: flex;
  384. align-items: center;
  385. width: 100%;
  386. height: 110rpx;
  387. line-height: 110rpx;
  388. justify-content: space-between;
  389. font-size: $font-size-28;
  390. background-color: #FFFFFF;
  391. z-index: 998;
  392. color: $text-color;
  393. .footer-le{
  394. width:550rpx;
  395. height:100%;
  396. float: left;
  397. }
  398. .footer-count{
  399. float: left;
  400. padding-left: 24rpx;
  401. font-weight: bold;
  402. }
  403. .footer-price{
  404. float: right;
  405. text-align: right;
  406. color: $text-color;
  407. font-weight: bold;
  408. padding-right: 24rpx;
  409. .price{
  410. font-size: $font-size-32;
  411. color: #FF2A2A;
  412. }
  413. }
  414. .footer-submit{
  415. display:flex;
  416. align-items:center;
  417. justify-content: center;
  418. width: 200rpx;
  419. height: 100%;
  420. color: #FFFFFF;
  421. background:linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%);
  422. }
  423. }
  424. </style>