123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450 |
- var app = getApp(),
- api = getApp().api,
- longitude = "",
- latitude = "",
- util = getApp().helper,
- is_loading_show = !1;
- Page({
- data: {
- total_price: 0,
- address: null,
- express_price: 0,
- express_price_1: 0,
- integral_radio: 1,
- new_total_price: 0,
- show_card: !1,
- payment: 3,
- show_payment: !1,
- show_more: !1,
- index: -1,
- mch_offline: !0,
- is_virtual: 0, //虚拟商品
- phone: '' //虚拟商品手机号
- },
- onLoad: function (t) {
- getApp().page.onLoad(this, t);
- var e = util.formatData(new Date);
- getApp().core.removeStorageSync(getApp().const.INPUT_DATA), this.setData({
- options: t,
- time: e
- }), is_loading_show = !1
- },
- bindContentInput: function (t) {
- this.data.mch_list[t.currentTarget.dataset.index].content = t.detail.value,
- this.setData({
- mch_list: this.data.mch_list
- })
- },
- // 虚拟商品电话
- bindMobileInput: function (t) {
- // console.log(t.detail.value)
- // console.log(t.currentTarget.dataset.index)
- // this.data.phone = t.detail.value,
- this.setData({
- phone: t.detail.value
- })
- },
- KeyName: function (t) {
- var e = this.data.mch_list;
- e[t.currentTarget.dataset.index].offline_name = t.detail.value, this.setData({
- mch_list: e
- })
- },
- KeyMobile: function (t) {
- var e = this.data.mch_list;
- e[t.currentTarget.dataset.index].offline_mobile = t.detail.value, this.setData({
- mch_list: e
- })
- },
- getOffline: function (t) {
- var e = this,
- a = t.currentTarget.dataset.offline,
- i = t.currentTarget.dataset.index,
- o = e.data.mch_list;
- o[i].offline = a, e.setData({
- mch_list: o
- }), 1 == o.length && 0 == o[0].mch_id && 1 == o[0].offline ? e.setData({
- mch_offline: !1
- }) : e.setData({
- mch_offline: !0
- }), e.getPrice()
- },
- dingwei: function () {
- var e = this;
- getApp().getauth({
- content: "需要获取您的地理位置授权,请到小程序设置中打开授权",
- author: "scope.userLocation",
- success: function (t) {
- t && (t.authSetting["scope.userLocation"] ? getApp().core.chooseLocation({
- success: function (t) {
- longitude = t.longitude, latitude = t.latitude, e.setData({
- location: t.address
- }), e.getOrderData(e.data.options)
- }
- }) : getApp().core.showToast({
- title: "您取消了授权",
- image: "/images/icon-warning.png"
- }))
- }
- })
- },
- orderSubmit: function (t) {
- var e = this,
- a = {},
- i = e.data.mch_list;
- console.log("data中的mch_list",i)
- for (var o in i) {
- var s = i[o].form;
- if (s && 1 == s.is_form && 0 == i[o].mch_id) {
- var n = s.list;
- for (var r in n)
- if (1 == n[r].required)
- if ("radio" == n[r].type || "checkbox" == n[r].type) {
- var c = !1;
- for (var p in n[r].default_list) 1 == n[r].default_list[p].is_selected && (c = !0);
- if (!c) return getApp().core.showModal({
- title: "提示",
- content: "请填写" + s.name + ",加‘*’为必填项",
- showCancel: !1
- }), !1
- } else if (!n[r].default || null == n[r].default)
- return getApp().core.showModal({
- title: "提示",
- content: "请填写" + s.name + ",加‘*’为必填项",
- showCancel: !1
- }), !1
- }
- if (1 == i.length && 0 == i[o].mch_id && 1 == i[o].offline);
- else {
- if(e.data.is_virtual == 0){
- if (!e.data.address)
- return getApp().core.showModal({
- title: "提示",
- content: "请选择收货地址",
- showCancel: !1
- }), !1;
- a.address_id = e.data.address.id
- }
- }
- }
- if(e.data.is_virtual == 1){
- if(e.data.phone == '' || e.data.phone == null){
- return getApp().core.showModal({
- title: "提示",
- content: "请填写电话号码",
- showCancel: !1
- }), !1;
- }
- }
- if (a.mch_list = JSON.stringify(i), 0 < e.data.pond_id) {
- if (0 < e.data.express_price && -1 == e.data.payment) return e.setData({
- show_payment: !0
- }), !1
- } else if (-1 == e.data.payment) return e.setData({
- show_payment: !0
- }), !1;
- 1 == e.data.integral_radio ? a.use_integral = 1 : a.use_integral = 2,
- a.payment = e.data.payment,
- a.phone = e.data.phone
- a.formId = t.detail.formId,
- e.order_submit(a, "s")
- },
- onReady: function () {},
- onShow: function (t) {
- if (!is_loading_show) {
- is_loading_show = !0, getApp().page.onShow(this);
- var e = this,
- a = getApp().core.getStorageSync(getApp().const.PICKER_ADDRESS);
- console.log('传过来的address地址信息',a)
- a && e.setData({
- address: a
- }),
- getApp().core.removeStorageSync(getApp().const.PICKER_ADDRESS), e.getOrderData(e.data.options)
- }
- },
- getOrderData: function (t) {
- var _ = this,
- e = {},
- a = "";
- _.data.address && _.data.address.id && (a = _.data.address.id),
- e.address_id = a,
- e.longitude = longitude,
- e.latitude = latitude, getApp().core.showLoading({
- title: "正在加载",
- mask: !0
- }), e.mch_list = t.mch_list,
- console.log('t.mch_list',t.mch_list)
- getApp().request({
- url: getApp().api.order.new_submit_preview,
- method: "POST",
- data: e,
- success: function (t) {
- if (getApp().core.hideLoading(), 0 == t.code) {
- if(t.data.is_virtual){
- _.setData({
- is_virtual: t.data.is_virtual
- })
- }
- var e = getApp().core.getStorageSync(getApp().const.INPUT_DATA),
- a = t.data,
- i = -1,
- o = 1,
- s = a.mch_list,
- n = [];
- for (var r in e && (n = e.mch_list, i = e.payment, o = e.integral_radio), a.integral_radio = o, a.pay_type_list) {
- if (i == a.pay_type_list[r].payment) {
- a.payment = i;
- break
- }
- if (1 == a.pay_type_list.length) {
- a.payment = a.pay_type_list[r].payment;
- break
- }
- }
- for (var r in s) {
- var c = {},
- p = {};
- if (s[r].show = !1, s[r].show_length = s[r].goods_list.length - 1, 0 != n.length)
- for (var d in n)
- s[r].mch_id == n[d].mch_id && (s[r].content = n[d].content, s[r].form = n[d].form, c = n[d].shop, p = n[d].picker_coupon, s[r].offline_name = n[d].offline_name, s[r].offline_mobile = n[d].offline_mobile);
- for (var d in s[r].shop_list) {
- if (c && c.id == s[r].shop_list[d].id) {
- s[r].shop = c;
- break
- }
- if (1 == s[r].shop_list.length) {
- s[r].shop = s[r].shop_list[d];
- break
- }
- if (1 == s[r].shop_list[d].is_default) {
- s[r].shop = s[r].shop_list[d];
- break
- }
- }
- if (p)
- for (var d in s[r].coupon_list)
- if (p.id == s[r].coupon_list[d].id) {
- s[r].picker_coupon = p;
- break
- }
- s[r].send_type && 2 == s[r].send_type ? (s[r].offline = 1, _.setData({
- mch_offline: !1
- })) : s[r].offline = 0
- }
- a.mch_list = s;
- var l = _.data.index; - 1 != l && s[l].shop_list && 0 < s[l].shop_list.length && _.setData({
- show_shop: !0,
- shop_list: s[l].shop_list
- }), _.setData(a), _.getPrice()
- }
- 1 == t.code && getApp().core.showModal({
- title: "提示",
- content: t.msg,
- showCancel: !1,
- confirmText: "返回",
- success: function (t) {
- t.confirm && getApp().core.navigateBack({
- delta: 1
- })
- }
- })
- }
- })
- },
- showCouponPicker: function (t) {
- var e = t.currentTarget.dataset.index,
- a = this.data.mch_list;
- this.getInputData(), a[e].coupon_list && 0 < a[e].coupon_list.length && this.setData({
- show_coupon_picker: !0,
- coupon_list: a[e].coupon_list,
- index: e
- })
- },
- pickCoupon: function (t) {
- var e = t.currentTarget.dataset.index,
- a = this.data.index,
- i = getApp().core.getStorageSync(getApp().const.INPUT_DATA);
- getApp().core.removeStorageSync(getApp().const.INPUT_DATA);
- var o = i.mch_list;
- o[a].picker_coupon = "-1" != e && -1 != e && this.data.coupon_list[e], i.show_coupon_picker = !1, i.mch_list = o, i.index = -1, this.setData(i), this.getPrice()
- },
- showShop: function (t) {
- var e = t.currentTarget.dataset.index;
- this.getInputData(), this.setData({
- index: e
- }), this.dingwei()
- },
- pickShop: function (t) {
- var e = t.currentTarget.dataset.index,
- a = this.data.index,
- i = getApp().core.getStorageSync(getApp().const.INPUT_DATA),
- o = i.mch_list;
- o[a].shop = "-1" != e && -1 != e && this.data.shop_list[e], i.show_shop = !1, i.mch_list = o, i.index = -1, this.setData(i), this.getPrice()
- },
- integralSwitchChange: function (t) {
- 0 != t.detail.value ? this.setData({
- integral_radio: 1
- }) : this.setData({
- integral_radio: 2
- }), this.getPrice()
- },
- integration: function (t) {
- var e = this.data.integral.integration;
- getApp().core.showModal({
- title: "积分使用规则",
- content: e,
- showCancel: !1,
- confirmText: "我知道了",
- confirmColor: "#ff4544",
- success: function (t) {
- t.confirm
- }
- })
- },
- contains: function (t, e) {
- for (var a = t.length; a--;)
- if (t[a] == e) return a;
- return -1
- },
- getPrice: function () {
- var o = this,
- t = o.data.mch_list,
- e = o.data.integral_radio,
- a = (o.data.integral, 0),
- i = 0,
- s = {},
- n = 0;
- for (var r in t) {
- var c = t[r],
- p = (parseFloat(c.total_price), parseFloat(c.level_price)),
- d = t[r].goods_list;
- n = 0, c.picker_coupon && 0 < c.picker_coupon.sub_price && (1 == c.picker_coupon.appoint_type && null != c.picker_coupon.cat_id_list ? d.forEach(function (t, e, a) {
- for (var i in t.cat_id) {
- -1 != o.contains(c.picker_coupon.cat_id_list, t.cat_id[i]) && (n += parseFloat(t.level_price))
- }
- }) : 2 == c.picker_coupon.appoint_type && null != c.picker_coupon.goods_id_list && d.forEach(function (t, e, a) {
- -1 != o.contains(c.picker_coupon.goods_id_list, t.goods_id) && (n += parseFloat(t.level_price))
- }), c.picker_coupon.sub_price > n && 0 < n ? p -= parseFloat(n) : p -= c.picker_coupon.sub_price), c.integral && 0 < c.integral.forehead && 1 == e && (p -= parseFloat(c.integral.forehead)), p = 0 <= p ? p : 0, 0 == c.offline && (c.express_price && (p += c.express_price), c.offer_rule && 1 == c.offer_rule.is_allowed && (s = c.offer_rule), 1 == c.is_area && (i = 1)), a += parseFloat(p)
- }
- a = 0 <= a ? a : 0, o.setData({
- new_total_price: a.toFixed(2),
- offer_rule: s,
- is_area: i
- })
- },
- cardDel: function () {
- this.setData({
- show_card: !1
- }), getApp().core.redirectTo({
- url: "/pages/order/order?status=1"
- })
- },
- cardTo: function () {
- this.setData({
- show_card: !1
- }), getApp().core.redirectTo({
- url: "/pages/card/card"
- })
- },
- formInput: function (t) {
- var e = t.currentTarget.dataset.index,
- a = t.currentTarget.dataset.formId,
- i = this.data.mch_list,
- o = i[e].form,
- s = o.list;
- s[a].default = t.detail.value, o.list = s, this.setData({
- mch_list: i
- })
- },
- selectForm: function (t) {
- var e = this.data.mch_list,
- a = t.currentTarget.dataset.index,
- i = t.currentTarget.dataset.formId,
- o = t.currentTarget.dataset.k,
- s = e[a].form,
- n = s.list,
- r = n[i].default_list;
- if ("radio" == n[i].type) {
- for (var c in r) c == o ? r[o].is_selected = 1 : r[c].is_selected = 0;
- n[i].default_list = r
- }
- "checkbox" == n[i].type && (1 == r[o].is_selected ? r[o].is_selected = 0 : r[o].is_selected = 1, n[i].default_list = r), s.list = n, e[a].form = s, this.setData({
- mch_list: e
- })
- },
- showPayment: function () {
- this.setData({
- show_payment: !0
- })
- },
- payPicker: function (t) {
- var e = t.currentTarget.dataset.index;
- this.setData({
- payment: e,
- show_payment: !1
- })
- },
- payClose: function () {
- this.setData({
- show_payment: !1
- })
- },
- getInputData: function () {
- var t = this.data.mch_list,
- e = {
- integral_radio: this.data.integral_radio,
- payment: this.data.payment,
- mch_list: t
- };
- getApp().core.setStorageSync(getApp().const.INPUT_DATA, e)
- },
- onHide: function () {
- getApp().page.onHide(this);
- this.getInputData()
- },
- onUnload: function () {
- getApp().page.onUnload(this), getApp().core.removeStorageSync(getApp().const.INPUT_DATA)
- },
- uploadImg: function (t) {
- var e = this,
- a = t.currentTarget.dataset.index,
- i = t.currentTarget.dataset.formId,
- o = e.data.mch_list,
- s = o[a].form;
- is_loading_show = !0, getApp().uploader.upload({
- start: function () {
- getApp().core.showLoading({
- title: "正在上传",
- mask: !0
- })
- },
- success: function (t) {
- 0 == t.code ? (s.list[i].default = t.data.url, e.setData({
- mch_list: o
- })) : e.showToast({
- title: t.msg
- })
- },
- error: function (t) {
- e.showToast({
- title: t
- })
- },
- complete: function () {
- getApp().core.hideLoading()
- }
- })
- },
- goToAddress: function () {
- is_loading_show = !1, getApp().core.navigateTo({
- url: "/pages/address-picker/address-picker"
- })
- },
- showMore: function (t) {
- var e = this.data.mch_list,
- a = t.currentTarget.dataset.index;
- e[a].show = !e[a].show, this.setData({
- mch_list: e
- })
- }
- });
|