edit.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. use yii\widgets\ActiveForm;
  3. use common\helpers\Html;
  4. use addons\TinyShop\common\enums\SpecTypeEnum;
  5. $this->title = $model->isNewRecord ? '创建' : '编辑';
  6. $this->params['breadcrumbs'][] = ['label' => '规格管理', 'url' => ['index']];
  7. $this->params['breadcrumbs'][] = $this->title;
  8. $updateName = $model->formName() . '[valueData][update]';
  9. $createName = $model->formName() . '[valueData][create]';
  10. ?>
  11. <div class="row">
  12. <div class="col-12 col-lg-12">
  13. <div class="box">
  14. <div class="box-header with-border">
  15. <h3 class="box-title">基本信息</h3>
  16. </div>
  17. <?php $form = ActiveForm::begin([]); ?>
  18. <div class="box-body">
  19. <div class="col-lg-12">
  20. <?= $form->field($model, 'title')->textInput()->label('规格名称'); ?>
  21. <?= $form->field($model, 'type')->radioList(SpecTypeEnum::getMap()); ?>
  22. <?= $form->field($model, 'sort')->textInput(); ?>
  23. <?= $form->field($model, 'explain')->textarea(); ?>
  24. <table class="table table-hover">
  25. <thead>
  26. <tr>
  27. <th>规格值</th>
  28. <th>排序</th>
  29. <th>操作</th>
  30. </tr>
  31. </thead>
  32. <tbody>
  33. <?php foreach ($model->value as $key => $option) { ?>
  34. <tr id="<?= $option['id']; ?>">
  35. <td class="col-lg-1">
  36. <?= Html::textInput($updateName . '[title][]', $option['title'], [
  37. 'class' => 'form-control title',
  38. ]) ?>
  39. </td>
  40. <td class="col-lg-1">
  41. <?= Html::textInput($updateName . '[sort][]', $option['sort'], [
  42. 'class' => 'form-control sort',
  43. ]) ?>
  44. </td>
  45. <td class="col-lg-2">
  46. <?= Html::hiddenInput($updateName . '[id][]', $option['id']) ?>
  47. <a href="javascript:void(0);" class="delete update blue"> 删除</a>
  48. </td>
  49. </tr>
  50. <?php } ?>
  51. <tr id="position">
  52. <td colspan="2"><a href="javascript:void(0);" id="add"><i class="iconfont iconplus-circle pointer"></i> 添加规格值</a></td>
  53. </tr>
  54. </tbody>
  55. </table>
  56. </div>
  57. </div>
  58. <div class="box-footer text-center">
  59. <span class="btn btn-primary" onclick="beforeSubmit()">保存</span>
  60. <span class="btn btn-white" onclick="history.go(-1)">返回</span>
  61. </div>
  62. <?php ActiveForm::end(); ?>
  63. </div>
  64. </div>
  65. </div>
  66. <!-- 添加模板 -->
  67. <script id="addHtml" type="text/html">
  68. <tr>
  69. <td class="col-lg-1">
  70. <?= Html::textInput($createName . '[title][]', '', [
  71. 'class' => 'form-control title',
  72. ]) ?>
  73. </td>
  74. <td class="col-lg-1">
  75. <?= Html::textInput($createName . '[sort][]', 999, [
  76. 'class' => 'form-control sort',
  77. ]) ?>
  78. </td>
  79. <td class="col-lg-2">
  80. <a href="javascript:void(0);" class="delete blue"> 删除</a>
  81. </td>
  82. </tr>
  83. </script>
  84. <script>
  85. // 增加属性
  86. $('#add').click(function () {
  87. let html = template('addHtml', []);
  88. $('#position').before(html);
  89. });
  90. // 删除属性
  91. $(document).on("click", ".delete", function () {
  92. $(this).parent().parent().remove()
  93. });
  94. // 验证提交
  95. function beforeSubmit() {
  96. var submit = true;
  97. $('.title').each(function () {
  98. if (!$(this).val()) {
  99. rfAffirm('请填写规格值内容');
  100. submit = false;
  101. }
  102. });
  103. $('.sort').each(function () {
  104. if (!$(this).val()) {
  105. rfAffirm('请填写排序内容');
  106. submit = false;
  107. }
  108. if (isNaN($(this).val())) {
  109. rfAffirm('排序只能为数字');
  110. submit = false;
  111. }
  112. });
  113. if (submit === true) {
  114. $('#w0').submit();
  115. }
  116. }
  117. </script>
粤ICP备19079148号