goods-publish.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. var app = new Vue({
  2. el: '#app',
  3. data: {
  4. submitStatus: false,
  5. info: {},
  6. // 会员信息
  7. memberInfo: {},
  8. // 提交状态
  9. submitting: false,
  10. // 分类数据
  11. cates: [],
  12. fileList: [],
  13. count: 0,
  14. },
  15. created: function () {
  16. this.getCates();
  17. this.getInfo();
  18. },
  19. methods: {
  20. // 获取信息
  21. getInfo: function(){
  22. var _this = this;
  23. var id = getParam('id');
  24. $.post('/weixin/goods/getInfo', {id: id,type:1}, function (res) {
  25. if (res.code == 'success') {
  26. _this.info = res.data
  27. _this.fileList = res.data.albums;
  28. } else if (res.code == 'login') {
  29. login(res.data.url);
  30. }
  31. }, "json");
  32. },
  33. // 获取分类
  34. getCates: function () {
  35. var _this = this;
  36. $.post('/weixin/goods/getCates', {}, function (res) {
  37. if (res.code == 'success') {
  38. _this.cates = res.data
  39. } else if (res.code == 'login') {
  40. login(res.data.url);
  41. }
  42. }, "json");
  43. },
  44. // 图片上传
  45. uploadImage: function(ele){
  46. var _this = this;
  47. var formData = new FormData();
  48. var img = $(ele.target)[0].files[0];
  49. if(img == null || img == ''){
  50. $.toast('请先选择图片','text');
  51. return false;
  52. }
  53. if(_this.count >=6){
  54. $.toast('最多上传6张','text');
  55. return false;
  56. }
  57. formData.append('image', img);
  58. $.showLoading('上传中...');
  59. $.ajax({
  60. url: '/weixin/upload/thumb',
  61. type: "post",
  62. dataType: 'json',
  63. data: formData,
  64. cache: false,
  65. contentType: false,
  66. processData: false,
  67. success: function (res) {
  68. $.hideLoading();
  69. if (res.code == 'success') {
  70. _this.fileList.push(res.data);
  71. _this.count++;
  72. } else if (res.code == 'login') {
  73. login(res.data.url);
  74. }else{
  75. $.toast(res.message,'text');
  76. }
  77. }
  78. });
  79. },
  80. // 删除图片
  81. imageDel: function(ele){
  82. this.count--;
  83. $(ele.target).parent().detach();
  84. },
  85. // 提交
  86. doSubmit: function () {
  87. var _this = this;
  88. if (_this.submitting) {
  89. return false;
  90. }
  91. if(_this.info.goods_name == '' || _this.info.goods_name == null){
  92. $.toast('请填写产品名称','text');
  93. return false;
  94. }
  95. if(_this.info.score<=0 || _this.info.score == '' || _this.info.score == null){
  96. $.toast('请填写兑换所需积分','text');
  97. return false;
  98. }
  99. if(_this.info.stock<=0 || _this.info.stock == '' || _this.info.stock == null){
  100. $.toast('请填写库存数量','text');
  101. return false;
  102. }
  103. if(_this.info.cate_id == 0){
  104. $.toast('请选择分类','text');
  105. return false;
  106. }
  107. var albums = [];
  108. $(".weui-uploader__file").each(function(k, item){
  109. var url = $(this).attr('data-url');
  110. if(url){
  111. albums.push({img: url});
  112. }
  113. })
  114. _this.info.albums = albums;
  115. if (confirm('确定提交该商品信息?')) {
  116. $.showLoading('数据提交中...');
  117. $.post('/weixin/goods/doPublish', _this.info, function (res) {
  118. $.hideLoading();
  119. if (res.code == 'success') {
  120. $.toast('商品发布成功...');
  121. setTimeout(function () {
  122. location.href = '/weixin/shop/goods';
  123. }, 800);
  124. } else if (res.code == 'login') {
  125. login(res.data.url);
  126. }else{
  127. $.toast(res.message,'text');
  128. }
  129. },'json');
  130. }
  131. },
  132. }
  133. });