address.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. const util = require('../../utils/util.js');
  2. Component({
  3. properties: {
  4. show:{
  5. type: Boolean,
  6. observer: function (val){
  7. this.setData({ show: val });
  8. }
  9. },
  10. data:{
  11. type:String,
  12. observer:function(newVal){
  13. if (!util.isEmpty(newVal)) {
  14. let datas = newVal.split(" ");
  15. this.setData({ name: datas[0], mobile: datas[1], provincial: (datas[2].split('/')).length - 1 <= 1 ? datas[2] + "/" : datas[2], address: datas[3]});
  16. }
  17. }
  18. }
  19. },
  20. data: {
  21. show:false,
  22. name:"",
  23. mobile:'',
  24. provincial:'',
  25. address:'',
  26. datas:{},
  27. region: ['浙江省', '杭州市', '上城区']
  28. },
  29. methods: {
  30. bindRegionChange(e) {
  31. let value = e.detail.value, provincial = this.data.provincial;
  32. if (value) provincial = value[0] + '/' + value[1] + '/' + value[2];
  33. this.setData({ provincial });
  34. },
  35. // 微信获取地址列表
  36. getAddressForWX(){
  37. let that=this;
  38. wx.getSetting({
  39. success (res) {
  40. console.log(res.authSetting['scope.address'])
  41. if (res.authSetting['scope.address']) {
  42. wx.authorize({
  43. scope: 'scope.address',
  44. success: (result)=>{
  45. that.chooseWxAddress()
  46. },fail: ()=>{
  47. util.showTips('您已拒绝授权');
  48. }
  49. })
  50. } else {
  51. wx.openSetting({
  52. success (res) {
  53. console.log(res)
  54. that.chooseWxAddress()
  55. },fail: ()=>{
  56. util.showTips('您已拒绝授权');
  57. }
  58. })
  59. }
  60. }
  61. })
  62. },
  63. chooseWxAddress(){
  64. let that =this;
  65. wx.chooseAddress({
  66. success (res) {
  67. console.log(res)
  68. let pro = res.provinceName+'/'+res.cityName+'/'+res.countyName
  69. console.log(pro)
  70. that.setData({name:res.userName,mobile:res.telNumber,provincial:pro,address:res.detailInfo})
  71. }
  72. })
  73. },
  74. save(e){
  75. let data = e.detail.value;
  76. if (util.isEmpty(data.name)) {
  77. util.showTips('姓名不能为空');
  78. return false;
  79. }
  80. if (util.isEmpty(data.mobile)) {
  81. util.showTips('手机号不能为空');
  82. return false;
  83. }
  84. if (util.isPhone(data.mobile)) {
  85. util.showTips('请正确填写手机号');;
  86. return false;
  87. }
  88. if (util.isEmpty(data.provincial)) {
  89. util.showTips('省市区不能为空');
  90. return false;
  91. }
  92. if (util.isEmpty(data.address)) {
  93. util.showTips('详细地址不能为空');
  94. return false;
  95. }
  96. if (data.address.length>100) {
  97. util.showTips('详细地址请输入100字以内信息');
  98. return false;
  99. }
  100. this.setData({show:false});
  101. this.triggerEvent("submit", data);
  102. },
  103. close() {
  104. this.setData({ show: false });
  105. this.triggerEvent("close", this.data.show);
  106. }
  107. }
  108. })