newReceive.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. var _request = require('../../../../../utils/request.js')
  2. var validator = require('../../../../../utils/validator.js')
  3. var _handle = require('../../../../../utils/handle.js')
  4. Page({
  5. data: {
  6. address: '请选择',
  7. region: ['北京市', '北京市', '东城区'],
  8. name: '',
  9. tel: 0,
  10. more: '',
  11. type: 0,//0为新建,1为编辑
  12. remark:''
  13. },
  14. onLoad: function (options) {
  15. console.log('options',options)
  16. if(options.type == 1){
  17. var address = wx.getStorageSync('editAddr');
  18. console.log('addrhere',address)
  19. this.setData({
  20. type: 1,
  21. tel:address.tel,
  22. name:address.contact,
  23. addrid:address.id,
  24. remark:address.remark
  25. })
  26. }
  27. },
  28. bindName: function (e) {
  29. this.setData({
  30. name: e.detail.value
  31. })
  32. },
  33. bindTel: function (e) {
  34. this.setData({
  35. tel: e.detail.value
  36. })
  37. },
  38. bindRemark: function (e) {
  39. this.setData({
  40. remark: e.detail.value
  41. })
  42. },
  43. bindMore: function (e) {
  44. this.setData({
  45. more: e.detail.value
  46. })
  47. },
  48. validate () {
  49. var msg
  50. if (!validator.required(this.data.name)) {
  51. msg = '提货人不能为空'
  52. } else if (!validator.required1(this.data.name)) {
  53. msg = '国家安全局规定:运单禁止出现“先生”,“小姐”,“女士”等,请填写完整名字'
  54. } else if (!validator.required(this.data.tel)) {
  55. msg = '联系电话不能为空'
  56. } else if (!validator.telphone(this.data.tel)) {
  57. msg = '手机号码格式不正确'
  58. }
  59. return { isOk: !msg, msg }
  60. },
  61. save: function (e) {
  62. _handle.setFormId(e)
  63. var { isOk, msg } = this.validate()
  64. if (isOk) {
  65. this.requestAddress()
  66. } else {
  67. wx.showToast({
  68. title: msg,
  69. icon: 'none',
  70. duration: 2000
  71. })
  72. }
  73. },
  74. requestAddress () {
  75. console.log('requestAddress')
  76. var that = this
  77. if(that.data.type == 1){
  78. var url = 'v1/pick_address/'+that.data.addrid;
  79. }else{
  80. var url = 'v1/pick_address';
  81. }
  82. var params = {
  83. contact: this.data.name,
  84. tel: this.data.tel,
  85. set_default: 1,
  86. }
  87. var success = function (res) {
  88. wx.navigateBack({
  89. delta: 1
  90. })
  91. }
  92. if(that.data.type == 1){
  93. _request.$put(url, params, success)
  94. }else{
  95. _request.$post(url, params, success)
  96. }
  97. },
  98. bindRegionChange: function (e) {
  99. console.log(e)
  100. this.setData({
  101. region: e.detail.value,
  102. address: e.detail.value[0] + e.detail.value[1] + e.detail.value[2]
  103. })
  104. },
  105. onShareAppMessage: function (val) {
  106. return _request.share({
  107. sc: 'xcx_user_newaddress'
  108. })
  109. }
  110. })