add.html 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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. <!--{if condition="$isCalendar neq 1 && $type neq 1"}-->
  7. <!--<div class="ibox-title">-->
  8. <!--<h5>{$meta_title}</h5>-->
  9. <!--<div class="ibox-tools">-->
  10. <!--<a class="toback" href="{:url('index',['mode'=>$mode])}">-->
  11. <!--返回上一页-->
  12. <!--</a>-->
  13. <!--</div>-->
  14. <!--</div>-->
  15. <!--{/if}-->
  16. <div class="ibox-content">
  17. <form method="post" action="{:url('add',['mode'=>$mode])}" class="form-horizontal">
  18. <input type="hidden" name="id" value="{$info['id']|default='0'}">
  19. <input type="hidden" name="type" value="{$type|default='0'}">
  20. <input type="hidden" name="isCalendar" value="{$isCalendar|default='0'}">
  21. <input type="hidden" name="patrol_mode" value="{$mode|default=''}">
  22. <div class="form-group">
  23. <label class="col-sm-2 control-label">任务名称<span class="text-danger">*</span></label>
  24. <div class="col-sm-8">
  25. <input type="text" class="form-control" name="title" value="{$info.title|default=''}" placeholder="请输入任务名称">
  26. </div>
  27. </div>
  28. <div id="vue-plan">
  29. <div class="form-group" {if $mode==4} style="display: block" {else} style="display: none" {/if}>
  30. <input type="hidden" name="cate_id" v-model="cate">
  31. <label class="col-sm-2 control-label">选择分类<span class="text-danger">*</span></label>
  32. <div class="col-sm-8">
  33. <el-select clearable multiple filterable v-model="cate" placeholder="请选择分类">
  34. <el-option
  35. v-for="item in cateList"
  36. :key="item.id"
  37. :label="item.title"
  38. :value="item.id.toString()">
  39. </el-option>
  40. </el-select>
  41. </div>
  42. </div>
  43. <div class="form-group">
  44. <label class="col-sm-2 control-label">地点<span class="text-danger">*</span></label>
  45. <div class="col-sm-8">
  46. <input type="hidden" name="addrs" value="" id="addrForms">
  47. <button class="btn btn-sm btn-primary" type="button" @click="selectAddr()">添加地点</button>
  48. <button class="btn btn-sm btn-primary" type="button" @click="selectForm()">设置检查内容</button>
  49. <button class="btn btn-sm btn-danger" type="button" @click="delAddrs">移除</button>
  50. <button class="btn btn-sm btn-primary" type="button" @click="sortAddrs">确定排序</button>
  51. <el-table
  52. v-if="tableData.length > 0"
  53. :data="tableData"
  54. height="250"
  55. border
  56. @selection-change="handleSelectionChange"
  57. style="width: 100%">
  58. <el-table-column
  59. type="selection"
  60. width="60">
  61. </el-table-column>
  62. <el-table-column
  63. prop="addrTitle"
  64. label="地点名称"
  65. width="180">
  66. </el-table-column>
  67. <el-table-column prop="formTitle" label="检查内容">
  68. <template slot-scope="scope">
  69. <span v-for="(item,index) in scope.row.forms" :key="index">{{item.title}};</span>
  70. </template>
  71. </el-table-column>
  72. <el-table-column prop="sorts" label="排序">
  73. <template slot-scope="scope">
  74. <input type="number" step="1" class="form-control" v-model="scope.row.sorts">
  75. </template>
  76. </el-table-column>
  77. <!--<el-table-column label="操作" width="130">-->
  78. <!--<template slot-scope="scope">-->
  79. <!--<button class="btn btn-sm" type="button" @click="moveUp(scope.$index, scope.row)">上移</button>-->
  80. <!--<button class="btn btn-sm" type="button" @click="moveDown(scope.$index, scope.row)">下移</button>-->
  81. <!--</template>-->
  82. <!--</el-table-column>-->
  83. </el-table>
  84. <el-dialog
  85. title="选择地点"
  86. :visible.sync="dialogVisibleAddr"
  87. width="500px"
  88. :before-close="handleClose"
  89. >
  90. <el-input
  91. placeholder="请输入"
  92. v-model="addrkeyword"
  93. @input="searchAddr"
  94. clearable>
  95. </el-input>
  96. <el-table
  97. ref="singleTable"
  98. :data="addrs"
  99. height="200"
  100. @selection-change="handleSelectionChangeAddr"
  101. style="width: 100%">
  102. <el-table-column
  103. type="selection"
  104. width="60">
  105. </el-table-column>
  106. <el-table-column
  107. property="title"
  108. label="名称"
  109. >
  110. </el-table-column>
  111. </el-table>
  112. <span slot="footer" class="dialog-footer">
  113. <el-button @click="dialogVisibleAddr = false">取 消</el-button>
  114. <el-button type="primary" @click="saveAddr">确 定</el-button>
  115. </span>
  116. </el-dialog>
  117. <el-dialog
  118. title="选择检查内容"
  119. :visible.sync="dialogVisibleForm"
  120. width="500px"
  121. :before-close="handleCloseForm"
  122. >
  123. <el-input
  124. placeholder="请输入"
  125. v-model="formkeyword"
  126. @input="searchForm"
  127. clearable>
  128. </el-input>
  129. <el-table
  130. ref="singleTable2"
  131. :data="forms"
  132. height="200"
  133. @selection-change="handleCurrentChange"
  134. style="width: 100%">
  135. <el-table-column
  136. type="selection"
  137. width="60">
  138. </el-table-column>
  139. <el-table-column
  140. property="title"
  141. label="名称"
  142. >
  143. </el-table-column>
  144. </el-table>
  145. <span slot="footer" class="dialog-footer">
  146. <el-button @click="dialogVisibleAddr = false">取 消</el-button>
  147. <el-button type="primary" @click="saveForm">确 定</el-button>
  148. </span>
  149. </el-dialog>
  150. </div>
  151. </div>
  152. <div class="form-group">
  153. <label class="col-sm-2 control-label">是否按顺序执行<span class="text-danger">*</span></label>
  154. <div class="col-sm-8" style="padding-top: 7px;">
  155. <input type="hidden" name="in_order" value="" id="inOrder">
  156. <el-radio v-model="inOrder" :label="0">否</el-radio>
  157. <el-radio v-model="inOrder" :label="1">是</el-radio>
  158. </div>
  159. </div>
  160. <input type="hidden" name="lines" value="" id="addrFormsLines">
  161. <div class="form-group" v-if="inOrder === 1 && lines.length > 0">
  162. <label class="col-sm-2 control-label">路线时间设置</label>
  163. <div class="col-sm-8" style="padding-top: 7px;">
  164. <table class="table table-bordered ctable text-center">
  165. <tr>
  166. <th class="text-center">路线</th>
  167. <th class="text-center">时间跨度(分钟)</th>
  168. <th class="text-center">浮动时间(分钟)</th>
  169. </tr>
  170. <tr v-for="(item,index) in lines" :key="index">
  171. <td>{{item.st}} ~ {{item.et}}</td>
  172. <td><el-input type="number" v-model="item.kd" size="small" style="width: 140px" placeholder=""></el-input></td>
  173. <td><el-input type="number" v-model="item.fd" size="small" style="width: 140px" placeholder=""></el-input></td>
  174. </tr>
  175. </table>
  176. </div>
  177. </div>
  178. </div>
  179. <div class="form-group">
  180. <label class="col-sm-2 control-label">检查人员<span class="text-danger">*</span></label>
  181. <div class="col-sm-8">
  182. {:widget_view('common/multiselect',['name'=>'user_ids','lists' =>$user, 'val' =>isset($info)?$info['task_user']:[]])}
  183. </div>
  184. </div>
  185. <div class="form-group">
  186. <label class="col-sm-2 control-label">开始时间<span class="text-danger">*</span></label>
  187. <div class="col-sm-8">
  188. <input class="form-control" id="date" readonly name="start_time" value="{$info.start_time|default=$start}">
  189. </div>
  190. </div>
  191. <div class="form-group">
  192. <label class="col-sm-2 control-label">结束时间<span class="text-danger">*</span></label>
  193. <div class="col-sm-8">
  194. <input class="form-control" id="date-one" readonly name="end_time" value="{$info.end_time|default=$end}">
  195. </div>
  196. </div>
  197. <div class="hr-line-dashed"></div>
  198. <div class="form-group">
  199. <div class="col-sm-8 col-sm-offset-2">
  200. <button class="btn btn-primary ajax-post" target-form="form-horizontal" data-layer_c="1" type="submit">确 定</button>
  201. {if $type==1}
  202. {if $isCalendar==1}
  203. <a href="{:url('calendar',['mode'=>$mode])}" class="btn btn-default">取 消</a>
  204. {else}
  205. <button class="btn cancel-btn btn-default" type="button">取 消</button>
  206. {/if}
  207. {else}
  208. <button class="btn cancel-btn btn-default" type="button">取 消</button>
  209. <!--<a href="{:url('index',['mode'=>$mode])}" class="btn btn-default">取 消</a>-->
  210. {/if}
  211. </div>
  212. </div>
  213. </form>
  214. </div>
  215. </div>
  216. </div>
  217. </div>
  218. {/block}
  219. {block name="script"}
  220. <script type="text/javascript" src="/static/layDate-v5.0.9/laydate.js"></script>
  221. <script>
  222. var time =new Date();
  223. //日期时间选择器
  224. laydate.render({
  225. elem: '#date',
  226. type: 'datetime',
  227. format:'yyyy-MM-dd HH:mm',
  228. trigger: 'click' ,
  229. theme:'#284a94'
  230. // value:dateFormat(),
  231. });
  232. laydate.render({
  233. elem: '#date-one',
  234. type: 'datetime',
  235. trigger: 'click' ,
  236. format:'yyyy-MM-dd HH:mm',
  237. theme:'#284a94'
  238. // value:dateFormatH(),
  239. });
  240. //当前日期格式化
  241. function dateFormat() {
  242. var year=time.getFullYear();
  243. var mouth=time.getMonth()+ 1;
  244. if(mouth < 10){
  245. var mouths='0'+mouth;
  246. }else {
  247. var mouths=mouth;
  248. }
  249. var day=time.getDate();
  250. if(day < 10){
  251. var days='0'+day;
  252. }else {
  253. var days=day;
  254. }
  255. var hour=time.getHours();
  256. if(hour < 10){
  257. var hours='0'+hour;
  258. }else {
  259. var hours=hour;
  260. }
  261. var minute=time.getMinutes();
  262. if(minute < 10){
  263. var minutes='0'+minute;
  264. }else {
  265. var minutes=minute;
  266. }
  267. var dateStr=year+'-'+mouths+'-'+days+' '+hours+':'+minutes;
  268. return dateStr;
  269. }
  270. function dateFormatH() {
  271. var year=time.getFullYear();
  272. var mouth=time.getMonth()+ 1;
  273. if(mouth < 10){
  274. var mouths='0'+mouth;
  275. }else {
  276. var mouths=mouth;
  277. }
  278. var day=time.getDate();
  279. if(day < 10){
  280. var days='0'+day;
  281. }else {
  282. var days=day;
  283. }
  284. var hour=time.getHours();
  285. if(hour < 10){
  286. var hours='0'+hour;
  287. }else {
  288. var hours=hour;
  289. }
  290. var minute=time.getMinutes()+20;
  291. var dateStr=year+'-'+mouths+'-'+days+' '+hours+':'+minute;
  292. return dateStr;
  293. }
  294. var ads = {:json_encode($address)};
  295. var frs = {:json_encode($patrolForm)};
  296. var addrForms = {:json_encode($info['addrForms'])};
  297. var cateList = {:json_encode($cateList)};
  298. var lis = {:json_encode($info['lines'])};
  299. console.log(addrForms);
  300. var info = {:json_encode($info)};
  301. new Vue({
  302. el: '#vue-plan',
  303. data: function() {
  304. return {
  305. title: '',
  306. dialogVisible: false,
  307. step: 0,
  308. date: '',
  309. tableData: addrForms,
  310. selAddrForms: [], // 选择的地址表单
  311. addrs: ads,
  312. selAddrs:[], // 选择地址
  313. dialogVisibleAddr: false,
  314. addrkeyword: '',
  315. forms: frs,
  316. selForm: null,
  317. formkeyword: '',
  318. dialogVisibleForm: false,
  319. lines: lis,
  320. inOrder: {$info.in_order},
  321. cateList:cateList,
  322. cate:[],
  323. frs:frs
  324. }
  325. },
  326. watch: {
  327. cate: function (newVal, oldVal) {
  328. var that = this;
  329. $.post('{:url("PatrolForm/getByCate")}',{id:newVal},function (res) {
  330. that.frs = res.data;
  331. })
  332. },
  333. nTableData(){
  334. console.log('nTableData1111');
  335. $('#addrForms').val(JSON.stringify(this.tableData));
  336. },
  337. nLines(){
  338. $('#addrFormsLines').val(JSON.stringify(this.lines));
  339. },
  340. inOrder(){
  341. $('#inOrder').val(this.inOrder);
  342. },
  343. addrIds() { // 以保存的地址id
  344. console.log('tableData',this.tableData);
  345. let lines1 = [];
  346. if(this.tableData.length >= 2){
  347. for (let i in this.tableData){
  348. if(i < this.tableData.length - 1){
  349. lines1.push({
  350. s: this.tableData[i].addrId,
  351. st: this.tableData[i].addrTitle,
  352. e: this.tableData[Number(i)+1].addrId,
  353. et: this.tableData[Number(i)+1].addrTitle,
  354. kd: 0,
  355. fd: 0,
  356. })
  357. }
  358. }
  359. }
  360. this.lines = JSON.parse(JSON.stringify(lines1));
  361. console.log('lines2222',this.lines);
  362. },
  363. },
  364. computed: {
  365. addrIds() { // 以保存的地址id
  366. console.log('111ssss');
  367. let ids = [];
  368. this.tableData.forEach((item) => {
  369. ids.push(item.addrId);
  370. });
  371. return ids;
  372. },
  373. nTableData() { // 以保存的地址id
  374. return JSON.parse(JSON.stringify(this.tableData));
  375. },
  376. nLines() { // 以保存的地址id
  377. return JSON.parse(JSON.stringify(this.lines));
  378. },
  379. },
  380. created(){
  381. // this.tableData = addrForms;
  382. this.cate = info.cate_id;
  383. $('#addrForms').val(JSON.stringify(this.tableData));
  384. $('#addrFormsLines').val(JSON.stringify(this.lines));
  385. $('#inOrder').val(this.inOrder);
  386. this.frsList();
  387. },
  388. methods: {
  389. frsList: function () {
  390. var that = this;
  391. $.post('{:url("PatrolForm/getByCate")}',{id:that.cate},function (res) {
  392. that.frs = res.data;
  393. })
  394. },
  395. handleSelectionChange(val){
  396. console.log(val);
  397. this.selAddrForms = val;
  398. },
  399. handleClose(){
  400. this.dialogVisibleAddr = false;
  401. },
  402. handleSelectionChangeAddr(val){
  403. console.log(val);
  404. this.selAddrs = val;
  405. },
  406. selectAddr(){
  407. console.log('aaaaaaaaaaa');
  408. this.dialogVisibleAddr = true;
  409. this.addrkeyword = '';
  410. this.addrs = ads.filter((item) => {
  411. return !this.addrIds.includes(item.id);
  412. });
  413. this.selAddrs = [];
  414. console.log('bbbbbbbbb',this.addrs);
  415. },
  416. searchAddr(){
  417. this.addrs= [];
  418. this.$nextTick(() => {
  419. if(this.addrkeyword){
  420. this.addrs = ads.filter((item) => {
  421. return item.title.indexOf(this.addrkeyword) !== -1;
  422. });
  423. }else{
  424. this.addrs = ads;
  425. }
  426. });
  427. },
  428. saveAddr(){
  429. const tbs = this.tableData;
  430. this.selAddrs.forEach((item) => {
  431. if(!this.addrIds.includes(item.id)){
  432. tbs.push({
  433. 'addrId': item.id,
  434. 'addrTitle': item.title,
  435. 'forms': []
  436. });
  437. }
  438. });
  439. this.dialogVisibleAddr = false;
  440. this.$nextTick(() => {
  441. this.tableData = tbs;
  442. });
  443. },
  444. moveUp(idx,obj){
  445. console.log(idx,obj);
  446. if(idx > 0){
  447. let old = JSON.parse(JSON.stringify(this.tableData[idx]));
  448. let up = JSON.parse(JSON.stringify(this.tableData[idx - 1]));
  449. let tbs = this.tableData;
  450. this.tableData = [];
  451. this.$nextTick(() => {
  452. tbs[idx] = up;
  453. tbs[idx - 1] = old;
  454. this.tableData = tbs;
  455. })
  456. }
  457. console.log(this.tableData);
  458. },
  459. moveDown(idx,obj){ // 下移
  460. console.log(idx,obj);
  461. let length = this.tableData.length;
  462. if(idx < length - 1){
  463. let old = JSON.parse(JSON.stringify(this.tableData[idx]));
  464. let up = JSON.parse(JSON.stringify(this.tableData[idx + 1]));
  465. let tbs = this.tableData;
  466. this.tableData = [];
  467. this.$nextTick(() => {
  468. tbs[idx] = up;
  469. tbs[idx + 1] = old;
  470. this.tableData = tbs;
  471. })
  472. }
  473. },
  474. delAddrs(){ // 移除
  475. let sids = [];
  476. this.selAddrForms.forEach((item) => {
  477. sids.push(item.addrId);
  478. });
  479. if(sids.length == 0){
  480. this.$message.error('未选择地点');
  481. return false;
  482. }
  483. let tbs = this.tableData;
  484. this.tableData = [];
  485. this.$nextTick(() => {
  486. this.tableData = tbs.filter((item) => {
  487. return !sids.includes(item.addrId);
  488. });
  489. this.selAddrForms = [];
  490. });
  491. console.log(this.selAddrForms,sids,this.tableData);
  492. },
  493. sortAddrs(){
  494. let ll = JSON.parse(JSON.stringify(this.tableData));
  495. ll.sort((a, b) => {
  496. return Number(a.sorts) > Number(b.sorts) ? 1 : -1;
  497. });
  498. console.log('ll',ll);
  499. this.tableData = [];
  500. this.$nextTick(() => {
  501. this.tableData = JSON.parse(JSON.stringify(ll));
  502. });
  503. },
  504. handleCurrentChange(val){ // 选中检查内容
  505. console.log(val);
  506. this.selForm = val;
  507. },
  508. handleCloseForm(){
  509. this.dialogVisibleForm = false;
  510. },
  511. searchForm(){
  512. this.forms= [];
  513. this.$nextTick(() => {
  514. if(this.formkeyword){
  515. this.forms = this.frs.filter((item) => {
  516. return item.title.indexOf(this.formkeyword) !== -1;
  517. });
  518. }else{
  519. this.forms = this.frs;
  520. }
  521. });
  522. },
  523. saveForm(){
  524. console.log('1111');
  525. const tbs = this.tableData;
  526. this.tableData = [];
  527. let sids = [];
  528. this.selAddrForms.forEach((item) => {
  529. sids.push(item.addrId);
  530. });
  531. tbs.forEach((item) => {
  532. if(sids.includes(item.addrId)){
  533. // item.formId = this.selForm?this.selForm.id:0;
  534. // item.formTitle = this.selForm?this.selForm.title:'';
  535. const ffs = [];
  536. this.selForm.forEach((fitem) => {
  537. ffs.push({
  538. id: fitem.id,
  539. title: fitem.title
  540. });
  541. });
  542. item.forms = JSON.parse(JSON.stringify(ffs));
  543. }
  544. });
  545. this.dialogVisibleForm = false;
  546. this.$nextTick(() => {
  547. this.tableData = tbs;
  548. });
  549. },
  550. selectForm(){
  551. let sids = [];
  552. this.selAddrForms.forEach((item) => {
  553. sids.push(item.addrId);
  554. });
  555. if(sids.length == 0){
  556. this.$message.error('未选择地点');
  557. return false;
  558. }
  559. this.dialogVisibleForm = true;
  560. this.forms = this.frs;
  561. this.selForm = null;
  562. },
  563. getDateAll(starDay, endDay) { // 获取两个时间段的所有日期
  564. var arr = [];
  565. var dates = [];
  566. // 设置两个日期UTC时间
  567. var db = new Date(starDay);
  568. var de = new Date(endDay);
  569. // 获取两个日期GTM时间
  570. var s = db.getTime() - 24 * 60 * 60 * 1000;
  571. var d = de.getTime() - 24 * 60 * 60 * 1000;
  572. // 获取到两个日期之间的每一天的毫秒数
  573. for (var i = s; i <= d; ) {
  574. i = i + 24 * 60 * 60 * 1000;
  575. arr.push(parseInt(i));
  576. }
  577. // 获取每一天的时间 YY-MM-DD
  578. for (var j in arr) {
  579. var time = new Date(arr[j]);
  580. var year = time.getFullYear(time);
  581. var mouth =
  582. time.getMonth() + 1 >= 10
  583. ? time.getMonth() + 1
  584. : "0" + (time.getMonth() + 1);
  585. var day =
  586. time.getDate() >= 10
  587. ? time.getDate()
  588. : "0" + time.getDate();
  589. var YYMMDD = year + "-" + mouth + "-" + day;
  590. dates.push(YYMMDD);
  591. }
  592. return dates;
  593. },
  594. getWeekByDay(dateString,t=0) { // 获取某天是周几
  595. var dateArray = dateString.split("-");
  596. date = new Date(dateArray[0], parseInt(dateArray[1] - 1), dateArray[2]);
  597. if(t == 1){
  598. return "周" + "日一二三四五六".charAt(date.getDay());
  599. }else{
  600. return date.getDay();
  601. }
  602. }
  603. }
  604. })
  605. </script>
  606. {/block}