123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448 |
- "use strict";
- const common_vendor = require("../common/vendor.js");
- const api_order = require("../api/order.js");
- const common_assets = require("../common/assets.js");
- const EvanSwitch = () => "../components/evan-switch/evan-switch.js";
- const popupBottom = () => "../components/px-popup-bottom/px-popup-bottom.js";
- const _sfc_main = {
- components: {
- EvanSwitch,
- popupBottom
- },
- data() {
- return {
- address: null,
- addressId: null,
- totalNum: null,
- orderKey: null,
- price: null,
- liveId: null,
- orderList: [],
- userInfo: null,
- userAddrLiat: [],
- //用户地址
- temps: [],
- couponUserId: null,
- couponText: "请选择",
- couponsList: [],
- couponVisible: false,
- priceAll: {
- payPrice: 0,
- totalPostage: 0,
- usedIntegral: 0,
- totalPrice: 0
- },
- carts: [],
- checked: false,
- type: null,
- cartIds: null,
- // form:{
- // useIntegral:0,
- // orderKey:null,
- // addressId:null,
- // mark:null,
- // companyId:null,
- // companyUserId:null,
- // createOrderKey:null,
- // },
- confirmParam: []
- };
- },
- computed: {
- priceSum() {
- return this.price * this.totalNum;
- }
- },
- onLoad(options) {
- console.log("确认订单", options);
- this.orderKey = options.orderKey;
- this.liveId = options.liveId;
- this.productId = options.productId;
- this.totalNum = Number(options.totalNum);
- this.price = Number(options.price);
- },
- mounted() {
- this.getUserAddr();
- common_vendor.index.$on("updateAddress", (e) => {
- this.address = e;
- this.addressId = e.addressId;
- });
- },
- beforeDestroy() {
- common_vendor.index.$off("updateAddress");
- },
- methods: {
- // 获取用户收货地址
- getUserAddr() {
- this.userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo"));
- api_order.userAddr(this.userInfo.userId).then(
- (res) => {
- if (res.code == 200) {
- console.log("用户收货地址>>>>", res.data);
- this.address = res.data.find((item) => item.isDefault == 1);
- } else {
- common_vendor.index.showToast({
- title: res.msg,
- icon: "none"
- });
- }
- },
- (rej) => {
- }
- );
- },
- // 创建订单
- createLiveOrder() {
- let data = {
- liveId: this.liveId,
- orderKey: this.orderKey,
- // storeId:this.storeId,,
- userName: this.address.realName,
- userPhone: this.address.phone,
- userAddress: this.address.province + this.address.city + this.address.district + this.address.detail,
- // cartId:"5",
- productId: this.productId,
- totalNum: this.totalNum
- // totalPrice:999,
- // remark:"随便备注",
- };
- return api_order.createliveOrder(data).then((res) => {
- if (res.code == 200) {
- this.orderList = res.order;
- return res.order;
- } else {
- common_vendor.index.showToast({
- title: res.msg,
- icon: "none"
- });
- throw new Error(res.msg);
- }
- });
- },
- getWeixinOrderTemps: function() {
- getWeixinOrderTemps().then(
- (res) => {
- if (res.code == 200) {
- this.temps = res.temp;
- }
- },
- (rej) => {
- }
- );
- },
- couponSelect(item) {
- this.couponText = "-¥" + item.couponPrice.toFixed(2);
- this.couponUserId = item.id;
- this.couponVisible = false;
- this.computed();
- },
- openCoupon() {
- let that = this;
- var data = {
- couponType: 2,
- useMinPrice: this.price.payPrice
- };
- getMyEnableCouponList(data).then((res) => {
- this.couponVisible = true;
- that.couponsList = res.data;
- });
- },
- integralChange(e) {
- this.form.useIntegral = e ? 1 : 0;
- this.computed();
- },
- // confirm(item) {
- // // let data = {type:this.type,cartIds:this.cartIds};
- // confirm(this.confirmParam).then(
- // res => {
- // if (res.code == 200) {
- // this.carts = res.carts.map(item => ({
- // ...item,
- // markinfo: ""
- // }));
- // this.form.orderKey = res.orderKeys;
- // if (res.address != null) {
- // this.form.addressId = res.address.id;
- // this.address = res.address;
- // }
- // this.computed()
- // } else {
- // uni.showToast({
- // icon: 'none',
- // title: res.msg,
- // });
- // }
- // },
- // rej => {}
- // );
- // },
- // computed(item) {
- // let data = {
- // createOrderKey: this.form.createOrderKey,
- // couponUserId: this.couponUserId,
- // orderKeys: this.form.orderKey,
- // addressId: this.form.addressId,
- // useIntegral: this.form.useIntegral
- // };
- // computed(data).then(
- // res => {
- // if (res.code == 200) {
- // // this.price=res.data
- // this.price = res.data && res.data.length > 0 ? res.data : []
- // this.priceAll = res.data && res.data.length > 0 ? res.data[res.data.length - 1] : {
- // payPrice: 0,
- // totalPostage: 0,
- // usedIntegral: 0,
- // totalPrice: 0.00,
- // }
- // } else {
- // if (res.code == 501) {
- // uni.showToast({
- // icon: 'none',
- // title: res.msg,
- // });
- // setTimeout(function() {
- // uni.navigateBack({
- // delta: 1
- // })
- // }, 500);
- // return;
- // } else {
- // uni.showToast({
- // icon: 'none',
- // title: res.msg,
- // });
- // }
- // }
- // },
- // rej => {}
- // );
- // },
- // 提交订单
- async submitOrder() {
- try {
- if (this.orderKey == null) {
- common_vendor.index.showToast({
- icon: "none",
- title: "订单KEY不存在"
- });
- return;
- }
- if (this.address == null) {
- common_vendor.index.showToast({
- icon: "none",
- title: "收货地址不能为空"
- });
- return;
- }
- const orderList = await this.createLiveOrder();
- const orderListStr = encodeURIComponent(JSON.stringify(orderList));
- common_vendor.index.navigateTo({
- url: `/pages_shop/paymentOrder?orderList=${orderListStr}`
- });
- } catch (error) {
- console.error("订单创建失败:", error);
- common_vendor.index.showToast({
- title: "提交失败",
- icon: "none"
- });
- }
- },
- // createOrder() {
- // const mark = this.carts.map(item => item.markinfo)
- // var that = this;
- // var data = null;
- // var tuiUserId = uni.getStorageSync('tuiUserId');
- // uni.showLoading({
- // title: '正在处理中...'
- // });
- // if (tuiUserId != null && tuiUserId != undefined && tuiUserId > 0) {
- // data = {
- // createOrderKey: this.form.createOrderKey,
- // orderCreateType: 3,
- // tuiUserId: tuiUserId,
- // companyId: this.form.companyId,
- // companyUserId: this.form.companyUserId,
- // couponUserId: this.couponUserId,
- // mark: mark,
- // orderKeys: this.form.orderKey,
- // addressId: this.form.addressId,
- // useIntegral: this.form.useIntegral,
- // payType: 1
- // };
- // } else {
- // data = {
- // createOrderKey: this.form.createOrderKey,
- // orderCreateType: 3,
- // companyId: this.form.companyId,
- // companyUserId: this.form.companyUserId,
- // couponUserId: this.couponUserId,
- // mark: mark,
- // orderKeys: this.form.orderKey,
- // addressId: this.form.addressId,
- // useIntegral: this.form.useIntegral,
- // payType: 1
- // };
- // }
- // create(data).then(
- // res => {
- // uni.hideLoading()
- // if (!res.code && res.code !== 0) {
- // uni.hideLoading()
- // // if(res.order.isPrescribe==1){
- // // setTimeout(function(){
- // // uni.redirectTo({
- // // url:"prescribe?orderId="+res.order.id
- // // })
- // // },200);
- // // }
- // // else{
- // // setTimeout(function(){
- // // uni.redirectTo({
- // // url: './paymentOrder?orderId='+res.order.id
- // // })
- // // },200);
- // // }
- // if (res.some(item => item.order.isPrescribe) == 1) {
- // setTimeout(function() {
- // let orderIds = res.filter(item => item.order.isPrescribe == 1).map(it => it
- // .order.id)
- // orderIds = orderIds.join(',')
- // uni.redirectTo({
- // url: "prescribe?orderId=" + orderIds + "&combinationOrderId=" +
- // encodeURIComponent(res[0].order.combinationOrderId)
- // })
- // }, 200);
- // } else {
- // setTimeout(function() {
- // uni.redirectTo({
- // url: './paymentOrder?combinationOrderId=' + encodeURIComponent(
- // res[0].order.combinationOrderId)
- // })
- // }, 200);
- // }
- // return;
- // } else {
- // if (res.code == 501) {
- // uni.showToast({
- // icon: 'none',
- // title: res.msg,
- // });
- // setTimeout(function() {
- // uni.navigateBack({
- // delta: 1
- // })
- // }, 200);
- // return;
- // } else {
- // uni.showToast({
- // icon: 'none',
- // title: res.msg,
- // });
- // }
- // }
- // },
- // rej => {}
- // );
- // },
- openAddress() {
- common_vendor.index.navigateTo({
- url: "/pages_user/address"
- });
- }
- }
- };
- if (!Array) {
- const _component_popupBottom = common_vendor.resolveComponent("popupBottom");
- _component_popupBottom();
- }
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- var _a, _b, _c;
- return common_vendor.e({
- a: $data.address == null
- }, $data.address == null ? {
- b: common_assets._imports_0$11,
- c: common_vendor.o(($event) => $options.openAddress())
- } : {}, {
- d: $data.address != null
- }, $data.address != null ? common_vendor.e({
- e: common_vendor.t($data.address.realName),
- f: $data.address.phone != null
- }, $data.address.phone != null ? {
- g: common_vendor.t(_ctx.$parsePhone($data.address.phone))
- } : {}, {
- h: common_vendor.t($data.address.province),
- i: common_vendor.t($data.address.city),
- j: common_vendor.t($data.address.district),
- k: common_vendor.t($data.address.detail),
- l: common_assets._imports_0$11,
- m: common_vendor.o(($event) => $options.openAddress())
- }) : {}, {
- n: common_vendor.f($data.carts, (shop, idx, i0) => {
- return common_vendor.e({
- a: shop.storeName && shop.storeName != "null"
- }, shop.storeName && shop.storeName != "null" ? {
- b: common_vendor.t(shop.storeName)
- } : {}, {
- c: common_vendor.f(shop.list, (item, index, i1) => {
- var _a2;
- return {
- a: item.productAttrImage ? item.productAttrImage : item.productImage,
- b: common_vendor.t(_ctx.utils.getDictLabelName("storeProductType", item.productType)),
- c: common_vendor.t(item.productName),
- d: common_vendor.t(item.productAttrName),
- e: common_vendor.t((_a2 = item.price) == null ? void 0 : _a2.toFixed(2)),
- f: common_vendor.t(item.cartNum),
- g: index
- };
- })
- }, $data.price && $data.price.length > 0 ? {
- d: common_vendor.t($data.price[idx].payPostage == null || $data.price[idx].payPostage == 0 ? "免运费" : $data.price[idx].payPostage.toFixed(2))
- } : {}, {
- e: shop.markinfo,
- f: common_vendor.o(($event) => shop.markinfo = $event.detail.value, idx),
- g: idx
- });
- }),
- o: $data.price && $data.price.length > 0,
- p: common_vendor.t((_a = $data.price) == null ? void 0 : _a.toFixed(2)),
- q: common_vendor.t((_b = $options.priceSum) == null ? void 0 : _b.toFixed(2)),
- r: common_vendor.t((_c = $options.priceSum) == null ? void 0 : _c.toFixed(2)),
- s: common_vendor.o((...args) => $options.submitOrder && $options.submitOrder(...args)),
- t: $data.couponsList.length > 0
- }, $data.couponsList.length > 0 ? {
- v: common_vendor.f($data.couponsList, (item, index, i0) => {
- return common_vendor.e({
- a: item.status == 0
- }, item.status == 0 ? {
- b: common_assets._imports_2$6
- } : {}, {
- c: item.status != 0
- }, item.status != 0 ? {
- d: common_assets._imports_3$2
- } : {}, {
- e: common_vendor.t(item.couponPrice),
- f: common_vendor.t(item.useMinPrice),
- g: common_vendor.t(item.couponTitle),
- h: common_vendor.t(item.limitTime),
- i: common_vendor.o(($event) => $options.couponSelect(item), index),
- j: index
- });
- })
- } : {}, {
- w: $data.couponsList.length == 0
- }, $data.couponsList.length == 0 ? {
- x: common_assets._imports_2$3
- } : {}, {
- y: common_vendor.sr("popup", "5fa01107-0"),
- z: common_vendor.p({
- visible: $data.couponVisible,
- title: " ",
- bgColor: "#f5f5f5",
- radius: "30",
- maxHeight: "60%"
- })
- });
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-5fa01107"]]);
- wx.createPage(MiniProgramPage);
|