new-order-submit.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. var app = getApp(),
  2. api = getApp().api,
  3. longitude = "",
  4. latitude = "",
  5. util = getApp().helper,
  6. is_loading_show = !1;
  7. Page({
  8. data: {
  9. total_price: 0,
  10. address: null,
  11. express_price: 0,
  12. express_price_1: 0,
  13. integral_radio: 1,
  14. new_total_price: 0,
  15. show_card: !1,
  16. payment: 3,
  17. show_payment: !1,
  18. show_more: !1,
  19. index: -1,
  20. mch_offline: !0,
  21. is_virtual: 0, //虚拟商品
  22. phone: '' //虚拟商品手机号
  23. },
  24. onLoad: function (t) {
  25. getApp().page.onLoad(this, t);
  26. var e = util.formatData(new Date);
  27. getApp().core.removeStorageSync(getApp().const.INPUT_DATA), this.setData({
  28. options: t,
  29. time: e
  30. }), is_loading_show = !1
  31. },
  32. bindContentInput: function (t) {
  33. this.data.mch_list[t.currentTarget.dataset.index].content = t.detail.value,
  34. this.setData({
  35. mch_list: this.data.mch_list
  36. })
  37. },
  38. // 虚拟商品电话
  39. bindMobileInput: function (t) {
  40. // console.log(t.detail.value)
  41. // console.log(t.currentTarget.dataset.index)
  42. // this.data.phone = t.detail.value,
  43. this.setData({
  44. phone: t.detail.value
  45. })
  46. },
  47. KeyName: function (t) {
  48. var e = this.data.mch_list;
  49. e[t.currentTarget.dataset.index].offline_name = t.detail.value, this.setData({
  50. mch_list: e
  51. })
  52. },
  53. KeyMobile: function (t) {
  54. var e = this.data.mch_list;
  55. e[t.currentTarget.dataset.index].offline_mobile = t.detail.value, this.setData({
  56. mch_list: e
  57. })
  58. },
  59. getOffline: function (t) {
  60. var e = this,
  61. a = t.currentTarget.dataset.offline,
  62. i = t.currentTarget.dataset.index,
  63. o = e.data.mch_list;
  64. o[i].offline = a, e.setData({
  65. mch_list: o
  66. }), 1 == o.length && 0 == o[0].mch_id && 1 == o[0].offline ? e.setData({
  67. mch_offline: !1
  68. }) : e.setData({
  69. mch_offline: !0
  70. }), e.getPrice()
  71. },
  72. dingwei: function () {
  73. var e = this;
  74. getApp().getauth({
  75. content: "需要获取您的地理位置授权,请到小程序设置中打开授权",
  76. author: "scope.userLocation",
  77. success: function (t) {
  78. t && (t.authSetting["scope.userLocation"] ? getApp().core.chooseLocation({
  79. success: function (t) {
  80. longitude = t.longitude, latitude = t.latitude, e.setData({
  81. location: t.address
  82. }), e.getOrderData(e.data.options)
  83. }
  84. }) : getApp().core.showToast({
  85. title: "您取消了授权",
  86. image: "/images/icon-warning.png"
  87. }))
  88. }
  89. })
  90. },
  91. orderSubmit: function (t) {
  92. var e = this,
  93. a = {},
  94. i = e.data.mch_list;
  95. console.log("data中的mch_list",i)
  96. for (var o in i) {
  97. var s = i[o].form;
  98. if (s && 1 == s.is_form && 0 == i[o].mch_id) {
  99. var n = s.list;
  100. for (var r in n)
  101. if (1 == n[r].required)
  102. if ("radio" == n[r].type || "checkbox" == n[r].type) {
  103. var c = !1;
  104. for (var p in n[r].default_list) 1 == n[r].default_list[p].is_selected && (c = !0);
  105. if (!c) return getApp().core.showModal({
  106. title: "提示",
  107. content: "请填写" + s.name + ",加‘*’为必填项",
  108. showCancel: !1
  109. }), !1
  110. } else if (!n[r].default || null == n[r].default)
  111. return getApp().core.showModal({
  112. title: "提示",
  113. content: "请填写" + s.name + ",加‘*’为必填项",
  114. showCancel: !1
  115. }), !1
  116. }
  117. if (1 == i.length && 0 == i[o].mch_id && 1 == i[o].offline);
  118. else {
  119. if(e.data.is_virtual == 0){
  120. if (!e.data.address)
  121. return getApp().core.showModal({
  122. title: "提示",
  123. content: "请选择收货地址",
  124. showCancel: !1
  125. }), !1;
  126. a.address_id = e.data.address.id
  127. }
  128. }
  129. }
  130. if(e.data.is_virtual == 1){
  131. if(e.data.phone == '' || e.data.phone == null){
  132. return getApp().core.showModal({
  133. title: "提示",
  134. content: "请填写电话号码",
  135. showCancel: !1
  136. }), !1;
  137. }
  138. }
  139. if (a.mch_list = JSON.stringify(i), 0 < e.data.pond_id) {
  140. if (0 < e.data.express_price && -1 == e.data.payment) return e.setData({
  141. show_payment: !0
  142. }), !1
  143. } else if (-1 == e.data.payment) return e.setData({
  144. show_payment: !0
  145. }), !1;
  146. 1 == e.data.integral_radio ? a.use_integral = 1 : a.use_integral = 2,
  147. a.payment = e.data.payment,
  148. a.phone = e.data.phone
  149. a.formId = t.detail.formId,
  150. e.order_submit(a, "s")
  151. },
  152. onReady: function () {},
  153. onShow: function (t) {
  154. if (!is_loading_show) {
  155. is_loading_show = !0, getApp().page.onShow(this);
  156. var e = this,
  157. a = getApp().core.getStorageSync(getApp().const.PICKER_ADDRESS);
  158. console.log('传过来的address地址信息',a)
  159. a && e.setData({
  160. address: a
  161. }),
  162. getApp().core.removeStorageSync(getApp().const.PICKER_ADDRESS), e.getOrderData(e.data.options)
  163. }
  164. },
  165. getOrderData: function (t) {
  166. var _ = this,
  167. e = {},
  168. a = "";
  169. _.data.address && _.data.address.id && (a = _.data.address.id),
  170. e.address_id = a,
  171. e.longitude = longitude,
  172. e.latitude = latitude, getApp().core.showLoading({
  173. title: "正在加载",
  174. mask: !0
  175. }), e.mch_list = t.mch_list,
  176. console.log('t.mch_list',t.mch_list)
  177. getApp().request({
  178. url: getApp().api.order.new_submit_preview,
  179. method: "POST",
  180. data: e,
  181. success: function (t) {
  182. if (getApp().core.hideLoading(), 0 == t.code) {
  183. if(t.data.is_virtual){
  184. _.setData({
  185. is_virtual: t.data.is_virtual
  186. })
  187. }
  188. var e = getApp().core.getStorageSync(getApp().const.INPUT_DATA),
  189. a = t.data,
  190. i = -1,
  191. o = 1,
  192. s = a.mch_list,
  193. n = [];
  194. for (var r in e && (n = e.mch_list, i = e.payment, o = e.integral_radio), a.integral_radio = o, a.pay_type_list) {
  195. if (i == a.pay_type_list[r].payment) {
  196. a.payment = i;
  197. break
  198. }
  199. if (1 == a.pay_type_list.length) {
  200. a.payment = a.pay_type_list[r].payment;
  201. break
  202. }
  203. }
  204. for (var r in s) {
  205. var c = {},
  206. p = {};
  207. if (s[r].show = !1, s[r].show_length = s[r].goods_list.length - 1, 0 != n.length)
  208. for (var d in n)
  209. 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);
  210. for (var d in s[r].shop_list) {
  211. if (c && c.id == s[r].shop_list[d].id) {
  212. s[r].shop = c;
  213. break
  214. }
  215. if (1 == s[r].shop_list.length) {
  216. s[r].shop = s[r].shop_list[d];
  217. break
  218. }
  219. if (1 == s[r].shop_list[d].is_default) {
  220. s[r].shop = s[r].shop_list[d];
  221. break
  222. }
  223. }
  224. if (p)
  225. for (var d in s[r].coupon_list)
  226. if (p.id == s[r].coupon_list[d].id) {
  227. s[r].picker_coupon = p;
  228. break
  229. }
  230. s[r].send_type && 2 == s[r].send_type ? (s[r].offline = 1, _.setData({
  231. mch_offline: !1
  232. })) : s[r].offline = 0
  233. }
  234. a.mch_list = s;
  235. var l = _.data.index; - 1 != l && s[l].shop_list && 0 < s[l].shop_list.length && _.setData({
  236. show_shop: !0,
  237. shop_list: s[l].shop_list
  238. }), _.setData(a), _.getPrice()
  239. }
  240. 1 == t.code && getApp().core.showModal({
  241. title: "提示",
  242. content: t.msg,
  243. showCancel: !1,
  244. confirmText: "返回",
  245. success: function (t) {
  246. t.confirm && getApp().core.navigateBack({
  247. delta: 1
  248. })
  249. }
  250. })
  251. }
  252. })
  253. },
  254. showCouponPicker: function (t) {
  255. var e = t.currentTarget.dataset.index,
  256. a = this.data.mch_list;
  257. this.getInputData(), a[e].coupon_list && 0 < a[e].coupon_list.length && this.setData({
  258. show_coupon_picker: !0,
  259. coupon_list: a[e].coupon_list,
  260. index: e
  261. })
  262. },
  263. pickCoupon: function (t) {
  264. var e = t.currentTarget.dataset.index,
  265. a = this.data.index,
  266. i = getApp().core.getStorageSync(getApp().const.INPUT_DATA);
  267. getApp().core.removeStorageSync(getApp().const.INPUT_DATA);
  268. var o = i.mch_list;
  269. 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()
  270. },
  271. showShop: function (t) {
  272. var e = t.currentTarget.dataset.index;
  273. this.getInputData(), this.setData({
  274. index: e
  275. }), this.dingwei()
  276. },
  277. pickShop: function (t) {
  278. var e = t.currentTarget.dataset.index,
  279. a = this.data.index,
  280. i = getApp().core.getStorageSync(getApp().const.INPUT_DATA),
  281. o = i.mch_list;
  282. 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()
  283. },
  284. integralSwitchChange: function (t) {
  285. 0 != t.detail.value ? this.setData({
  286. integral_radio: 1
  287. }) : this.setData({
  288. integral_radio: 2
  289. }), this.getPrice()
  290. },
  291. integration: function (t) {
  292. var e = this.data.integral.integration;
  293. getApp().core.showModal({
  294. title: "积分使用规则",
  295. content: e,
  296. showCancel: !1,
  297. confirmText: "我知道了",
  298. confirmColor: "#ff4544",
  299. success: function (t) {
  300. t.confirm
  301. }
  302. })
  303. },
  304. contains: function (t, e) {
  305. for (var a = t.length; a--;)
  306. if (t[a] == e) return a;
  307. return -1
  308. },
  309. getPrice: function () {
  310. var o = this,
  311. t = o.data.mch_list,
  312. e = o.data.integral_radio,
  313. a = (o.data.integral, 0),
  314. i = 0,
  315. s = {},
  316. n = 0;
  317. for (var r in t) {
  318. var c = t[r],
  319. p = (parseFloat(c.total_price), parseFloat(c.level_price)),
  320. d = t[r].goods_list;
  321. 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) {
  322. for (var i in t.cat_id) {
  323. -1 != o.contains(c.picker_coupon.cat_id_list, t.cat_id[i]) && (n += parseFloat(t.level_price))
  324. }
  325. }) : 2 == c.picker_coupon.appoint_type && null != c.picker_coupon.goods_id_list && d.forEach(function (t, e, a) {
  326. -1 != o.contains(c.picker_coupon.goods_id_list, t.goods_id) && (n += parseFloat(t.level_price))
  327. }), 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)
  328. }
  329. a = 0 <= a ? a : 0, o.setData({
  330. new_total_price: a.toFixed(2),
  331. offer_rule: s,
  332. is_area: i
  333. })
  334. },
  335. cardDel: function () {
  336. this.setData({
  337. show_card: !1
  338. }), getApp().core.redirectTo({
  339. url: "/pages/order/order?status=1"
  340. })
  341. },
  342. cardTo: function () {
  343. this.setData({
  344. show_card: !1
  345. }), getApp().core.redirectTo({
  346. url: "/pages/card/card"
  347. })
  348. },
  349. formInput: function (t) {
  350. var e = t.currentTarget.dataset.index,
  351. a = t.currentTarget.dataset.formId,
  352. i = this.data.mch_list,
  353. o = i[e].form,
  354. s = o.list;
  355. s[a].default = t.detail.value, o.list = s, this.setData({
  356. mch_list: i
  357. })
  358. },
  359. selectForm: function (t) {
  360. var e = this.data.mch_list,
  361. a = t.currentTarget.dataset.index,
  362. i = t.currentTarget.dataset.formId,
  363. o = t.currentTarget.dataset.k,
  364. s = e[a].form,
  365. n = s.list,
  366. r = n[i].default_list;
  367. if ("radio" == n[i].type) {
  368. for (var c in r) c == o ? r[o].is_selected = 1 : r[c].is_selected = 0;
  369. n[i].default_list = r
  370. }
  371. "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({
  372. mch_list: e
  373. })
  374. },
  375. showPayment: function () {
  376. this.setData({
  377. show_payment: !0
  378. })
  379. },
  380. payPicker: function (t) {
  381. var e = t.currentTarget.dataset.index;
  382. this.setData({
  383. payment: e,
  384. show_payment: !1
  385. })
  386. },
  387. payClose: function () {
  388. this.setData({
  389. show_payment: !1
  390. })
  391. },
  392. getInputData: function () {
  393. var t = this.data.mch_list,
  394. e = {
  395. integral_radio: this.data.integral_radio,
  396. payment: this.data.payment,
  397. mch_list: t
  398. };
  399. getApp().core.setStorageSync(getApp().const.INPUT_DATA, e)
  400. },
  401. onHide: function () {
  402. getApp().page.onHide(this);
  403. this.getInputData()
  404. },
  405. onUnload: function () {
  406. getApp().page.onUnload(this), getApp().core.removeStorageSync(getApp().const.INPUT_DATA)
  407. },
  408. uploadImg: function (t) {
  409. var e = this,
  410. a = t.currentTarget.dataset.index,
  411. i = t.currentTarget.dataset.formId,
  412. o = e.data.mch_list,
  413. s = o[a].form;
  414. is_loading_show = !0, getApp().uploader.upload({
  415. start: function () {
  416. getApp().core.showLoading({
  417. title: "正在上传",
  418. mask: !0
  419. })
  420. },
  421. success: function (t) {
  422. 0 == t.code ? (s.list[i].default = t.data.url, e.setData({
  423. mch_list: o
  424. })) : e.showToast({
  425. title: t.msg
  426. })
  427. },
  428. error: function (t) {
  429. e.showToast({
  430. title: t
  431. })
  432. },
  433. complete: function () {
  434. getApp().core.hideLoading()
  435. }
  436. })
  437. },
  438. goToAddress: function () {
  439. is_loading_show = !1, getApp().core.navigateTo({
  440. url: "/pages/address-picker/address-picker"
  441. })
  442. },
  443. showMore: function (t) {
  444. var e = this.data.mch_list,
  445. a = t.currentTarget.dataset.index;
  446. e[a].show = !e[a].show, this.setData({
  447. mch_list: e
  448. })
  449. }
  450. });