海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.6 KiB

  1. Date.prototype.format = function(fmt) {
  2. var o = {
  3. "M+" : this.getMonth()+1, //月份
  4. "d+" : this.getDate(), //日
  5. "h+" : this.getHours(), //小时
  6. "m+" : this.getMinutes(), //分
  7. "s+" : this.getSeconds(), //秒
  8. "q+" : Math.floor((this.getMonth()+3)/3), //季度
  9. "S" : this.getMilliseconds() //毫秒
  10. };
  11. if(/(y+)/.test(fmt)) {
  12. fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
  13. }
  14. for(var k in o) {
  15. if(new RegExp("("+ k +")").test(fmt)){
  16. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
  17. }
  18. }
  19. return fmt;
  20. }
  21. $(function() {
  22. $(".has-many-spec .add.btn")
  23. .after('<div class="btn btn-spec batch-sub btn-primary btn-outline btn-sm" style="margin-left:10px;"><i class="feather icon-minus"></i>&nbsp;删除所有</div>')
  24. .after('<div class="btn btn-spec batch-add btn-primary btn-outline btn-sm" style="margin-left:10px;"><i class="feather icon-plus"></i>&nbsp;批量新增</div>');
  25. //批量新增
  26. $(".has-many-spec .batch-add").click(function() {
  27. var name = prompt("请输入规格名称");
  28. if(!name) return;
  29. var num = parseInt(prompt("请输入新增数量,最多只能是100", 30));
  30. if(isNaN(num) || !num) return;
  31. if(num > 100) num = 100;
  32. var date = new Date();
  33. date = prompt("请输入起始日期", date.format("yyyy-MM-dd"));
  34. if(!date) return;
  35. var stock = prompt("请输入默认库存", 9999);
  36. if(!stock) return;
  37. var original_price = prompt("请输入默认原价");
  38. if(!original_price) return;
  39. var price = prompt("请输入默认售价");
  40. if(!price) return;
  41. $("template.spec-tpl .field_name").prop("value", name);
  42. var html = $("template.spec-tpl").html()
  43. var fields = {'name' : name, 'date' : date, 'stock' : stock, 'original_price' : original_price, 'price' : price};
  44. for(var key in fields) {
  45. html = html.replace('name="spec[new___LA_KEY__][' + key + ']" value=""', 'name="spec[new___LA_KEY__][' + key + ']" value="' + fields[key] + '"');
  46. }
  47. var nestedIndex = $(".has-many-spec-forms tr").length - 1;
  48. function replaceNestedFormIndex(value) {
  49. return String(value).replace(/__LA_KEY__/g, nestedIndex);
  50. }
  51. for(var i=0; i<num; i++) {
  52. nestedIndex++;
  53. var d = new Date(date);
  54. d.setDate(d.getDate() + i);
  55. var template = replaceNestedFormIndex(html.replace(date, d.format('yyyy-MM-dd')));
  56. $(".has-many-spec-forms").append(template);
  57. }
  58. });
  59. //清空全部
  60. $(".has-many-spec .batch-sub").click(function() {
  61. $(".has-many-spec-forms .remove.btn").click();
  62. console.log(123213)
  63. });
  64. });