index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. import { getAdminOrderDelivery, getLogistics, setAdminOrderDelivery } from "../../../api/admin";
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. parameter: {
  9. 'navbar': '1',
  10. 'return': '1',
  11. 'title': '订单发货',
  12. 'color': false
  13. },
  14. types: [
  15. {
  16. type: "express",
  17. title: "发货"
  18. },
  19. {
  20. type: "send",
  21. title: "送货"
  22. },
  23. {
  24. type: "fictitious",
  25. title: "无需发货"
  26. }
  27. ],
  28. order_id: '',
  29. delivery:{},
  30. active: 0,
  31. delivery_type: "express",
  32. logistics: [],
  33. index:0,
  34. // delivery_id: "",
  35. // delivery_name:'',
  36. // delivery_phone:''
  37. },
  38. /**
  39. * 生命周期函数--监听页面加载
  40. */
  41. onLoad: function (options) {
  42. if (options.order_id) this.setData({ order_id: options.order_id });
  43. },
  44. /**
  45. * 登录授权回调
  46. *
  47. */
  48. onLoadFun: function () {
  49. this.getOrderInfo();
  50. this.getLogisticsChange();
  51. },
  52. /**
  53. * 快递公司选择
  54. *
  55. */
  56. bindPickerChange: function (e) {
  57. this.setData({ index: e.detail.value });
  58. },
  59. /**
  60. * 提交
  61. */
  62. formSubmit: function (e) {
  63. let save = {};
  64. save.order_id = this.data.order_id;
  65. save.delivery_type = this.data.delivery_type;
  66. switch (this.data.delivery_type) {
  67. case "send":
  68. if (!e.detail.value.delivery_name) return app.Tips({ title: '请填写送货人' });
  69. if (!e.detail.value.delivery_phone) return app.Tips({ title: '请填写送货电话' });
  70. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(e.detail.value.delivery_phone)) return app.Tips({ title: '输入正确的手机号码' });
  71. save.delivery_name = e.detail.value.delivery_name;
  72. save.delivery_id = e.detail.value.delivery_phone;
  73. this.setInfo(save);
  74. break;
  75. case "express":
  76. if (!e.detail.value.delivery_id) return app.Tips({ title: '请填写快递单号' });
  77. save.delivery_name = this.data.logistics[this.data.index];
  78. save.delivery_id = e.detail.value.delivery_id;
  79. this.setInfo(save);
  80. break;
  81. case "fictitious":
  82. this.setInfo(save);
  83. break;
  84. }
  85. },
  86. setInfo: function (save) {
  87. setAdminOrderDelivery(save).then(res => {
  88. app.Tips({ title: res.msg, icon: 'success' });
  89. setTimeout(function () {
  90. wx.navigateBack({ delta: 1 });
  91. }, 500);
  92. }).catch(err => {
  93. return app.Tips({ title: err });
  94. })
  95. },
  96. /**
  97. * 快递公司
  98. *
  99. */
  100. getLogisticsChange: function () {
  101. let logisticsArr = [];
  102. getLogistics().then(res => {
  103. res.data.map((item) => {
  104. logisticsArr.push(item.name)
  105. })
  106. this.setData({
  107. logistics: logisticsArr
  108. });
  109. }).catch(err => {
  110. app.Tips({ title: err });
  111. });
  112. },
  113. /**
  114. *选择
  115. */
  116. changeType: function (e) {
  117. this.setData({
  118. active: e.currentTarget.dataset.indexs,
  119. delivery_type: e.currentTarget.dataset.rows.type
  120. });
  121. },
  122. /**
  123. * 获取订单发货详细信息
  124. *
  125. */
  126. getOrderInfo: function () {
  127. wx.showLoading({ title: "正在加载中" });
  128. getAdminOrderDelivery(this.data.order_id).then(res => {
  129. wx.hideLoading();
  130. this.setData({
  131. delivery: res.data
  132. });
  133. }).catch(err => {
  134. wx.hideLoading();
  135. app.Tips({ title: err });
  136. });
  137. },
  138. /**
  139. *
  140. * 剪切订单号
  141. */
  142. copyOrderId: function () {
  143. wx.setClipboardData({ data: this.data.orderInfo.order_id });
  144. },
  145. /**
  146. *
  147. * 操作 一键改价 修改备注 打开组件
  148. */
  149. modify: function (e) {
  150. let status = e.currentTarget.dataset.status;
  151. this.setData({
  152. change: true,
  153. status: status,
  154. orderInfo: this.data.orderInfo
  155. });
  156. },
  157. /**
  158. * 关闭组件
  159. *
  160. */
  161. change: function () {
  162. this.setData({ change: false });
  163. },
  164. /**
  165. * 事件回调
  166. *
  167. */
  168. onChangeFun: function (e) {
  169. let opt = e.detail;
  170. let action = opt.action || null;
  171. let value = opt.value != undefined ? opt.value : null;
  172. (action && this[action]) && this[action](value);
  173. },
  174. /**
  175. * 生命周期函数--监听页面初次渲染完成
  176. */
  177. onReady: function () {
  178. },
  179. /**
  180. * 生命周期函数--监听页面显示
  181. */
  182. onShow: function () {
  183. },
  184. /**
  185. * 生命周期函数--监听页面隐藏
  186. */
  187. onHide: function () {
  188. },
  189. /**
  190. * 生命周期函数--监听页面卸载
  191. */
  192. onUnload: function () {
  193. },
  194. /**
  195. * 页面相关事件处理函数--监听用户下拉动作
  196. */
  197. onPullDownRefresh: function () {
  198. },
  199. /**
  200. * 页面上拉触底事件的处理函数
  201. */
  202. onReachBottom: function () {
  203. },
  204. /**
  205. * 用户点击右上角分享
  206. */
  207. onShareAppMessage: function () {
  208. }
  209. })