businessVideoManage.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. const { getOrderList, postOrderDelete, postOrderDiffPay, postOrderCancel } = require('./api/index')
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. tabs: [
  8. {
  9. name: '全部',
  10. value: '0'
  11. },
  12. {
  13. name: '已发布',
  14. value: '1'
  15. },
  16. {
  17. name: '未发布',
  18. value: '2'
  19. }
  20. ],
  21. active: '0', // 顶部菜单栏默认选中,订单状态:(0全部1待支付2待出发3进行中4已结束)
  22. current: 0, // 轮播图默认选中
  23. pageSize: 20,
  24. originScrollViewData: [],
  25. booDeleteOrder: false,
  26. booLock: false,
  27. refresherThreshold: 60, // 自定义下拉刷新阈值
  28. booCancelOrder: false,
  29. booPayment: false,
  30. itemData: {} // 当前选中的订单
  31. },
  32. // 下拉刷新加锁
  33. freshing: false,
  34. timer: null,
  35. /**
  36. * 生命周期函数--监听页面加载
  37. */
  38. onLoad: function (options) {
  39. this.setOriginScrollViewData()
  40. },
  41. /**
  42. * 生命周期函数--监听页面初次渲染完成
  43. */
  44. onReady: function () {
  45. },
  46. /**
  47. * 生命周期函数--监听页面显示
  48. */
  49. onShow: function () {
  50. },
  51. /**
  52. * 生命周期函数--监听页面隐藏
  53. */
  54. onHide: function () {
  55. },
  56. /**
  57. * 生命周期函数--监听页面卸载
  58. */
  59. onUnload: function () {
  60. clearTimeout(this.timer)
  61. },
  62. bindCallBack() {
  63. this.onRefresh({ detail: { dy: this.data.refresherThreshold } })
  64. },
  65. jumpOrderDetail(e) {
  66. const { orderId } = e.currentTarget.dataset
  67. wx.navigateTo({
  68. url: '/pages/orderDetail/orderDetail?orderId=' + orderId
  69. })
  70. },
  71. setOriginScrollViewData() {
  72. const temp = []
  73. for (let i = 0; i < this.data.tabs.length; i++) {
  74. temp.push({
  75. finished: false, // 所有数据是否加载完
  76. isRefresh: false, // 是否下拉刷新
  77. isFetchLock: false, // 接口调用加锁
  78. pageNum: 0,
  79. list: [],
  80. scrollY: 0,
  81. isFirst: true // 是否首次获取列表
  82. })
  83. }
  84. this.setData({
  85. originScrollViewData: temp
  86. }, () => {
  87. // this.fetOrderList()
  88. })
  89. },
  90. changeTabs(e) {
  91. const value = e.currentTarget.dataset.value
  92. const index = this.data.tabs.findIndex(item => item.value === value)
  93. const temp = this.data.originScrollViewData[index]
  94. this.setData({
  95. active: value,
  96. current: index
  97. }, () => {
  98. if (temp.isFirst) {
  99. // this.fetOrderList()
  100. }
  101. })
  102. },
  103. handleSwiper(e) {
  104. const { current, source } = e.detail
  105. const item = this.data.tabs[current]
  106. if (source) {
  107. this.setData({
  108. active: item.value
  109. }, () => {
  110. const temp = this.data.originScrollViewData[current]
  111. if (temp.isFirst) {
  112. // this.fetOrderList()
  113. }
  114. })
  115. }
  116. },
  117. async fetOrderList() {
  118. const that = this
  119. const _tab = that.data.tabs.findIndex(item => item.value === that.data.active)
  120. const temp = that.data.originScrollViewData[_tab]
  121. if (Object.prototype.toString.call(temp) !== '[object Object]') {
  122. return
  123. }
  124. if (temp.finished) {
  125. return
  126. }
  127. if (temp.isFetchLock) {
  128. return
  129. }
  130. that.setData({
  131. ['originScrollViewData[' + _tab + '].isFetchLock']: true,
  132. ['originScrollViewData[' + _tab + '].pageNum']: temp.pageNum + 1
  133. })
  134. try {
  135. const { status, data, msg } = await getOrderList({
  136. pageNum: that.data.originScrollViewData[_tab].pageNum,
  137. pageSize: that.data.pageSize,
  138. type: that.data.tabs[_tab].value
  139. })
  140. if (status) {
  141. const { list } = data
  142. if (Array.isArray(list)) {
  143. const arr = list.map(item => {
  144. return {
  145. ...item,
  146. created_at: item.created_at.replace(/(.*)(:\d{2})/, '$1')
  147. }
  148. })
  149. const _list = temp.isRefresh
  150. ? [].concat(arr)
  151. : that.data.originScrollViewData[_tab].list.concat(arr)
  152. that.setData({
  153. ['originScrollViewData[' + _tab + '].list']: _list,
  154. ['originScrollViewData[' + _tab + '].finished']: list.length < 10,
  155. ['originScrollViewData[' + _tab + '].isRefresh']: false,
  156. ['originScrollViewData[' + _tab + '].isFetchLock']: false,
  157. ['originScrollViewData[' + _tab + '].isFirst']: false
  158. })
  159. }
  160. } else {
  161. wx.showToast({
  162. title: msg,
  163. icon: 'none'
  164. })
  165. }
  166. } catch (e) {}
  167. if (that.freshing) {
  168. that.freshing = false
  169. }
  170. },
  171. onRefresh(e) {
  172. const { dy } = e.detail
  173. if (dy < this.data.refresherThreshold || this.freshing) {
  174. return
  175. }
  176. const _tab = this.data.tabs.findIndex(item => item.value === this.data.active)
  177. this.freshing = true
  178. // 这里设置延时的目的:页面数据不足一屏时,更好的展示下拉刷新动画
  179. this.timer = setTimeout(() => {
  180. clearTimeout(this.timer)
  181. this.setData({
  182. ['originScrollViewData[' + _tab + '].pageNum']: 0,
  183. pageSize: 20,
  184. ['originScrollViewData[' + _tab + '].finished']: false,
  185. ['originScrollViewData[' + _tab + '].isRefresh']: true,
  186. ['originScrollViewData[' + _tab + '].isFetchLock']: false
  187. }, () => {
  188. // this.fetOrderList()
  189. })
  190. }, 1000)
  191. },
  192. showDeleteOrder(e) {
  193. const { item } = e.currentTarget.dataset
  194. this.setData({
  195. booDeleteOrder: true,
  196. itemData: item
  197. })
  198. },
  199. hideDeleteOrder() {
  200. this.setData({
  201. booDeleteOrder: false,
  202. itemData: {}
  203. })
  204. },
  205. async confirmDeleteOrder() {
  206. const { id } = this.data.itemData
  207. this.setData({
  208. booLock: true
  209. })
  210. try {
  211. const { status, msg } = await postOrderDelete(id)
  212. let _msg = ''
  213. if (status) {
  214. _msg = '订单删除成功'
  215. // 更新全部:去除各个列表中有相同id的
  216. const originScrollViewData = this.data.originScrollViewData
  217. for (let i = 0; i < originScrollViewData.length; i++) {
  218. const _list = originScrollViewData[i].list
  219. const _delIndex = _list.findIndex(item => item.id === id)
  220. if (_delIndex > -1) {
  221. _list.splice(_delIndex, 1)
  222. this.setData({
  223. ['originScrollViewData[' + i + '].list']: _list
  224. })
  225. }
  226. }
  227. this.hideDeleteOrder()
  228. } else {
  229. _msg = msg
  230. }
  231. wx.showToast({
  232. title: _msg,
  233. icon: 'none'
  234. })
  235. } catch (err) {}
  236. this.setData({
  237. booLock: false
  238. })
  239. },
  240. showPayment(e) {
  241. const { item } = e.currentTarget.dataset
  242. this.setData({
  243. itemData: item,
  244. booPayment: true
  245. })
  246. },
  247. hidePayment() {
  248. this.setData({
  249. booPayment: false,
  250. itemData: {}
  251. })
  252. },
  253. async handleOrderDiffPay() {
  254. const { order_number, id } = this.data.itemData
  255. this.setData({
  256. booLock: true
  257. })
  258. try {
  259. const { status, data, msg } = await postOrderDiffPay(order_number)
  260. if (status) {
  261. const { time_stamp, nonce_str, sign_type, pay_sign } = data.pay_data
  262. wx.requestPayment({
  263. timeStamp: time_stamp,
  264. nonceStr: nonce_str,
  265. package: data.pay_data.package,
  266. signType: sign_type,
  267. paySign: pay_sign,
  268. success(res) {
  269. if (res.errMsg === 'requestPayment:ok') {
  270. wx.redirectTo({
  271. url: '/pages/orderDetail/orderDetail?orderId=' + id
  272. })
  273. } else {
  274. wx.showToast({
  275. title: '支付出错,请重试~',
  276. icon: 'none'
  277. })
  278. }
  279. },
  280. fail(err) {
  281. console.log(err)
  282. }
  283. })
  284. } else {
  285. wx.showToast({
  286. title: msg,
  287. icon: 'none'
  288. })
  289. }
  290. } catch (err) {}
  291. this.setData({
  292. booLock: false
  293. })
  294. },
  295. showCancelOrder(e) {
  296. const { item } = e.currentTarget.dataset
  297. this.setData({
  298. itemData: item,
  299. booCancelOrder: true
  300. })
  301. },
  302. hideCancelOrder() {
  303. this.setData({
  304. booCancelOrder: false,
  305. itemData: {}
  306. })
  307. },
  308. async confirmCancelOrder() {
  309. const { id } = this.data.itemData
  310. this.setData({
  311. booLock: true
  312. })
  313. try {
  314. const { status, msg } = await postOrderCancel(id)
  315. if (status) {
  316. this.hideCancelOrder()
  317. wx.redirectTo({
  318. url: '/pages/orderCancel/orderCancel?orderId=' + id
  319. })
  320. } else {
  321. wx.showToast({
  322. title: msg,
  323. icon: 'none'
  324. })
  325. }
  326. } catch (err) {}
  327. this.setData({
  328. booLock: false
  329. })
  330. }
  331. })