last_save.html 3.6 KB

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