index.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. const Parse = getApp().Parse
  2. const company = getApp().globalData.company
  3. const dateF = require('../../../utils/date')
  4. const req = require('../../utils/request')
  5. const colorChange = require("../../utils/color");
  6. // const activeColor=getApp().globalData.activeColor
  7. let {
  8. statusBarHeight
  9. } = wx.getSystemInfoSync();
  10. statusBarHeight = Math.abs(statusBarHeight)
  11. let custom = wx.getMenuButtonBoundingClientRect();
  12. let customBarHeight = custom.bottom + custom.top - statusBarHeight;
  13. customBarHeight = Math.abs(customBarHeight)
  14. Page({
  15. data: {
  16. status: 1,
  17. active: null,
  18. activeColor: null,
  19. goodsList: [],
  20. currentGoods: null,
  21. type: null, // 订单类型
  22. themeColor: '',
  23. themeRGB: [],
  24. customBarHeight,
  25. },
  26. onChange(e) {
  27. console.log(e)
  28. console.log(e.detail)
  29. let {
  30. index
  31. } = e.detail
  32. this.setData({
  33. active: index
  34. })
  35. console.log(index, e.detail)
  36. let switchFn = {
  37. '0': 0,
  38. '1': 100,
  39. '2': 200,
  40. '3': 300,
  41. '4': 400
  42. }
  43. this.setData({
  44. goodsList:[]
  45. })
  46. this.queryShopOrder(switchFn[index])
  47. },
  48. //删除
  49. delOrder(e) {
  50. console.log(e);
  51. let {
  52. index
  53. } = e.currentTarget.dataset
  54. let {
  55. goodsList
  56. } = this.data
  57. let _this = this
  58. wx.showModal({
  59. title: '',
  60. content: '你确定删除该订单吗?',
  61. showCancel: true,
  62. cancelText: '取消',
  63. cancelColor: '#000000',
  64. confirmText: '确定',
  65. confirmColor: '#3CC51F',
  66. success: async (result) => {
  67. if (result.confirm) {
  68. await this.upDel(goodsList[index].objectId)
  69. goodsList.splice(index, 1)
  70. _this.setData({
  71. goodsList
  72. })
  73. wx.showToast({
  74. title: '已取消',
  75. icon: 'none',
  76. image: '',
  77. duration: 1500,
  78. });
  79. }
  80. },
  81. fail: () => { },
  82. complete: () => { }
  83. });
  84. },
  85. async upDel(id) {
  86. let ShopOrder = new Parse.Query('Order')
  87. let order = await ShopOrder.get(id)
  88. if (order && order.id) {
  89. console.log(order);
  90. await order.destroy()
  91. }
  92. },
  93. // 查看物流
  94. onShowExpress(e) {
  95. let { item } = e.currentTarget.dataset
  96. console.log(item)
  97. if (item?.trackingNumber) {
  98. let url = `/common-page/pages/nova-express/index?num=${item.trackingNumber}&com=${item.expressCompany && item.expressCompany.code}`
  99. wx.navigateTo({
  100. url: url,
  101. });
  102. return
  103. }
  104. wx.showToast({
  105. title: '暂无物流信息',
  106. icon: 'error',
  107. image: '',
  108. duration: 1500,
  109. mask: false,
  110. });
  111. },
  112. //确认收货
  113. receipt(e) {
  114. console.log(e);
  115. let {
  116. index
  117. } = e.currentTarget.dataset
  118. let {
  119. goodsList
  120. } = this.data
  121. let _this = this
  122. wx.showModal({
  123. title: '',
  124. content: '是否确认收货',
  125. showCancel: true,
  126. cancelText: '取消',
  127. cancelColor: '#000000',
  128. confirmText: '确定',
  129. confirmColor: '#3CC51F',
  130. success: async (result) => {
  131. if (result.confirm) {
  132. await _this.upOk(goodsList[index].objectId)
  133. wx.showToast({
  134. title: '已收货',
  135. icon: 'none',
  136. image: '',
  137. duration: 1500,
  138. });
  139. }
  140. },
  141. fail: () => { },
  142. complete: () => { }
  143. });
  144. },
  145. async upOk(id) {
  146. let {
  147. active
  148. } = this.data
  149. let ShopOrder = new Parse.Query('Order')
  150. let order = await ShopOrder.get(id)
  151. if (order && order.id) {
  152. order.set("status", '400')
  153. await order.save()
  154. let e = {
  155. detail: active
  156. }
  157. this.onChange(e)
  158. }
  159. },
  160. toUrl(e) {
  161. let {
  162. url
  163. } = e.currentTarget.dataset
  164. wx.navigateTo({
  165. url: url,
  166. });
  167. },
  168. /**
  169. * 生命周期函数--监听页面加载
  170. */
  171. onLoad:async function (options) {
  172. //测试数据
  173. console.log(getApp().globalData.activeColor);
  174. let status = options.status ? Number(options.status) : 0
  175. let type = options.type;
  176. let themeColor = options.themeColor || getApp().globalData.activeColor;
  177. let titleColor = getApp().globalData.titleColor;
  178. console.log(status, 11111)
  179. this.setData({
  180. status: status,
  181. type,
  182. themeColor,
  183. titleColor
  184. })
  185. console.log(titleColor);
  186. themeColor && this.changeTheme()
  187. let switchFn = {
  188. '100': 1,
  189. '200': 2,
  190. '300': 3,
  191. '400': 4
  192. }
  193. let active = switchFn[status] ? switchFn[status] : 0
  194. await this.queryShopOrder(status)
  195. this.setData({
  196. active: active
  197. })
  198. },
  199. async reqSql() {
  200. let user = Parse.User.current().id
  201. let type = this.data.type;
  202. let sql = `select sr."objectId",sr.name,sr.price,sr.count,sr."createdAt",sr.status,
  203. gd.desc,gd.image
  204. from "ShopOrder" as sr
  205. join "ShopGoods" as gd
  206. on gd."objectId" = sr."goods"
  207. where sr.user = '${user}' and sr.type = '${type}'
  208. and (sr.status = 400 or sr.status = 800)`
  209. let res = await req.customSQL(sql)
  210. console.log(res);
  211. let goodsList = res.reduce((total, item) => {
  212. item.orderTime = dateF.formatTime("YYYY-mm-dd HH:MM:SS", item.createdAt)
  213. total.push(item)
  214. return total
  215. }, [])
  216. this.setData({
  217. goodsList: goodsList
  218. })
  219. },
  220. async queryShopOrder(status) {
  221. let user = Parse.User.current()
  222. let type = this.data.type;
  223. let ShopOrder = new Parse.Query('Order')
  224. ShopOrder.equalTo('company', company)
  225. ShopOrder.equalTo('user', user.id)
  226. ShopOrder.equalTo('type', 'goods')
  227. ShopOrder.include('targetObject')
  228. ShopOrder.descending('createdAt')
  229. ShopOrder.limit(6)
  230. ShopOrder.skip(this.data.goodsList.length)
  231. if (status != 0 && status) {
  232. ShopOrder.equalTo('status', String(status))
  233. }
  234. if (type) {
  235. ShopOrder.equalTo('type', type)
  236. }
  237. let orders = await ShopOrder.find()
  238. if (orders && orders.length > 0) {
  239. let orderJSON = this.data.goodsList ? this.data.goodsList : []
  240. orders.forEach(order => {
  241. let orderObj = order.toJSON()
  242. orderObj.orderTime = dateF.formatTime("YYYY-mm-dd HH:MM:SS", orderObj.createdAt)
  243. orderJSON.push(orderObj)
  244. })
  245. this.setData({
  246. goodsList: orderJSON
  247. })
  248. console.log(this.data.goodsList)
  249. } else {
  250. let orderJSON = this.data.goodsList ? this.data.goodsList : []
  251. this.setData({
  252. goodsList: orderJSON
  253. })
  254. }
  255. },
  256. showPay(e) {
  257. let item = e.currentTarget.dataset.item
  258. let id = item.objectId
  259. console.log(id);
  260. let specMap = e.currentTarget.dataset.specMap ? e.currentTarget.dataset.specMap : null
  261. wx.navigateTo({
  262. url: `/nova-shop/pages/shop-goods/pay/index?id=${id}&specMap=${specMap}&count=${item.count}`
  263. });
  264. },
  265. //支付
  266. async acceptResult(e) {
  267. let that = this
  268. let {
  269. params,
  270. no
  271. } = e.detail;
  272. that.setData({
  273. show: false
  274. })
  275. try {
  276. if (params == "ok") {
  277. wx.showLoading({
  278. title: "处理中",
  279. mask: true
  280. });
  281. let shopOrder = new Parse.Query("Order")
  282. let isOrder = await shopOrder.get(this.data.PayId)
  283. if (isOrder && isOrder.id) {
  284. isOrder.set('isPay', true)
  285. isOrder.set('status', '200')
  286. let order = await isOrder.save()
  287. if (order && order.id) {
  288. wx.hideLoading();
  289. wx.showToast({
  290. title: "支付成功",
  291. icon: "success",
  292. duration: 1500,
  293. });
  294. // 存储云仓
  295. if (order.get('giftList') && order.get('giftList').length > 0) {
  296. order.get('giftList').forEach(li => {
  297. if (li.type == 'stock') {
  298. that.creatShopStock(li, order.id)
  299. }
  300. if (li.type == 'agentlevel') {
  301. that.updateUserAgent(li)
  302. }
  303. })
  304. }
  305. // 更换经销商等级
  306. wx.navigateTo({
  307. url: "/nova-zhiliang/pages/my/myOrder/index",
  308. });
  309. } else {
  310. wx.showToast({
  311. title: "支付成功, 订单状态修改失败,请联系客服",
  312. icon: "error",
  313. duration: 1500,
  314. });
  315. }
  316. }
  317. } else {
  318. wx.hideLoading();
  319. this.setData({
  320. show: false
  321. })
  322. }
  323. } catch (error) {
  324. wx.showToast({
  325. title: "支付失败",
  326. icon: "error",
  327. duration: 1500,
  328. });
  329. wx.hideLoading()
  330. }
  331. },
  332. //修改地址
  333. modify(e) {
  334. console.log(e)
  335. let id = e.currentTarget.dataset.item.objectId
  336. wx.navigateTo({
  337. url: "/nova-zhiliang/pages/my/myOrder/order-detail/index?id=" + id
  338. })
  339. },
  340. //催单
  341. reminder() {
  342. wx.showToast({
  343. title: '催单成功',
  344. icon: 'success',
  345. duration: 2000,
  346. });
  347. },
  348. //查看物流
  349. logistics(e) {
  350. let {
  351. item
  352. } = e.currentTarget.dataset
  353. console.log(item);
  354. this.setData({
  355. showExpress: true,
  356. express: item.express
  357. })
  358. },
  359. /**
  360. * 生命周期函数--监听页面初次渲染完成
  361. */
  362. onReady: function () {
  363. },
  364. changeTheme() {
  365. let themeColor = this.data.themeColor;
  366. console.log(themeColor);
  367. let colorRgb = colorChange.hexToRgb(themeColor); // 十六进制转rgb
  368. console.log(colorRgb);
  369. let {
  370. r,
  371. g,
  372. b
  373. } = colorRgb;
  374. this.setData({
  375. themeRGB: [r, g, b]
  376. })
  377. },
  378. /**
  379. * 生命周期函数--监听页面显示
  380. */
  381. onShow: function () {
  382. },
  383. /**
  384. * 生命周期函数--监听页面隐藏
  385. */
  386. onHide: function () {
  387. },
  388. /**
  389. * 生命周期函数--监听页面卸载
  390. */
  391. onUnload: function () {
  392. },
  393. /**
  394. * 页面相关事件处理函数--监听用户下拉动作
  395. */
  396. onPullDownRefresh: function () {
  397. },
  398. /**
  399. * 页面上拉触底事件的处理函数
  400. */
  401. onReachBottom: function () {
  402. let switchFn = {
  403. '0': 0,
  404. '1': 100,
  405. '2': 200,
  406. '3': 300,
  407. '4': 400
  408. }
  409. let active = this.data.active
  410. console.log(111)
  411. this.queryShopOrder(switchFn[active])
  412. },
  413. /**
  414. * 用户点击右上角分享
  415. */
  416. onShareAppMessage: function () {
  417. }
  418. })