add.html 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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-title">
  7. <h5>{$meta_title}</h5>
  8. <div class="ibox-tools">
  9. <a class="toback" href="{:url('Burst/index')}">
  10. 返回上一页
  11. </a>
  12. </div>
  13. </div>
  14. <div class="ibox-content">
  15. <form method="post" action="{:url('add')}" class="form-horizontal">
  16. <input type="hidden" name="id" value="{$info['id']|default='0'}">
  17. <div class="form-group">
  18. <label class="col-sm-2 control-label">事件名称</label>
  19. <div class="col-sm-6">
  20. <input type="text" class="form-control" name="title" value="{$info.title|default=''}">
  21. </div>
  22. </div>
  23. <div class="form-group">
  24. <label class="col-sm-2 control-label">备注</label>
  25. <div class="col-sm-6">
  26. <textarea name="remark" class="form-control">{$info.remark|default=''}</textarea>
  27. </div>
  28. </div>
  29. <div class="form-group">
  30. <label class="col-sm-2 control-label">事件流程</label>
  31. <div class="col-sm-6">
  32. <input type="hidden" name="content" id="content" value="{$info.content|default=''}">
  33. <div id="vueapp">
  34. <div>
  35. <table class="table table-bordered">
  36. <tr>
  37. <th>步骤</th>
  38. <th>操作</th>
  39. </tr>
  40. <tr v-for="(item,index) in question" :key="index">
  41. <td>
  42. <div style="margin-bottom: 10px;">
  43. <input type="text" class="form-control" v-model="item.title" placeholder="步骤名称">
  44. </div>
  45. <div style="margin-bottom: 10px;">
  46. <input type="number" min="0" step="1" v-model="item.time" class="form-control" placeholder="时间(分钟)">
  47. </div>
  48. <div>
  49. <table class="table table-bordered">
  50. <tr>
  51. <th>事项</th>
  52. </tr>
  53. <tr v-for="(item2,index2) in item.options" :key="index2">
  54. <td>
  55. <input v-if="item.options.length <= 1" type="text" class="form-control" v-model="item2.text" placeholder="事项">
  56. <div v-if="item.options.length > 1" class="input-group">
  57. <input type="text" v-model="item2.text" class="form-control search-query" placeholder="事项">
  58. <span class="input-group-btn">
  59. <button type="button" @click="delOptions(index,index2)" class="btn btn-danger btn-sm">
  60. 删除
  61. </button>
  62. </span>
  63. </div>
  64. </td>
  65. </tr>
  66. </table>
  67. <a href="javascript:;" @click="addOptions(index)">添加事项</a>
  68. </div>
  69. </td>
  70. <td>
  71. <button type="button" class="btn btn-sm btn-danger" v-if="question.length > 1" @click="delQuestion(index)">删除</button>
  72. </td>
  73. </tr>
  74. </table>
  75. <a href="javascript:;" @click="addQuestion">添加步骤</a>
  76. </div>
  77. </div>
  78. </div>
  79. </div>
  80. <div class="form-group">
  81. <label class="col-sm-2 control-label">状态</label>
  82. <div class="col-sm-6">
  83. <label class="cr-inline">
  84. <input type="radio" value="1" name="enable">正常&nbsp;&nbsp;
  85. </label>
  86. <label class="cr-inline">
  87. <input type="radio" value="0" name="enable">禁用
  88. </label>
  89. </div>
  90. </div>
  91. <div class="hr-line-dashed"></div>
  92. <div class="form-group">
  93. <div class="col-sm-6 col-sm-offset-2">
  94. <button class="btn btn-primary ajax-post" target-form="form-horizontal" type="submit">确 定</button>
  95. </div>
  96. </div>
  97. </form>
  98. </div>
  99. </div>
  100. </div>
  101. </div>
  102. {/block}
  103. {block name="script"}
  104. <script>
  105. $(document).ready(function(){
  106. formSetValue("enable", {$info.enable|default=1});
  107. formSetValue("type", {$info.type|default=0});
  108. });
  109. {if condition="isset($info)"}
  110. var question = {$info['content']|raw};
  111. {else /}
  112. var question = [];
  113. {/if}
  114. new Vue({
  115. el: '#vueapp',
  116. data: {
  117. question: question,
  118. info: {
  119. title: "",
  120. time: "",
  121. options: [{
  122. text: "",
  123. status: 0,
  124. }],
  125. status: 0
  126. }
  127. },
  128. computed: {
  129. resoptions: function () {
  130. return JSON.parse(JSON.stringify(this.question));
  131. }
  132. },
  133. watch: {
  134. resoptions: function (newval, oldval) {
  135. console.log(newval, oldval);
  136. this.formatData();
  137. },
  138. },
  139. created: function () {
  140. if(this.question.length == 0) {
  141. this.question.push(JSON.parse(JSON.stringify(this.info)));
  142. }
  143. this.formatData();
  144. },
  145. methods: {
  146. addQuestion() {
  147. // const item = JSON.parse(JSON.stringify(this.info));
  148. this.question.push(JSON.parse(JSON.stringify(this.info)));
  149. console.log(this.question);
  150. },
  151. delQuestion(index) {
  152. console.log(index);
  153. let qes = [];
  154. this.question.forEach((item,index2) => {
  155. if(index != index2){
  156. qes.push(item);
  157. }
  158. });
  159. this.question = JSON.parse(JSON.stringify(qes));
  160. },
  161. addOptions(index){
  162. this.question.forEach((item,idx) => {
  163. const info1 = item;
  164. if(index == idx){
  165. info1.options.push({
  166. text: "",
  167. status: 0
  168. });
  169. }
  170. })
  171. },
  172. delOptions(index,index2){
  173. this.question.forEach((item,idx) => {
  174. const info1 = item;
  175. if(index == idx){
  176. let ops = [];
  177. info1.options.forEach((item2,idx2) => {
  178. if(idx2 != index2){
  179. ops.push(item2);
  180. }
  181. });
  182. info1.options = JSON.parse(JSON.stringify(ops));
  183. }
  184. })
  185. },
  186. formatData(){
  187. if(this.question.length > 0){
  188. $('#content').val(JSON.stringify(this.question));
  189. }else{
  190. $('#content').val('');
  191. }
  192. },
  193. }
  194. })
  195. </script>
  196. {/block}