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

98 lines
2.7 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
  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 num = parseInt(prompt('请输入新增数量,最多不超过180', '30'));
  32. if (isNaN(num) || !num) {
  33. return;
  34. }
  35. if (num > 180) {
  36. num = 180;
  37. }
  38. var date = new Date();
  39. date = prompt('请输入起始日期', date.format('yyyy-MM-dd'));
  40. if (!date) {
  41. return;
  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. $('template.spec-tpl .field_name').prop('value', name);
  56. var html = $('template.spec-tpl').html();
  57. var fields = {
  58. 'name': name,
  59. 'date': date,
  60. 'stock': stock,
  61. 'original_price': original_price,
  62. 'price': price
  63. };
  64. for (var key in fields) {
  65. html = html.replace('name="spec[new___LA_KEY__][' + key + ']" value=""', 'name="spec[new___LA_KEY__][' + key + ']" value="' + fields[key] + '"');
  66. }
  67. var nestedIndex = $('.has-many-spec-forms tr').length - 1;
  68. function replaceNestedFormIndex(value) {
  69. return String(value).replace(/__LA_KEY__/g, nestedIndex);
  70. }
  71. for (var i = 0; i < num; i++) {
  72. nestedIndex++;
  73. var d = new Date(date);
  74. d.setDate(d.getDate() + i);
  75. var template = replaceNestedFormIndex(html.replace(date, d.format('yyyy-MM-dd')));
  76. $('.has-many-spec-forms').append(template);
  77. }
  78. });
  79. //清空全部
  80. $('.has-many-spec .batch-sub').click(function () {
  81. $('.has-many-spec-forms .remove.btn').click();
  82. });
  83. });