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

108 lines
3.1 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
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 (!num || isNaN(num)) {
  38. return;
  39. }
  40. if (num > 180) {
  41. num = 180;
  42. }
  43. var stock = parseInt(prompt('请输入默认库存', '9999'));
  44. if (!stock || isNaN(stock)) {
  45. return;
  46. }
  47. var original_price = parseFloat(prompt('请输入默认市场价'));
  48. if (!original_price || isNaN(original_price)) {
  49. return;
  50. }
  51. var price = parseFloat(prompt('请输入默认销售价'));
  52. if (!price || isNaN(price)) {
  53. return;
  54. }
  55. var cost_price = 0;
  56. //行业产品不需要成本价
  57. if (location.href.indexOf('industry') === -1) {
  58. cost_price = parseFloat(prompt('请输入默认成本价'));
  59. if (!cost_price || isNaN(cost_price)) {
  60. return;
  61. }
  62. }
  63. $('template.spec-tpl .field_name').prop('value', name);
  64. var html = $('template.spec-tpl').html();
  65. var fields = {
  66. 'name': name,
  67. 'date': date,
  68. 'stock': stock,
  69. 'original_price': original_price,
  70. 'price': price,
  71. 'cost_price': cost_price,
  72. };
  73. for (var key in fields) {
  74. html = html.replace('name="spec[new___LA_KEY__][' + key + ']" value=""', 'name="spec[new___LA_KEY__][' + key + ']" value="' + fields[key] + '"');
  75. }
  76. var nestedIndex = $('.has-many-spec-forms tr').length - 1;
  77. function replaceNestedFormIndex(value) {
  78. return String(value).replace(/__LA_KEY__/g, nestedIndex);
  79. }
  80. for (var i = 0; i < num; i++) {
  81. nestedIndex++;
  82. var d = new Date(date);
  83. d.setDate(d.getDate() + i);
  84. var template = replaceNestedFormIndex(html.replace(date, d.format('yyyy-MM-dd')));
  85. $('.has-many-spec-forms').append(template);
  86. }
  87. });
  88. //清空全部
  89. $('.has-many-spec .batch-sub').click(function () {
  90. $('.has-many-spec-forms .remove.btn').click();
  91. });
  92. });