0
0

add.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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')}">
  11. 返回上一页
  12. </a>
  13. </div>
  14. </div>
  15. {/if}
  16. <div class="ibox-content">
  17. <form method="post" action="{:url('add')}" 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. <div class="form-group">
  22. <label class="col-sm-2 control-label">任务名称<span class="text-danger">*</span></label>
  23. <div class="col-sm-8">
  24. <input type="text" class="form-control" name="title" value="{$info.title|default=''}" placeholder="请输入任务名称">
  25. </div>
  26. </div>
  27. <div class="form-group" id="vue-plan">
  28. <label class="col-sm-2 control-label">地点<span class="text-danger">*</span></label>
  29. <div class="col-sm-8">
  30. <input type="hidden" name="addrs" value="" id="addrForms">
  31. <button class="btn btn-sm btn-primary" type="button" @click="selectAddr()">添加地点</button>
  32. <button class="btn btn-sm btn-primary" type="button" @click="selectForm()">设置检查内容</button>
  33. <button class="btn btn-sm btn-danger" type="button" @click="delAddrs">移除</button>
  34. <el-table
  35. v-if="tableData.length > 0"
  36. :data="tableData"
  37. height="250"
  38. border
  39. @selection-change="handleSelectionChange"
  40. style="width: 100%">
  41. <el-table-column
  42. type="selection"
  43. width="60">
  44. </el-table-column>
  45. <el-table-column
  46. prop="addrTitle"
  47. label="地点名称"
  48. width="180">
  49. </el-table-column>
  50. <el-table-column
  51. prop="formTitle"
  52. label="检查内容"
  53. >
  54. </el-table-column>
  55. <el-table-column label="操作" width="130">
  56. <template slot-scope="scope">
  57. <button class="btn btn-sm" type="button" @click="moveUp(scope.$index, scope.row)">上移</button>
  58. <button class="btn btn-sm" type="button" @click="moveDown(scope.$index, scope.row)">下移</button>
  59. </template>
  60. </el-table-column>
  61. </el-table>
  62. <el-dialog
  63. title="选择地点"
  64. :visible.sync="dialogVisibleAddr"
  65. width="500px"
  66. :before-close="handleClose"
  67. >
  68. <el-input
  69. placeholder="请输入"
  70. v-model="addrkeyword"
  71. @input="searchAddr"
  72. clearable>
  73. </el-input>
  74. <el-table
  75. ref="singleTable"
  76. :data="addrs"
  77. height="200"
  78. @selection-change="handleSelectionChangeAddr"
  79. style="width: 100%">
  80. <el-table-column
  81. type="selection"
  82. width="60">
  83. </el-table-column>
  84. <el-table-column
  85. property="title"
  86. label="名称"
  87. >
  88. </el-table-column>
  89. </el-table>
  90. <span slot="footer" class="dialog-footer">
  91. <el-button @click="dialogVisibleAddr = false">取 消</el-button>
  92. <el-button type="primary" @click="saveAddr">确 定</el-button>
  93. </span>
  94. </el-dialog>
  95. <el-dialog
  96. title="选择检查内容"
  97. :visible.sync="dialogVisibleForm"
  98. width="500px"
  99. :before-close="handleCloseForm"
  100. >
  101. <el-input
  102. placeholder="请输入"
  103. v-model="formkeyword"
  104. @input="searchForm"
  105. clearable>
  106. </el-input>
  107. <el-table
  108. ref="singleTable2"
  109. :data="forms"
  110. highlight-current-row
  111. height="200"
  112. @current-change="handleCurrentChange"
  113. style="width: 100%">
  114. <el-table-column
  115. type="index"
  116. label="序号"
  117. width="60">
  118. </el-table-column>
  119. <el-table-column
  120. property="title"
  121. label="名称"
  122. >
  123. </el-table-column>
  124. </el-table>
  125. <span slot="footer" class="dialog-footer">
  126. <el-button @click="dialogVisibleAddr = false">取 消</el-button>
  127. <el-button type="primary" @click="saveForm">确 定</el-button>
  128. </span>
  129. </el-dialog>
  130. </div>
  131. </div>
  132. <div class="form-group">
  133. <label class="col-sm-2 control-label">检查人员<span class="text-danger">*</span></label>
  134. <div class="col-sm-8">
  135. {:widget_view('common/multiselect',['name'=>'user_ids','lists' =>$user, 'val' =>isset($info)?$info['task_user']:[]])}
  136. </div>
  137. </div>
  138. <div class="form-group">
  139. <label class="col-sm-2 control-label">开始时间<span class="text-danger">*</span></label>
  140. <div class="col-sm-8">
  141. <input class="form-control" id="date" readonly name="start_time" value="{$info.start_time|default=$start}">
  142. </div>
  143. </div>
  144. <div class="form-group">
  145. <label class="col-sm-2 control-label">结束时间<span class="text-danger">*</span></label>
  146. <div class="col-sm-8">
  147. <input class="form-control" id="date-one" readonly name="end_time" value="{$info.end_time|default=$end}">
  148. </div>
  149. </div>
  150. <div class="hr-line-dashed"></div>
  151. <div class="form-group">
  152. <div class="col-sm-8 col-sm-offset-2">
  153. <button class="btn btn-primary ajax-post" target-form="form-horizontal"{if $type==1 && $isCalendar!=1} data-layer="1"{/if} type="submit">确 定</button>
  154. {if $type==1}
  155. {if $isCalendar==1}
  156. <a href="{:url('calendar')}" class="btn btn-default">取 消</a>
  157. {else}
  158. <button class="btn cancel-btn btn-default" type="button">取 消</button>
  159. {/if}
  160. {else}
  161. <a href="{:url('index')}" class="btn btn-default">取 消</a>
  162. {/if}
  163. </div>
  164. </div>
  165. </form>
  166. </div>
  167. </div>
  168. </div>
  169. </div>
  170. {/block}
  171. {block name="script"}
  172. <script type="text/javascript" src="/static/layDate-v5.0.9/laydate.js"></script>
  173. <script>
  174. var time =new Date();
  175. //日期时间选择器
  176. laydate.render({
  177. elem: '#date',
  178. type: 'datetime',
  179. format:'yyyy-MM-dd HH:mm',
  180. trigger: 'click' ,
  181. theme:'#6eb7ff'
  182. // value:dateFormat(),
  183. });
  184. laydate.render({
  185. elem: '#date-one',
  186. type: 'datetime',
  187. trigger: 'click' ,
  188. format:'yyyy-MM-dd HH:mm',
  189. theme:'#6eb7ff'
  190. // value:dateFormatH(),
  191. });
  192. //当前日期格式化
  193. function dateFormat() {
  194. var year=time.getFullYear();
  195. var mouth=time.getMonth()+ 1;
  196. if(mouth < 10){
  197. var mouths='0'+mouth;
  198. }else {
  199. var mouths=mouth;
  200. }
  201. var day=time.getDate();
  202. if(day < 10){
  203. var days='0'+day;
  204. }else {
  205. var days=day;
  206. }
  207. var hour=time.getHours();
  208. if(hour < 10){
  209. var hours='0'+hour;
  210. }else {
  211. var hours=hour;
  212. }
  213. var minute=time.getMinutes();
  214. if(minute < 10){
  215. var minutes='0'+minute;
  216. }else {
  217. var minutes=minute;
  218. }
  219. var dateStr=year+'-'+mouths+'-'+days+' '+hours+':'+minutes;
  220. return dateStr;
  221. }
  222. function dateFormatH() {
  223. var year=time.getFullYear();
  224. var mouth=time.getMonth()+ 1;
  225. if(mouth < 10){
  226. var mouths='0'+mouth;
  227. }else {
  228. var mouths=mouth;
  229. }
  230. var day=time.getDate();
  231. if(day < 10){
  232. var days='0'+day;
  233. }else {
  234. var days=day;
  235. }
  236. var hour=time.getHours();
  237. if(hour < 10){
  238. var hours='0'+hour;
  239. }else {
  240. var hours=hour;
  241. }
  242. var minute=time.getMinutes()+20;
  243. var dateStr=year+'-'+mouths+'-'+days+' '+hours+':'+minute;
  244. return dateStr;
  245. }
  246. var ads = {:json_encode($address)};
  247. var frs = {:json_encode($greenForm)};
  248. var addrForms = {:json_encode($info['addrForms'])};
  249. new Vue({
  250. el: '#vue-plan',
  251. data: function() {
  252. return {
  253. title: '',
  254. dialogVisible: false,
  255. step: 0,
  256. date: '',
  257. tableData: [],
  258. selAddrForms: [], // 选择的地址表单
  259. addrs: ads,
  260. selAddrs:[], // 选择地址
  261. dialogVisibleAddr: false,
  262. addrkeyword: '',
  263. forms: frs,
  264. selForm: null,
  265. formkeyword: '',
  266. dialogVisibleForm: false,
  267. }
  268. },
  269. watch: {
  270. nTableData(){
  271. console.log('nTableData1111');
  272. $('#addrForms').val(JSON.stringify(this.tableData));
  273. }
  274. },
  275. computed: {
  276. addrIds() { // 以保存的地址id
  277. console.log('111ssss');
  278. let ids = [];
  279. this.tableData.forEach((item) => {
  280. ids.push(item.addrId);
  281. });
  282. return ids;
  283. },
  284. nTableData() { // 以保存的地址id
  285. return JSON.parse(JSON.stringify(this.tableData));
  286. },
  287. },
  288. created(){
  289. this.tableData = addrForms;
  290. },
  291. methods: {
  292. handleSelectionChange(val){
  293. console.log(val);
  294. this.selAddrForms = val;
  295. },
  296. handleClose(){
  297. this.dialogVisibleAddr = false;
  298. },
  299. handleSelectionChangeAddr(val){
  300. console.log(val);
  301. this.selAddrs = val;
  302. },
  303. selectAddr(){
  304. console.log('aaaaaaaaaaa');
  305. this.dialogVisibleAddr = true;
  306. this.addrkeyword = '';
  307. this.addrs = ads.filter((item) => {
  308. return !this.addrIds.includes(item.id);
  309. });
  310. this.selAddrs = [];
  311. console.log('bbbbbbbbb',this.addrs);
  312. },
  313. searchAddr(){
  314. this.addrs= [];
  315. this.$nextTick(() => {
  316. if(this.addrkeyword){
  317. this.addrs = ads.filter((item) => {
  318. return item.title.indexOf(this.addrkeyword) !== -1;
  319. });
  320. }else{
  321. this.addrs = ads;
  322. }
  323. });
  324. },
  325. saveAddr(){
  326. const tbs = this.tableData;
  327. this.selAddrs.forEach((item) => {
  328. if(!this.addrIds.includes(item.id)){
  329. tbs.push({
  330. 'addrId': item.id,
  331. 'addrTitle': item.title,
  332. 'formId': 0,
  333. 'formTitle': '',
  334. });
  335. }
  336. });
  337. this.dialogVisibleAddr = false;
  338. this.$nextTick(() => {
  339. this.tableData = tbs;
  340. });
  341. },
  342. moveUp(idx,obj){
  343. console.log(idx,obj);
  344. if(idx > 0){
  345. let old = JSON.parse(JSON.stringify(this.tableData[idx]));
  346. let up = JSON.parse(JSON.stringify(this.tableData[idx - 1]));
  347. let tbs = this.tableData;
  348. this.tableData = [];
  349. this.$nextTick(() => {
  350. tbs[idx] = up;
  351. tbs[idx - 1] = old;
  352. this.tableData = tbs;
  353. })
  354. }
  355. console.log(this.tableData);
  356. },
  357. moveDown(idx,obj){ // 下移
  358. console.log(idx,obj);
  359. let length = this.tableData.length;
  360. if(idx < length - 1){
  361. let old = JSON.parse(JSON.stringify(this.tableData[idx]));
  362. let up = JSON.parse(JSON.stringify(this.tableData[idx + 1]));
  363. let tbs = this.tableData;
  364. this.tableData = [];
  365. this.$nextTick(() => {
  366. tbs[idx] = up;
  367. tbs[idx + 1] = old;
  368. this.tableData = tbs;
  369. })
  370. }
  371. },
  372. delAddrs(){ // 移除
  373. let sids = [];
  374. this.selAddrForms.forEach((item) => {
  375. sids.push(item.addrId);
  376. });
  377. if(sids.length == 0){
  378. this.$message.error('未选择地点');
  379. return false;
  380. }
  381. let tbs = this.tableData;
  382. this.tableData = [];
  383. this.$nextTick(() => {
  384. this.tableData = tbs.filter((item) => {
  385. return !sids.includes(item.addrId);
  386. });
  387. });
  388. console.log(this.selAddrForms,sids,this.tableData);
  389. },
  390. handleCurrentChange(val){ // 选中检查内容
  391. console.log(val);
  392. this.selForm = val;
  393. },
  394. handleCloseForm(){
  395. this.dialogVisibleForm = false;
  396. },
  397. searchForm(){
  398. this.forms= [];
  399. this.$nextTick(() => {
  400. if(this.formkeyword){
  401. this.forms = frs.filter((item) => {
  402. return item.title.indexOf(this.formkeyword) !== -1;
  403. });
  404. }else{
  405. this.forms = frs;
  406. }
  407. });
  408. },
  409. saveForm(){
  410. console.log('1111');
  411. const tbs = this.tableData;
  412. this.tableData = [];
  413. let sids = [];
  414. this.selAddrForms.forEach((item) => {
  415. sids.push(item.addrId);
  416. });
  417. tbs.forEach((item) => {
  418. if(sids.includes(item.addrId)){
  419. item.formId = this.selForm?this.selForm.id:0;
  420. item.formTitle = this.selForm?this.selForm.title:'';
  421. }
  422. });
  423. this.dialogVisibleForm = false;
  424. this.$nextTick(() => {
  425. this.tableData = tbs;
  426. });
  427. },
  428. selectForm(){
  429. let sids = [];
  430. this.selAddrForms.forEach((item) => {
  431. sids.push(item.addrId);
  432. });
  433. if(sids.length == 0){
  434. this.$message.error('未选择地点');
  435. return false;
  436. }
  437. this.dialogVisibleForm = true;
  438. this.forms = frs;
  439. this.selForm = null;
  440. },
  441. getDateAll(starDay, endDay) { // 获取两个时间段的所有日期
  442. var arr = [];
  443. var dates = [];
  444. // 设置两个日期UTC时间
  445. var db = new Date(starDay);
  446. var de = new Date(endDay);
  447. // 获取两个日期GTM时间
  448. var s = db.getTime() - 24 * 60 * 60 * 1000;
  449. var d = de.getTime() - 24 * 60 * 60 * 1000;
  450. // 获取到两个日期之间的每一天的毫秒数
  451. for (var i = s; i <= d; ) {
  452. i = i + 24 * 60 * 60 * 1000;
  453. arr.push(parseInt(i));
  454. }
  455. // 获取每一天的时间 YY-MM-DD
  456. for (var j in arr) {
  457. var time = new Date(arr[j]);
  458. var year = time.getFullYear(time);
  459. var mouth =
  460. time.getMonth() + 1 >= 10
  461. ? time.getMonth() + 1
  462. : "0" + (time.getMonth() + 1);
  463. var day =
  464. time.getDate() >= 10
  465. ? time.getDate()
  466. : "0" + time.getDate();
  467. var YYMMDD = year + "-" + mouth + "-" + day;
  468. dates.push(YYMMDD);
  469. }
  470. return dates;
  471. },
  472. getWeekByDay(dateString,t=0) { // 获取某天是周几
  473. var dateArray = dateString.split("-");
  474. date = new Date(dateArray[0], parseInt(dateArray[1] - 1), dateArray[2]);
  475. if(t == 1){
  476. return "周" + "日一二三四五六".charAt(date.getDay());
  477. }else{
  478. return date.getDay();
  479. }
  480. }
  481. }
  482. })
  483. </script>
  484. {/block}