add.html 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336
  1. {extend name="common/common2" /}
  2. {block name="main"}
  3. <style>
  4. .ctable td{
  5. min-width: 150px!important;
  6. max-width: 300px!important;
  7. }
  8. </style>
  9. <div class="row">
  10. <div class="col-sm-12">
  11. <div class="ibox float-e-margins">
  12. <!-- <div class="ibox-title">
  13. <h5>{$meta_title}</h5>
  14. <div class="ibox-tools">
  15. <a class="toback" href="{:url('index',['mode'=>$mode])}">
  16. 返回上一页
  17. </a>
  18. </div>
  19. </div>-->
  20. <div class="ibox-content" id="vue-plan">
  21. <p><br></p>
  22. <div class="row">
  23. <div class="col-xs-6 col-xs-offset-3">
  24. <el-steps :active="step" align-center finish-status="success">
  25. <el-step title="配置地点"></el-step>
  26. <el-step title="配置排班"></el-step>
  27. <el-step title="任务确认"></el-step>
  28. </el-steps>
  29. </div>
  30. </div>
  31. <p><br></p>
  32. <form method="post" class="form-horizontal">
  33. <div v-if="step == 0">
  34. <div class="form-group">
  35. <label class="col-sm-2 control-label">任务名称<span class="text-danger">*</span></label>
  36. <div class="col-sm-8">
  37. <input type="text" class="form-control" v-model="title" value="" placeholder="请输入任务名称">
  38. </div>
  39. </div>
  40. <div class="form-group">
  41. <label class="col-sm-2 control-label">计划时间<span class="text-danger">*</span></label>
  42. <div class="col-sm-8">
  43. <el-date-picker
  44. style="width: 100%"
  45. size="small"
  46. v-model="date"
  47. type="daterange"
  48. range-separator="至"
  49. value-format="yyyy-MM-dd"
  50. start-placeholder="开始日期"
  51. end-placeholder="结束日期">
  52. </el-date-picker>
  53. </div>
  54. </div>
  55. <div class="form-group" {if $mode==4} style="display: block" {else} style="display: none" {/if}>
  56. <label class="col-sm-2 control-label">选择分类<span class="text-danger">*</span></label>
  57. <div class="col-sm-8">
  58. <el-select clearable multiple filterable v-model="cate" placeholder="请选择分类">
  59. <el-option
  60. v-for="item in cateList"
  61. :key="item.id"
  62. :label="item.title"
  63. :value="item.id.toString()">
  64. </el-option>
  65. </el-select>
  66. </div>
  67. </div>
  68. <div class="form-group">
  69. <label class="col-sm-2 control-label">地点<span class="text-danger">*</span></label>
  70. <div class="col-sm-8">
  71. <button class="btn btn-sm btn-primary" type="button" @click="selectAddr()">添加地点</button>
  72. <button class="btn btn-sm btn-primary" type="button" @click="selectForm()">设置检查内容</button>
  73. <button class="btn btn-sm btn-danger" type="button" @click="delAddrs">移除</button>
  74. <button class="btn btn-sm btn-primary" type="button" @click="sortAddrs">确定排序</button>
  75. <el-table
  76. v-if="tableData.length > 0"
  77. :data="tableData"
  78. height="350"
  79. border
  80. @selection-change="handleSelectionChange"
  81. style="width: 100%">
  82. <el-table-column
  83. type="selection"
  84. width="60">
  85. </el-table-column>
  86. <el-table-column
  87. prop="addrTitle"
  88. label="地点名称"
  89. width="180">
  90. </el-table-column>
  91. <el-table-column prop="formTitle" label="检查内容">
  92. <template slot-scope="scope">
  93. <span v-for="(item,index) in scope.row.forms" :key="index">{{item.title}};</span>
  94. </template>
  95. </el-table-column>
  96. <el-table-column prop="sorts" label="排序">
  97. <template slot-scope="scope">
  98. <input type="number" step="1" class="form-control" v-model="scope.row.sorts">
  99. </template>
  100. </el-table-column>
  101. <!-- <el-table-column label="操作" width="180">-->
  102. <!-- <template slot-scope="scope">-->
  103. <!-- <button class="btn btn-sm" type="button" @click="moveUp(scope.$index, scope.row)">上移</button>-->
  104. <!-- <button class="btn btn-sm" type="button" @click="moveDown(scope.$index, scope.row)">下移</button>-->
  105. <!-- </template>-->
  106. <!-- </el-table-column>-->
  107. </el-table>
  108. </div>
  109. </div>
  110. <div class="form-group">
  111. <label class="col-sm-2 control-label">是否按顺序执行<span class="text-danger">*</span></label>
  112. <div class="col-sm-8" style="padding-top: 7px;">
  113. <el-radio v-model="inOrder" :label="0">否</el-radio>
  114. <el-radio v-model="inOrder" :label="1">是</el-radio>
  115. </div>
  116. </div>
  117. <div class="form-group" v-if="inOrder === 1 && lines.length > 0">
  118. <label class="col-sm-2 control-label">路线时间设置</label>
  119. <div class="col-sm-8" style="padding-top: 7px;">
  120. <table class="table table-bordered ctable text-center">
  121. <tr>
  122. <th class="text-center">路线</th>
  123. <th class="text-center">时间跨度(分钟)</th>
  124. <th class="text-center">浮动时间(分钟)</th>
  125. </tr>
  126. <tr v-for="(item,index) in lines" :key="index">
  127. <td>{{item.st}} ~ {{item.et}}</td>
  128. <td><el-input type="number" v-model="item.kd" size="small" style="width: 140px" placeholder=""></el-input></td>
  129. <td><el-input type="number" v-model="item.fd" size="small" style="width: 140px" placeholder=""></el-input></td>
  130. </tr>
  131. </table>
  132. </div>
  133. </div>
  134. </div>
  135. <div v-if="step == 1">
  136. <div class="form-group">
  137. <label class="col-sm-2 control-label">设置人员<span class="text-danger">*</span></label>
  138. <div class="col-sm-8">
  139. <el-select
  140. clearable filterable
  141. v-model="userIds"
  142. multiple
  143. collapse-tags
  144. style="width: 100%"
  145. size="small"
  146. placeholder="请选择">
  147. <el-option
  148. v-for="item in users"
  149. :key="item.id"
  150. :label="item.title"
  151. :value="item.id">
  152. </el-option>
  153. </el-select>
  154. </div>
  155. </div>
  156. <div class="form-group">
  157. <label class="col-sm-2 control-label">时间段配置<span class="text-danger">*</span></label>
  158. <div class="col-sm-8">
  159. <el-select v-model="dateType" placeholder="请选择" style="width: 100px;" size="small">
  160. <el-option
  161. v-for="item in dateTypes"
  162. :key="item.id"
  163. :label="item.title"
  164. :value="item.id">
  165. </el-option>
  166. </el-select>
  167. <span v-if="dateType == 3">
  168. <el-date-picker
  169. style="width: 130px"
  170. size="small"
  171. v-model="dateFrom"
  172. type="date"
  173. value-format="yyyy-MM-dd"
  174. placeholder="请选择日期">
  175. </el-date-picker>
  176. 开始,工作
  177. <el-input type="number" @input="changePlay" v-model="datePlay" size="small" style="width: 80px;" placeholder="请输入天数"></el-input>
  178. 天,
  179. 暂停
  180. <el-input type="number" @input="changePause" v-model="datePause" size="small" style="width: 80px;" placeholder="请输入天数"></el-input>
  181. 天,每天的
  182. </span>
  183. <button v-if="dateType == 2" class="btn btn-sm btn-default" type="button" @click="selectWeek">添加周</button>
  184. <button class="btn btn-sm btn-default" type="button" @click="selectTime">添加时间段</button>
  185. 开始任务
  186. <div v-if="dateType == 2" style="padding: 5px 0">
  187. 已选择周:
  188. <el-tag
  189. style="margin-right: 5px;cursor: pointer"
  190. v-for="item in dateWeeks"
  191. size="small"
  192. :key="item.id"
  193. :type="item.type"
  194. effect="dark"
  195. >
  196. {{ item.title }}
  197. </el-tag>
  198. </div>
  199. <div style="padding: 5px 0">
  200. 已选择时间段:
  201. <el-tag
  202. style="margin-right: 5px;margin-bottom: 5px"
  203. :key="index"
  204. v-for="(item,index) in dateTimes"
  205. size="small"
  206. >
  207. {{item.stime}} ~ <span v-if="item.stype == 1">{{item.sday}}天后</span>{{item.etime}}
  208. </el-tag>
  209. </div>
  210. <el-button @click="createClass" size="small">生成任务表</el-button>
  211. <div style="padding: 5px 0">
  212. <div class="table-responsive" v-if="tasks.list.length > 0">
  213. <table class="table table-bordered ctable text-center">
  214. <tr>
  215. <td></td>
  216. <td v-for="(item,index) in tasks.days" :key="index">{{item}}</td>
  217. </tr>
  218. <tr v-for="(vo,idx) in tasks.list" :key="idx">
  219. <td>{{vo.time.stime}} ~ <span v-if="vo.time.stype == 1">{{vo.time.sday}}天后</span>{{vo.time.etime}}</td>
  220. <td v-for="(item,index) in tasks.days" :key="index">
  221. <template v-for="(v,id) in vo.list">
  222. <span v-if="item == v.day" :key="id">{{v.userNames}}</span>
  223. </template>
  224. </td>
  225. </tr>
  226. </table>
  227. </div>
  228. </div>
  229. </div>
  230. </div>
  231. </div>
  232. <div v-if="step == 2">
  233. <div style="padding: 5px 0">
  234. <div class="table-responsive" v-if="tasks.list.length > 0">
  235. <table class="table table-bordered ctable text-center">
  236. <tr>
  237. <td></td>
  238. <td></td>
  239. <td v-for="(item,index) in tasks.days" :key="index"><a href="javascript:;" @click="delDay(item)">删除列</a></td>
  240. </tr>
  241. <tr>
  242. <td></td>
  243. <td></td>
  244. <td v-for="(item,index) in tasks.days" :key="index">{{item}}</td>
  245. </tr>
  246. <tr v-for="(vo,idx) in tasks.list" :key="idx">
  247. <td><a href="javascript:;" @click="delTimes(vo.time)">删除行</a></td>
  248. <td>{{vo.time.stime}} ~ <span v-if="vo.time.stype == 1">{{vo.time.sday}}日后</span>{{vo.time.etime}}</td>
  249. <td v-for="(item,index) in tasks.days" :key="index">
  250. <template v-for="(v,id) in vo.list">
  251. <span v-if="item == v.day" :key="id">{{v.userNames}}</span>
  252. </template>
  253. </td>
  254. </tr>
  255. </table>
  256. </div>
  257. </div>
  258. </div>
  259. <div class="hr-line-dashed"></div>
  260. <div class="form-group">
  261. <div class="col-sm-6 col-sm-offset-2">
  262. <button v-if="step == 2" class="btn btn-primary" target-form="form-horizontal" type="button" id="saveSubmit" @click="saveSubmit">保 存</button>
  263. <button v-if="step == 1||step == 2" class="btn btn-default" type="button" @click="pre">上一步</button>
  264. <button v-if="step == 0||step == 1" class="btn btn-info" type="button" @click="next">下一步</button>
  265. </div>
  266. </div>
  267. </form>
  268. <el-dialog
  269. title="选择地点"
  270. :visible.sync="dialogVisibleAddr"
  271. width="500px"
  272. :before-close="handleClose"
  273. >
  274. <el-input
  275. placeholder="请输入"
  276. v-model="addrkeyword"
  277. @input="searchAddr"
  278. clearable>
  279. </el-input>
  280. <el-table
  281. ref="singleTable"
  282. :data="addrs"
  283. height="300"
  284. @selection-change="handleSelectionChangeAddr"
  285. style="width: 100%">
  286. <el-table-column
  287. type="selection"
  288. width="60">
  289. </el-table-column>
  290. <el-table-column
  291. property="title"
  292. label="名称"
  293. >
  294. </el-table-column>
  295. </el-table>
  296. <span slot="footer" class="dialog-footer">
  297. <el-button @click="dialogVisibleAddr = false">取 消</el-button>
  298. <el-button type="primary" @click="saveAddr">确 定</el-button>
  299. </span>
  300. </el-dialog>
  301. <el-dialog
  302. title="选择检查内容"
  303. :visible.sync="dialogVisibleForm"
  304. width="500px"
  305. :before-close="handleCloseForm"
  306. >
  307. <el-input
  308. placeholder="请输入"
  309. v-model="formkeyword"
  310. @input="searchForm"
  311. clearable>
  312. </el-input>
  313. <el-table
  314. v-if="dialogVisibleForm"
  315. ref="singleTable2"
  316. :data="forms"
  317. height="300"
  318. @selection-change="handleCurrentChange"
  319. style="width: 100%">
  320. <el-table-column
  321. type="selection"
  322. width="60">
  323. </el-table-column>
  324. <el-table-column
  325. property="title"
  326. label="名称"
  327. >
  328. </el-table-column>
  329. </el-table>
  330. <span slot="footer" class="dialog-footer">
  331. <el-button @click="handleCloseForm">取 消</el-button>
  332. <el-button type="primary" @click="saveForm">确 定</el-button>
  333. </span>
  334. </el-dialog>
  335. <el-dialog
  336. title="选择周"
  337. :visible.sync="dialogVisibleWeek"
  338. width="500px"
  339. :before-close="handleCloseWeek"
  340. >
  341. <div class="text-center">
  342. <el-tag
  343. style="margin-right: 5px;cursor: pointer"
  344. v-for="item in weeks"
  345. size="small"
  346. :key="item.id"
  347. :type="item.type"
  348. effect="dark"
  349. @click="handleWeek(item)"
  350. >
  351. {{ item.title }}
  352. </el-tag>
  353. </div>
  354. <span slot="footer" class="dialog-footer">
  355. <el-button @click="dialogVisibleWeek = false">取 消</el-button>
  356. <el-button type="primary" @click="saveWeek">确 定</el-button>
  357. </span>
  358. </el-dialog>
  359. <el-dialog
  360. title="时间段选择"
  361. :visible.sync="dialogVisibleTime"
  362. width="700px"
  363. :before-close="handleCloseTime"
  364. >
  365. <div style="padding: 5px 0">
  366. <el-tabs v-model="activeTabName">
  367. <el-tab-pane label="逐个添加" name="first"></el-tab-pane>
  368. <el-tab-pane label="批量添加" name="second"></el-tab-pane>
  369. </el-tabs>
  370. </div>
  371. <div style="padding: 5px 0">
  372. 选择时段:
  373. <span v-if="activeTabName === 'first'">
  374. <el-time-picker style="width:130px" v-model="stime" format="HH:mm" value-format="HH:mm" size="small" key="first01" placeholder="请选择时间"></el-time-picker>
  375. <el-select style="width:80px" v-model="stype" placeholder="请选择" size="small">
  376. <el-option label="今日" :value="0"></el-option>
  377. <el-option label="其他" :value="1"></el-option>
  378. </el-select>
  379. <el-input v-if="stype == 1" @input="changeSday" type="number" v-model="sday" size="small" style="width: 70px;" placeholder="天数"></el-input> 天后
  380. <el-time-picker style="width:130px" v-model="etime" format="HH:mm" value-format="HH:mm" size="small" key="first02" placeholder="请选择时间"></el-time-picker>
  381. <el-button @click="addTime" size="small">添加</el-button>
  382. </span>
  383. <span v-if="activeTabName === 'second'">
  384. <el-time-picker
  385. style="width:290px"
  386. is-range
  387. v-model="setime"
  388. key="second01"
  389. format="HH:mm"
  390. value-format="HH:mm"
  391. size="small"
  392. range-separator="至"
  393. start-placeholder="开始时间"
  394. end-placeholder="结束时间"
  395. placeholder="选择时间范围"
  396. ></el-time-picker>
  397. 每隔
  398. <el-input type="number" v-model="snums" size="small" style="width: 70px;" placeholder="天数"></el-input> 小时执行一次
  399. <el-button @click="addBatchTime" size="small">添加</el-button>
  400. </span>
  401. </div>
  402. <div style="padding: 5px 0">
  403. 已选择时间段:
  404. <el-tag
  405. style="margin-right: 5px;margin-bottom: 5px"
  406. size="small"
  407. :key="index"
  408. v-for="(item,index) in selTimes"
  409. closable
  410. @close="handleCloseTimes(item)">
  411. {{item.stime}} ~ <span v-if="item.stype == 1">{{item.sday}}天后</span>{{item.etime}}
  412. </el-tag>
  413. </div>
  414. <span slot="footer" class="dialog-footer">
  415. <el-button @click="dialogVisibleTime = false">取 消</el-button>
  416. <el-button type="primary" @click="saveTime">确 定</el-button>
  417. </span>
  418. </el-dialog>
  419. </div>
  420. </div>
  421. </div>
  422. </div>
  423. {/block}
  424. {block name="script"}
  425. <script>
  426. var ads = {:json_encode($address)};
  427. var frs = {:json_encode($patrolForm)};
  428. var us = {:json_encode($user)};
  429. var cateList = {:json_encode($cateList)};
  430. var mode = {$mode};
  431. {empty name="info"}
  432. var info = null;
  433. {else /}
  434. var info = {:json_encode($info)};
  435. {/empty}
  436. new Vue({
  437. el: '#vue-plan',
  438. data: function() {
  439. return {
  440. title: '',
  441. dialogVisible: false,
  442. step: 0,
  443. date: '',
  444. tableData: [],
  445. selAddrForms: [], // 选择的地址表单
  446. addrs: ads,
  447. selAddrs:[], // 选择地址
  448. dialogVisibleAddr: false,
  449. addrkeyword: '',
  450. forms: frs,
  451. selForm: [],
  452. formkeyword: '',
  453. dialogVisibleForm: false,
  454. users: us, // 人员列表
  455. userIds:[], // 选择的人员
  456. dateTypes: [
  457. {id: 1,title: '天'},
  458. {id: 2,title: '周'},
  459. {id: 4,title: '月'},
  460. {id: 3,title: '自定义'},
  461. ],
  462. dateType: 1,
  463. dateFrom: '', // 自定义类型从哪天开始
  464. datePlay: 1,
  465. datePause: 1,
  466. dateWeeks: [], // 已选择的周
  467. dateTimes: [], // 已添加的时间段
  468. weeks: [
  469. {id:1,title:'周一',type: 'info'},
  470. {id:2,title:'周二',type: 'info'},
  471. {id:3,title:'周三',type: 'info'},
  472. {id:4,title:'周四',type: 'info'},
  473. {id:5,title:'周五',type: 'info'},
  474. {id:6,title:'周六',type: 'info'},
  475. {id:0,title:'周日',type: 'info'},
  476. ],
  477. selWeeks: [],
  478. dialogVisibleWeek: false,
  479. dialogVisibleTime: false,
  480. stime: '',
  481. etime: '',
  482. stype: 0,
  483. sday: 1,
  484. selTimes: [], // 弹框已选的时间段
  485. tasks: { // 任务
  486. days: [],
  487. list: [],
  488. },
  489. activeTabName: 'first',
  490. setime: '',
  491. snums: 1,
  492. inOrder: 0,
  493. lines: [],
  494. cateList:cateList,
  495. cate:[],
  496. frs:frs
  497. }
  498. },
  499. watch: {
  500. cate: function (newVal, oldVal) {
  501. if(parseInt('{$mode}')==4){
  502. var that = this;
  503. $.post('{:url("PatrolForm/getByCate")}',{id:newVal},function (res) {
  504. that.frs = res.data;
  505. })
  506. }
  507. },
  508. addrIds() { // 以保存的地址id
  509. console.log('tableData',this.tableData);
  510. let lines = [];
  511. if(this.tableData.length >= 2){
  512. for (let i in this.tableData){
  513. if(i < this.tableData.length - 1){
  514. lines.push({
  515. s: this.tableData[i].addrId,
  516. st: this.tableData[i].addrTitle,
  517. e: this.tableData[Number(i)+1].addrId,
  518. et: this.tableData[Number(i)+1].addrTitle,
  519. kd: 0,
  520. fd: 0,
  521. })
  522. }
  523. }
  524. }
  525. this.lines = JSON.parse(JSON.stringify(lines));
  526. console.log('lines',this.lines);
  527. },
  528. },
  529. computed: {
  530. addrIds() { // 以保存的地址id
  531. let ids = [];
  532. this.tableData.forEach((item) => {
  533. ids.push(item.addrId);
  534. });
  535. return ids;
  536. },
  537. },
  538. created(){
  539. if(info){
  540. this.title = info.title;
  541. this.date = [info.start_time,info.end_time];
  542. this.cate = info.cate_id;
  543. this.tableData = info.content.addrForms;
  544. this.userIds = info.content.userIds;
  545. this.dateType = info.content.dateType;
  546. this.dateForm = info.content.dateForm;
  547. this.datePlay = info.content.datePlay;
  548. this.datePause = info.content.datePause;
  549. this.dateWeeks = info.content.dateWeeks;
  550. this.dateTimes = info.content.dateTimes;
  551. this.datePause = info.content.datePause;
  552. this.datePause = info.content.datePause;
  553. this.lines = info.lines;
  554. this.inOrder = info.in_order;
  555. }
  556. },
  557. methods: {
  558. next() {
  559. if(this.step == 0){ // 检查必填项
  560. if(!this.title){
  561. this.$message.error('请输入任务名称');
  562. return false;
  563. }
  564. if(!this.date){
  565. this.$message.error('请选择任务时间');
  566. return false;
  567. }
  568. if(this.tableData.length == 0){
  569. this.$message.error('请选择任务地点');
  570. return false;
  571. }
  572. let ff = false;
  573. this.tableData.forEach((item) => {
  574. if(item.forms.length == 0){
  575. ff = true;
  576. }
  577. });
  578. if(ff){
  579. this.$message.error('任务地点未配置检查内容');
  580. return false;
  581. }
  582. } else if(this.step == 1){
  583. if(this.userIds.length <= 0){
  584. this.$message.error('未设置人员');
  585. return false;
  586. }
  587. if(this.dateType == 2 && this.dateWeeks.length <= 0){ // 周
  588. this.$message.error('未选择周');
  589. return false;
  590. }
  591. if(this.dateTimes.length <= 0){
  592. this.$message.error('未选择时间段');
  593. return false;
  594. }
  595. if(this.dateType == 3){ // 自定义
  596. if(!this.dateFrom){
  597. this.$message.error('未选择自定义开始日期');
  598. return false;
  599. }
  600. if(this.datePlay <= 0){
  601. this.$message.error('任务天数必须大于0');
  602. return false;
  603. }
  604. if(this.datePause < 0){
  605. this.$message.error('暂停天数必须大于等于0');
  606. return false;
  607. }
  608. }
  609. // 重新生成任务
  610. this.createClass();
  611. }
  612. if (this.step++ > 2) this.step = 0;
  613. },
  614. pre() {
  615. if (this.step-- < 0) this.step = 2;
  616. },
  617. handleSelectionChange(val){
  618. this.selAddrForms = val;
  619. console.log('selAddrForms',this.selAddrForms);
  620. },
  621. handleClose(){
  622. this.dialogVisibleAddr = false;
  623. },
  624. handleSelectionChangeAddr(val){
  625. this.selAddrs = val;
  626. },
  627. selectAddr(){
  628. this.dialogVisibleAddr = true;
  629. this.addrkeyword = '';
  630. this.addrs = ads.filter((item) => {
  631. return !this.addrIds.includes(item.id);
  632. });
  633. this.selAddrs = [];
  634. },
  635. sortAddrs(){
  636. let ll = JSON.parse(JSON.stringify(this.tableData));
  637. ll.sort((a, b) => {
  638. return Number(a.sorts) > Number(b.sorts) ? 1 : -1;
  639. });
  640. console.log('ll',ll);
  641. this.tableData = [];
  642. this.$nextTick(() => {
  643. this.tableData = JSON.parse(JSON.stringify(ll));
  644. });
  645. },
  646. searchAddr(){
  647. this.addrs= [];
  648. this.$nextTick(() => {
  649. if(this.addrkeyword){
  650. this.addrs = ads.filter((item) => {
  651. return item.title.indexOf(this.addrkeyword) !== -1;
  652. });
  653. }else{
  654. this.addrs = ads;
  655. }
  656. });
  657. },
  658. saveAddr(){
  659. const tbs = this.tableData;
  660. this.selAddrs.forEach((item) => {
  661. if(!this.addrIds.includes(item.id)){
  662. tbs.push({
  663. 'addrId': item.id,
  664. 'addrTitle': item.title,
  665. 'forms': [],
  666. 'sorts': 0
  667. });
  668. }
  669. });
  670. this.dialogVisibleAddr = false;
  671. this.$nextTick(() => {
  672. this.tableData = tbs;
  673. });
  674. },
  675. moveUp(idx,obj){
  676. if(idx > 0){
  677. let old = JSON.parse(JSON.stringify(this.tableData[idx]));
  678. let up = JSON.parse(JSON.stringify(this.tableData[idx - 1]));
  679. let tbs = this.tableData;
  680. this.tableData = [];
  681. this.$nextTick(() => {
  682. tbs[idx] = up;
  683. tbs[idx - 1] = old;
  684. this.tableData = tbs;
  685. })
  686. }
  687. },
  688. moveDown(idx,obj){ // 下移
  689. let length = this.tableData.length;
  690. if(idx < length - 1){
  691. let old = JSON.parse(JSON.stringify(this.tableData[idx]));
  692. let up = JSON.parse(JSON.stringify(this.tableData[idx + 1]));
  693. let tbs = this.tableData;
  694. this.tableData = [];
  695. this.$nextTick(() => {
  696. tbs[idx] = up;
  697. tbs[idx + 1] = old;
  698. this.tableData = tbs;
  699. })
  700. }
  701. },
  702. delAddrs(){ // 移除
  703. let sids = [];
  704. this.selAddrForms.forEach((item) => {
  705. sids.push(item.addrId);
  706. });
  707. if(sids.length == 0){
  708. this.$message.error('未选择地点');
  709. return false;
  710. }
  711. let tbs = this.tableData;
  712. this.tableData = [];
  713. this.$nextTick(() => {
  714. this.tableData = tbs.filter((item) => {
  715. return !sids.includes(item.addrId);
  716. });
  717. this.selAddrForms = [];
  718. });
  719. },
  720. handleCurrentChange(val){ // 选中检查内容
  721. this.selForm = val;
  722. },
  723. handleCloseForm(){
  724. this.dialogVisibleForm = false;
  725. },
  726. searchForm(){
  727. this.forms= [];
  728. this.$nextTick(() => {
  729. if(this.formkeyword){
  730. this.forms = this.frs.filter((item) => {
  731. return item.title.indexOf(this.formkeyword) !== -1;
  732. });
  733. }else{
  734. this.forms = this.frs;
  735. }
  736. });
  737. },
  738. saveForm(){
  739. const tbs = this.tableData;
  740. this.tableData = [];
  741. let sids = [];
  742. this.selAddrForms.forEach((item) => {
  743. sids.push(item.addrId);
  744. });
  745. tbs.forEach((item) => {
  746. if(sids.includes(item.addrId)){
  747. // item.formId = this.selForm?this.selForm.id:0;
  748. // item.formTitle = this.selForm?this.selForm.title:'';
  749. const ffs = [];
  750. this.selForm.forEach((fitem) => {
  751. ffs.push({
  752. id: fitem.id,
  753. title: fitem.title
  754. });
  755. });
  756. item.forms = JSON.parse(JSON.stringify(ffs));
  757. }
  758. });
  759. this.dialogVisibleForm = false;
  760. this.$nextTick(() => {
  761. this.tableData = tbs;
  762. this.selAddrForms = [];
  763. });
  764. },
  765. selectForm(){
  766. let sids = [];
  767. this.selAddrForms.forEach((item) => {
  768. sids.push(item.addrId);
  769. });
  770. if(sids.length == 0){
  771. this.$message.error('未选择地点');
  772. return false;
  773. }
  774. console.log('ss',this.selAddrForms);
  775. this.dialogVisibleForm = true;
  776. this.forms = this.frs;
  777. this.selForm = null;
  778. },
  779. handleCloseWeek(){
  780. this.dialogVisibleWeek = false;
  781. },
  782. saveWeek(){
  783. let ll = [];
  784. this.weeks.forEach((item) => {
  785. if(this.selWeeks.includes(item.id)){
  786. ll.push({
  787. id: item.id,
  788. title: item.title,
  789. type: 'primary'
  790. })
  791. }
  792. });
  793. this.dateWeeks = ll;
  794. this.dialogVisibleWeek = false;
  795. },
  796. handleWeek(obj){
  797. console.log(obj);
  798. if(this.selWeeks.includes(obj.id)){
  799. this.selWeeks = this.selWeeks.filter((item) => {
  800. return item !== obj.id;
  801. });
  802. }else{
  803. this.selWeeks.push(obj.id);
  804. }
  805. this.weeks.forEach((item) => {
  806. if(this.selWeeks.includes(item.id)){
  807. item.type = 'primary';
  808. }else{
  809. item.type = 'info';
  810. }
  811. });
  812. },
  813. selectWeek(){
  814. this.selWeeks = [];
  815. this.dateWeeks.forEach((item) => {
  816. this.selWeeks.push(item.id);
  817. });
  818. this.weeks.forEach((item) => {
  819. if(this.selWeeks.includes(item.id)){
  820. item.type = 'primary';
  821. }else{
  822. item.type = 'info';
  823. }
  824. });
  825. this.dialogVisibleWeek = true;
  826. },
  827. handleCloseTime(){
  828. this.dialogVisibleTime = false;
  829. },
  830. addTime(){
  831. if(!this.stime || !this.etime){
  832. this.$message.error('请选择时间段');
  833. return false;
  834. }
  835. if(this.stype == 0 && this.stime >= this.etime){
  836. this.$message.error('时间段错误');
  837. return false;
  838. }
  839. if(this.stype == 1 && this.sday < 1){
  840. this.$message.error('天数必须大于0');
  841. return false;
  842. }
  843. // 检查时间段是否重复
  844. let ff = false;
  845. this.selTimes.forEach((item) => {
  846. if(item.stype == this.stype &&item.sday == this.sday && item.stime == this.stime && item.etime == this.etime){
  847. ff = true;
  848. }
  849. });
  850. if(ff){
  851. this.$message.error('该时间段已存在');
  852. return false;
  853. }
  854. this.selTimes.push({
  855. stime: this.stime,
  856. etime: this.etime,
  857. stype: this.stype,
  858. sday: this.sday
  859. })
  860. },
  861. addBatchTime(){
  862. if(!this.setime || this.setime.length !== 2){
  863. this.$message.error('请选择时间段');
  864. return false;
  865. }
  866. if(this.snums <= 0){
  867. this.$message.error('请输入间隔小时数');
  868. return false;
  869. }
  870. // let min = 0;
  871. // let max = 23*50 + 59;
  872. let st = this.timeToNum(this.setime[0]);
  873. let et = this.timeToNum(this.setime[1]);
  874. let times = [];
  875. let start = this.timeToNum(this.setime[0]);
  876. let end = this.timeToNum(this.setime[0]);
  877. let i = 1;
  878. while (true){
  879. end = this.timeToNum(this.setime[0]) + 60*this.snums*i;
  880. let jg = et - start;
  881. if(end > et && jg < 10){
  882. break;
  883. }else if(end > et && jg > 10){
  884. end = et;
  885. }
  886. this.stime = this.numToTime(start);
  887. this.etime = this.numToTime(end);
  888. this.stype = 0;
  889. this.sday = 0;
  890. // 检查时间段是否重复
  891. let ff = false;
  892. this.selTimes.forEach((item) => {
  893. if(item.stype == this.stype &&item.sday == this.sday && item.stime == this.stime && item.etime == this.etime){
  894. ff = true;
  895. }
  896. });
  897. if(ff){
  898. this.$message.error('该时间段已存在');
  899. return false;
  900. }
  901. this.selTimes.push({
  902. stime: this.stime,
  903. etime: this.etime,
  904. stype: this.stype,
  905. sday: this.sday
  906. });
  907. start = this.timeToNum(this.setime[0]) + 60*this.snums*i;
  908. i++;
  909. }
  910. console.log('this.selTimes',this.selTimes);
  911. },
  912. timeToNum(time){ // time格式12:30
  913. let ts = time.split(':');
  914. if(ts.length !== 2){
  915. return 0;
  916. }
  917. return Number(ts[0])*60 + Number(ts[1]);
  918. },
  919. numToTime(num){ // 数字转时间
  920. let h = parseInt(num/60);
  921. let m = num - h*60;
  922. let str = '';
  923. if(h < 10){
  924. str += '0' + h + ':';
  925. }else{
  926. str += h + ':';
  927. }
  928. if(m < 10){
  929. str += '0' + m;
  930. }else{
  931. str += m;
  932. }
  933. return str;
  934. },
  935. saveTime(){
  936. this.dateTimes = JSON.parse(JSON.stringify(this.selTimes));
  937. this.handleCloseTime();
  938. },
  939. handleCloseTimes(obj){
  940. this.selTimes = this.selTimes.filter((item) => {
  941. return item.stime != obj.stime || item.etime != obj.etime || item.stype != obj.stype || item.sday != obj.sday;
  942. })
  943. },
  944. selectTime(){
  945. this.dialogVisibleTime = true;
  946. this.selTimes = JSON.parse(JSON.stringify(this.dateTimes));
  947. this.stime = '';
  948. this.etime = '';
  949. this.stype = 0;
  950. this.sday = 1;
  951. },
  952. changeSday(){
  953. if (this.sday) {
  954. // 限制整数
  955. this.sday = this.sday.replace(/[^\d]/g, '');
  956. }
  957. },
  958. createClass(){
  959. if(this.userIds.length <= 0){
  960. this.$message.error('未设置人员');
  961. return false;
  962. }
  963. if(this.dateType == 2 && this.dateWeeks.length <= 0){ // 周
  964. this.$message.error('未选择周');
  965. return false;
  966. }
  967. if(this.dateTimes.length <= 0){
  968. this.$message.error('未选择时间段');
  969. return false;
  970. }
  971. if(this.dateType == 3){ // 自定义
  972. if(!this.dateFrom){
  973. this.$message.error('未选择自定义开始日期');
  974. return false;
  975. }
  976. if(this.datePlay <= 0){
  977. this.$message.error('任务天数必须大于0');
  978. return false;
  979. }
  980. if(this.datePause < 0){
  981. this.$message.error('暂停天数必须大于等于0');
  982. return false;
  983. }
  984. }
  985. let days = this.formatDays();
  986. this.formatTasks(days);
  987. },
  988. formatTasks(days){
  989. this.tasks = {
  990. days: days,
  991. list: [],
  992. };
  993. let list = [];
  994. this.dateTimes.forEach((item) => {
  995. let ts = [];
  996. days.forEach((item2) => {
  997. ts.push({
  998. day: item2,
  999. userIds: this.userIds,
  1000. userNames: this.getUserNames(),
  1001. });
  1002. });
  1003. list.push({
  1004. time: item,
  1005. list: ts,
  1006. })
  1007. });
  1008. this.tasks = {
  1009. days: days,
  1010. list: list,
  1011. };
  1012. console.log('tasks',this.tasks);
  1013. },
  1014. delDay(day){ // 删除列
  1015. let ts = JSON.parse(JSON.stringify(this.tasks));
  1016. this.tasks = null;
  1017. let days = ts.days.filter((item) => {
  1018. return item != day;
  1019. });
  1020. this.formatTasks(days);
  1021. },
  1022. delTimes(obj){ // 删除行
  1023. let days = JSON.parse(JSON.stringify(this.tasks.days));
  1024. this.tasks = null;
  1025. this.dateTimes = this.dateTimes.filter((item) => {
  1026. return item.stime != obj.stime || item.etime != obj.etime || item.stype != obj.stype || item.sday != obj.sday;
  1027. });
  1028. this.formatTasks(days);
  1029. },
  1030. saveSubmit(){ // 表单提交
  1031. if(this.tasks.days.length <= 0||this.tasks.list.length <= 0){
  1032. this.$message.error('未设置任务');
  1033. return false;
  1034. }
  1035. let content = {
  1036. addrForms: this.tableData,
  1037. userIds: this.userIds,
  1038. dateType: this.dateType,
  1039. dateFrom: this.dateType == 3?this.dateFrom:'',
  1040. datePlay: this.dateType == 3?this.datePlay:0,
  1041. datePause: this.dateType == 3?this.datePause:0,
  1042. dateWeeks: this.dateType == 2?this.dateWeeks:[],
  1043. dateTimes: this.dateTimes,
  1044. tasks: this.tasks,
  1045. };
  1046. let json = {
  1047. title: this.title,
  1048. start_time: this.date[0],
  1049. end_time: this.date[1],
  1050. content: JSON.stringify(content),
  1051. mode: mode,
  1052. cate_id:this.cate.join(','),
  1053. in_order: this.inOrder,
  1054. lines: this.lines.length > 0?JSON.stringify(this.lines):''
  1055. };
  1056. let that = this;
  1057. $('#saveSubmit').attr("disabled", true).html('保 存 中');
  1058. $.ajax({
  1059. url: "{:url('PatrolPlan/add')}",
  1060. type: 'POST',
  1061. data: json,
  1062. success: function(ret){
  1063. if(ret.code == 1){
  1064. that.$message.success('操作成功');
  1065. parent.layer.closeAll();
  1066. window.location.href = "{:url('index',['mode'=>$mode])}";
  1067. }else{
  1068. that.$message.error(ret.msg);
  1069. }
  1070. $('#saveSubmit').attr("disabled", false).html('保 存');
  1071. },
  1072. error: function (){
  1073. that.$message.error('请求失败');
  1074. $('#saveSubmit').attr("disabled", false).html('保 存');
  1075. }
  1076. });
  1077. },
  1078. getUserNames(){
  1079. let ns = [];
  1080. this.userIds.forEach((item) => {
  1081. this.users.forEach((item2) => {
  1082. if(item2.id == item){
  1083. ns.push(item2.title);
  1084. }
  1085. });
  1086. });
  1087. return ns.join(',');
  1088. },
  1089. formatDays(){ // 格式化任务日期
  1090. let days = this.getDateAll(this.date[0],this.date[1]);
  1091. let nday = [];
  1092. let ws = [];
  1093. this.dateWeeks.forEach((item) => {
  1094. ws.push(item.id);
  1095. });
  1096. let i = 0;
  1097. let j = 0;
  1098. if(this.dateType==4){
  1099. days = this.dateCutByMonth(this.date[0],this.date[1]);
  1100. }
  1101. days.forEach((item) => {
  1102. if(this.dateType == 1){ // 日
  1103. nday.push(item);
  1104. }else if(this.dateType == 2){ // 周
  1105. let ww = this.getWeekByDay(item);
  1106. if(ws.includes(ww)){
  1107. nday.push(item);
  1108. }
  1109. }else if(this.dateType == 3){ // 自定义
  1110. if(this.dateFrom <= item){
  1111. if(i + j < this.datePlay){
  1112. nday.push(item);
  1113. i++;
  1114. }else if((i + j) >= this.datePlay && (i+j) < this.datePause){
  1115. j++;
  1116. }else{
  1117. i = 0;
  1118. j = 0;
  1119. }
  1120. }
  1121. }else if(this.dateType == 4){ // 月
  1122. nday.push(item);
  1123. }
  1124. });
  1125. return nday;
  1126. },
  1127. changePlay(){
  1128. if (this.datePlay) {
  1129. // 限制整数
  1130. this.datePlay = this.datePlay.replace(/[^\d]/g, '');
  1131. }
  1132. },
  1133. changePause(){
  1134. if (this.datePause) {
  1135. // 限制整数
  1136. this.datePause = this.datePause.replace(/[^\d]/g, '');
  1137. }
  1138. },
  1139. getDateAll(starDay, endDay) { // 获取两个时间段的所有日期
  1140. var arr = [];
  1141. var dates = [];
  1142. // 设置两个日期UTC时间
  1143. var db = new Date(starDay);
  1144. var de = new Date(endDay);
  1145. // 获取两个日期GTM时间
  1146. var s = db.getTime() - 24 * 60 * 60 * 1000;
  1147. var d = de.getTime() - 24 * 60 * 60 * 1000;
  1148. // 获取到两个日期之间的每一天的毫秒数
  1149. for (var i = s; i <= d; ) {
  1150. i = i + 24 * 60 * 60 * 1000;
  1151. arr.push(parseInt(i));
  1152. }
  1153. // 获取每一天的时间 YY-MM-DD
  1154. for (var j in arr) {
  1155. var time = new Date(arr[j]);
  1156. var year = time.getFullYear(time);
  1157. var mouth =
  1158. time.getMonth() + 1 >= 10
  1159. ? time.getMonth() + 1
  1160. : "0" + (time.getMonth() + 1);
  1161. var day =
  1162. time.getDate() >= 10
  1163. ? time.getDate()
  1164. : "0" + time.getDate();
  1165. var YYMMDD = year + "-" + mouth + "-" + day;
  1166. dates.push(YYMMDD);
  1167. }
  1168. return dates;
  1169. },
  1170. getWeekByDay(dateString,t=0) { // 获取某天是周几
  1171. var dateArray = dateString.split("-");
  1172. date = new Date(dateArray[0], parseInt(dateArray[1] - 1), dateArray[2]);
  1173. if(t == 1){
  1174. return "周" + "日一二三四五六".charAt(date.getDay());
  1175. }else{
  1176. return date.getDay();
  1177. }
  1178. },
  1179. dateCutByMonth(beginDate, endDate) {
  1180. //分割好的数组
  1181. var dateCutList = new Array();
  1182. var b_date = new Date(beginDate);
  1183. var e_date = new Date(endDate);
  1184. //获取各个的年份
  1185. var b_year = parseInt(b_date.getFullYear());
  1186. var e_year = parseInt(e_date.getFullYear());
  1187. //获取各个的月份
  1188. var b_month = parseInt(b_date.getMonth()) + 1;
  1189. var e_month = parseInt(e_date.getMonth()) + 1;
  1190. //获取日期之间想差的月数;
  1191. var month_list = this.monthList();
  1192. //按月份分割日期
  1193. if(month_list.length==1){
  1194. dateCutList.push(beginDate+'~'+endDate);
  1195. }else {
  1196. for (var i = 0; i < month_list.length; i++) {
  1197. //当前月开始日期:第一天
  1198. var i_b_date = new Date(month_list[i]);
  1199. i_b_date.setDate(1);
  1200. //当前月最后一天
  1201. var i_e_date = new Date(month_list[i]);
  1202. i_e_date.setMonth(i_e_date.getMonth() + 1);
  1203. i_e_date.setDate(1);
  1204. i_e_date.setDate(i_e_date.getDate() - 1);
  1205. //第一次循环:开始月份
  1206. if (i == 0) {
  1207. var i_e_ymd = this.parseTime(i_e_date).split(" ")[0];
  1208. dateCutList.push(beginDate+'~'+i_e_ymd);
  1209. //除第一次和最后一次循环:中间月份
  1210. } else if (i != 0 && i != month_list.length - 1) {
  1211. var i_b_ymd = this.parseTime(i_b_date).split(" ")[0];
  1212. var i_e_ymd = this.parseTime(i_e_date).split(" ")[0];
  1213. dateCutList.push(i_b_ymd+'~'+i_e_ymd);
  1214. // //最后一次循环:结束月份
  1215. } else if (i == month_list.length - 1) {
  1216. var i_b_ymd = this.parseTime(i_b_date).split(" ")[0];
  1217. dateCutList.push(i_b_ymd+'~'+endDate);
  1218. }
  1219. }
  1220. }
  1221. return dateCutList;
  1222. },
  1223. monthList() {
  1224. //相差的月份总数
  1225. var result = new Array();
  1226. var b_date = new Date(this.date[0]);
  1227. var e_date = new Date(this.date[1]);
  1228. //获取各个的年份
  1229. var b_year = parseInt(b_date.getFullYear());
  1230. var e_year = parseInt(e_date.getFullYear());
  1231. //获取各个的月份
  1232. var b_month = parseInt(b_date.getMonth()) + 1;
  1233. var e_month = parseInt(e_date.getMonth()) + 1;
  1234. var b = new Date(b_year, b_month - 1, 1);
  1235. var e = new Date(e_year, e_month - 1, 1);
  1236. while (b < e) {
  1237. result.push(b.getFullYear() + "-" + (b.getMonth() + 1));
  1238. b.setMonth(b.getMonth() + 1);
  1239. }
  1240. result.push(e_year + "-" + e_month);
  1241. return result;
  1242. },
  1243. parseTime(time, pattern) {
  1244. if (arguments.length === 0 || !time) {
  1245. return null
  1246. }
  1247. const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}'
  1248. let date
  1249. if (typeof time === 'object') {
  1250. date = time
  1251. } else {
  1252. if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
  1253. time = parseInt(time)
  1254. } else if (typeof time === 'string') {
  1255. time = time.replace(new RegExp(/-/gm), '/').replace('T', ' ').replace(new RegExp(/\.[\d]{3}/gm),'');
  1256. }
  1257. if ((typeof time === 'number') && (time.toString().length === 10)) {
  1258. time = time * 1000
  1259. }
  1260. date = new Date(time)
  1261. }
  1262. const formatObj = {
  1263. y: date.getFullYear(),
  1264. m: date.getMonth() + 1,
  1265. d: date.getDate(),
  1266. h: date.getHours(),
  1267. i: date.getMinutes(),
  1268. s: date.getSeconds(),
  1269. a: date.getDay()
  1270. }
  1271. const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
  1272. let value = formatObj[key]
  1273. // Note: getDay() returns 0 on Sunday
  1274. if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value] }
  1275. if (result.length > 0 && value < 10) {
  1276. value = '0' + value
  1277. }
  1278. return value || 0
  1279. })
  1280. return time_str
  1281. }
  1282. }
  1283. })
  1284. </script>
  1285. {/block}