logistics.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. var _request = require('../../../../utils/request.js')
  2. var validator = require('../../../../utils/validator.js')
  3. var rid
  4. var fomlds = []
  5. Page({
  6. data: {
  7. order: {},
  8. company: '',
  9. express: '',
  10. company1: '',
  11. express1: '',
  12. company2: '',
  13. express2: '',
  14. secondshow: false,
  15. thirdshow: false,
  16. },
  17. bindCompany (e) {
  18. this.setData({
  19. company: e.detail.value
  20. })
  21. },
  22. bindExpress (e) {
  23. this.setData({
  24. express: e.detail.value
  25. })
  26. },
  27. bindCompany1 (e) {
  28. this.setData({
  29. company1: e.detail.value
  30. })
  31. },
  32. bindExpress1 (e) {
  33. this.setData({
  34. express1: e.detail.value
  35. })
  36. },
  37. bindCompany2 (e) {
  38. this.setData({
  39. company2: e.detail.value
  40. })
  41. },
  42. bindExpress2 (e) {
  43. this.setData({
  44. express2: e.detail.value
  45. })
  46. },
  47. onLoad: function (options) {
  48. rid = options.id
  49. this.getRadish()
  50. },
  51. onHide: function (val) {
  52. this.sendFomlds()
  53. },
  54. getRadish () {
  55. var that = this
  56. var url = 'v1/merchant/order/detail/' + rid
  57. var params = {
  58. }
  59. var success = function (res) {
  60. var data = res.data
  61. that.setData({
  62. order: data
  63. })
  64. if (that.data.order.ex_company_array.length === 1 && that.data.order.ex_order_no_array.length === 1) {
  65. that.setData({
  66. company: data.ex_company_array[0],
  67. express: data.ex_order_no_array[0]
  68. })
  69. }
  70. else if (that.data.order.ex_company_array.length === 2 && that.data.order.ex_order_no_array.length === 2) {
  71. that.setData({
  72. secondshow: true,
  73. company: data.ex_company_array[0],
  74. express: data.ex_order_no_array[0],
  75. company1: data.ex_company_array[1],
  76. express1: data.ex_order_no_array[1]
  77. })
  78. }
  79. else if (that.data.order.ex_company_array.length === 3 && that.data.order.ex_order_no_array.length === 3) {
  80. that.setData({
  81. secondshow: true,
  82. thirdshow: true,
  83. company: data.ex_company_array[0],
  84. express: data.ex_order_no_array[0],
  85. company1: data.ex_company_array[1],
  86. express1: data.ex_order_no_array[1],
  87. company2: data.ex_company_array[2],
  88. express2: data.ex_order_no_array[2],
  89. })
  90. }
  91. else if (getApp().globalData.merchant) {
  92. that.setData({
  93. company: getApp().globalData.merchant
  94. })
  95. }
  96. }
  97. _request.$get(url, params, success)
  98. },
  99. setExpressRequest: function () {
  100. var id = this.data.order.order_id
  101. var that = this
  102. var url = 'v1/merchant/order/' + id
  103. var company = that.data.company
  104. var express = that.data.express
  105. if (that.data.secondshow === true) {
  106. company = that.data.company + '/' + that.data.company1
  107. express = that.data.express + '/' + that.data.express1
  108. }
  109. if (that.data.thirdshow === true) {
  110. company = that.data.company + '/' + that.data.company1 + '/' + that.data.company2
  111. express = that.data.express + '/' + that.data.express1 + '/' + that.data.express2
  112. }
  113. var params = {
  114. express_company: company,
  115. express_order_no: express,
  116. status: 'dispatch'
  117. }
  118. var success = function (res) {
  119. getApp().globalData.order = true
  120. getApp().globalData.merchant = that.data.company
  121. wx.navigateBack()
  122. }
  123. _request.$put(url, params, success)
  124. },
  125. putExpressRequest: function () {
  126. var id = this.data.order.order_id
  127. var that = this
  128. var url = 'v1/merchant/order/' + id
  129. var company = that.data.company
  130. var express = that.data.express
  131. if (that.data.secondshow === true) {
  132. company = that.data.company + '/' + that.data.company1
  133. express = that.data.express + '/' + that.data.express1
  134. }
  135. if (that.data.thirdshow === true) {
  136. company = that.data.company + '/' + that.data.company1 + '/' + that.data.company2
  137. express = that.data.express + '/' + that.data.express1 + '/' + that.data.express2
  138. }
  139. var params = {
  140. express_company: company,
  141. express_order_no: express
  142. }
  143. var success = function (res) {
  144. getApp().globalData.order = true
  145. getApp().globalData.merchant = that.data.company
  146. wx.navigateBack()
  147. }
  148. _request.$put(url, params, success)
  149. },
  150. jstext (val) {
  151. var strshow = val.indexOf('/')
  152. if (strshow >= 0) {
  153. return false
  154. }
  155. if (strshow < 0) {
  156. return true
  157. }
  158. },
  159. validate () {
  160. var msg
  161. if (!validator.required(this.data.company)) {
  162. msg = '物流公司不能为空'
  163. } else if (!validator.required(this.data.express)) {
  164. msg = '物流号不能为空'
  165. } else if (!this.jstext(this.data.company) || !this.jstext(this.data.express)) {
  166. msg = '请不要输入"/"等特殊字符'
  167. } else if (this.data.secondshow === true && !validator.required(this.data.company1)) {
  168. msg = '物流公司不能为空'
  169. } else if (this.data.secondshow === true && !validator.required(this.data.express1)) {
  170. msg = '物流号不能为空'
  171. } else if (this.data.secondshow === true && (!this.jstext(this.data.company1) || !this.jstext(this.data.express1))) {
  172. msg = '请不要输入"/"等特殊字符'
  173. } else if (this.data.thirdshow === true && !validator.required(this.data.company2)) {
  174. msg = '物流公司不能为空'
  175. } else if (this.data.thirdshow === true && !validator.required(this.data.express2)) {
  176. msg = '物流号不能为空'
  177. } else if (this.data.secondshow === true && (!this.jstext(this.data.company2) || !this.jstext(this.data.express2))) {
  178. msg = '请不要输入"/"等特殊字符'
  179. }
  180. return { isOk: !msg, msg }
  181. },
  182. setExpress: function (e) {
  183. this.formSubmit(e)
  184. var { isOk, msg } = this.validate()
  185. if (isOk) {
  186. this.setExpressRequest()
  187. } else {
  188. wx.showToast({
  189. title: msg,
  190. icon: 'none',
  191. duration: 2000
  192. })
  193. }
  194. },
  195. putExpress: function (e) {
  196. this.formSubmit(e)
  197. var { isOk, msg } = this.validate()
  198. if (isOk) {
  199. this.putExpressRequest()
  200. } else {
  201. wx.showToast({
  202. title: msg,
  203. icon: 'none',
  204. duration: 2000
  205. })
  206. }
  207. },
  208. getqcode: function () {
  209. var that = this
  210. wx.scanCode({
  211. success: (res) => {
  212. that.setData({
  213. express: res.result
  214. })
  215. }
  216. })
  217. },
  218. getqcode1: function () {
  219. var that = this
  220. wx.scanCode({
  221. success: (res) => {
  222. that.setData({
  223. express1: res.result
  224. })
  225. }
  226. })
  227. },
  228. getqcode2: function () {
  229. var that = this
  230. wx.scanCode({
  231. success: (res) => {
  232. that.setData({
  233. express2: res.result
  234. })
  235. }
  236. })
  237. },
  238. formSubmit: function (e) {
  239. fomlds = e.detail.formId
  240. this.sendFomlds()
  241. },
  242. sendFomlds: function () {
  243. var that = this
  244. var url = 'v1/formid'
  245. var params = {
  246. formIds: fomlds
  247. }
  248. var success = function (res) {
  249. console.log(res)
  250. }
  251. _request.$post(url, params, success)
  252. },
  253. pluslist () {
  254. var that = this
  255. if (that.data.secondshow === false) {
  256. that.setData({
  257. secondshow: true
  258. })
  259. } else {
  260. that.setData({
  261. thirdshow: true
  262. })
  263. }
  264. },
  265. miuslist () {
  266. var that = this
  267. if (that.data.secondshow === true && that.data.thirdshow === false) {
  268. that.setData({
  269. secondshow: false,
  270. express1: '',
  271. company1: '',
  272. })
  273. } else if (that.data.secondshow === true && that.data.thirdshow === true) {
  274. that.setData({
  275. thirdshow: false,
  276. express2: '',
  277. company2: '',
  278. })
  279. }
  280. }
  281. })