details.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. var app = getApp();
  2. var canHexiao = true;
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. salesroom_id: '',
  9. hxNum: 1
  10. },
  11. salesroom_id: '',
  12. code: '',
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function (options) {
  17. let code = options.code || '';
  18. this.code = code;
  19. this.salesroom_id = options.salesroom_id || '';
  20. this.getHexiaoInfo(code);
  21. },
  22. /**
  23. * 生命周期函数--监听页面显示
  24. */
  25. onShow: function () {
  26. },
  27. actionConfirm: function(content) {
  28. return new Promise((resolve, reject)=>{
  29. wx.showModal({
  30. title: '提示',
  31. content,
  32. showCancel: true,
  33. success: (result) => {
  34. if (result.confirm) {
  35. resolve();
  36. } else if (result.cancel) {
  37. console.log('用户点击取消')
  38. }
  39. }
  40. })
  41. })
  42. },
  43. getHexiaoInfo: function(hexiao_volume_code) {
  44. let token = wx.getStorageSync('token');
  45. app.util.ProReq('hexiao.hexiao_order_info', { token, hexiao_volume_code }).then(res => {
  46. let { orders, order_goods_count, order_goods_saleshexiao_list } = res.data;
  47. this.setData({
  48. orders, order_goods_count, order_goods_saleshexiao_list
  49. })
  50. }).catch(err => {
  51. console.log(err)
  52. wx.showModal({
  53. title: '提示',
  54. content: err.msg || '请求出错',
  55. showCancel: false,
  56. confirmColor: '#ff5041',
  57. complete: function() {
  58. app.util.navigateBack({});
  59. }
  60. });
  61. })
  62. },
  63. goHexiao: function(event) {
  64. let hexiao_id = event.currentTarget.dataset.id || '';
  65. let type = event.currentTarget.dataset.type || 0;
  66. let token = wx.getStorageSync('token');
  67. let salesroom_id = this.salesroom_id;
  68. let data = { token, hexiao_id, salesroom_id };
  69. if(type==0) {
  70. // 按订单核销
  71. if(!canHexiao) return;
  72. canHexiao = false;
  73. this.orderHexiao(data);
  74. } else {
  75. // 按次数核销 弹窗显示具体信息
  76. this.getNumHexiaoInfo(data);
  77. }
  78. },
  79. /**
  80. * 获取按次数核销信息
  81. * @param {*} data
  82. */
  83. getNumHexiaoInfo: function(data){
  84. wx.showLoading();
  85. app.util.ProReq('hexiao.get_hxgoods_bytimes', data).then(res => {
  86. wx.hideLoading();
  87. let { hexiao_record_list, order_goods_info, saleshexiao_info } = res.data;
  88. this.setData({ hexiao_record_list, order_goods_info, saleshexiao_info, showHexiaoModal: true })
  89. }).catch(err => {
  90. console.log(err)
  91. app.util.message(err.msg || '请求出错', '', 'error');
  92. })
  93. },
  94. /**
  95. * 按订单核销
  96. * @param {*} data
  97. */
  98. orderHexiao: function(data) {
  99. wx.showLoading();
  100. app.util.ProReq('hexiao.hx_order_goods', data).then(res => {
  101. canHexiao = true;
  102. app.util.message('核销成功', '', 'error');
  103. this.getHexiaoInfo(this.code);
  104. }).catch(err => {
  105. console.log(err)
  106. canHexiao = true;
  107. app.util.message(err.msg || '请求出错', '', 'error');
  108. })
  109. },
  110. /**
  111. * 按次数核销
  112. * @param {*} data
  113. */
  114. numHexiao: function(event) {
  115. let hexiao_id = event.currentTarget.dataset.id || '';
  116. let token = wx.getStorageSync('token');
  117. let salesroom_id = this.salesroom_id;
  118. let hx_times = this.data.hxNum;
  119. let data = { token, hexiao_id, salesroom_id, hx_times };
  120. wx.showLoading();
  121. app.util.ProReq('hexiao.hx_order_goods_bytimes', data).then(res => {
  122. wx.hideLoading();
  123. this.handleHexiaoModal();
  124. app.util.message('核销成功', '', 'error');
  125. this.getHexiaoInfo(this.code);
  126. }).catch(err => {
  127. console.log(err)
  128. wx.hideLoading();
  129. app.util.message(err.msg || '请求出错', '', 'error');
  130. })
  131. },
  132. /**
  133. * 全部订单核销
  134. * @param {*} event
  135. */
  136. allHexiao: function(event) {
  137. this.actionConfirm('确认全部核销').then(()=>{
  138. let order_goods_saleshexiao_list = this.data.order_goods_saleshexiao_list;
  139. let order_ids = [];
  140. order_goods_saleshexiao_list.map(item=>{
  141. (item.is_hexiao_over==0)&&order_ids.push(item.order_id)
  142. })
  143. let order_id = order_ids.join(',');
  144. let token = wx.getStorageSync('token');
  145. let salesroom_id = this.salesroom_id;
  146. app.util.ProReq('hexiao.all_hx_order', { token, order_id, salesroom_id }).then(res => {
  147. this.getHexiaoInfo(this.code);
  148. }).catch(err => {
  149. console.log(err)
  150. app.util.message(err.msg || '请求出错', '', 'error');
  151. })
  152. });
  153. },
  154. /**
  155. * 单商品按次数全部核销
  156. */
  157. allHexiaoBytimes: function(event) {
  158. this.actionConfirm('确认全部核销').then(()=>{
  159. let hexiao_id = event.currentTarget.dataset.id || '';
  160. let token = wx.getStorageSync('token');
  161. let salesroom_id = this.salesroom_id;
  162. app.util.ProReq('hexiao.all_hx_order_goods_bytimes', { token, hexiao_id, salesroom_id }).then(res => {
  163. this.setData({showHexiaoModal: false});
  164. this.getHexiaoInfo(this.code);
  165. }).catch(err => {
  166. console.log(err)
  167. app.util.message(err.msg || '请求出错', '', 'error');
  168. })
  169. });
  170. },
  171. /**
  172. * 次数核销弹窗
  173. */
  174. handleHexiaoModal: function() {
  175. this.setData({
  176. showHexiaoModal: !this.data.showHexiaoModal,
  177. hxNum: 1
  178. })
  179. },
  180. /**
  181. * 输入框改变监控
  182. * @param {*} t
  183. */
  184. changeNumber: function (t) {
  185. var e = t.detail;
  186. console.log(e)
  187. e&&this.setData({ hxNum: e.value })
  188. },
  189. /**
  190. * 输入极值限制
  191. * @param {*} t
  192. */
  193. outOfMax: function (t) {
  194. // var e = t.detail;
  195. wx.showToast({
  196. title: "不能再多了~",
  197. icon: "none"
  198. })
  199. }
  200. })