add.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 method="post" action="{:url('add')}" class="form-horizontal">
  8. <input type="hidden" name="dep_id">
  9. <input type="hidden" name="items">
  10. <div id="dispatchapp">
  11. <div class="form-group">
  12. <label class="col-sm-2 control-label">地点<span class="text-danger">*</span></label>
  13. <div class="col-sm-6">
  14. <el-select v-model="v1" clearable filterable placeholder="请选择">
  15. <el-option
  16. v-for="item in dep"
  17. :key="item.id"
  18. :label="item.title"
  19. :value="item.id">
  20. </el-option>
  21. </el-select>
  22. </div>
  23. </div>
  24. <div class="form-group">
  25. <label class="col-sm-2 control-label">物品<span class="text-danger">*</span></label>
  26. <div class="col-sm-6">
  27. <el-select
  28. v-model="v2"
  29. multiple
  30. collapse-tags
  31. placeholder="请选择">
  32. <el-option v-for="item in items" :key="item.id" :label="item.title" :value="item.id"> </el-option>
  33. </el-select>
  34. </div>
  35. </div>
  36. <div v-if="spec.length > 0">
  37. <div class="form-group" :key="index" v-for="(item,index) in spec">
  38. <label class="col-sm-2 control-label">{{item.title}}数量<span class="text-danger">*</span></label>
  39. <div class="col-sm-6">
  40. <input type="text" @input="setValue" v-model="spec[index].num" class="form-control" >
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. <div class="hr-line-dashed"></div>
  46. <div class="form-group">
  47. <div class="col-sm-6 col-sm-offset-2">
  48. <button class="btn btn-primary ajax-post" data-layer="1" target-form="form-horizontal" type="submit">确 定</button>
  49. <button class="btn cancel-btn btn-default" type="button">取 消</button>
  50. </div>
  51. </div>
  52. </form>
  53. </div>
  54. </div>
  55. </div>
  56. </div>
  57. {/block}
  58. {block name="script"}
  59. <script>
  60. $(document).ready(function(){
  61. formSetValue("enable", {$info.enable|default=1});
  62. formSetValue("is_show", {$info.is_show|default=0});
  63. });
  64. new Vue({
  65. el: '#dispatchapp',
  66. data: function() { // value: 'zhinan', label: '指南',children
  67. return {
  68. dep: {:json_encode($dep)},
  69. items: {:json_encode($items)},
  70. v1: '',
  71. v2: '',
  72. spec:[]
  73. }
  74. },
  75. watch: {
  76. v1: function (newQuestion, oldQuestion) {
  77. $("input[name=dep_id]").val(newQuestion);
  78. },
  79. v2: function (newQuestion, oldQuestion) {
  80. let newspec = [];
  81. newQuestion.forEach((item) => {
  82. let num = 0;
  83. let title = '';
  84. this.spec.forEach((item2) => {
  85. if(item2.id.toString() == item.toString()){
  86. num = item2.num;
  87. title = item2.title;
  88. }
  89. });
  90. if(!title){
  91. this.items.forEach((item3) => {
  92. if(item3.id.toString() == item){
  93. title = item3.title
  94. }
  95. });
  96. }
  97. newspec.push({
  98. id: item,
  99. num: num,
  100. title: title
  101. })
  102. });
  103. this.spec = JSON.parse(JSON.stringify(newspec));
  104. $("input[name=items]").val(JSON.stringify(this.spec));
  105. },
  106. },
  107. methods:{
  108. setValue:function () {
  109. console.log(this.spec);
  110. $("input[name=items]").val(JSON.stringify(this.spec));
  111. }
  112. }
  113. });
  114. </script>
  115. {/block}