create.vue 12 KB

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