create.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. <template>
  2. <view>
  3. <!-- 收货人 -->
  4. <view class="gap"></view>
  5. <use-list-title v-if="!(addrData && addrData.id)" color="#333" title="选择收货人" iconfont="icondizhi-" @goto="toaddr"></use-list-title>
  6. <view v-else class="padding dflex-b bg-main" @click="toaddr">
  7. <view class="dflex">
  8. <view class="iconfont icondizhi- margin-right ft-main"></view>
  9. <view class="w-full dflex-wrap-w">
  10. <view class="margin-bottom-xs">
  11. <text>{{ addrData.province }}{{ addrData.city }}{{ addrData.county }} {{ addrData.address }}</text>
  12. </view>
  13. <view>
  14. <text>{{ addrData.receiverName }}</text>
  15. <text class="margin-left">{{ addrData.phoneNum }}</text>
  16. </view>
  17. </view>
  18. </view>
  19. <view class="iconfont iconjiantou-01 fs-sm"></view>
  20. </view>
  21. <view class="gap"></view>
  22. <view class="goods-area bg-main padding">
  23. <!-- 商品列表 -->
  24. <view class="goods-item" :class="{ 'margin-top': index > 0 }" v-for="(item, index) in goodsDatas"
  25. :key="index">
  26. <view class="pos-r">
  27. <image mode="aspectFill" :src="item.goodsMasterImg"></image>
  28. <!-- <view v-if="(item.goods.stock_num < 10 || item.goods.stock_num < item.goods.goods_num)"
  29. class="disabled dflex-c dflex-flow-c pos-a pos-tl-c border-radius-c">
  30. <text>库存不足</text><text class="margin-left-xs fs-xs" v-if="item.goods.stock_num > 0">剩余
  31. {{item.goods.stock_num}}</text>
  32. </view> -->
  33. </view>
  34. <view class="flex1 padding-left-sm">
  35. <text class="title clamp-2">{{ item.goodsName || '' }} </text>
  36. <view class="ft-dark fs-xs padding-top-xs">
  37. <text v-if="cart_ids && cart_ids.length > 0" class="margin-right">× {{item.goodsCount}}</text>
  38. {{ (item.goodsAttr) || '&nbsp;&nbsp;' }}
  39. </view>
  40. <view class="pos-r dflex-b padding-top">
  41. <view class="price flex1">{{ item.goodsActualPrice || '' }}</view>
  42. <!-- + - 数量 -->
  43. <!-- <use-number-box v-if="!(cart_ids && cart_ids.length > 0)" :min="1" :max="item.goods.stock_num"
  44. :value="item.goods.goods_num > item.goods.stock_num ? item.goods.stock_num : item.goods.goods_num"
  45. :is-max="item.goods.goods_num >= item.goods.stock_num" :is-min="item.goods.goods_num === 1"
  46. :index="index" direction="right" @eventChange="numberChange"></use-number-box> -->
  47. <use-number-box v-if="!(cart_ids && cart_ids.length > 0)" :min="1"
  48. :value="item.goodsCount"
  49. :index="index" direction="right" @eventChange="numberChange"></use-number-box>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. <view class="gap"></view>
  55. <!-- 优惠券 -->
  56. <!-- <use-list-title title="优惠券" :tip="couponName" color="#333" iconfont="iconyouhui" @goto="couponShow = true">
  57. </use-list-title> -->
  58. <!-- 优惠券弹出层 -->
  59. <use-popup mode="bottom" v-model="couponShow" @open="couponOpen">
  60. <!-- 优惠券区 -->
  61. <!-- <view class="coupon-area padding bg-drak">
  62. <view class="coupon-item bg-main pos-r fs-xs" v-for="(item, index) in couponDatas" :key="index">
  63. <view class="content pos-r padding dflex-b">
  64. <view class="">
  65. <view class="margin-bottom-xs fs">{{ item.name }}</view>
  66. <view class="ft-dark">有效期至 {{ item.end_time.split(' ')[0] }}</view>
  67. </view>
  68. <view class="tar">
  69. <view class="margin-bottom-xs price">{{ item.price }}</view>
  70. <view v-if="item.order_amount > 0" class="ft-dark">满{{ item.order_amount }}可用</view>
  71. <view v-else class="ft-dark">不限</view>
  72. </view>
  73. <view class="circle l"></view>
  74. <view class="circle r"></view>
  75. </view>
  76. <view class="dflex-b">
  77. <text class="ft-dark padding-lr">{{ item.type }}</text>
  78. <text class="ft-base padding-tb-sm padding-lr" @click="couponUse(item)">立即使用</text>
  79. </view>
  80. </view>
  81. <view v-if="!couponDatas || couponDatas.length <= 0" class="coupon-none">
  82. <text class="coupon-none-tip">开发中!!!!!</text>
  83. </view>
  84. </view> -->
  85. </use-popup>
  86. <view class="gap"></view>
  87. <!-- 金额明细 -->
  88. <view class="bg-main">
  89. <view class="dflex-b padding-lr padding-tb-sm">
  90. <view class="flex1">总金额</view>
  91. <view class=""><text style="font-size: 24rpx;">¥</text>{{ goods_money }}</view>
  92. </view>
  93. <!-- <view v-if="total_coupon_money > 0" class="dflex-b padding-lr padding-tb-sm">
  94. <view class="flex1">优惠金额</view>
  95. <view class="ft-base">-¥{{ total_coupon_money }}</view>
  96. </view> -->
  97. <view class="dflex-b padding-lr padding-tb-sm">
  98. <view class="margin-right-xl">备注</view>
  99. <input class="flex1 padding-sm" type="text" v-model="order_desc" placeholder="请填写买家备注"
  100. placeholder-class="placeholder" />
  101. </view>
  102. </view>
  103. <view class="gap"></view>
  104. <!-- 底部 -->
  105. <view class="oper-area pos-f pos-bottom w-full dflex-b bg-main safe-area-inset-bottom padding-left">
  106. <view>
  107. <text class="fs-sm">实付款</text>
  108. <text class="price margin-left-sm fs-xl">{{ total_money }}</text>
  109. </view>
  110. <view class="submit dflex-c bg-base-ding fs animated-all" :class="is_submit === 1 ? 'bg-disabled' : ''" @click="submit">提交订单</view>
  111. </view>
  112. </view>
  113. </template>
  114. <script>
  115. import {
  116. confirmorder,
  117. submitorder,
  118. addresslist
  119. } from '../../utils/api_user.js'
  120. import useNumberBox from '../../../packageShang/components/use-number-box/use-number-box.vue'
  121. // 收获人地址
  122. const _address = 'usemall-member-address'
  123. export default {
  124. components:{
  125. useNumberBox
  126. },
  127. data() {
  128. return {
  129. // 收货地址
  130. addrData: {},
  131. // 商品数据
  132. goodsDatas: [],
  133. // 产品金额
  134. goods_money: 0,
  135. // 优惠券
  136. couponShow: false,
  137. couponName: '选择优惠券',
  138. couponDatas: [],
  139. // 优惠券类型 满减|折扣
  140. coupon_type: '满减',
  141. // 优惠券金额
  142. coupon_money: 0,
  143. // 实付金额
  144. total_money: 0,
  145. // 优惠金额
  146. total_coupon_money: 0,
  147. // 购物车 ids
  148. cart_ids: [],
  149. // 商品 id
  150. goods_id: 0,
  151. // 商品数量
  152. goods_num: 1,
  153. // 商品 sku id
  154. goods_sku_id: 0,
  155. // 使用优惠券ID
  156. order_coupon_id: 0,
  157. // 买家备注
  158. order_desc: '',
  159. is_submit: 1,
  160. platform: '',
  161. platform_name: '',
  162. type:'',//确认订单type
  163. submitToken:'',//提交令牌
  164. };
  165. },
  166. onLoad(options) {
  167. console.log(options)
  168. this.type=options.type
  169. let _this = this;
  170. this.$api.get_env(res => {
  171. this.platform = res.platform;
  172. this.platform_name = res.platform_name;
  173. });
  174. // 商品 ids
  175. this.goods_id = options.goods_id || '';
  176. this.goods_num=options.num
  177. // 商品 sku
  178. // if (options.skuId) {
  179. // this.goods_sku_id = options.skuId.split(',') || '';
  180. // }
  181. this.goods_sku_id = options.skuId || '';
  182. // 购物车 ids
  183. if (options.cart_ids) {
  184. this.cart_ids = options.cart_ids.split(',');
  185. }
  186. // 加载商品数据
  187. this.loadData();
  188. uni.$on('__event_choice_address', data => {
  189. this.addrData = data;
  190. });
  191. },
  192. onShow() {
  193. // 加载商品数据
  194. this.loadData();
  195. // if (this.addrData && this.addrData.id) return;
  196. // this.$db[_address].where('create_uid == $env.uid').tofirst()
  197. // .then(res => {
  198. // console.log('res', res);
  199. // if (res && res.code === 200) {
  200. // this.addrData = res.datas;
  201. // }
  202. // })
  203. },
  204. methods: {
  205. // 加载数据
  206. loadData() {
  207. var _self=this
  208. _self.goodsDatas = []
  209. _self.addrData={}
  210. _self.submitToken=''
  211. if(_self.type==1){
  212. var goodsId=_self.goods_id
  213. var good_sku=_self.goods_sku_id
  214. }else{
  215. var goodsId=''//_self.cart_ids.toString()
  216. var good_sku=''
  217. }
  218. // 确认订单
  219. var data={
  220. "type": _self.type,
  221. "goodId": goodsId,
  222. "skuId":good_sku,
  223. "num":_self.goods_num
  224. }
  225. confirmorder(data).then((res) => {
  226. if(res.success){
  227. _self.goodsDatas = res.data.orderDetails;
  228. _self.addrData=res.data.address
  229. _self.submitToken=res.data.token.token
  230. _self.calcTotalMoney();
  231. _self.is_submit = 0;
  232. console.log(!(_self.addrData && _self.addrData.id),'p')
  233. if (!(_self.addrData && _self.addrData.id)) {
  234. uni.navigateTo({
  235. url:'/packageShang/pages/user/address/address'
  236. })
  237. return;
  238. }
  239. return
  240. }
  241. _self.$api.msg(res.msg);
  242. })
  243. },
  244. // 计算实际支付 总金额
  245. calcTotalMoney() {
  246. // 服务项总金额
  247. let service_money = 0;
  248. this.goods_money = 0;
  249. this.goodsDatas.forEach(x => {
  250. if (x.goods_sku && x.goods_sku.price) {
  251. x.goods.price = x.goods_sku.price;
  252. x.goods.stock_num = x.goods_sku.stock_num;
  253. }
  254. if (x.cart && x.goodsCount) {
  255. x.goodsCount = x.goodsCount;
  256. }
  257. this.goods_money += (x.goodsActualPrice) * x.goodsCount;
  258. this.total_money =this.goods_money
  259. });
  260. // 商品金额 + 服务金额 - 优惠金额
  261. // if (this.coupon_type == '满减') {
  262. // this.total_coupon_money = this.coupon_money;
  263. // this.total_money = (this.goods_money + service_money - this.coupon_money).toFixed(2);
  264. // } else if (this.coupon_type == '折扣') {
  265. // this.total_coupon_money = (this.goods_money + service_money) - ((this.goods_money + service_money) *
  266. // this.coupon_money).toFixed(2);
  267. // this.total_money = ((this.goods_money + service_money) * this.coupon_money).toFixed(2);
  268. // }
  269. },
  270. // +- 下单数量
  271. numberChange(options) {
  272. let data = this.goodsDatas[options.index];
  273. data.goodsCount = options.number;
  274. if (this.goods_id) this.goods_num = options.number;
  275. this.calcTotalMoney();
  276. },
  277. // 打开优惠券
  278. couponOpen() {
  279. let _this = this;
  280. // 加载可使用优惠券数据 couponDatas
  281. },
  282. // 使用优惠券
  283. couponUse(coupon) {
  284. let _this = this;
  285. _this.order_coupon_id = coupon._id;
  286. _this.coupon_money = coupon.price;
  287. _this.coupon_type = coupon.type;
  288. _this.couponName = coupon.name;
  289. _this.calcTotalMoney();
  290. _this.couponShow = false;
  291. },
  292. // 提交订单
  293. submit() {
  294. if (!(this.addrData && this.addrData.id)) {
  295. this.$api.msg('请选择收货人');
  296. return;
  297. }
  298. if (this.is_submit) {
  299. this.$api.msg('提交中');
  300. return;
  301. }
  302. this.is_submit = 1;
  303. let _this = this;
  304. if(_this.type==1){
  305. var goodsId=_this.goods_id
  306. var goodNum=_this.goods_num
  307. }else{
  308. var goodsId=_this.cart_ids.toString()
  309. var goodNum= _this.goodsDatas.reduce((sum,current)=>sum+current.goodsCount,0)
  310. }
  311. let obj = {
  312. "submitToken": _this.submitToken,
  313. "userAddressId": _this.addrData.id,
  314. "buyerRemark": _this.order_desc,
  315. "orderPaidAmt": _this.total_money,
  316. "submitType": _this.type,
  317. "orderFrom": "1",
  318. "orderDetails": [
  319. {
  320. "goodsId": goodsId,
  321. "goodsCount": goodNum,
  322. "skuId":_this.goods_sku_id
  323. }
  324. ]
  325. };
  326. // 提交订单
  327. submitorder(obj).then((res) => {
  328. if(res.success){
  329. // 跳转支付页
  330. _this.$api.topay({
  331. order_id: res.data.orderId,
  332. money: res.data.orderAmount,
  333. type: 'redirect'
  334. });
  335. return
  336. }
  337. _this.$api.msg(res.message);
  338. _this.is_submit = 0;
  339. })
  340. },
  341. // 选择收货人
  342. toaddr() {
  343. uni.navigateTo({
  344. url: '/packageShang/pages/user/address/address?source=1',
  345. complete() {}
  346. });
  347. },
  348. }
  349. };
  350. </script>
  351. <style lang="scss">
  352. @import url('/packageShang/components/iconfont/iconfont.css');
  353. @import url('/packageShang/common/common.scss');
  354. page {
  355. background: $page-color-base;
  356. padding-bottom: 100rpx;
  357. }
  358. .goods-area {
  359. .goods-item {
  360. display: flex;
  361. .disabled {
  362. color: #fff !important;
  363. width: 70%;
  364. height: 70%;
  365. background-color: rgba(51, 51, 51, 0.5);
  366. }
  367. image {
  368. flex-shrink: 0;
  369. display: block;
  370. width: 180rpx;
  371. height: 180rpx;
  372. border-radius: 4rpx;
  373. }
  374. }
  375. }
  376. .oper-area {
  377. z-index: 998;
  378. box-shadow: 0 -1px 5px rgba(0, 0, 0, 0.1);
  379. .submit {
  380. width: 280rpx;
  381. height: 100rpx;
  382. }
  383. }
  384. /* 优惠券区 */
  385. .coupon-area {
  386. max-height: 60vh;
  387. overflow: auto;
  388. .coupon-item {
  389. margin-bottom: 20rpx;
  390. &:last-child {
  391. margin-bottom: 0;
  392. }
  393. .content {
  394. &:after {
  395. position: absolute;
  396. left: 0;
  397. bottom: 0;
  398. content: '';
  399. width: 100%;
  400. height: 0;
  401. border-bottom: 1px dashed #f3f3f3;
  402. transform: scaleY(50%);
  403. }
  404. }
  405. .circle {
  406. position: absolute;
  407. bottom: -10rpx;
  408. z-index: 10;
  409. width: 20rpx;
  410. height: 20rpx;
  411. background: #f5f5f5;
  412. border-radius: 50%;
  413. &.r {
  414. right: -6rpx;
  415. }
  416. &.l {
  417. left: -6rpx;
  418. }
  419. }
  420. }
  421. }
  422. .coupon-none {
  423. width: 100%;
  424. height: 100%;
  425. line-height: 30vh;
  426. display: flex;
  427. align-items: center;
  428. justify-content: center;
  429. .coupon-none-tip {
  430. color: #909399;
  431. }
  432. }
  433. </style>