shop-apply.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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. map: null,
  15. },
  16. created: function () {
  17. this.getCates();
  18. },
  19. mounted: function () {
  20. // 地区
  21. $("#city-picker").cityPicker({
  22. title: "请选择地区",
  23. });
  24. },
  25. methods: {
  26. // 加载地图
  27. showMap: function(){
  28. var _this = this;
  29. var lng = _this.shopInfo.lng>0? _this.shopInfo.lng : '108.360806';
  30. var lat = _this.shopInfo.lat>0? _this.shopInfo.lat : '22.819143';
  31. $("#modal").popup();
  32. var map = new BMap.Map('map');
  33. var poi = new BMap.Point(lng, lat);
  34. map.enableScrollWheelZoom();
  35. map.centerAndZoom(poi, 12);
  36. var mark = new BMap.Marker(poi);
  37. map.addOverlay(mark);
  38. mark.addEventListener("dragend", showInfo);
  39. mark.enableDragging(); //可拖拽
  40. /*map.addEventListener("mousemove",function(e){
  41. console.log(e.point)
  42. poi = new BMap.Point(e.point.lng, e.point.lat);
  43. mark = new BMap.Marker(poi);
  44. mark.addEventListener("dragend", showInfo);
  45. mark.enableDragging(); //可拖拽
  46. _this.shopInfo.lng = e.point.lng;
  47. _this.shopInfo.lat = e.point.lat;
  48. });*/
  49. map.addEventListener("click",function(e){
  50. poi = new BMap.Point(e.point.lng, e.point.lat);
  51. mark = new BMap.Marker(poi);
  52. mark.addEventListener("dragend", showInfo);
  53. mark.enableDragging(); //可拖拽
  54. _this.shopInfo.lng = e.point.lng;
  55. _this.shopInfo.lat = e.point.lat;
  56. });
  57. // 获取地址信息
  58. function showInfo(e){
  59. console.log(e)
  60. var gc = new BMap.Geocoder();
  61. gc.getLocation(e.point, function(rs){
  62. var addComp = rs.addressComponents;
  63. var address = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber;//获取地址
  64. _this.shopInfo.address = address;
  65. alert(addComp);
  66. console.log(_this.shopInfo)
  67. console.log(addComp)
  68. });
  69. }
  70. },
  71. // 隐藏地图
  72. hideMap: function(){
  73. $.closePopup();
  74. },
  75. // 获取申请信息
  76. getShopInfo: function(){
  77. var _this = this;
  78. $.post('/weixin/shop/getInfo', {}, function (res) {
  79. if (res.code == 'success') {
  80. _this.shopInfo = res.data
  81. if (!_this.shopInfo) {
  82. shopInfo = sessionStorage.getItem('shopInfo');
  83. _this.shopInfo = shopInfo? JSON.parse(shopInfo) : {};
  84. }
  85. } else if (res.code == 'login') {
  86. login(res.data.url);
  87. }
  88. _this.catePicker(false);
  89. }, "json");
  90. },
  91. // 获取分类
  92. getCates: function () {
  93. var _this = this;
  94. $.post('/weixin/shop/getCates', {}, function (res) {
  95. if (res.code == 'success') {
  96. _this.cates = res.data
  97. // 初始化数据
  98. _this.getShopInfo();
  99. } else if (res.code == 'login') {
  100. login(res.data.url);
  101. }
  102. }, "json");
  103. },
  104. // 提交
  105. doSubmit: function () {
  106. var _this = this;
  107. if (_this.submitting) {
  108. return false;
  109. }
  110. if(_this.shopInfo.name == '' || _this.shopInfo.name == null){
  111. $.toast('请填写店铺名称','text');
  112. return false;
  113. }
  114. if(_this.shopInfo.business_project == '' || _this.shopInfo.business_project == null){
  115. $.toast('请填写主营项目','text');
  116. return false;
  117. }
  118. if(_this.shopInfo.cate1 == 0 || _this.shopInfo.cate2 == 0){
  119. $.toast('请选择主营分类','text');
  120. return false;
  121. }
  122. if(_this.shopInfo.contact_name == '' || _this.shopInfo.contact_name == null){
  123. $.toast('请填写联系人','text');
  124. return false;
  125. }
  126. if(_this.shopInfo.mobile == '' || _this.shopInfo.mobile == null){
  127. $.toast('请填写手机号','text');
  128. return false;
  129. }
  130. var mobilePatt = /^1[3-9][0-9]{9}$/;
  131. if(!mobilePatt.test(_this.shopInfo.mobile)){
  132. $.toast('手机号格式错误','text');
  133. return false;
  134. }
  135. _this.shopInfo.address = $("#city-picker").val();
  136. if(_this.shopInfo.address == '' || _this.shopInfo.address == null){
  137. $.toast('请选择所在地区','text');
  138. return false;
  139. }
  140. var formData = new FormData();
  141. _this.shopInfo.city_codes = $("#city-picker").attr('data-codes');
  142. $.each(_this.shopInfo, function ($k, $item) {
  143. formData.append($k,$item);
  144. })
  145. sessionStorage.setItem('shopInfo', JSON.stringify(_this.shopInfo));
  146. var logo = $("#logo")[0].files[0];
  147. if(logo == null || logo == ''){
  148. $.toast('请先上传店铺LOGO','text');
  149. return false;
  150. }
  151. var idcard_front = $("#idcard_front")[0].files[0];
  152. if(idcard_front == null || idcard_front == ''){
  153. $.toast('请先上传身份证正面','text');
  154. return false;
  155. }
  156. var idcard_back = $("#idcard_back")[0].files[0];
  157. if(idcard_back == null || idcard_back == ''){
  158. $.toast('请先上传身份证反面','text');
  159. return false;
  160. }
  161. var business_img = $("#business_img")[0].files[0];
  162. if(business_img == null || business_img == ''){
  163. $.toast('请先上传营业执照','text');
  164. return false;
  165. }
  166. formData.append('logo', logo);
  167. formData.append('idcard_front', idcard_front);
  168. formData.append('idcard_back', idcard_back);
  169. formData.append('business_img', business_img);
  170. var agree = $("#agree").is(":checked") ? true : false;
  171. if (!agree) {
  172. $.toast('请先阅读店铺入驻协议并确定', 'text');
  173. return false;
  174. }
  175. if (confirm('确定提交该店铺入驻申请?')) {
  176. $.showLoading('申请提交...');
  177. $.ajax({
  178. url: '/weixin/shop/applySubmit',
  179. type: "post",
  180. dataType: 'json',
  181. data: formData,
  182. cache: false,
  183. contentType: false,
  184. processData: false,
  185. success: function (res) {
  186. $.hideLoading();
  187. if (res.code == 'success') {
  188. sessionStorage.setItem('shopInfo', null);
  189. $.toast('入驻申请提交成功,请耐心等候审核...');
  190. setTimeout(function () {
  191. location.href = '/weixin/news/index';
  192. }, 800);
  193. } else if (res.code == 'login') {
  194. login(res.data.url);
  195. }else{
  196. $.toast(res.message,'text');
  197. }
  198. }
  199. });
  200. }
  201. },
  202. // 提交
  203. doSave: function () {
  204. var _this = this;
  205. if (_this.submitting) {
  206. return false;
  207. }
  208. if(_this.shopInfo.name == '' || _this.shopInfo.name == null){
  209. $.toast('请填写店铺名称','text');
  210. return false;
  211. }
  212. if(_this.shopInfo.business_project == '' || _this.shopInfo.business_project == null){
  213. $.toast('请填写主营项目','text');
  214. return false;
  215. }
  216. if(_this.shopInfo.cate1 == 0 || _this.shopInfo.cate2 == 0){
  217. $.toast('请选择主营分类','text');
  218. return false;
  219. }
  220. if(_this.shopInfo.contact_name == '' || _this.shopInfo.contact_name == null){
  221. $.toast('请填写联系人','text');
  222. return false;
  223. }
  224. if(_this.shopInfo.mobile == '' || _this.shopInfo.mobile == null){
  225. $.toast('请填写手机号','text');
  226. return false;
  227. }
  228. var mobilePatt = /^1[3-9][0-9]{9}$/;
  229. if(!mobilePatt.test(_this.shopInfo.mobile)){
  230. $.toast('手机号格式错误','text');
  231. return false;
  232. }
  233. _this.shopInfo.area = $("#city-picker").val();
  234. if(_this.shopInfo.area == '' || _this.shopInfo.area == null){
  235. $.toast('请选择所在地区','text');
  236. return false;
  237. }
  238. if(_this.shopInfo.address == '' || _this.shopInfo.address == null){
  239. $.toast('请选择店铺定位地址','text');
  240. return false;
  241. }
  242. var formData = new FormData();
  243. _this.shopInfo.city_codes = $("#city-picker").attr('data-codes');
  244. $.each(_this.shopInfo, function ($k, $item) {
  245. formData.append($k,$item);
  246. })
  247. sessionStorage.setItem('shopInfo', JSON.stringify(_this.shopInfo));
  248. var logo = $("#logo")[0].files[0];
  249. var idcard_front = $("#idcard_front")[0].files[0];
  250. var idcard_back = $("#idcard_back")[0].files[0];
  251. var business_img = $("#business_img")[0].files[0];
  252. if(logo){
  253. formData.append('logo', logo);
  254. }
  255. if(idcard_front){
  256. formData.append('idcard_front', idcard_front);
  257. }
  258. if(idcard_back){
  259. formData.append('idcard_back', idcard_back);
  260. }
  261. if(business_img){
  262. formData.append('business_img', business_img);
  263. }
  264. var agree = $("#agree").is(":checked") ? true : false;
  265. if (!agree) {
  266. $.toast('请先阅读店铺入驻协议并确定', 'text');
  267. return false;
  268. }
  269. if (confirm('确定提交该店铺入驻申请?')) {
  270. $.showLoading('申请提交...');
  271. $.ajax({
  272. url: '/weixin/shop/applySubmit',
  273. type: "post",
  274. dataType: 'json',
  275. data: formData,
  276. cache: false,
  277. contentType: false,
  278. processData: false,
  279. success: function (res) {
  280. $.hideLoading();
  281. if (res.code == 'success') {
  282. sessionStorage.setItem('shopInfo', null);
  283. $.toast('入驻申请提交成功,请耐心等候审核...');
  284. setTimeout(function () {
  285. location.href = '/weixin/news/index';
  286. }, 800);
  287. } else if (res.code == 'login') {
  288. login(res.data.url);
  289. }else{
  290. $.toast(res.message,'text');
  291. }
  292. }
  293. });
  294. }
  295. },
  296. // 选择图片
  297. selectPhoto: function (ele) {
  298. var file = ele.target.files[0];
  299. if (file) {
  300. var reader = new FileReader();
  301. reader.readAsDataURL(file);
  302. reader.onloadend = function (even) {
  303. $(ele.target).siblings('.preview').attr("src", even.currentTarget.result);
  304. }
  305. }
  306. },
  307. // 分类选择
  308. catePicker: function (reload) {
  309. var _this = this;
  310. var data1 = _this.cates;
  311. if (data1.length <= 0) {
  312. return false;
  313. }
  314. if(reload){
  315. _this.shopInfo.cate2 = 0;
  316. }
  317. _this.subCates = [];
  318. if (_this.shopInfo.cate1>0) {
  319. $.each(data1, function (k, item) {
  320. if (item.id == _this.shopInfo.cate1) {
  321. _this.subCates = item.subCates.length ? item.subCates : [];
  322. }
  323. })
  324. } else if(data1.length>0){
  325. _this.shopInfo.cate1 = 0;
  326. _this.subCates = data1[0].subCates;
  327. }
  328. }
  329. }
  330. });