| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- var app = new Vue({
- el: '#app',
- data: {
- submitStatus: false,
- shopInfo: {},
- // 会员信息
- memberInfo: {},
- // 提交状态
- submitting: false,
- // 分类数据
- cates: [],
- // 二级分类数据
- subCates: [],
- },
- created: function () {
- this.getCates();
- },
- mounted: function () {
- // 地区
- $("#city-picker").cityPicker({
- title: "请选择地区",
- });
- },
- methods: {
- // 获取申请信息
- getShopInfo: function(){
- var _this = this;
- $.post('/weixin/shop/getInfo', {}, function (res) {
- if (res.code == 'success') {
- _this.shopInfo = res.data
- if (!_this.shopInfo) {
- shopInfo = sessionStorage.getItem('shopInfo');
- _this.shopInfo = shopInfo? JSON.parse(shopInfo) : {};
- }
- } else if (res.code == 'login') {
- login(res.data.url);
- }
- _this.catePicker(false);
- }, "json");
- },
- // 获取分类
- getCates: function () {
- var _this = this;
- $.post('/weixin/shop/getCates', {}, function (res) {
- if (res.code == 'success') {
- _this.cates = res.data
- // 初始化数据
- _this.getShopInfo();
- } else if (res.code == 'login') {
- login(res.data.url);
- }
- }, "json");
- },
- // 提交
- doSave: function () {
- var _this = this;
- if (_this.submitting) {
- return false;
- }
- if(_this.shopInfo.name == '' || _this.shopInfo.name == null){
- $.toast('请填写店铺名称','text');
- return false;
- }
- if(_this.shopInfo.business_project == '' || _this.shopInfo.business_project == null){
- $.toast('请填写主营项目','text');
- return false;
- }
- if(_this.shopInfo.cate1 == 0 || _this.shopInfo.cate2 == 0){
- $.toast('请选择主营分类','text');
- return false;
- }
- if(_this.shopInfo.contact_name == '' || _this.shopInfo.contact_name == null){
- $.toast('请填写联系人','text');
- return false;
- }
- if(_this.shopInfo.mobile == '' || _this.shopInfo.mobile == null){
- $.toast('请填写手机号','text');
- return false;
- }
- var mobilePatt = /^1[3-9][0-9]{9}$/;
- if(!mobilePatt.test(_this.shopInfo.mobile)){
- $.toast('手机号格式错误','text');
- return false;
- }
- _this.shopInfo.address = $("#city-picker").val();
- if(_this.shopInfo.address == '' || _this.shopInfo.address == null){
- $.toast('请选择所在地区','text');
- return false;
- }
- var formData = new FormData();
- _this.shopInfo.city_codes = $("#city-picker").attr('data-codes');
- $.each(_this.shopInfo, function ($k, $item) {
- formData.append($k,$item);
- })
- sessionStorage.setItem('shopInfo', JSON.stringify(_this.shopInfo));
- if (confirm('确定修改商家信息?')) {
- $.showLoading('申请提交...');
- $.ajax({
- url: '/weixin/shop/doSave',
- type: "post",
- dataType: 'json',
- data: formData,
- cache: false,
- contentType: false,
- processData: false,
- success: function (res) {
- $.hideLoading();
- if (res.code == 'success') {
- sessionStorage.setItem('shopInfo', null);
- $.toast('商家信息修改成功...');
- } else if (res.code == 'login') {
- login(res.data.url);
- }else{
- $.toast(res.message,'text');
- }
- }
- });
- }
- },
- // 选择图片
- selectPhoto: function (ele) {
- var file = ele.target.files[0];
- if (file) {
- var reader = new FileReader();
- reader.readAsDataURL(file);
- reader.onloadend = function (even) {
- $(ele.target).siblings('.preview').attr("src", even.currentTarget.result);
- }
- }
- },
- // 分类选择
- catePicker: function (reload) {
- var _this = this;
- var data1 = _this.cates;
- if (data1.length <= 0) {
- return false;
- }
- if(reload){
- _this.shopInfo.cate2 = 0;
- }
- _this.subCates = [];
- if (_this.shopInfo.cate1>0) {
- $.each(data1, function (k, item) {
- if (item.id == _this.shopInfo.cate1) {
- _this.subCates = item.subCates.length ? item.subCates : [];
- }
- })
- } else if(data1.length>0){
- _this.shopInfo.cate1 = 0;
- _this.subCates = data1[0].subCates;
- }
- }
- }
- });
|