| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- var app = new Vue({
- el: '#app',
- data: {
- submitStatus: false,
- info: {},
- // 会员信息
- memberInfo: {},
- // 提交状态
- submitting: false,
- // 分类数据
- cates: [],
- fileList: [],
- count: 0,
- },
- created: function () {
- this.getCates();
- this.getInfo();
- },
- methods: {
- // 获取信息
- getInfo: function(){
- var _this = this;
- var id = getParam('id');
- $.post('/weixin/goods/getInfo', {id: id,type:1}, function (res) {
- if (res.code == 'success') {
- _this.info = res.data
- _this.fileList = res.data.albums;
- } else if (res.code == 'login') {
- login(res.data.url);
- }
- }, "json");
- },
- // 获取分类
- getCates: function () {
- var _this = this;
- $.post('/weixin/goods/getCates', {}, function (res) {
- if (res.code == 'success') {
- _this.cates = res.data
- } else if (res.code == 'login') {
- login(res.data.url);
- }
- }, "json");
- },
- // 图片上传
- uploadImage: function(ele){
- var _this = this;
- var formData = new FormData();
- var img = $(ele.target)[0].files[0];
- if(img == null || img == ''){
- $.toast('请先选择图片','text');
- return false;
- }
- if(_this.count >=6){
- $.toast('最多上传6张','text');
- return false;
- }
- formData.append('image', img);
- $.showLoading('上传中...');
- $.ajax({
- url: '/weixin/upload/thumb',
- type: "post",
- dataType: 'json',
- data: formData,
- cache: false,
- contentType: false,
- processData: false,
- success: function (res) {
- $.hideLoading();
- if (res.code == 'success') {
- _this.fileList.push(res.data);
- _this.count++;
- } else if (res.code == 'login') {
- login(res.data.url);
- }else{
- $.toast(res.message,'text');
- }
- }
- });
- },
- // 删除图片
- imageDel: function(ele){
- this.count--;
- $(ele.target).parent().detach();
- },
- // 提交
- doSubmit: function () {
- var _this = this;
- if (_this.submitting) {
- return false;
- }
- if(_this.info.goods_name == '' || _this.info.goods_name == null){
- $.toast('请填写产品名称','text');
- return false;
- }
- if(_this.info.score<=0 || _this.info.score == '' || _this.info.score == null){
- $.toast('请填写兑换所需积分','text');
- return false;
- }
- if(_this.info.stock<=0 || _this.info.stock == '' || _this.info.stock == null){
- $.toast('请填写库存数量','text');
- return false;
- }
- if(_this.info.cate_id == 0){
- $.toast('请选择分类','text');
- return false;
- }
- var albums = [];
- $(".weui-uploader__file").each(function(k, item){
- var url = $(this).attr('data-url');
- if(url){
- albums.push({img: url});
- }
- })
- _this.info.albums = albums;
- if (confirm('确定提交该商品信息?')) {
- $.showLoading('数据提交中...');
- $.post('/weixin/goods/doPublish', _this.info, function (res) {
- $.hideLoading();
- if (res.code == 'success') {
- $.toast('商品发布成功...');
- setTimeout(function () {
- location.href = '/weixin/shop/goods';
- }, 800);
- } else if (res.code == 'login') {
- login(res.data.url);
- }else{
- $.toast(res.message,'text');
- }
- },'json');
- }
- },
- }
- });
|