index.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // components/inner-order-item/index.js
  2. import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
  3. import http from '../../utils/http'
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. lifetimes: {
  9. attached: function () {
  10. // 在组件实例进入页面节点树时执行
  11. this.setData({
  12. user_id: wx.getStorageSync('sg-userinfo').id
  13. })
  14. },
  15. detached: function () {
  16. // 在组件实例被从页面节点树移除时执行
  17. },
  18. },
  19. properties: {
  20. item: Object,
  21. role: Object,
  22. showDelete: {
  23. type: Boolean,
  24. value: true
  25. }
  26. },
  27. /**
  28. * 组件的初始数据
  29. */
  30. data: {
  31. user_id: ""
  32. },
  33. /**
  34. * 组件的方法列表
  35. */
  36. methods: {
  37. navigate: function (e) {
  38. wx.navigateTo({
  39. url: e.currentTarget.dataset.url,
  40. })
  41. },
  42. doAction: function (e) {
  43. var type = e.currentTarget.dataset.type
  44. var that = this
  45. var order = e.currentTarget.dataset.order
  46. if (type == 'edit' || type == 'detail') {
  47. this.navigate(e)
  48. } else if (type == 'confirm') {
  49. Dialog.confirm({
  50. title: '提示',
  51. message: '确定订单吗',
  52. })
  53. .then(() => {
  54. that.submitCheck(order)
  55. }).catch(() => {
  56. Dialog.close()
  57. })
  58. } else if (type == 'delete') {
  59. Dialog.confirm({
  60. title: '提示',
  61. message: '确定删除订单吗',
  62. })
  63. .then(() => {
  64. that.delete(order)
  65. }).catch(() => {
  66. Dialog.close()
  67. })
  68. }
  69. },
  70. delete(order) {
  71. var that = this
  72. http({
  73. url: 'orders/delete',
  74. data: {
  75. id: order.id
  76. },
  77. success: function (res) {
  78. if (res.code == 0) {
  79. that.triggerEvent("update")
  80. Dialog.close()
  81. }
  82. }
  83. })
  84. },
  85. submitCheck(order) {
  86. var that = this
  87. http({
  88. url: 'orders/check',
  89. data: {
  90. id: order.id,
  91. type: 'confirm',
  92. remark: order.remark
  93. },
  94. success: function (res) {
  95. if (res.code == 0) {
  96. that.triggerEvent('update', {})
  97. Dialog.close()
  98. }
  99. }
  100. })
  101. },
  102. }
  103. })