newBulitOrder.vue 14 KB

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