海南旅游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.

104 lines
2.9 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  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) {
  29. return;
  30. }
  31. var date = new Date();
  32. date = prompt('请输入起始日期', date.format('yyyy-MM-dd'));
  33. if (!date || isNaN(new Date(date).getTime())) {
  34. return;
  35. }
  36. var num = parseInt(prompt('请输入新增数量,最多不超过180', '30'));
  37. if (isNaN(num) || !num) {
  38. return;
  39. }
  40. if (num > 180) {
  41. num = 180;
  42. }
  43. var stock = prompt('请输入默认库存', '9999');
  44. if (!stock) {
  45. return;
  46. }
  47. var original_price = prompt('请输入默认市场价');
  48. if (!original_price) {
  49. return;
  50. }
  51. var price = prompt('请输入默认销售价');
  52. if (!price) {
  53. return;
  54. }
  55. var cost_price = prompt('请输入默认成本价');
  56. if (!cost_price) {
  57. return;
  58. }
  59. $('template.spec-tpl .field_name').prop('value', name);
  60. var html = $('template.spec-tpl').html();
  61. var fields = {
  62. 'name': name,
  63. 'date': date,
  64. 'stock': stock,
  65. 'original_price': original_price,
  66. 'price': price,
  67. 'cost_price': cost_price,
  68. };
  69. for (var key in fields) {
  70. html = html.replace('name="spec[new___LA_KEY__][' + key + ']" value=""', 'name="spec[new___LA_KEY__][' + key + ']" value="' + fields[key] + '"');
  71. }
  72. var nestedIndex = $('.has-many-spec-forms tr').length - 1;
  73. function replaceNestedFormIndex(value) {
  74. return String(value).replace(/__LA_KEY__/g, nestedIndex);
  75. }
  76. for (var i = 0; i < num; i++) {
  77. nestedIndex++;
  78. var d = new Date(date);
  79. d.setDate(d.getDate() + i);
  80. var template = replaceNestedFormIndex(html.replace(date, d.format('yyyy-MM-dd')));
  81. $('.has-many-spec-forms').append(template);
  82. }
  83. });
  84. //清空全部
  85. $('.has-many-spec .batch-sub').click(function () {
  86. $('.has-many-spec-forms .remove.btn').click();
  87. });
  88. });