index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. var globalMethods = function(vm,swal){
  2. return {
  3. swal:swal,
  4. layer:layer,
  5. openImage:function(href){
  6. return layer.open({
  7. type: 1,
  8. title: false,
  9. closeBtn: 0,
  10. shadeClose: true,
  11. content: '<img src="'+href+'" style="display: block;width: 100%;" />'
  12. });
  13. },
  14. $swal:function(type,param,code){
  15. if(param === undefined) param = function(){};
  16. switch (type){
  17. case 'delete':
  18. if(typeof code != 'object') code = {};
  19. swal({
  20. title: code.title || "您确定要删除这条信息吗",
  21. text: code.text || "删除后将无法恢复,请谨慎操作!",
  22. type: code.type || "warning",
  23. showCancelButton: true,
  24. confirmButtonColor: "#DD6B55",
  25. confirmButtonText: code.confirm || "是的,我要删除!",
  26. cancelButtonText: code.cancel || "让我再考虑一下…",
  27. closeOnConfirm: false,
  28. closeOnCancel: false
  29. }).then(param).catch(console.log);
  30. break;
  31. case 'error':
  32. swal("错误",param,"error");
  33. break;
  34. case 'success':
  35. swal("成功",param,"success");
  36. break;
  37. case 'status':
  38. code == 200 ? this.$swal('success',param) : this.$swal('error',param);
  39. break;
  40. case 'message':
  41. swal(param);
  42. break;
  43. }
  44. },
  45. $alert:function(type,params,succFn){
  46. switch (type){
  47. case 'textarea':
  48. swal({
  49. title: params.title != undefined ? params.title.toString() : "请输入内容",
  50. input: 'textarea',
  51. inputValue: params.value || '',
  52. confirmButtonText:"提交",
  53. cancelButtonText: "取消",
  54. showCancelButton: true
  55. }).then(succFn).catch(console.log);
  56. break;
  57. }
  58. },
  59. message:function(type,config){
  60. /*content 提示内容 String -
  61. render 自定义描述内容,使用 Vue 的 Render 函数 Function -
  62. duration 自动关闭的延时,单位秒,不关闭可以写 0 Number 1.5
  63. onClose 关闭时的回调 Function -
  64. closable 是否显示关闭按钮*/
  65. vm.$Message.config({
  66. top: 1,
  67. duration:5
  68. });
  69. switch (type) {
  70. case 'success':
  71. return vm.$Message.success(config);
  72. break;
  73. case 'warning':
  74. return vm.$Message.warning(config);
  75. break;
  76. case 'error':
  77. return vm.$Message.error(config);
  78. break;
  79. case 'loading':
  80. return vm.$Message.loading(config);
  81. break;
  82. default :
  83. return vm.$Message.info(config || type);
  84. break;
  85. }
  86. },
  87. notice:function(type,config){
  88. switch (type) {
  89. case 'info':
  90. return vm.$Notice.info(config);
  91. break;
  92. case 'success':
  93. return vm.$Notice.success(config);
  94. break;
  95. case 'warning':
  96. return vm.$Notice.warning(config);
  97. break;
  98. case 'error':
  99. return vm.$Notice.error(config);
  100. break;
  101. default :
  102. return vm.$Notice.open(config || type);
  103. break;
  104. }
  105. },
  106. noticeClose:function(name){
  107. return vm.$Notice.close(name);
  108. },
  109. noticeDestroy:function(){
  110. return vm.$Notice.destroy();
  111. },
  112. modal:function(type,config){
  113. switch (type) {
  114. case 'confirm':
  115. return vm.$Modal.confirm(config);
  116. break;
  117. case 'success':
  118. return vm.$Modal.success(config);
  119. break;
  120. case 'warning':
  121. return vm.$Modal.warning(config);
  122. break;
  123. case 'error':
  124. return vm.$Modal.error(config);
  125. break;
  126. default :
  127. return vm.$Modal.info(config || type);
  128. break;
  129. }
  130. },
  131. modalRemove:function(){
  132. return vm.$modal.remove();
  133. },
  134. loading:function(type,percent){
  135. switch (type){
  136. case 'start':
  137. return vm.$Loading.start();
  138. break;
  139. case 'finish':
  140. return vm.$Loading.finish();
  141. break;
  142. case 'error':
  143. return vm.$Loading.error();
  144. break;
  145. case 'update':
  146. return vm.$Loading.update(percent);
  147. break;
  148. }
  149. }
  150. }
  151. };
  152. setTimeout(function(){
  153. mpFrame.start(function(Vue){
  154. requirejs(['sweetalert','axios'],function(swal,axios){
  155. axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
  156. axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
  157. new Vue({
  158. el:'#vm',
  159. data:{
  160. chnNumChar:["零","一","二","三","四","五","六","七","八","九"],
  161. chnUnitSection : ["","万","亿","万亿","亿亿"],
  162. chnUnitChar : ["","十","百","千"],
  163. noticeTime:7
  164. },
  165. methods:{
  166. globalApi:function(){
  167. var api = globalMethods(this,swal);
  168. api.closeModalFrame = function(name){
  169. layer.close(layer.getFrameIndex(name) || name);
  170. //关闭页面刷新
  171. // window.frames[$(".page-tabs-content .active").index()].location.reload();
  172. };
  173. api.h = this.$createElement;
  174. api.axios = axios;
  175. api.createModalFrame = this.createModalFrame;
  176. api.mpFrame = mpFrame;
  177. api.layer = layer;
  178. return api;
  179. },
  180. createModalFrame:function(title,src,opt){
  181. opt === undefined && (opt = {});
  182. var h = 0;
  183. if(window.innerHeight < 800 && window.innerHeight >= 700){
  184. h=window.innerHeight-50;
  185. }else if(window.innerHeight < 900 && window.innerHeight >= 800){
  186. h=window.innerHeight-100;
  187. }else if(window.innerHeight < 1000 && window.innerHeight >= 900){
  188. h=window.innerHeight-150;
  189. }else if(window.innerHeight >= 1000){
  190. h=window.innerHeight-200;
  191. }else{
  192. h=window.innerHeight;
  193. }
  194. var area=[(opt.w || window.innerWidth/2)+'px', (!opt.h || opt.h > h ? h : opt.h )+'px'];
  195. return layer.open({
  196. type: 2,
  197. title:title,
  198. area: area,
  199. fixed: false, //不固定
  200. maxmin: true,
  201. moveOut:false,//true 可以拖出窗外 false 只能在窗内拖
  202. anim:5,//出场动画 isOutAnim bool 关闭动画
  203. offset:'auto',//['100px','100px'],//'auto',//初始位置 ['100px','100px'] t[ 上 左]
  204. shade:0,//遮罩
  205. resize:true,//是否允许拉伸
  206. content: src,//内容
  207. move:'.layui-layer-title',// 默认".layui-layer-title",// 触发拖动的元素
  208. moveEnd:function(){//拖动之后回调
  209. // console.log(this);
  210. }
  211. });
  212. },
  213. SectionToChinese:function (section) {
  214. var strIns = '', chnStr = '';
  215. var unitPos = 0;
  216. var zero = true;
  217. while(section > 0){
  218. var v = section % 10;
  219. if(v === 0){
  220. if(!zero){
  221. zero = true;
  222. chnStr = this.chnNumChar[v] + chnStr;
  223. }
  224. }else{
  225. zero = false;
  226. strIns = this.chnNumChar[v];
  227. strIns += this.chnUnitChar[unitPos];
  228. chnStr = strIns + chnStr;
  229. }
  230. unitPos++;
  231. section = Math.floor(section / 10);
  232. }
  233. return chnStr;
  234. },
  235. NumberToChinese:function (num) {
  236. var unitPos = 0;
  237. var strIns = '', chnStr = '';
  238. var needZero = false;
  239. if(num === 0) return this.chnNumChar[0];
  240. while(num > 0){
  241. var section = num % 10000;
  242. if(needZero){
  243. chnStr = this.chnNumChar[0] + chnStr;
  244. }
  245. strIns = this.SectionToChinese(section);
  246. strIns += (section !== 0) ? this.chnUnitSection[unitPos] : this.chnUnitSection[0];
  247. chnStr = strIns + chnStr;
  248. needZero = (section < 1000) && (section > 0);
  249. num = Math.floor(num / 10000);
  250. unitPos++;
  251. }
  252. return chnStr;
  253. },
  254. titleRoll:function (newTitle) {
  255. var time=this.noticeTime,oldTitle='CRMEB管理系统';
  256. var timeInterval=setInterval(function () {
  257. console.log(time);
  258. if(time <= 0){
  259. clearInterval(timeInterval);
  260. document.title=oldTitle;
  261. return;
  262. }
  263. document.title=newTitle.substring(1,newTitle.length)+newTitle.substring(0,1);
  264. newTitle=document.title.substring(0,newTitle.length);
  265. time--;
  266. },1000)
  267. }
  268. },
  269. mounted:function(){
  270. window._mpApi = this.globalApi(),that=this;
  271. $('.admin_close').on('click',function (e) {
  272. $('.admin_open').removeClass('open');
  273. });
  274. function getnotice() {
  275. $.getJSON("/admin/index/Jnotice",function(res){
  276. var info = eval("("+res+")");
  277. var data = info.data;
  278. $('#msgcount').html(data.msgcount);
  279. $('#ordernum').html(data.ordernum + '个');
  280. $('#inventory').html(data.inventory + '个');
  281. $('#commentnum').html(data.commentnum + '个');
  282. $('#reflectnum').html(data.reflectnum + '个');
  283. if(data.newOrderId.length){
  284. if(window.newOrderAudioLink) (new Audio(window.newOrderAudioLink)).play();
  285. var title='您有'+that.NumberToChinese(data.newOrderId.length)+'个新订单请及时处理!';
  286. _mpApi.notice('info',{
  287. title:title,
  288. desc:'<a href="javascript:;" class="opFrames" data-name="订单管理" data-href="/admin/order.store_order/index/status/1.html">立即去处理</a>',
  289. duration:that.noticeTime,
  290. });
  291. that.titleRoll(title);
  292. $(document).on('click','.opFrames',function () {
  293. window.addframes($(this).data('href'),'',$(this).data('name'));
  294. });
  295. }
  296. });
  297. }
  298. getnotice();
  299. setInterval(getnotice,6000);
  300. }
  301. })
  302. })
  303. });
  304. },0);