last_save.html 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. {extend name="common/common2" /}
  2. {block name="main"}
  3. <div class="row">
  4. <div class="col-sm-12">
  5. <div class="ibox float-e-margins">
  6. <div class="ibox-content">
  7. <form class="form ajax-form" action="lastSave" method="POST">
  8. <div id="vueapp">
  9. <table class="table table-bordered">
  10. <tr>
  11. <th>名称</th>
  12. <th>数量</th>
  13. <th>操作</th>
  14. </tr>
  15. <tr v-for="(item, index) in options" :key="index">
  16. <td>{{item.title}}</td>
  17. <td style="width: 150px;"><input v-model="item.nums" type="number" class="form-control"></td>
  18. <td style="width: 150px;"><button v-if="options.length > 1" @click="delOption(index)">删除</button></td>
  19. </tr>
  20. </table>
  21. <input type="hidden" id="datioptions" name="options" value="">
  22. <input type="hidden" name="name" value="{$name}">
  23. <input type="hidden" name="phone" value="{$phone}">
  24. <input type="hidden" name="remark" value="{$remark}">
  25. <button type="button" class="btn btn-primary btn-cus" >保存</button>
  26. </div>
  27. </form>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. {/block}
  33. {block name="script"}
  34. <script>
  35. var vm = new Vue({
  36. el: '#vueapp',
  37. data: {
  38. options: {:json_encode($lists,302)},
  39. },
  40. computed: {
  41. // 计算属性的 getter
  42. resoptions: function () {
  43. return JSON.parse(JSON.stringify(this.options));
  44. }
  45. },
  46. watch: {
  47. resoptions: function (newval, oldval) {
  48. this.formatData();
  49. },
  50. type: function (newval, oldval) {
  51. },
  52. },
  53. created: function () {
  54. this.formatData();
  55. },
  56. methods: {
  57. delOption(index) {
  58. let oldoptions = JSON.parse(JSON.stringify(this.options));
  59. let newoptions = [];
  60. for(let o in oldoptions){
  61. if(o != index){
  62. newoptions.push(oldoptions[o]);
  63. }
  64. }
  65. this.options = JSON.parse(JSON.stringify(newoptions));
  66. },
  67. formatData(){
  68. let ops = JSON.parse(JSON.stringify(this.options));
  69. console.log('ret',JSON.stringify(ops));
  70. $('#datioptions').val(JSON.stringify(ops));
  71. }
  72. }
  73. })
  74. $('.btn-cus').click(function () {
  75. var data = $('.ajax-form').serialize();
  76. $.post('lastSave',data,function (res) {
  77. console.log(res);
  78. if(res.code==0){
  79. layer.msg(res.msg);
  80. return;
  81. }else if (res.code==1){
  82. layer.msg(res.msg,{time:2000},function () {
  83. parent.layer.closeAll();
  84. });
  85. }
  86. })
  87. })
  88. </script>
  89. {/block}