create.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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. this.goods_sku_id = options.skuId || '';
  179. // 购物车 ids
  180. if (options.cart_ids) {
  181. this.cart_ids = options.cart_ids.split(',');
  182. }
  183. // 加载商品数据
  184. this.loadData();
  185. uni.$on('__event_choice_address', data => {
  186. this.addrData = data;
  187. });
  188. },
  189. onShow() {
  190. // 加载商品数据
  191. this.loadData();
  192. // if (this.addrData && this.addrData.id) return;
  193. // this.$db[_address].where('create_uid == $env.uid').tofirst()
  194. // .then(res => {
  195. // console.log('res', res);
  196. // if (res && res.code === 200) {
  197. // this.addrData = res.datas;
  198. // }
  199. // })
  200. },
  201. methods: {
  202. // 加载数据
  203. loadData() {
  204. var _self=this
  205. _self.goodsDatas = []
  206. _self.addrData={}
  207. _self.submitToken=''
  208. if(_self.type==1){
  209. var goodsId=_self.goods_id
  210. }else{
  211. var goodsId=''//_self.cart_ids.toString()
  212. }
  213. // 确认订单
  214. var data={
  215. "type": _self.type,
  216. "goodId": goodsId,
  217. "skuId":_self.goods_sku_id,
  218. "num":_self.goods_num
  219. }
  220. confirmorder(data).then((res) => {
  221. if(res.success){
  222. _self.goodsDatas = res.data.orderDetails;
  223. _self.addrData=res.data.address
  224. _self.submitToken=res.data.token.token
  225. _self.calcTotalMoney();
  226. _self.is_submit = 0;
  227. console.log(!(_self.addrData && _self.addrData.id),'p')
  228. if (!(_self.addrData && _self.addrData.id)) {
  229. uni.navigateTo({
  230. url:'/packageShang/pages/user/address/address'
  231. })
  232. return;
  233. }
  234. return
  235. }
  236. _self.$api.msg(res.msg);
  237. })
  238. },
  239. // 计算实际支付 总金额
  240. calcTotalMoney() {
  241. // 服务项总金额
  242. let service_money = 0;
  243. this.goods_money = 0;
  244. this.goodsDatas.forEach(x => {
  245. if (x.goods_sku && x.goods_sku.price) {
  246. x.goods.price = x.goods_sku.price;
  247. x.goods.stock_num = x.goods_sku.stock_num;
  248. }
  249. if (x.cart && x.goodsCount) {
  250. x.goodsCount = x.goodsCount;
  251. }
  252. this.goods_money += (x.goodsActualPrice) * x.goodsCount;
  253. this.total_money =this.goods_money
  254. });
  255. // 商品金额 + 服务金额 - 优惠金额
  256. // if (this.coupon_type == '满减') {
  257. // this.total_coupon_money = this.coupon_money;
  258. // this.total_money = (this.goods_money + service_money - this.coupon_money).toFixed(2);
  259. // } else if (this.coupon_type == '折扣') {
  260. // this.total_coupon_money = (this.goods_money + service_money) - ((this.goods_money + service_money) *
  261. // this.coupon_money).toFixed(2);
  262. // this.total_money = ((this.goods_money + service_money) * this.coupon_money).toFixed(2);
  263. // }
  264. },
  265. // +- 下单数量
  266. numberChange(options) {
  267. let data = this.goodsDatas[options.index];
  268. data.goodsCount = options.number;
  269. if (this.goods_id) this.goods_num = options.number;
  270. this.calcTotalMoney();
  271. },
  272. // 打开优惠券
  273. couponOpen() {
  274. let _this = this;
  275. // 加载可使用优惠券数据 couponDatas
  276. },
  277. // 使用优惠券
  278. couponUse(coupon) {
  279. let _this = this;
  280. _this.order_coupon_id = coupon._id;
  281. _this.coupon_money = coupon.price;
  282. _this.coupon_type = coupon.type;
  283. _this.couponName = coupon.name;
  284. _this.calcTotalMoney();
  285. _this.couponShow = false;
  286. },
  287. // 提交订单
  288. submit() {
  289. if (!(this.addrData && this.addrData.id)) {
  290. this.$api.msg('请选择收货人');
  291. return;
  292. }
  293. if (this.is_submit) {
  294. this.$api.msg('提交中');
  295. return;
  296. }
  297. this.is_submit = 1;
  298. let _this = this;
  299. if(_this.type==1){
  300. var goodsId=_this.goods_id
  301. var goodNum=_this.goods_num
  302. }else{
  303. var goodsId=_this.cart_ids.toString()
  304. var goodNum= _this.goodsDatas.reduce((sum,current)=>sum+current.goodsCount,0)
  305. }
  306. let obj = {
  307. "submitToken": _this.submitToken,
  308. "userAddressId": _this.addrData.id,
  309. "buyerRemark": _this.order_desc,
  310. "orderPaidAmt": _this.total_money,
  311. "submitType": _this.type,
  312. "orderFrom": "1",
  313. "orderDetails": [
  314. {
  315. "goodsId": goodsId,
  316. "goodsCount": goodNum,
  317. "skuId":_this.goods_sku_id
  318. }
  319. ]
  320. };
  321. // 提交订单
  322. submitorder(obj).then((res) => {
  323. if(res.success){
  324. // 跳转支付页
  325. _this.$api.topay({
  326. order_id: res.data.orderId,
  327. money: res.data.orderAmount,
  328. type: 'redirect'
  329. });
  330. return
  331. }
  332. _this.$api.msg(res.msg);
  333. _this.is_submit = 0;
  334. })
  335. },
  336. // 选择收货人
  337. toaddr() {
  338. uni.navigateTo({
  339. url: '/packageShang/pages/user/address/address?source=1',
  340. complete() {}
  341. });
  342. },
  343. }
  344. };
  345. </script>
  346. <style lang="scss">
  347. @import url('/packageShang/components/iconfont/iconfont.css');
  348. @import url('/packageShang/common/common.scss');
  349. page {
  350. background: $page-color-base;
  351. padding-bottom: 100rpx;
  352. }
  353. .goods-area {
  354. .goods-item {
  355. display: flex;
  356. .disabled {
  357. color: #fff !important;
  358. width: 70%;
  359. height: 70%;
  360. background-color: rgba(51, 51, 51, 0.5);
  361. }
  362. image {
  363. flex-shrink: 0;
  364. display: block;
  365. width: 180rpx;
  366. height: 180rpx;
  367. border-radius: 4rpx;
  368. }
  369. }
  370. }
  371. .oper-area {
  372. z-index: 998;
  373. box-shadow: 0 -1px 5px rgba(0, 0, 0, 0.1);
  374. .submit {
  375. width: 280rpx;
  376. height: 100rpx;
  377. }
  378. }
  379. /* 优惠券区 */
  380. .coupon-area {
  381. max-height: 60vh;
  382. overflow: auto;
  383. .coupon-item {
  384. margin-bottom: 20rpx;
  385. &:last-child {
  386. margin-bottom: 0;
  387. }
  388. .content {
  389. &:after {
  390. position: absolute;
  391. left: 0;
  392. bottom: 0;
  393. content: '';
  394. width: 100%;
  395. height: 0;
  396. border-bottom: 1px dashed #f3f3f3;
  397. transform: scaleY(50%);
  398. }
  399. }
  400. .circle {
  401. position: absolute;
  402. bottom: -10rpx;
  403. z-index: 10;
  404. width: 20rpx;
  405. height: 20rpx;
  406. background: #f5f5f5;
  407. border-radius: 50%;
  408. &.r {
  409. right: -6rpx;
  410. }
  411. &.l {
  412. left: -6rpx;
  413. }
  414. }
  415. }
  416. }
  417. .coupon-none {
  418. width: 100%;
  419. height: 100%;
  420. line-height: 30vh;
  421. display: flex;
  422. align-items: center;
  423. justify-content: center;
  424. .coupon-none-tip {
  425. color: #909399;
  426. }
  427. }
  428. </style>