DataSync.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <template>
  2. <div class="container-fluid">
  3. <div>
  4. <Navbar
  5. :title="'U8资产同步'"
  6. :is-go-back="false"
  7. />
  8. </div>
  9. <div>
  10. <ul id="myTab" class="nav nav-tabs">
  11. <li class="active"><a href="#base" data-toggle="tab">{{ $t('lang.DataSync.basicDataSynchronization') }}</a></li>
  12. <li><a href="#add" data-toggle="tab">{{ $t('lang.DataSync.assetCardToBeAdded') }}</a></li>
  13. <li><a href="#update" data-toggle="tab">{{ $t('lang.DataSync.assetCardToBeUpdated') }}</a></li>
  14. <span class="badge span-refresh" @click="getAssetU8()">
  15. <span class="glyphicon glyphicon-refresh" />
  16. </span>
  17. </ul>
  18. <div id="myTabContent" class="tab-content div-content">
  19. <div id="base" class="tab-pane fade in active">
  20. <button type="button" class="btn btn-primary btn-block sync-base-btn" @click="syncBase">{{ $t('lang.DataSync.performSynchronization') }}</button>
  21. <div v-if="U8SyncItems.length > 0" class="table-box">
  22. <table class="table table-bordered">
  23. <thead>
  24. <tr>
  25. <td width="50px">{{ $t('lang.DataSync.serialNumber') }}</td>
  26. <td width="150px">{{ $t('lang.DataSync.synchronizationItem') }}</td>
  27. <td width="150px">{{ $t('lang.DataSync.synchronizationResults') }}</td>
  28. </tr>
  29. </thead>
  30. <tbody>
  31. <tr v-for="item, index in U8SyncItems" :key="item.id">
  32. <td>{{ index + 1 }}</td>
  33. <td>{{ item.name }}</td>
  34. <td>{{ item.success?$t('lang.DataSync.success'):$t('lang.DataSync.fail') }}</td>
  35. </tr>
  36. </tbody>
  37. </table>
  38. </div>
  39. </div>
  40. <div id="add" class="tab-pane fade">
  41. <div class="table-box">
  42. <table class="table table-bordered">
  43. <thead>
  44. <tr>
  45. <td>{{ $t('lang.DataSync.serialNumber') }}</td>
  46. <td>{{ $t('lang.DataSync.assetNumber') }}</td>
  47. <td>{{ $t('lang.DataSync.assetName') }}</td>
  48. <td>{{ $t('lang.DataSync.type') }}</td>
  49. <td>{{ $t('lang.DataSync.departmentNumber') }}</td>
  50. <td>
  51. <div class="checkbox noMargin">
  52. <label><input v-model="processAllAdds" autocomplete="off" type="checkbox" />{{ $t('lang.DataSync.handle') }}</label>
  53. </div>
  54. </td>
  55. </tr>
  56. </thead>
  57. <tbody>
  58. <tr v-if="adds.length == 0">
  59. <td colspan="6">{{ $t('lang.DataSync.noData') }}</td>
  60. </tr>
  61. <tr v-for="item, index in adds" v-else :key="item.id">
  62. <td>{{ index + 1 }}</td>
  63. <td>{{ item.assetNo }}</td>
  64. <td>{{ item.name }}</td>
  65. <td>{{ item.type }}</td>
  66. <td>{{ item.deptNum }}</td>
  67. <td>
  68. <div class="checkbox noMargin">
  69. <label><input v-model="item.isDispose" autocomplete="off" type="checkbox" />{{ $t('lang.DataSync.handle') }}</label>
  70. </div>
  71. </td>
  72. </tr>
  73. </tbody>
  74. </table>
  75. </div>
  76. <button type="button" class="btn btn-primary btn-block" @click="syncAdds">{{ $t('lang.DataSync.performSynchronization') }}</button>
  77. </div>
  78. <div id="update" class="tab-pane fade">
  79. <div class="table-box">
  80. <table class="table table-bordered">
  81. <thead>
  82. <tr>
  83. <td>{{ $t('lang.DataSync.serialNumber') }}</td>
  84. <td>{{ $t('lang.DataSync.assetNumber') }}</td>
  85. <td>{{ $t('lang.DataSync.assetName') }}</td>
  86. <td>{{ $t('lang.DataSync.type') }}</td>
  87. <td>{{ $t('lang.DataSync.departmentNumber') }}</td>
  88. <td>
  89. <div class="checkbox noMargin">
  90. <label><input v-model="processAllUpdates" autocomplete="off" type="checkbox" />{{ $t('lang.DataSync.handle') }}</label>
  91. </div>
  92. </td>
  93. </tr>
  94. </thead>
  95. <tbody>
  96. <tr v-if="updates.length == 0">
  97. <td colspan="6">{{ $t('lang.DataSync.noData') }}</td>
  98. </tr>
  99. <tr v-for="item, index in updates" v-else :key="item.id">
  100. <td>{{ index + 1 }}</td>
  101. <td>{{ item.assetNo }}</td>
  102. <td>{{ item.name }}</td>
  103. <td>{{ item.type }}</td>
  104. <td>{{ item.deptNum }}</td>
  105. <td>
  106. <div class="checkbox noMargin">
  107. <label><input v-model="item.isDispose" autocomplete="off" type="checkbox" />{{ $t('lang.DataSync.handle') }}</label>
  108. </div>
  109. </td>
  110. </tr>
  111. </tbody>
  112. </table>
  113. </div>
  114. <button type="button" class="btn btn-primary btn-block" @click="syncUpdates">{{ $t('lang.DataSync.performSynchronization') }}</button>
  115. </div>
  116. </div>
  117. </div>
  118. <Loading v-if="loading" />
  119. </div>
  120. </template>
  121. <script>
  122. import Common from '../../common/Common.js';
  123. import { Notify } from 'pc-component-v3';
  124. export default {
  125. components: {
  126. },
  127. data : function(){
  128. return{
  129. U8SyncItems: [],
  130. adds: [],
  131. updates: [],
  132. processAllAdds: true,
  133. processAllUpdates: true,
  134. loading: false,
  135. };
  136. },
  137. watch: {
  138. processAllAdds: function(to){
  139. this.adds.forEach(function(item){
  140. item.isDispose = to;
  141. });
  142. },
  143. processAllUpdates: function(to){
  144. this.updates.forEach(function(item){
  145. item.isDispose = to;
  146. });
  147. },
  148. },
  149. mounted: function() {
  150. this.getAssetU8();
  151. },
  152. methods: {
  153. /**
  154. * 同步基础数据
  155. */
  156. syncBase: function(){
  157. var _self = this;
  158. _self.loading=true;
  159. $.ajax({
  160. url: Common.getApiURL('dataSyncResource/syncBaseItem'),
  161. type: 'get',
  162. dataType: 'json',
  163. beforeSend:function(request){
  164. Common.addTokenToRequest(request);
  165. },
  166. success: function(data){
  167. _self.U8SyncItems = data;
  168. _self.loading=false;
  169. },
  170. error: function (XMLHttpRequest, textStatus, errorThrown){
  171. _self.loading=false;
  172. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  173. },
  174. });
  175. },
  176. /**
  177. * 获取u8资产数据
  178. */
  179. getAssetU8: function(){
  180. var _self = this;
  181. _self.loading=true;
  182. $.ajax({
  183. url: Common.getApiURL('dataSyncResource/getAssetU8'),
  184. type: 'get',
  185. dataType: 'json',
  186. beforeSend:function(request){
  187. Common.addTokenToRequest(request);
  188. },
  189. success: function(data){
  190. if(data){
  191. _self.adds = data.adds;
  192. _self.updates = data.updates;
  193. }
  194. _self.loading=false;
  195. },
  196. error: function (XMLHttpRequest, textStatus, errorThrown){
  197. _self.loading=false;
  198. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  199. },
  200. });
  201. },
  202. /**
  203. * 同步新增数据
  204. */
  205. syncAdds: function(){
  206. var _self = this;
  207. _self.loading=true;
  208. var datas = new Array();
  209. _self.adds.forEach(function(item){
  210. if(item.isDispose){
  211. datas.push(item);
  212. }
  213. });
  214. if(datas.length == 0){
  215. _self.loading=false;
  216. Notify.error('错误', '没有可同步的数据', true);
  217. }else{
  218. $.ajax({
  219. url: Common.getApiURL('dataSyncResource/syncAssetAdd'),
  220. type: 'post',
  221. dataType: 'json',
  222. contentType: 'application/json',
  223. beforeSend:function(request){
  224. Common.addTokenToRequest(request);
  225. },
  226. data: JSON.stringify(datas),
  227. success: function(data){
  228. _self.loading=false;
  229. Notify.success('成功', '数据同步成功', true);
  230. _self.getAssetU8();
  231. },
  232. error: function (XMLHttpRequest, textStatus, errorThrown){
  233. _self.loading=false;
  234. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  235. },
  236. });
  237. }
  238. },
  239. /**
  240. * 同步更新数据
  241. */
  242. syncUpdates: function(){
  243. var _self = this;
  244. _self.loading=true;
  245. var datas = new Array();
  246. _self.updates.forEach(function(item){
  247. if(item.isDispose){
  248. datas.push(item);
  249. }
  250. });
  251. if(datas.length == 0){
  252. _self.loading=false;
  253. Notify.error('错误', '没有可同步的数据', true);
  254. }else{
  255. $.ajax({
  256. url: Common.getApiURL('dataSyncResource/syncAssetUpdate'),
  257. type: 'post',
  258. dataType: 'json',
  259. contentType: 'application/json',
  260. beforeSend:function(request){
  261. Common.addTokenToRequest(request);
  262. },
  263. data: JSON.stringify(datas),
  264. success: function(data){
  265. _self.loading=false;
  266. Notify.success('成功', '数据同步成功', true);
  267. _self.getAssetU8();
  268. },
  269. error: function (XMLHttpRequest, textStatus, errorThrown){
  270. _self.loading=false;
  271. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  272. },
  273. });
  274. }
  275. },
  276. },
  277. };
  278. </script>
  279. <style scoped>
  280. .noMargin {
  281. margin: 0 !important;
  282. }
  283. .div-content{
  284. margin: 15px 0px;
  285. }
  286. .sync-base-btn{
  287. margin-bottom: 10px;
  288. }
  289. .table-box{
  290. max-height: 500px;
  291. overflow: auto;
  292. margin-bottom:15px;
  293. }
  294. td{
  295. text-align: center;
  296. }
  297. .span-refresh {
  298. margin: 10px 0px 0px 10px;
  299. }
  300. </style>