shop-apply.js 13 KB

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