newBulitOrder.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. <template>
  2. <view class="page">
  3. <!-- 地址 -->
  4. <view class="address" @click="toadd">
  5. <view class="u-flex u-row-between">
  6. <view class="add" v-if="JSON.stringify(addinfo) != '{}'">{{
  7. addinfo.full_address
  8. }}</view>
  9. <view class="" v-else>{{ i18n.shippingaddress }}</view>
  10. <u-icon name="arrow-right" size="16"></u-icon>
  11. </view>
  12. <view class="info" v-if="JSON.stringify(addinfo) != '{}'">
  13. <text>{{ addinfo.name }}</text>
  14. <text style="margin-left: 20rpx">{{
  15. replacePhoneToStar(addinfo.mobile)
  16. }}</text>
  17. </view>
  18. </view>
  19. <!-- 地址 -->
  20. <!-- 需要下单的商品列表 -->
  21. <Commodity :goodsList="goodsList" :goodsValue="goodsValue" @changeGoodsNum="changeGoodsNum" />
  22. <!-- 需要下单的商品列表 -->
  23. <!-- 选择物流 -->
  24. <view class="logistics u-flex u-row-between">
  25. <text style="font-weight: 600; width: 320rpx">{{ i18n.flow }}</text>
  26. <view class="u-flex" @click="openLogistics">
  27. <text class="change">{{
  28. containname ? transportTypeName + " | " + containname : i18n.selection
  29. }}</text>
  30. <u-icon name="arrow-right" size="16"></u-icon>
  31. </view>
  32. </view>
  33. <!-- 选择物流 -->
  34. <!-- 选择物流弹窗 -->
  35. <SelectLogistics :logisticsShow="logisticsShow" @closeLogistics="closeLogistics" :containerList="containerList"
  36. :language="language" @openContainer="openContainer" />
  37. <!-- 选择物流弹窗 -->
  38. <!-- 选择物流价格之后的下一步 -->
  39. <NextLogistics :nextLogisticsShow="nextLogisticsShow" :language="language" :goodinfo="goodinfo"
  40. :goodsValue="goodsValue" :specificationsPrice="specificationsPrice" @closeLogistics="closeLogistics"
  41. :goodsArr="goodsArr" :addinfo='addinfo' @calculate='calculate'/>
  42. <!-- 选择物流价格之后的下一步 -->
  43. <!-- 推荐商品 -->
  44. <RecommendGoods :swiptlist="swiptlist" />
  45. <!-- 推荐商品 -->
  46. <!-- 商品信息 -->
  47. <GoodsInformation :goodinfo="goodinfo" :containname="containname" :goodsPrice="goodsList.order.goods_amount"
  48. :countGoodsInformation="countGoodsInformation" :goodsValue="goodsValue"
  49. :specificationsPrice="specificationsPrice" :goodsWeight="countGoodsInformation.goodsWeight" />
  50. <!-- 商品信息 -->
  51. <view class="btn u-flex u-row-right">
  52. <view class="u-flex">
  53. <text class="kg"
  54. v-show="containname">{{ i18n.Atotalof }}{{ countGoodsInformation.goodsWeight }}kg,</text>
  55. <text>{{ i18n.total }}:</text>
  56. <text class="money" style="font-size: 28rpx">¥</text>
  57. <view class="">
  58. <!-- <text class="money" v-if="countGoodsInformation.containname">{{
  59. Number(specificationsPrice) + Number(countGoodsInformation.sum)
  60. }}</text> -->
  61. <text class="money">{{
  62. Number(specificationsPrice) + Number(countGoodsInformation.sum)
  63. }}</text>
  64. </view>
  65. </view>
  66. <view class="order" @click="topay">
  67. {{ i18n.Submitorder }}
  68. </view>
  69. </view>
  70. </view>
  71. </template>
  72. <script>
  73. import Commodity from "./component/commodity.vue";
  74. import SelectLogistics from "./component/selectLogistics.vue";
  75. import NextLogistics from "./component/nextLogistics.vue";
  76. import RecommendGoods from "./component/recommendGoods.vue";
  77. import GoodsInformation from "./component/goodsInformation.vue";
  78. export default {
  79. components: {
  80. Commodity,
  81. SelectLogistics,
  82. NextLogistics,
  83. RecommendGoods,
  84. GoodsInformation,
  85. },
  86. data() {
  87. return {
  88. addinfo: {}, //地址信息
  89. province_id: "",
  90. country_id:'',
  91. containerList: [],
  92. transport_type_id: "", //运输方式ID
  93. transportTypeName: "", //运输方式名称
  94. swiptlist: [], //推荐商品
  95. goodsList: [], //需要下单的商品
  96. logisticsShow: false, //打开选择物流窗口
  97. language: this._language, //语言
  98. nextLogisticsShow: false, //打开选择货柜窗口
  99. goodinfo: {}, //商品信息
  100. goodsValue: 0, //商品数量
  101. sku_info: {},
  102. containname: "", //货柜名称
  103. countGoodsInformation: {},
  104. goodsWeight: 0, //商品重量
  105. goodsId: "", //商品id
  106. sku_item_id: "", //商品规格id
  107. merchant_goods_id: "", //店铺商品id
  108. goodsSource: "", //商品归属
  109. isDiscount: "", //商品是否存在打折
  110. specificationsPrice: 0, //订单商品总金额
  111. goodsArr: [], //多商品用的商品规格
  112. };
  113. },
  114. computed: {
  115. i18n() {
  116. return this.$t("index");
  117. },
  118. },
  119. onLoad(options) {
  120. this.getOrderGoods(options.orderId);
  121. this.recommend();
  122. },
  123. onShow() {
  124. console.log(this.language);
  125. // if (uni.getStorageSync("language") != "") {
  126. // this.language = uni.getStorageSync("language");
  127. // }
  128. },
  129. methods: {
  130. //关闭选择物流窗口
  131. closeLogistics(data) {
  132. this.logisticsShow = false;
  133. this.nextLogisticsShow = false;
  134. //判断是哪一步关闭,接受数据
  135. if (data.type == "second" && data.containname) {
  136. this.containname = data.containname;
  137. this.countGoodsInformation = data;
  138. this.calculate()
  139. }
  140. },
  141. // //下单前计算数据
  142. calculate() {
  143. uni.$u.http
  144. .post("/api/order/calculate", {
  145. address_id: this.addinfo.id, //3 是 String 地址ID
  146. merchant_goods_id: this.merchant_goods_id || "", //39 是 String 团长商品id
  147. container_id: this.countGoodsInformation.containid, //1 是 String 货柜id
  148. share_member_id: "", // 是 String 分享团长id 分享商品的时候传
  149. belong: this.goodsSource || "", //0 是 String 商品归属 0团长 1平台自营 2团长发布或者分享的平台自营商品、供应链商品
  150. goods_arr: JSON.stringify(this.goodsArr),
  151. })
  152. .then((res) => {
  153. console.log(res);
  154. this.countGoodsInformation.sum = res.freight
  155. })
  156. .catch(() => {});
  157. },
  158. //打开选择货柜弹窗
  159. openContainer(data) {
  160. this.goodinfo.province_id = this.province_id;
  161. this.goodinfo.country_id = this.country_id;
  162. this.goodinfo.transport_type_id = this.transport_type_id;
  163. let weight = 0;
  164. let height = 0;
  165. let length = 0;
  166. let price = 0;
  167. let width = 0;
  168. this.goodsList.goods.map((item) => {
  169. console.log(item);
  170. weight += item.sku_item.weight;
  171. height += item.sku_item.height;
  172. length += item.sku_item.length;
  173. width += item.sku_item.width;
  174. price += Number(item.sku_item.price);
  175. // this.goodinfo.type = item.goods.status;
  176. });
  177. //等待后端解决多商品之后放开注释
  178. // this.goodinfo.weight = weight;
  179. // this.goodinfo.height = height;
  180. // this.goodinfo.length = length;
  181. // this.goodinfo.width = width;
  182. // this.goodinfo.price = price;
  183. //等待后端解决多商品删除,采用上面几行
  184. this.goodinfo.weight = 10;
  185. this.goodinfo.height = 10;
  186. this.goodinfo.length = 10;
  187. this.goodinfo.width = 10;
  188. this.goodinfo.price = 10;
  189. this.logisticsShow = false;
  190. this.nextLogisticsShow = true;
  191. //判断打开的窗口是第几步,将选中的运输方式传回
  192. if (data.type == "first" && data.transportTypeName) {
  193. this.transportTypeName = data.transportTypeName;
  194. }
  195. },
  196. //运费满减
  197. async config() {
  198. var that = this;
  199. await uni.$u.http
  200. .get("/api/config", {
  201. params: {
  202. module: "free_shipping",
  203. },
  204. })
  205. .then((res) => {
  206. let goodsum = "";
  207. goodsum = Number(that.specificationsPrice) * that.goodsValue;
  208. if (goodsum > res.free_shipping) {
  209. that.countGoodsInformation.sum = 0;
  210. that.countGoodsInformation.unit_price = 0;
  211. } else {
  212. this.countGoodsInformation.sum =
  213. this.countGoodsInformation.unchangedFreight;
  214. this.countGoodsInformation.unit_price =
  215. this.countGoodsInformation.unchangedUnit_price;
  216. }
  217. })
  218. .catch(() => {});
  219. },
  220. //提交订单
  221. topay() {
  222. uni.$u.http
  223. .post("/api/order", {
  224. address_id: this.addinfo.id, //3 是 String 地址ID
  225. goods_id: this.goodsId, //65 是 String 商品id
  226. goods_num: this.goodsValue, //2 是 String 商品数量
  227. sku_item_id: this.sku_item_id, //60 是 String 规格id
  228. cart_ids: "", //8,9 是 String 购物车id
  229. remark: "", //备注 是 String 备注
  230. merchant_goods_id: this.merchant_goods_id || "", //39 是 String 团长商品id
  231. container_id: this.countGoodsInformation.containid, //1 是 String 货柜id
  232. share_member_id: "", // 是 String 分享团长id 分享商品的时候传
  233. belong: this.goodsSource || "", //0 是 String 商品归属 0团长 1平台自营 2团长发布或者分享的平台自营商品、供应链商品
  234. goods_arr: JSON.stringify(this.goodsArr),
  235. })
  236. .then((res) => {
  237. uni.navigateTo({
  238. // url: '/pageA/payorder?sum=' + (Number(this.sum*10000+ Number(this.sku_info.discount_price)*Number(this.value)*10000))/10000 +'&orderid=' + res.id
  239. url: "/pageA/payorder?orderid=" + res.id + "&sum=" + res.amount,
  240. });
  241. })
  242. .catch(() => {});
  243. },
  244. //打开选择物流窗口
  245. openLogistics() {
  246. this.logisticsShow = true;
  247. this.transport();
  248. },
  249. //获取订单商品
  250. getOrderGoods(id) {
  251. uni.$u.http.get(`/api/order/read?id=${id}`).then((res) => {
  252. this.goodsList = res;
  253. this.goodsValue = this.goodsList.goods[0].goods_num;
  254. this.goodsList.goods.map((item) => {
  255. this.goodsId = item.goods_id;
  256. this.sku_item_id = item.sku_item_id;
  257. this.merchant_goods_id = item.merchant_goods_id;
  258. // this.goodsSource = item.goods.source;
  259. //库存商品大于需要购买的数量
  260. if (item.true_stock > item.goods_num) {
  261. this.goodsWeight += item.sku_item.weight * item.goods_num; //商品重量
  262. //多商品获取规格商品id
  263. let obj = {
  264. merchant_goods_id: item.merchant_goods_id,
  265. goods_num: item.goods_num,
  266. sku_item_id: item.sku_item_id,
  267. };
  268. this.goodsArr.push(obj);
  269. //获取订单商品总金额
  270. this.specificationsPrice +=
  271. Number(item.discount_price) * item.goods_num;
  272. }
  273. });
  274. if (this.goodsArr.length < this.goodsList.goods.length) {
  275. uni.showToast({
  276. title: "已自动去除库存不足的商品",
  277. icon: "none",
  278. });
  279. }
  280. });
  281. },
  282. //跳转到填写地址
  283. toadd() {
  284. var that = this;
  285. uni.navigateTo({
  286. url: "/pageC/addressManagement/addressManagement?tabs=" + Number(0),
  287. events: {
  288. getadd(res) {
  289. console.log(res);
  290. that.addinfo = res;
  291. that.province_id = res.province_id;
  292. that.country_id = res.country_id
  293. that.transport();
  294. },
  295. },
  296. });
  297. },
  298. //货运类型列表
  299. transport() {
  300. uni.$u.http
  301. .get("/api/transport-type", {
  302. params: {
  303. province_id: this.province_id,
  304. country_id:this.country_id
  305. },
  306. })
  307. .then((res) => {
  308. this.containerList = res;
  309. this.transport_type_id = res[0].id;
  310. this.transportTypeName = res[0].name_cn; //等待后续更改language删除掉
  311. //根据不同的语言选择不用的类型
  312. if (this.language == "zh-CN") {
  313. this.transportTypeName = res[0].name_cn;
  314. }
  315. if (this.language == "en-US") {
  316. this.transportTypeName = res[0].name_en;
  317. }
  318. if (this.language == "es-ES") {
  319. this.transportTypeName = res[0].name_es;
  320. }
  321. if (this.language == "it-IT") {
  322. this.transportTypeName = res[0].name_ita;
  323. }
  324. })
  325. .catch(() => {});
  326. },
  327. //正则匹配手机号
  328. replacePhoneToStar: function(phone) {
  329. if (phone) {
  330. return phone.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
  331. }
  332. },
  333. //商品推荐
  334. recommend() {
  335. uni.$u.http
  336. .post("/api/goods/recommend", {
  337. keyword: "",
  338. })
  339. .then((res) => {
  340. this.swiptlist = res;
  341. })
  342. .catch(() => {});
  343. },
  344. //增加 or 减少 商品数量
  345. changeGoodsNum(type) {
  346. if (type == "increase") {
  347. this.goodsValue++;
  348. this.config();
  349. } else if (this.goodsValue > 1) {
  350. this.goodsValue--;
  351. this.config();
  352. }
  353. },
  354. },
  355. };
  356. </script>
  357. <style scoped lang="scss">
  358. .page {
  359. background: rgba(244, 244, 244, 1);
  360. padding: 20rpx 24rpx;
  361. box-sizing: border-box;
  362. padding-bottom: 200rpx;
  363. // 地址
  364. .address {
  365. width: 702rpx;
  366. // height: 182rpx;
  367. background: #ffffff;
  368. border-radius: 16rpx;
  369. padding: 32rpx 24rpx;
  370. box-sizing: border-box;
  371. .add {
  372. font-family: SFPro, SFPro;
  373. font-weight: 500;
  374. font-size: 32rpx;
  375. color: #222222;
  376. line-height: 36rpx;
  377. text-align: left;
  378. font-style: normal;
  379. }
  380. .info {
  381. font-family: SFPro, SFPro;
  382. font-weight: 400;
  383. font-size: 24rpx;
  384. color: #555555;
  385. line-height: 28rpx;
  386. text-align: left;
  387. font-style: normal;
  388. margin-top: 20rpx;
  389. }
  390. }
  391. //物流
  392. .logistics {
  393. width: 702rpx;
  394. background: #ffffff;
  395. border-radius: 16rpx;
  396. padding: 28rpx 22rpx;
  397. box-sizing: border-box;
  398. margin-top: 20rpx;
  399. .change {
  400. font-family: PingFangSC, PingFang SC;
  401. font-weight: 400;
  402. font-size: 28rpx;
  403. color: #f83224;
  404. line-height: 40rpx;
  405. text-align: left;
  406. font-style: normal;
  407. margin-right: 8rpx;
  408. }
  409. }
  410. .btn {
  411. width: 750rpx;
  412. height: 166rpx;
  413. background: #ffffff;
  414. box-shadow: 0rpx -1rpx 0rpx 0rpx rgba(0, 0, 0, 0.05);
  415. position: fixed;
  416. bottom: 0;
  417. left: 0;
  418. padding: 0 24rpx 5rpx 5rpx;
  419. box-sizing: border-box;
  420. .money {
  421. font-family: HarmonyOS_Sans_Medium;
  422. font-size: 48rpx;
  423. color: #f83224;
  424. line-height: 38rpx;
  425. text-align: left;
  426. font-style: normal;
  427. // font-weight: 500;
  428. font-weight: bold;
  429. }
  430. .kg {
  431. font-family: PingFangSC, PingFang SC;
  432. font-weight: 400;
  433. font-size: 24rpx;
  434. color: #333333;
  435. line-height: 34rpx;
  436. text-align: left;
  437. font-style: normal;
  438. }
  439. .order {
  440. width: 232rpx;
  441. height: 80rpx;
  442. background: #f83224;
  443. border-radius: 40rpx;
  444. font-family: PingFangTC, PingFangTC;
  445. font-weight: 500;
  446. font-size: 32rpx;
  447. color: #ffffff;
  448. line-height: 80rpx;
  449. text-align: center;
  450. font-style: normal;
  451. margin-left: 20rpx;
  452. }
  453. }
  454. }
  455. </style>