shop-apply.js 14 KB

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