index.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. import * as API_Order from '../../api/order.js'
  5. import * as Common from '../../utils/common.js'
  6. import * as API_Logistic from '../../api/logistic'
  7. import {
  8. $wuxToptips,
  9. $wuxToast,
  10. $wuxLoading,
  11. $wuxDialog
  12. } from '../../wux/index.js'
  13. Page({
  14. data: {
  15. pageParam: {
  16. page_size: 10,
  17. page_no: 1,
  18. order_status: 'WAIT_SHIP'
  19. },
  20. finished: false,
  21. orderList: [],
  22. loading:true,
  23. logistics:[],
  24. shippingShow:false,
  25. shippingModeShow:false,
  26. selectLogi:null,
  27. ship_no:'',
  28. ship_out_sn:''
  29. },
  30. onLoad: function() {
  31. const bool_o2o=app.globalData.authorInfo.boolO2o
  32. if(bool_o2o===0){
  33. wx.redirectTo({
  34. url:'/pages/noshop/index'
  35. })
  36. }
  37. this.getLogisticCompany()
  38. },
  39. /**
  40. * 页面相关事件处理函数--监听用户下拉动作
  41. */
  42. onPullDownRefresh: function() {
  43. //wx.startPullDownRefresh()
  44. wx.showNavigationBarLoading()
  45. this.setData({
  46. ['pageParam.page_no']: 1,
  47. finished: false,
  48. })
  49. this.getOrderData().then(res => {
  50. wx.hideNavigationBarLoading()
  51. wx.stopPullDownRefresh()
  52. })
  53. },
  54. /**
  55. * 页面上拉触底事件的处理函数
  56. */
  57. onReachBottom: function() {
  58. if (!this.data.finished) {
  59. this.setData({
  60. ['pageParam.page_no']: this.data.pageParam.page_no + 1
  61. })
  62. this.getOrderData()
  63. }
  64. },
  65. /** 显示底部导航 */
  66. onShow() {
  67. //下拉刷新时,可能用户未登录,再返回此页时顶部会一直显示加载状态,这里首先隐藏加载状态
  68. wx.hideNavigationBarLoading()
  69. this.setData({
  70. ['pageParam.page_no']: 1,
  71. finished: false
  72. })
  73. this.getOrderData()
  74. Common.getCurrentShopData().then(res => {
  75. this.getTabBar().init()
  76. })
  77. },
  78. onChange(event) {
  79. this.setData({
  80. activeNames: event.detail
  81. });
  82. },
  83. getOrderData() {
  84. return new Promise((resolve, reject) => {
  85. let that = this
  86. const authorInfo=app.globalData.authorInfo
  87. if(authorInfo===null||authorInfo===''){ //授权信息不存,不发起请求
  88. return
  89. }
  90. if (authorInfo.boolO2o===0){ //非o2o店铺 不发起请求
  91. return
  92. }
  93. $wuxLoading().show({
  94. text: '加载中...',
  95. })
  96. API_Order.getOrderList(that.data.pageParam).then(res => {
  97. const {
  98. data
  99. } = res
  100. let orders = []
  101. if (that.data.orderList.length === 0 ||that.data.pageParam.page_no===1) {
  102. orders = [...data]
  103. } else {
  104. orders = that.data.orderList
  105. orders.push(...data)
  106. }
  107. if (data.length < 10) {
  108. that.setData({
  109. finished: true
  110. })
  111. }
  112. that.setData({
  113. orderList: orders,
  114. loading:false
  115. })
  116. $wuxLoading().hide()
  117. resolve(res)
  118. }).catch(e => {
  119. $wuxToptips().error({
  120. icon: 'cancel',
  121. hidden: false,
  122. text: e?e.error:e.message,
  123. duration: 3000
  124. })
  125. that.setData({loading:false})
  126. //reject()
  127. })
  128. })
  129. },
  130. delivery(e) {
  131. const {
  132. sn
  133. } = e.currentTarget.dataset
  134. const that = this
  135. // const order=that.data.orderList.find(p=>p.sn===sn)
  136. that.setData({
  137. shippingShow:true,
  138. ship_out_sn:sn
  139. })
  140. // $wuxDialog().confirm({
  141. // resetOnClose: true,
  142. // closable: true,
  143. // title: '操作提示',
  144. // content: '该订单需线下配送,确认发货?',
  145. // onConfirm(e) {
  146. // API_Order.deliveryGoods(sn, {
  147. // 'ship_no': '线下配送',
  148. // 'logi_id': 0,
  149. // 'logi_name': '线下配送'
  150. // }).then(res => {
  151. // if (res === '') {
  152. // $wuxToptips().success({
  153. // hidden: false,
  154. // text: '发货成功',
  155. // duration: 3000,
  156. // success: () => {
  157. // that.setData({
  158. // ['pageParam.page_no']: 1,
  159. // finished: false,
  160. // orderList: []
  161. // })
  162. // that.getOrderData()
  163. // Common.getCurrentShopData().then(response => {
  164. // that.getTabBar().init()
  165. // })
  166. //
  167. // }
  168. // })
  169. //
  170. //
  171. // } else {
  172. // $wuxToptips().error({
  173. // icon: 'cancel',
  174. // hidden: false,
  175. // text: res.message,
  176. // duration: 3000
  177. // })
  178. // }
  179. // }).catch(error => {
  180. // $wuxToptips().error({
  181. // icon: 'cancel',
  182. // hidden: false,
  183. // text: error.message,
  184. // duration: 3000
  185. // })
  186. // })
  187. // },
  188. // onCancel(e) {
  189. //
  190. // },
  191. // })
  192. },
  193. shipout(){
  194. let that = this
  195. if(!that.data.selectLogi){
  196. $wuxToptips().error({
  197. icon: 'cancel',
  198. hidden: false,
  199. text: '请选择快递公司',
  200. duration: 3000
  201. })
  202. return
  203. }
  204. const logi =that.data.logistics.find(p=>p.logi_id===that.data.selectLogi)
  205. if (logi.name === '无需物流') {
  206. that.data.ship_no = logi.name
  207. } else {
  208. if(!that.data.ship_no.trim()){
  209. $wuxToptips().error({
  210. icon: 'cancel',
  211. hidden: false,
  212. text: '请填写快递单号',
  213. duration: 3000
  214. })
  215. return
  216. }
  217. }
  218. API_Order.deliveryGoods(that.data.ship_out_sn, {
  219. 'ship_no': that.data.ship_no,
  220. 'logi_id': that.data.selectLogi,
  221. 'logi_name': logi.name
  222. }).then(res => {
  223. if (res === '') {
  224. $wuxToptips().success({
  225. hidden: false,
  226. text: '发货成功',
  227. duration: 3000,
  228. success: () => {
  229. that.setData({
  230. ['pageParam.page_no']: 1,
  231. finished: false,
  232. orderList: [],
  233. shippingShow:false,
  234. shippingModeShow:false
  235. })
  236. that.getOrderData()
  237. Common.getCurrentShopData().then(response => {
  238. that.getTabBar().init()
  239. })
  240. }
  241. })
  242. } else {
  243. $wuxToptips().error({
  244. icon: 'cancel',
  245. hidden: false,
  246. text: res.message,
  247. duration: 3000
  248. })
  249. }
  250. }).catch(error => {
  251. $wuxToptips().error({
  252. icon: 'cancel',
  253. hidden: false,
  254. text: error.message,
  255. duration: 3000
  256. })
  257. })
  258. },
  259. showShippingMode(){
  260. this.setData({
  261. shippingModeShow:true
  262. })
  263. },
  264. getLogisticCompany(){
  265. let that = this
  266. API_Logistic.getExpressCompanyList().then(res=>{
  267. that.setData({
  268. logistics:[...res]
  269. })
  270. })
  271. },
  272. onClose(){
  273. this.setData({
  274. shippingShow:false
  275. })
  276. },
  277. onClose2(){
  278. this.setData({
  279. shippingModeShow:false
  280. })
  281. },
  282. /** 物流公司信息开启 /关闭 */
  283. switchLogisState(e){
  284. const {logi_id}=e.currentTarget.dataset
  285. let row=this.data.logistics.find(p=>p.logi_id===logi_id)
  286. const _tip = (row.shop_id ? '关闭' : '开启')+row.name
  287. let that = this
  288. wx.showModal({
  289. title: '提示',
  290. content: _tip,
  291. success (res) {
  292. if (res.confirm) {
  293. if(row.shop_id){
  294. that.closeLogistics(row.logi_id)
  295. }else{
  296. that.openLogistics(row.logi_id)
  297. }
  298. } else if (res.cancel) {
  299. }
  300. }
  301. })
  302. },
  303. /** 执行关闭 */
  304. closeLogistics(logi_id) {
  305. let that = this
  306. API_Logistic.closeExpressPower(logi_id, {}).then(response => {
  307. wx.showToast({
  308. title: '关闭成功',
  309. })
  310. that.getLogisticCompany()
  311. })
  312. },
  313. /** 执行开启 */
  314. openLogistics(logi_id) {
  315. let that = this
  316. API_Logistic.openExpressPower(logi_id, {}).then(response => {
  317. wx.showToast({
  318. title: '开启成功',
  319. })
  320. that.getLogisticCompany()
  321. })
  322. },
  323. radioClick(event){
  324. const { name } = event.currentTarget.dataset;
  325. this.setData({
  326. selectLogi: name,
  327. })
  328. },
  329. shipNoChange(e){
  330. this.setData({
  331. ship_no:e.detail
  332. })
  333. },
  334. scanShipNo(){
  335. let that =this
  336. wx.scanCode({
  337. success (res) {
  338. that.setData({
  339. ship_no:res.result
  340. })
  341. }
  342. })
  343. }
  344. })