index.js 5.8 KB

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