add.html 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990
  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')}">
  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">
  56. <label class="col-sm-2 control-label">地点<span class="text-danger">*</span></label>
  57. <div class="col-sm-8">
  58. <button class="btn btn-sm btn-primary" type="button" @click="selectAddr()">添加地点</button>
  59. <button class="btn btn-sm btn-primary" type="button" @click="selectForm()">设置检查内容</button>
  60. <button class="btn btn-sm btn-danger" type="button" @click="delAddrs">移除</button>
  61. <el-table
  62. v-if="tableData.length > 0"
  63. :data="tableData"
  64. height="350"
  65. border
  66. @selection-change="handleSelectionChange"
  67. style="width: 100%">
  68. <el-table-column
  69. type="selection"
  70. width="60">
  71. </el-table-column>
  72. <el-table-column
  73. prop="addrTitle"
  74. label="地点名称"
  75. width="180">
  76. </el-table-column>
  77. <el-table-column
  78. prop="formTitle"
  79. label="表单内容"
  80. >
  81. </el-table-column>
  82. <el-table-column label="操作" width="180">
  83. <template slot-scope="scope">
  84. <button class="btn btn-sm" type="button" @click="moveUp(scope.$index, scope.row)">上移</button>
  85. <button class="btn btn-sm" type="button" @click="moveDown(scope.$index, scope.row)">下移</button>
  86. </template>
  87. </el-table-column>
  88. </el-table>
  89. </div>
  90. </div>
  91. </div>
  92. <div v-if="step == 1">
  93. <div class="form-group">
  94. <label class="col-sm-2 control-label">设置人员<span class="text-danger">*</span></label>
  95. <div class="col-sm-8">
  96. <el-select
  97. v-model="userIds"
  98. multiple
  99. collapse-tags
  100. style="width: 100%"
  101. size="small"
  102. placeholder="请选择">
  103. <el-option
  104. v-for="item in users"
  105. :key="item.id"
  106. :label="item.title"
  107. :value="item.id">
  108. </el-option>
  109. </el-select>
  110. </div>
  111. </div>
  112. <div class="form-group">
  113. <label class="col-sm-2 control-label">时间段配置<span class="text-danger">*</span></label>
  114. <div class="col-sm-8">
  115. <el-select v-model="dateType" placeholder="请选择" style="width: 100px;" size="small">
  116. <el-option
  117. v-for="item in dateTypes"
  118. :key="item.id"
  119. :label="item.title"
  120. :value="item.id">
  121. </el-option>
  122. </el-select>
  123. <span v-if="dateType == 3">
  124. <el-date-picker
  125. style="width: 130px"
  126. size="small"
  127. v-model="dateFrom"
  128. type="date"
  129. value-format="yyyy-MM-dd"
  130. placeholder="请选择日期">
  131. </el-date-picker>
  132. 开始,工作
  133. <el-input type="number" @input="changePlay" v-model="datePlay" size="small" style="width: 80px;" placeholder="请输入天数"></el-input>
  134. 天,
  135. 暂停
  136. <el-input type="number" @input="changePause" v-model="datePause" size="small" style="width: 80px;" placeholder="请输入天数"></el-input>
  137. 天,每天的
  138. </span>
  139. <button v-if="dateType == 2" class="btn btn-sm btn-default" type="button" @click="selectWeek">添加周</button>
  140. <button class="btn btn-sm btn-default" type="button" @click="selectTime">添加时间段</button>
  141. 开始任务
  142. <div v-if="dateType == 2" style="padding: 5px 0">
  143. 已选择周:
  144. <el-tag
  145. style="margin-right: 5px;cursor: pointer"
  146. v-for="item in dateWeeks"
  147. size="small"
  148. :key="item.id"
  149. :type="item.type"
  150. effect="dark"
  151. >
  152. {{ item.title }}
  153. </el-tag>
  154. </div>
  155. <div style="padding: 5px 0">
  156. 已选择时间段:
  157. <el-tag
  158. style="margin-right: 5px;margin-bottom: 5px"
  159. :key="index"
  160. v-for="(item,index) in dateTimes"
  161. size="small"
  162. >
  163. {{item.stime}} ~ <span v-if="item.stype == 1">{{item.sday}}天后</span>{{item.etime}}
  164. </el-tag>
  165. </div>
  166. <el-button @click="createClass" size="small">生成任务表</el-button>
  167. <div style="padding: 5px 0">
  168. <div class="table-responsive" v-if="tasks.list.length > 0">
  169. <table class="table table-bordered ctable text-center">
  170. <tr>
  171. <td></td>
  172. <td v-for="(item,index) in tasks.days" :key="index">{{item}}</td>
  173. </tr>
  174. <tr v-for="(vo,idx) in tasks.list" :key="idx">
  175. <td>{{vo.time.stime}} ~ <span v-if="vo.time.stype == 1">{{vo.time.sday}}天后</span>{{vo.time.etime}}</td>
  176. <td v-for="(item,index) in tasks.days" :key="index">
  177. <template v-for="(v,id) in vo.list">
  178. <span v-if="item == v.day" :key="id">{{v.userNames}}</span>
  179. </template>
  180. </td>
  181. </tr>
  182. </table>
  183. </div>
  184. </div>
  185. </div>
  186. </div>
  187. </div>
  188. <div v-if="step == 2">
  189. <div style="padding: 5px 0">
  190. <div class="table-responsive" v-if="tasks.list.length > 0">
  191. <table class="table table-bordered ctable text-center">
  192. <tr>
  193. <td></td>
  194. <td></td>
  195. <td v-for="(item,index) in tasks.days" :key="index"><a href="javascript:;" @click="delDay(item)">删除列</a></td>
  196. </tr>
  197. <tr>
  198. <td></td>
  199. <td></td>
  200. <td v-for="(item,index) in tasks.days" :key="index">{{item}}</td>
  201. </tr>
  202. <tr v-for="(vo,idx) in tasks.list" :key="idx">
  203. <td><a href="javascript:;" @click="delTimes(vo.time)">删除行</a></td>
  204. <td>{{vo.time.stime}} ~ <span v-if="vo.time.stype == 1">{{vo.time.sday}}日后</span>{{vo.time.etime}}</td>
  205. <td v-for="(item,index) in tasks.days" :key="index">
  206. <template v-for="(v,id) in vo.list">
  207. <span v-if="item == v.day" :key="id">{{v.userNames}}</span>
  208. </template>
  209. </td>
  210. </tr>
  211. </table>
  212. </div>
  213. </div>
  214. </div>
  215. <div class="hr-line-dashed"></div>
  216. <div class="form-group">
  217. <div class="col-sm-6 col-sm-offset-2">
  218. <button v-if="step == 2" class="btn btn-primary" target-form="form-horizontal" type="button" id="saveSubmit" @click="saveSubmit">保 存</button>
  219. <button v-if="step == 1||step == 2" class="btn btn-default" type="button" @click="pre">上一步</button>
  220. <button v-if="step == 0||step == 1" class="btn btn-info" type="button" @click="next">下一步</button>
  221. </div>
  222. </div>
  223. </form>
  224. <el-dialog
  225. title="选择地点"
  226. :visible.sync="dialogVisibleAddr"
  227. width="500px"
  228. :before-close="handleClose"
  229. >
  230. <el-input
  231. placeholder="请输入"
  232. v-model="addrkeyword"
  233. @input="searchAddr"
  234. clearable>
  235. </el-input>
  236. <el-table
  237. ref="singleTable"
  238. :data="addrs"
  239. height="300"
  240. @selection-change="handleSelectionChangeAddr"
  241. style="width: 100%">
  242. <el-table-column
  243. type="selection"
  244. width="60">
  245. </el-table-column>
  246. <el-table-column
  247. property="title"
  248. label="名称"
  249. >
  250. </el-table-column>
  251. </el-table>
  252. <span slot="footer" class="dialog-footer">
  253. <el-button @click="dialogVisibleAddr = false">取 消</el-button>
  254. <el-button type="primary" @click="saveAddr">确 定</el-button>
  255. </span>
  256. </el-dialog>
  257. <el-dialog
  258. title="选择检查内容"
  259. :visible.sync="dialogVisibleForm"
  260. width="500px"
  261. :before-close="handleCloseForm"
  262. >
  263. <el-input
  264. placeholder="请输入"
  265. v-model="formkeyword"
  266. @input="searchForm"
  267. clearable>
  268. </el-input>
  269. <el-table
  270. v-if="dialogVisibleForm"
  271. ref="singleTable2"
  272. :data="forms"
  273. highlight-current-row
  274. height="300"
  275. @current-change="handleCurrentChange"
  276. style="width: 100%">
  277. <el-table-column
  278. type="index"
  279. label="序号"
  280. width="60">
  281. </el-table-column>
  282. <el-table-column
  283. property="title"
  284. label="名称"
  285. >
  286. </el-table-column>
  287. </el-table>
  288. <span slot="footer" class="dialog-footer">
  289. <el-button @click="handleCloseForm">取 消</el-button>
  290. <el-button type="primary" @click="saveForm">确 定</el-button>
  291. </span>
  292. </el-dialog>
  293. <el-dialog
  294. title="选择周"
  295. :visible.sync="dialogVisibleWeek"
  296. width="500px"
  297. :before-close="handleCloseWeek"
  298. >
  299. <div class="text-center">
  300. <el-tag
  301. style="margin-right: 5px;cursor: pointer"
  302. v-for="item in weeks"
  303. size="small"
  304. :key="item.id"
  305. :type="item.type"
  306. effect="dark"
  307. @click="handleWeek(item)"
  308. >
  309. {{ item.title }}
  310. </el-tag>
  311. </div>
  312. <span slot="footer" class="dialog-footer">
  313. <el-button @click="dialogVisibleWeek = false">取 消</el-button>
  314. <el-button type="primary" @click="saveWeek">确 定</el-button>
  315. </span>
  316. </el-dialog>
  317. <el-dialog
  318. title="时间段选择"
  319. :visible.sync="dialogVisibleTime"
  320. width="700px"
  321. :before-close="handleCloseTime"
  322. >
  323. <div style="padding: 5px 0">
  324. 选择时段:
  325. <el-time-picker style="width:130px" v-model="stime" format="HH:mm" value-format="HH:mm" size="small" placeholder="请选择时间"></el-time-picker>
  326. <el-select style="width:80px" v-model="stype" placeholder="请选择" size="small">
  327. <el-option label="今日" :value="0"></el-option>
  328. <el-option label="其他" :value="1"></el-option>
  329. </el-select>
  330. <el-input v-if="stype == 1" @input="changeSday" type="number" v-model="sday" size="small" style="width: 70px;" placeholder="天数"></el-input> 天后
  331. <el-time-picker style="width:130px" v-model="etime" format="HH:mm" value-format="HH:mm" size="small" placeholder="请选择时间"></el-time-picker>
  332. <el-button @click="addTime" size="small">添加</el-button>
  333. </div>
  334. <div style="padding: 5px 0">
  335. 已选择时间段:
  336. <el-tag
  337. style="margin-right: 5px;margin-bottom: 5px"
  338. size="small"
  339. :key="index"
  340. v-for="(item,index) in selTimes"
  341. closable
  342. @close="handleCloseTimes(item)">
  343. {{item.stime}} ~ <span v-if="item.stype == 1">{{item.sday}}天后</span>{{item.etime}}
  344. </el-tag>
  345. </div>
  346. <span slot="footer" class="dialog-footer">
  347. <el-button @click="dialogVisibleTime = false">取 消</el-button>
  348. <el-button type="primary" @click="saveTime">确 定</el-button>
  349. </span>
  350. </el-dialog>
  351. </div>
  352. </div>
  353. </div>
  354. </div>
  355. {/block}
  356. {block name="script"}
  357. <script>
  358. var ads = {:json_encode($address)};
  359. var frs = {:json_encode($greenForm)};
  360. var us = {:json_encode($user)};
  361. {empty name="info"}
  362. var info = null;
  363. {else /}
  364. var info = {:json_encode($info)};
  365. {/empty}
  366. new Vue({
  367. el: '#vue-plan',
  368. data: function() {
  369. return {
  370. title: '',
  371. dialogVisible: false,
  372. step: 0,
  373. date: '',
  374. tableData: [],
  375. selAddrForms: [], // 选择的地址表单
  376. addrs: ads,
  377. selAddrs:[], // 选择地址
  378. dialogVisibleAddr: false,
  379. addrkeyword: '',
  380. forms: frs,
  381. selForm: null,
  382. formkeyword: '',
  383. dialogVisibleForm: false,
  384. users: us, // 人员列表
  385. userIds:[], // 选择的人员
  386. dateTypes: [
  387. {id: 1,title: '天'},
  388. {id: 2,title: '周'},
  389. {id: 3,title: '自定义'},
  390. ],
  391. dateType: 1,
  392. dateFrom: '', // 自定义类型从哪天开始
  393. datePlay: 1,
  394. datePause: 1,
  395. dateWeeks: [], // 已选择的周
  396. dateTimes: [], // 已添加的时间段
  397. weeks: [
  398. {id:1,title:'周一',type: 'info'},
  399. {id:2,title:'周二',type: 'info'},
  400. {id:3,title:'周三',type: 'info'},
  401. {id:4,title:'周四',type: 'info'},
  402. {id:5,title:'周五',type: 'info'},
  403. {id:6,title:'周六',type: 'info'},
  404. {id:0,title:'周日',type: 'info'},
  405. ],
  406. selWeeks: [],
  407. dialogVisibleWeek: false,
  408. dialogVisibleTime: false,
  409. stime: '',
  410. etime: '',
  411. stype: 0,
  412. sday: 1,
  413. selTimes: [], // 弹框已选的时间段
  414. tasks: { // 任务
  415. days: [],
  416. list: [],
  417. },
  418. }
  419. },
  420. watch: {
  421. },
  422. computed: {
  423. addrIds() { // 以保存的地址id
  424. let ids = [];
  425. this.tableData.forEach((item) => {
  426. ids.push(item.addrId);
  427. });
  428. return ids;
  429. },
  430. },
  431. created(){
  432. if(info){
  433. this.title = info.title;
  434. this.date = [info.start_time,info.end_time];
  435. this.tableData = info.content.addrForms;
  436. this.userIds = info.content.userIds;
  437. this.dateType = info.content.dateType;
  438. this.dateForm = info.content.dateForm;
  439. this.datePlay = info.content.datePlay;
  440. this.datePause = info.content.datePause;
  441. this.dateWeeks = info.content.dateWeeks;
  442. this.dateTimes = info.content.dateTimes;
  443. this.datePause = info.content.datePause;
  444. this.datePause = info.content.datePause;
  445. }
  446. },
  447. methods: {
  448. next() {
  449. if(this.step == 0){ // 检查必填项
  450. if(!this.title){
  451. this.$message.error('请输入任务名称');
  452. return false;
  453. }
  454. if(!this.date){
  455. this.$message.error('请选择任务时间');
  456. return false;
  457. }
  458. if(this.tableData.length == 0){
  459. this.$message.error('请选择任务地点');
  460. return false;
  461. }
  462. let ff = false;
  463. this.tableData.forEach((item) => {
  464. if(item.formId == 0){
  465. ff = true;
  466. }
  467. });
  468. if(ff){
  469. this.$message.error('任务地点未配置检查内容');
  470. return false;
  471. }
  472. } else if(this.step == 1){
  473. if(this.userIds.length <= 0){
  474. this.$message.error('未设置人员');
  475. return false;
  476. }
  477. if(this.dateType == 2 && this.dateWeeks.length <= 0){ // 周
  478. this.$message.error('未选择周');
  479. return false;
  480. }
  481. if(this.dateTimes.length <= 0){
  482. this.$message.error('未选择时间段');
  483. return false;
  484. }
  485. if(this.dateType == 3){ // 自定义
  486. if(!this.dateFrom){
  487. this.$message.error('未选择自定义开始日期');
  488. return false;
  489. }
  490. if(this.datePlay <= 0){
  491. this.$message.error('任务天数必须大于0');
  492. return false;
  493. }
  494. if(this.datePause < 0){
  495. this.$message.error('暂停天数必须大于等于0');
  496. return false;
  497. }
  498. }
  499. // 重新生成任务
  500. this.createClass();
  501. }
  502. if (this.step++ > 2) this.step = 0;
  503. },
  504. pre() {
  505. if (this.step-- < 0) this.step = 2;
  506. },
  507. handleSelectionChange(val){
  508. this.selAddrForms = val;
  509. },
  510. handleClose(){
  511. this.dialogVisibleAddr = false;
  512. },
  513. handleSelectionChangeAddr(val){
  514. this.selAddrs = val;
  515. },
  516. selectAddr(){
  517. this.dialogVisibleAddr = true;
  518. this.addrkeyword = '';
  519. this.addrs = ads.filter((item) => {
  520. return !this.addrIds.includes(item.id);
  521. });
  522. this.selAddrs = [];
  523. },
  524. searchAddr(){
  525. this.addrs= [];
  526. this.$nextTick(() => {
  527. if(this.addrkeyword){
  528. this.addrs = ads.filter((item) => {
  529. return item.title.indexOf(this.addrkeyword) !== -1;
  530. });
  531. }else{
  532. this.addrs = ads;
  533. }
  534. });
  535. },
  536. saveAddr(){
  537. const tbs = this.tableData;
  538. this.selAddrs.forEach((item) => {
  539. if(!this.addrIds.includes(item.id)){
  540. tbs.push({
  541. 'addrId': item.id,
  542. 'addrTitle': item.title,
  543. 'formId': 0,
  544. 'formTitle': '',
  545. });
  546. }
  547. });
  548. this.dialogVisibleAddr = false;
  549. this.$nextTick(() => {
  550. this.tableData = tbs;
  551. });
  552. },
  553. moveUp(idx,obj){
  554. if(idx > 0){
  555. let old = JSON.parse(JSON.stringify(this.tableData[idx]));
  556. let up = JSON.parse(JSON.stringify(this.tableData[idx - 1]));
  557. let tbs = this.tableData;
  558. this.tableData = [];
  559. this.$nextTick(() => {
  560. tbs[idx] = up;
  561. tbs[idx - 1] = old;
  562. this.tableData = tbs;
  563. })
  564. }
  565. console.log(this.tableData);
  566. },
  567. moveDown(idx,obj){ // 下移
  568. let length = this.tableData.length;
  569. if(idx < length - 1){
  570. let old = JSON.parse(JSON.stringify(this.tableData[idx]));
  571. let up = JSON.parse(JSON.stringify(this.tableData[idx + 1]));
  572. let tbs = this.tableData;
  573. this.tableData = [];
  574. this.$nextTick(() => {
  575. tbs[idx] = up;
  576. tbs[idx + 1] = old;
  577. this.tableData = tbs;
  578. })
  579. }
  580. },
  581. delAddrs(){ // 移除
  582. let sids = [];
  583. this.selAddrForms.forEach((item) => {
  584. sids.push(item.addrId);
  585. });
  586. if(sids.length == 0){
  587. this.$message.error('未选择地点');
  588. return false;
  589. }
  590. let tbs = this.tableData;
  591. this.tableData = [];
  592. this.$nextTick(() => {
  593. this.tableData = tbs.filter((item) => {
  594. return !sids.includes(item.addrId);
  595. });
  596. });
  597. console.log(this.selAddrForms,sids,this.tableData);
  598. },
  599. handleCurrentChange(val){ // 选中检查内容
  600. this.selForm = val;
  601. },
  602. handleCloseForm(){
  603. this.dialogVisibleForm = false;
  604. },
  605. searchForm(){
  606. this.forms= [];
  607. this.$nextTick(() => {
  608. if(this.formkeyword){
  609. this.forms = frs.filter((item) => {
  610. return item.title.indexOf(this.formkeyword) !== -1;
  611. });
  612. }else{
  613. this.forms = frs;
  614. }
  615. });
  616. },
  617. saveForm(){
  618. const tbs = this.tableData;
  619. this.tableData = [];
  620. let sids = [];
  621. this.selAddrForms.forEach((item) => {
  622. sids.push(item.addrId);
  623. });
  624. tbs.forEach((item) => {
  625. if(sids.includes(item.addrId)){
  626. item.formId = this.selForm?this.selForm.id:0;
  627. item.formTitle = this.selForm?this.selForm.title:'';
  628. }
  629. });
  630. this.dialogVisibleForm = false;
  631. this.$nextTick(() => {
  632. this.tableData = tbs;
  633. });
  634. },
  635. selectForm(){
  636. let sids = [];
  637. this.selAddrForms.forEach((item) => {
  638. sids.push(item.addrId);
  639. });
  640. if(sids.length == 0){
  641. this.$message.error('未选择地点');
  642. return false;
  643. }
  644. this.dialogVisibleForm = true;
  645. this.forms = frs;
  646. this.selForm = null;
  647. },
  648. handleCloseWeek(){
  649. this.dialogVisibleWeek = false;
  650. },
  651. saveWeek(){
  652. let ll = [];
  653. this.weeks.forEach((item) => {
  654. if(this.selWeeks.includes(item.id)){
  655. ll.push({
  656. id: item.id,
  657. title: item.title,
  658. type: 'primary'
  659. })
  660. }
  661. });
  662. this.dateWeeks = ll;
  663. this.dialogVisibleWeek = false;
  664. },
  665. handleWeek(obj){
  666. console.log(obj);
  667. if(this.selWeeks.includes(obj.id)){
  668. this.selWeeks = this.selWeeks.filter((item) => {
  669. return item !== obj.id;
  670. });
  671. }else{
  672. this.selWeeks.push(obj.id);
  673. }
  674. this.weeks.forEach((item) => {
  675. if(this.selWeeks.includes(item.id)){
  676. item.type = 'primary';
  677. }else{
  678. item.type = 'info';
  679. }
  680. });
  681. },
  682. selectWeek(){
  683. this.selWeeks = [];
  684. this.dateWeeks.forEach((item) => {
  685. this.selWeeks.push(item.id);
  686. });
  687. this.weeks.forEach((item) => {
  688. if(this.selWeeks.includes(item.id)){
  689. item.type = 'primary';
  690. }else{
  691. item.type = 'info';
  692. }
  693. });
  694. this.dialogVisibleWeek = true;
  695. },
  696. handleCloseTime(){
  697. this.dialogVisibleTime = false;
  698. },
  699. addTime(){
  700. if(!this.stime || !this.etime){
  701. this.$message.error('请选择时间段');
  702. return false;
  703. }
  704. if(this.stype == 0 && this.stime >= this.etime){
  705. this.$message.error('时间段错误');
  706. return false;
  707. }
  708. if(this.stype == 1 && this.sday < 1){
  709. this.$message.error('天数必须大于0');
  710. return false;
  711. }
  712. // 检查时间段是否重复
  713. let ff = false;
  714. this.selTimes.forEach((item) => {
  715. if(item.stype == this.stype &&item.sday == this.sday && item.stime == this.stime && item.etime == this.etime){
  716. ff = true;
  717. }
  718. });
  719. if(ff){
  720. this.$message.error('该时间段已存在');
  721. return false;
  722. }
  723. this.selTimes.push({
  724. stime: this.stime,
  725. etime: this.etime,
  726. stype: this.stype,
  727. sday: this.sday
  728. })
  729. },
  730. saveTime(){
  731. this.dateTimes = JSON.parse(JSON.stringify(this.selTimes));
  732. this.handleCloseTime();
  733. },
  734. handleCloseTimes(obj){
  735. this.selTimes = this.selTimes.filter((item) => {
  736. return item.stime != obj.stime || item.etime != obj.etime || item.stype != obj.stype || item.sday != obj.sday;
  737. })
  738. },
  739. selectTime(){
  740. this.dialogVisibleTime = true;
  741. this.selTimes = JSON.parse(JSON.stringify(this.dateTimes));
  742. this.stime = '';
  743. this.etime = '';
  744. this.stype = 0;
  745. this.sday = 1;
  746. },
  747. changeSday(){
  748. if (this.sday) {
  749. // 限制整数
  750. this.sday = this.sday.replace(/[^\d]/g, '');
  751. }
  752. },
  753. createClass(){
  754. if(this.userIds.length <= 0){
  755. this.$message.error('未设置人员');
  756. return false;
  757. }
  758. if(this.dateType == 2 && this.dateWeeks.length <= 0){ // 周
  759. this.$message.error('未选择周');
  760. return false;
  761. }
  762. if(this.dateTimes.length <= 0){
  763. this.$message.error('未选择时间段');
  764. return false;
  765. }
  766. if(this.dateType == 3){ // 自定义
  767. if(!this.dateFrom){
  768. this.$message.error('未选择自定义开始日期');
  769. return false;
  770. }
  771. if(this.datePlay <= 0){
  772. this.$message.error('任务天数必须大于0');
  773. return false;
  774. }
  775. if(this.datePause < 0){
  776. this.$message.error('暂停天数必须大于等于0');
  777. return false;
  778. }
  779. }
  780. let days = this.formatDays();
  781. this.formatTasks(days);
  782. },
  783. formatTasks(days){
  784. this.tasks = {
  785. days: days,
  786. list: [],
  787. };
  788. let list = [];
  789. this.dateTimes.forEach((item) => {
  790. let ts = [];
  791. days.forEach((item2) => {
  792. ts.push({
  793. day: item2,
  794. userIds: this.userIds,
  795. userNames: this.getUserNames(),
  796. });
  797. });
  798. list.push({
  799. time: item,
  800. list: ts,
  801. })
  802. });
  803. this.tasks = {
  804. days: days,
  805. list: list,
  806. };
  807. console.log('tasks',this.tasks);
  808. },
  809. delDay(day){ // 删除列
  810. let ts = JSON.parse(JSON.stringify(this.tasks));
  811. this.tasks = null;
  812. let days = ts.days.filter((item) => {
  813. return item != day;
  814. });
  815. this.formatTasks(days);
  816. },
  817. delTimes(obj){ // 删除行
  818. let days = JSON.parse(JSON.stringify(this.tasks.days));
  819. this.tasks = null;
  820. this.dateTimes = this.dateTimes.filter((item) => {
  821. return item.stime != obj.stime || item.etime != obj.etime || item.stype != obj.stype || item.sday != obj.sday;
  822. });
  823. this.formatTasks(days);
  824. },
  825. saveSubmit(){ // 表单提交
  826. if(this.tasks.days.length <= 0||this.tasks.list.length <= 0){
  827. this.$message.error('未设置任务');
  828. return false;
  829. }
  830. let content = {
  831. addrForms: this.tableData,
  832. userIds: this.userIds,
  833. dateType: this.dateType,
  834. dateFrom: this.dateType == 3?this.dateFrom:'',
  835. datePlay: this.dateType == 3?this.datePlay:0,
  836. datePause: this.dateType == 3?this.datePause:0,
  837. dateWeeks: this.dateType == 2?this.dateWeeks:[],
  838. dateTimes: this.dateTimes,
  839. tasks: this.tasks
  840. };
  841. let json = {
  842. title: this.title,
  843. start_time: this.date[0],
  844. end_time: this.date[1],
  845. content: JSON.stringify(content),
  846. };
  847. let that = this;
  848. $('#saveSubmit').attr("disabled", true).html('保 存 中');
  849. $.ajax({
  850. url: "{:url('GreenPlan/add')}",
  851. type: 'POST',
  852. data: json,
  853. success: function(ret){
  854. if(ret.code == 1){
  855. window.location.href = "{:url('index')}";
  856. }else{
  857. that.$message.error(ret.msg);
  858. }
  859. $('#saveSubmit').attr("disabled", false).html('保 存');
  860. },
  861. error: function (){
  862. that.$message.error('请求失败');
  863. $('#saveSubmit').attr("disabled", false).html('保 存');
  864. }
  865. });
  866. },
  867. getUserNames(){
  868. let ns = [];
  869. this.userIds.forEach((item) => {
  870. this.users.forEach((item2) => {
  871. if(item2.id == item){
  872. ns.push(item2.title);
  873. }
  874. });
  875. });
  876. return ns.join(',');
  877. },
  878. formatDays(){ // 格式化任务日期
  879. let days = this.getDateAll(this.date[0],this.date[1]);
  880. let nday = [];
  881. let ws = [];
  882. this.dateWeeks.forEach((item) => {
  883. ws.push(item.id);
  884. });
  885. let i = 0;
  886. let j = 0;
  887. days.forEach((item) => {
  888. if(this.dateType == 1){ // 日
  889. nday.push(item);
  890. }else if(this.dateType == 2){ // 周
  891. let ww = this.getWeekByDay(item);
  892. if(ws.includes(ww)){
  893. nday.push(item);
  894. }
  895. }else if(this.dateType == 3){ // 自定义
  896. if(this.dateFrom <= item){
  897. if(i + j < this.datePlay){
  898. nday.push(item);
  899. i++;
  900. }else if((i + j) >= this.datePlay && (i+j) < this.datePause){
  901. j++;
  902. }else{
  903. i = 0;
  904. j = 0;
  905. }
  906. }
  907. }
  908. });
  909. return nday;
  910. },
  911. changePlay(){
  912. if (this.datePlay) {
  913. // 限制整数
  914. this.datePlay = this.datePlay.replace(/[^\d]/g, '');
  915. }
  916. },
  917. changePause(){
  918. if (this.datePause) {
  919. // 限制整数
  920. this.datePause = this.datePause.replace(/[^\d]/g, '');
  921. }
  922. },
  923. getDateAll(starDay, endDay) { // 获取两个时间段的所有日期
  924. var arr = [];
  925. var dates = [];
  926. // 设置两个日期UTC时间
  927. var db = new Date(starDay);
  928. var de = new Date(endDay);
  929. // 获取两个日期GTM时间
  930. var s = db.getTime() - 24 * 60 * 60 * 1000;
  931. var d = de.getTime() - 24 * 60 * 60 * 1000;
  932. // 获取到两个日期之间的每一天的毫秒数
  933. for (var i = s; i <= d; ) {
  934. i = i + 24 * 60 * 60 * 1000;
  935. arr.push(parseInt(i));
  936. }
  937. // 获取每一天的时间 YY-MM-DD
  938. for (var j in arr) {
  939. var time = new Date(arr[j]);
  940. var year = time.getFullYear(time);
  941. var mouth =
  942. time.getMonth() + 1 >= 10
  943. ? time.getMonth() + 1
  944. : "0" + (time.getMonth() + 1);
  945. var day =
  946. time.getDate() >= 10
  947. ? time.getDate()
  948. : "0" + time.getDate();
  949. var YYMMDD = year + "-" + mouth + "-" + day;
  950. dates.push(YYMMDD);
  951. }
  952. return dates;
  953. },
  954. getWeekByDay(dateString,t=0) { // 获取某天是周几
  955. var dateArray = dateString.split("-");
  956. date = new Date(dateArray[0], parseInt(dateArray[1] - 1), dateArray[2]);
  957. if(t == 1){
  958. return "周" + "日一二三四五六".charAt(date.getDay());
  959. }else{
  960. return date.getDay();
  961. }
  962. }
  963. }
  964. })
  965. </script>
  966. {/block}