order-submit.js 14 KB

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