template.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <link type="text/css" rel="stylesheet" href="/css/needDetail.css" />
  2. <script type="text/javascript" src="/js/vue.min.js"></script>
  3. <div class="main-content-inner">
  4. <ul class="clearfix main-content-inner-ul">
  5. <?php if(Yii::app()->session['coachInfo']['leader']==1){?>
  6. <li class="pull-left">
  7. <button onclick='location.href="<?php echo $this->createUrl("semester/index");?>"' class="button button_normal button_group button_arrow" data-button="red">学期管理</button>
  8. <img src="/images/line.jpg" style="height:45px;" />
  9. </li>
  10. <?php }?>
  11. <li class="pull-left">
  12. <button onclick='location.href="<?php echo $this->createUrl("teacher/index");?>"' class="button button_normal button_group button_arrow" data-button="red">教师管理</button>
  13. <img src="/images/line.jpg" style="height:45px;" />
  14. </li>
  15. <li class="pull-left">
  16. <button onclick='location.href="<?php echo $this->createUrl("classes/index");?>"' class="button button_normal button_group button_arrow" data-button="red">班级管理</button>
  17. <img src="/images/line.jpg" style="height:45px;" />
  18. </li>
  19. <li class="pull-left">
  20. <button onclick='location.href="<?php echo $this->createUrl("studentinfo/index");?>"' class="button button_normal button_group button_arrow button_active" data-button="red">学生管理</button>
  21. <img src="/images/line.jpg" style="height:45px;" />
  22. </li>
  23. <li class="pull-left">
  24. <button onclick='location.href="<?php echo $this->createUrl("classes/export");?>"' class="button button_normal button_group button_arrow " data-button="red">导出学生</button>
  25. <img src="/images/line.jpg" style="height:45px;" />
  26. </li>
  27. </ul>
  28. <title>Document</title>
  29. <style>
  30. * {
  31. margin: 0;
  32. padding: 0;
  33. }
  34. #app {
  35. padding: 0 20px;
  36. }
  37. .body {
  38. display: flex;
  39. /* align-items: center; */
  40. margin-top: 20px;
  41. padding: 0 10px;
  42. max-width: 100%;
  43. overflow: auto;
  44. }
  45. th, td {
  46. padding: 5px 15px;
  47. min-height: 30px;
  48. border: 1px solid #cccccc;
  49. }
  50. td > div {
  51. min-height: 20px;
  52. white-space: nowrap;
  53. }
  54. td.reducer {
  55. padding: 10px 10px 0;
  56. }
  57. td.reducer div {
  58. border: 2px solid #619aff;
  59. text-align: center;
  60. font-size: 30px
  61. }
  62. tfoot td {
  63. border: none;
  64. }
  65. div.add {
  66. display: flex;
  67. margin-left: 10px;
  68. width: 50px;
  69. min-width: 50px;
  70. justify-content: center;
  71. align-items: center;
  72. border: 2px solid #619aff;
  73. font-size: 30px;
  74. }
  75. div.table-wrap {
  76. display: inline-block;
  77. overflow: auto;
  78. }
  79. div.head {
  80. display: flex;
  81. align-items: center;
  82. justify-content: space-between;
  83. margin-top: 20px;
  84. padding: 0 10px 5px;
  85. border-bottom: 1px solid #cccccc;
  86. color: #585858;
  87. }
  88. div.head a {
  89. color: green;
  90. text-decoration: none;
  91. }
  92. </style>
  93. <div class="layout-gap" id="app">
  94. <section class="anc-top flex status_1 <?php if(isset($is_last) && $is_last==1) echo 'hide'?>">
  95. <div class="flex-one flex">
  96. <p class="anc-title">自定义设置导入模板</p>
  97. </div>
  98. <div class="anc-opt-btn green-font pointer reback" ><a href="<?php echo $this->createUrl('importstudent/index');?>">返回</a></div>
  99. </section>
  100. <div class="body">
  101. <div class="table-wrap">
  102. <table border="0" cellspacing="0">
  103. <thead>
  104. <tr>
  105. <th v-for="(td,index) in theadData">{{chars[index]}}</th>
  106. </tr>
  107. </thead>
  108. <tbody>
  109. <tr v-for="(tr,trIndex) in tbodyData">
  110. <td v-for="(td,tdIndex) in tr">
  111. <template v-if="trIndex==0">
  112. <template v-if="tdIndex>=5">
  113. <div>
  114. <select v-model="tr[tdIndex]" @change="selectChange(tdIndex)">
  115. <option value="-1">请选择要导入的信息</option>
  116. <option v-for="(val) in selectors[tdIndex]" :value="val">{{orginalSelectOptionMap[val]}}</option>
  117. </select>
  118. </div>
  119. </template>
  120. <div v-else>{{td}}</div>
  121. </template>
  122. <div v-else>{{td}}</div>
  123. </td>
  124. </tr>
  125. </tbody>
  126. <tfoot>
  127. <tr>
  128. <td colspan="5">
  129. <div></div>
  130. </td>
  131. <td class="reducer" v-for="(td,index) in tfootData">
  132. <div class="btnReducer" @click="removeColumn(index)">-</div>
  133. </td>
  134. </tr>
  135. </tfoot>
  136. </table>
  137. </div>
  138. <div class="add" id="btnAdd" @click="addColumn" v-if="tbodyData[0].length<selectOptionVals.length+5">
  139. <span>+</span>
  140. </div>
  141. </div>
  142. <section class="anc-finish-opt gray-border-top" >
  143. <div class="anc-finish-btn i_fl save_result " @click="save" >保存模板</div>
  144. </section>
  145. </div>
  146. </div>
  147. <script>
  148. (function f() {
  149. var orginalSelectOptionMap = {
  150. <?php
  151. if($fileName){
  152. foreach ($fileName as $key => $val){
  153. echo "$key:'{$val}',";
  154. }
  155. }
  156. ?>
  157. };
  158. var aa =[
  159. <?php
  160. if(isset($tpl_data)){
  161. foreach ($tpl_data as $val){
  162. echo "'{$val}',";
  163. };
  164. }else{
  165. echo "-1";
  166. }
  167. ?>
  168. ];
  169. var tbodyData = [
  170. [1, '班级', '姓名', '性别(男/女)', '系统准考证号'],
  171. [2, '', '', '', ''],
  172. [3, '', '', '', ''],
  173. [4, '', '', '', ''],
  174. [5, '', '', '', ''],
  175. [6, '', '', '', ''],
  176. ]
  177. tbodyData = tbodyData.map(function (tItem,index){
  178. if(index===0){
  179. tItem= tItem.concat(aa)
  180. }else{
  181. tItem=tItem.concat(aa.map(function () {
  182. return ''
  183. }))
  184. }
  185. return tItem
  186. })
  187. var selectOptionVals = Object.keys(orginalSelectOptionMap);
  188. var selectors = ['', '', '', '', '']
  189. // selectOptionVals.forEach(function (item, index) {
  190. // var index = tbodyData[0].indexOf(item)
  191. // var arr = selectors[index]||[]
  192. // if(index>-1 && selectors){
  193. //
  194. // }
  195. // })
  196. var selectOptionValsCopy=selectOptionVals.slice();
  197. aa.forEach(function (aItem) {
  198. var index = selectOptionValsCopy.indexOf(aItem)
  199. if(index>-1){
  200. selectOptionValsCopy.splice(index,1)
  201. }
  202. });
  203. selectors= selectors.concat(aa.map(function () {
  204. return selectOptionValsCopy.slice()
  205. }));
  206. selectors.forEach(function (item, index) {
  207. if(index>=5){
  208. item.push(aa[index-5])
  209. }
  210. })
  211. // selectOptionValsCopy.forEach(function (sovItem) {
  212. // var index= aa.indexOf(sovItem)
  213. // if(index>-1){
  214. // selectors[index+4].push(sovItem)
  215. // }
  216. // })
  217. // selectors.forEach(function (sItem,sIndex) {
  218. // if(sIndex>=4){
  219. // sItem.push(aa[sIndex-4])
  220. // }
  221. // })
  222. // tbodyData[0].slice(4).forEach(function (item,index) {
  223. // var selectOptionValsCopy=selectOptionVals.slice()
  224. // selectors.push(selectOptionValsCopy)
  225. // selectOptionValsCopy.forEach(function (sovcItem) {
  226. // sovcItem
  227. // })
  228. // var index = selectOptionValsCopy.indexOf(item)
  229. // if(index>-1){
  230. // selectOptionValsCopy.splice(index,1)
  231. // }
  232. // selectors.push(selectOptionValsCopy)
  233. // })
  234. // aa.forEach(function (item,aIndex) {
  235. // var sov = selectOptionVals.slice()
  236. // var index = sov.indexOf(item)
  237. // if(index>-1){
  238. //
  239. // selectors.forEach(function (sItem,selectorIndex,arr) {
  240. // if(selectorIndex>=4){
  241. // let sItemIndex = sItem.indexOf(item);
  242. // if(sItemIndex>-1){
  243. // sItem.splice(sItemIndex,1)
  244. // }
  245. // }
  246. // })
  247. // selectors.push(sov)
  248. // }else{
  249. // selectors.push(selectOptionVals.slice())
  250. // }
  251. //
  252. // })
  253. var chars = ['', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
  254. var theadData = ['', 'A', 'B', 'C','D']
  255. theadData = theadData.concat(aa.map(function (item,index) {
  256. return chars[theadData.length+index]
  257. }))
  258. var tfootData = [].concat(aa.map(function () {
  259. return ''
  260. }))
  261. window.__vm = new Vue({
  262. el: '#app',
  263. data: {
  264. chars: chars,
  265. orginalSelectOptionMap: orginalSelectOptionMap,
  266. selectOptionVals: selectOptionVals,
  267. theadData: theadData,
  268. tbodyData: tbodyData,
  269. tfootData: tfootData,
  270. selectors: selectors
  271. },
  272. methods: {
  273. addColumn: function () {
  274. this.theadData.push(this.chars[this.theadData.length]);
  275. this.tfootData.push('');
  276. this.tbodyData.forEach(function (item, index) {
  277. item.push(index === 0 ? '-1' : '')
  278. });
  279. var selectedVals = this.tbodyData[0].slice(5, this.tbodyData[0].length - 1);
  280. var selectOptionVals = JSON.parse(JSON.stringify(this.selectOptionVals));
  281. selectedVals.forEach(function (item) {
  282. var index = selectOptionVals.indexOf(item);
  283. if (index > -1) {
  284. selectOptionVals.splice(index, 1)
  285. }
  286. });
  287. this.selectors.push(selectOptionVals)
  288. },
  289. removeColumn: function (index) {
  290. this.theadData.splice(index + 5, 1);
  291. this.tfootData.splice(index, 1);
  292. this.selectors.splice(index + 5, 1);
  293. this.tbodyData.forEach(function(trData) {
  294. trData.splice(index + 5, 1)
  295. });
  296. this.rebuildSelectors()
  297. },
  298. selectChange: function (index) {
  299. var val = this.tbodyData[0][index];
  300. this.rebuildSelectors(val)
  301. },
  302. rebuildSelectors:function(val) {
  303. var selectedVals = this.tbodyData[0].filter(function (item) {
  304. return item!=='-1'
  305. });
  306. val && selectedVals.push(val);
  307. var _this = this
  308. this.selectors.forEach(function(s, i) {
  309. if (i >= 5) {
  310. var sval = _this.tbodyData[0][i];
  311. var selectOptionVals = JSON.parse(JSON.stringify(_this.selectOptionVals));
  312. selectedVals.forEach(function (item) {
  313. var index = selectOptionVals.indexOf(item);
  314. if (index > -1) {
  315. selectOptionVals.splice(index, 1)
  316. }
  317. });
  318. selectOptionVals.push(sval);
  319. _this.selectors[i] = selectOptionVals
  320. }
  321. });
  322. },
  323. save: function () {
  324. var post_data=this.tbodyData;
  325. $.ajax({
  326. url:'<?php echo $this->createUrl('importstudent/save_template')?>',
  327. type:'POST',
  328. dataType:'json',
  329. data:{"data":post_data},
  330. success:function(res){
  331. console.log(res.status)
  332. if(res.status==1){
  333. layer.msg('保存成功');
  334. }else{
  335. layer.msg('保存失败');
  336. }
  337. }
  338. });
  339. }
  340. }
  341. })
  342. })()
  343. </script>