shop-info.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. var app = new Vue({
  2. el: '#app',
  3. data: {
  4. submitStatus: false,
  5. shopInfo: {},
  6. // 会员信息
  7. memberInfo: {},
  8. // 提交状态
  9. submitting: false,
  10. // 分类数据
  11. cates: [],
  12. // 二级分类数据
  13. subCates: [],
  14. },
  15. created: function () {
  16. this.getCates();
  17. },
  18. mounted: function () {
  19. // 地区
  20. $("#city-picker").cityPicker({
  21. title: "请选择地区",
  22. });
  23. },
  24. methods: {
  25. // 获取申请信息
  26. getShopInfo: function(){
  27. var _this = this;
  28. $.post('/weixin/shop/getInfo', {}, function (res) {
  29. if (res.code == 'success') {
  30. _this.shopInfo = res.data
  31. if (!_this.shopInfo) {
  32. shopInfo = sessionStorage.getItem('shopInfo');
  33. _this.shopInfo = shopInfo? JSON.parse(shopInfo) : {};
  34. }
  35. } else if (res.code == 'login') {
  36. login(res.data.url);
  37. }
  38. _this.catePicker(false);
  39. }, "json");
  40. },
  41. // 获取分类
  42. getCates: function () {
  43. var _this = this;
  44. $.post('/weixin/shop/getCates', {}, function (res) {
  45. if (res.code == 'success') {
  46. _this.cates = res.data
  47. // 初始化数据
  48. _this.getShopInfo();
  49. } else if (res.code == 'login') {
  50. login(res.data.url);
  51. }
  52. }, "json");
  53. },
  54. // 提交
  55. doSave: function () {
  56. var _this = this;
  57. if (_this.submitting) {
  58. return false;
  59. }
  60. if(_this.shopInfo.name == '' || _this.shopInfo.name == null){
  61. $.toast('请填写店铺名称','text');
  62. return false;
  63. }
  64. if(_this.shopInfo.business_project == '' || _this.shopInfo.business_project == null){
  65. $.toast('请填写主营项目','text');
  66. return false;
  67. }
  68. if(_this.shopInfo.cate1 == 0 || _this.shopInfo.cate2 == 0){
  69. $.toast('请选择主营分类','text');
  70. return false;
  71. }
  72. if(_this.shopInfo.contact_name == '' || _this.shopInfo.contact_name == null){
  73. $.toast('请填写联系人','text');
  74. return false;
  75. }
  76. if(_this.shopInfo.mobile == '' || _this.shopInfo.mobile == null){
  77. $.toast('请填写手机号','text');
  78. return false;
  79. }
  80. var mobilePatt = /^1[3-9][0-9]{9}$/;
  81. if(!mobilePatt.test(_this.shopInfo.mobile)){
  82. $.toast('手机号格式错误','text');
  83. return false;
  84. }
  85. _this.shopInfo.address = $("#city-picker").val();
  86. if(_this.shopInfo.address == '' || _this.shopInfo.address == null){
  87. $.toast('请选择所在地区','text');
  88. return false;
  89. }
  90. var formData = new FormData();
  91. _this.shopInfo.city_codes = $("#city-picker").attr('data-codes');
  92. $.each(_this.shopInfo, function ($k, $item) {
  93. formData.append($k,$item);
  94. })
  95. sessionStorage.setItem('shopInfo', JSON.stringify(_this.shopInfo));
  96. if (confirm('确定修改商家信息?')) {
  97. $.showLoading('申请提交...');
  98. $.ajax({
  99. url: '/weixin/shop/doSave',
  100. type: "post",
  101. dataType: 'json',
  102. data: formData,
  103. cache: false,
  104. contentType: false,
  105. processData: false,
  106. success: function (res) {
  107. $.hideLoading();
  108. if (res.code == 'success') {
  109. sessionStorage.setItem('shopInfo', null);
  110. $.toast('商家信息修改成功...');
  111. } else if (res.code == 'login') {
  112. login(res.data.url);
  113. }else{
  114. $.toast(res.message,'text');
  115. }
  116. }
  117. });
  118. }
  119. },
  120. // 选择图片
  121. selectPhoto: function (ele) {
  122. var file = ele.target.files[0];
  123. if (file) {
  124. var reader = new FileReader();
  125. reader.readAsDataURL(file);
  126. reader.onloadend = function (even) {
  127. $(ele.target).siblings('.preview').attr("src", even.currentTarget.result);
  128. }
  129. }
  130. },
  131. // 分类选择
  132. catePicker: function (reload) {
  133. var _this = this;
  134. var data1 = _this.cates;
  135. if (data1.length <= 0) {
  136. return false;
  137. }
  138. if(reload){
  139. _this.shopInfo.cate2 = 0;
  140. }
  141. _this.subCates = [];
  142. if (_this.shopInfo.cate1>0) {
  143. $.each(data1, function (k, item) {
  144. if (item.id == _this.shopInfo.cate1) {
  145. _this.subCates = item.subCates.length ? item.subCates : [];
  146. }
  147. })
  148. } else if(data1.length>0){
  149. _this.shopInfo.cate1 = 0;
  150. _this.subCates = data1[0].subCates;
  151. }
  152. }
  153. }
  154. });