Blame view

public/assets/js/backend/fastflow/flow/ebill.js 13.3 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
  require.config({
      paths: {
          'html2canvas': "../addons/fastflow/plugins/html2canvas/html2canvas.min",
          'compression': "../addons/fastflow/plugins/compression/compression",
          'qrcode': "../addons/fastflow/plugins/node-qrcode-master/qrcode.min",
      },
      shim:{
          'qrcode': {
              deps: ['jquery'],
              exports: 'QRCode'
          },
      }
  });
  
  define(['jquery', 'bootstrap', 'backend', 'form', 'html2canvas', 'compression', 'qrcode'], function ($, undefined, Backend, Form, Html2canvas, Compression, QRCode) {
  
      var Controller = {
          currentBillId: null,
          base64: null,
          preview: function () {
              var index = layer.load();
              if(Config.hasSignature === true){
                  containerWidth = $('#ebill').css('width').replace('px','');
                  contentWidth = $('#ebill-content').css('width').replace('px','');
                  $('#ebill').animate({scrollLeft:(contentWidth - containerWidth + 12) / 2},0);
                  layer.close(index);
                  return;
              }
              if (Config.qrcode == "true"){
                  var pos = {
                      "topleft":"top:30px;left:30px;",
                      "topright":"top:30px;right:30px;",
                      "bottomleft":"bottom:30px;left:30px;",
                      "bottomright":"bottom:30px;right:30px;"
                  };
                  var img = '<image class="qrcode" style="' + pos[Config.qrcodepos] + 'height: ' + Config.qrcodesieze + 'px; width: ' + Config.qrcodesieze + 'px;">';
                  $('section','#ebill-html').append(img);
                  QRCode.toDataURL(Config.detail_url, { errorCorrectionLevel: 'M'}, function (err, url) {
                      $('.qrcode').attr('src', url);
                  });
              }
  
              Controller.api.screenShot('ebill-html', function (canvas) {
                  if (canvas !== null) {
                      var canvasWidth = canvas.width;
                      var canvasHeight = canvas.height;
                      var div = document.createElement('div');
                      $(div)
                          .css('width', canvasWidth)
                          .css('height', canvasHeight)
                          .css('backgroundImage', "url(" + canvas.toDataURL() + ")")
                          .css('margin', '0px auto 0px auto')
                          .attr('id', 'ebill-content')
                          .attr('data-fswidth', $('section:first', '#ebill-html').css('width'))
                          .attr('data-fsheight', $('section:first', '#ebill-html').css('height'))
                          .attr('data-title',Config.bill_name !== undefined ? Config.bill_name + '(' + Config.bill_id + ')电子表单' : '');
                      $('#ebill').html(div);
  
                      containerWidth = $('#ebill').css('width').replace('px','');
                      contentWidth = $(div).css('width').replace('px','');
                      $('#ebill').animate({scrollLeft:(contentWidth - containerWidth + 12) / 2},0);
                  }
                  var parentSubmitBtn = parent.$('#ebill-form #submit', parent.document);
                  if (parentSubmitBtn.length !== 0) {
                      canvas === null ? parentSubmitBtn.addClass('disabled') : parentSubmitBtn.removeClass('disabled');
                  }
                  layer.close(index);
              });
          },
          index: function () {
              Controller.api.refreshEbillList();
              require.config({
                  paths: {
                      'classie': "../addons/fastflow/plugins/select/js/classie",
                      'SelectFx': "../addons/fastflow/plugins/select/js/selectFx",
                  },
                  shim: {
                      'classie': {
                          exports: 'classie'
                      },
                      'SelectFx': {
                          exports: 'SelectFx'
                      },
                  },
              });
              require(['classie', 'SelectFx', 'template'], function (classie, SelectFx, Template) {
                  var select = document.getElementById('bill-select');
                  window.classie = classie;
                  new SelectFx(select, {
                      onChange: function (val) {
                          Controller.currentBillId = val;
                          Controller.api.refreshEbillList();
                      }
                  });
              });
              Controller.api.bindListToolBarEvent();
          },
          add: function () {
              Controller.api.bindAddEditEvent();
          },
          edit: function () {
              Controller.api.bindAddEditEvent();
          },
          api: {
              bindAddEditEvent: function () {
                  //上传成功回调
                  $('#faupload-file').data('upload-success', function () {
                      var file = $('input[name="row[file]"]').val();
                      $('#ebill-iframe').attr('src', 'preview?action=preview&file=' + file);
                  });
                  //监听文件变化
                  $('#file-preview').on('fa.preview.change', function () {
                      $('#ebill-iframe').attr('src', '');
                      $('#submit').addClass('disabled');
                  });
                  $('#submit').on('click', function (e) {
                      e.stopPropagation();
                      e.preventDefault();
                      var ebillContent = $('#ebill-iframe').contents().find('#ebill-content');
                      if (ebillContent.length === 0) {
                          Toastr.error('文件格式错误,请重新选择Word2007及更高版本文件');
                          $('#submit').addClass('disabled');
                          return false;
                      }
                      var ebillImage = ebillContent.css('backgroundImage').replace('url("', '').replace('")', '');
                      var thumWidth = ebillContent.data('fswidth').replace('px', '');
                      var thumHeight = ebillContent.data('fsheight').replace('px', '');
                      Compression.Clipping(ebillImage, thumWidth, thumHeight, 1, function (result) {
                          //处理base64字符串,将特殊符号%、&、+等进行转义
                          result = result
                              .replace(/%/g, "%25")
                              .replace(/&/g, "%26")
                              .replace(/\+/g, "%2B");
                          $.ajax({
                              type: "post",
                              url: location.href,
                              data: $('#ebill-form').serialize()
                                  + '&file=' + $('input[name="row[file]"]').val()
                                  + '&thumb_width=' + ebillContent.css('width')
                                  + '&thumb_height=' + ebillContent.css('height')
                                  + '&thumbnail=' + result,
                              success: function (data) {
                                  if (data['code'] === 1) {
                                      parent.Toastr.success(data['msg']);
                                      let index = parent.Layer.getFrameIndex(window.name);
                                      parent.Layer.close(index);
                                      parent.$('#refresh-ebill', parent.document).trigger('click');
                                  } else if (data['code'] === 0) {
                                      Toastr.error(data['msg']);
                                  }
                              },
                          });
                      });
                  });
                  Form.api.bindevent($("form[role=form]"));
              },
              bindListToolBarEvent: function () {
                  $('#add-ebill').click(function (e) {
                      $(this).data('area', ['95%', '95%']);
                      Fast.api.open('fastflow/flow/ebill/add?bill_id=' + Controller.currentBillId, '添加电子表单', $(this).data() || {});
                  });
                  $('#refresh-ebill').click(function (e) {
                      Controller.api.refreshEbillList();
                  });
              },
              bindEbillTrashEvent: function () {
                  $('.ebill-trash').click(function (e) {
                      ebillId = $(this).data('id');
                      var that = this;
                      var top = $(that).offset().top - $(window).scrollTop();
                      var left = $(that).offset().left - $(window).scrollLeft() - 160;
                      if (top + 154 > $(window).height()) {
                          top = top - 154;
                      }
                      if ($(window).width() < 480) {
                          top = left = undefined;
                      }
                      Layer.confirm(
                          __('确定删除吗?'),
                          {
                              icon: 3,
                              title: __('Warning'),
                              offset: [top, left],
                              shadeClose: true,
                              btn: [__('OK'), __('Cancel')]
                          },
                          function (index) {
                              $.ajax({
                                  type: "post",
                                  url: "fastflow/flow/ebill/del",
                                  data: {
                                      ids: ebillId
                                  },
                                  success: function (data) {
                                      if (data['code'] == 1) {
                                          Toastr.success('删除成功');
                                          Controller.api.refreshEbillList();
                                      } else if (data['code'] == 0) {
                                          Toastr.error(data['msg']);
                                      }
                                      layer.close(index);
                                  },
                                  error: function (e) {
                                      layer.close(index);
                                  }
                              });
                              Layer.close(index);
                          }
                      );
                  });
              },
              bindEbillThumbnailEvent: function () {
                  $('.imgProd', '#contenedorCards').click(function () {
                      let ebillId = $(this).data('id');
                      let title = $(this).data('title');
                      $(this).data('area', ['75%', '90%']);
                      Fast.api.open('fastflow/flow/ebill/preview?id=' + ebillId + '&action=preview', title, $(this).data() || {});
                  });
                  $('.preview-btn', '#contenedorCards').click(function (e) {
                      var ebillThumbnail = $(this).closest('.wrapper').find('.imgProd')[0];
                      ebillThumbnail.click();
                  });
              },
              bindEbillEditEvent: function () {
                  $('.ebill-edit').click(function (e) {
                      $(this).data('area', ['95%', '95%']);
                      Fast.api.open('fastflow/flow/ebill/edit?ids=' + $(this).data('id'), '编辑电子表单', $(this).data() || {});
                  });
              },
              refreshEbillList: function () {
                  var index = layer.load();
                  Controller.currentBillId = Controller.currentBillId === null ? $('option:first', '#bill-select').attr('value') : Controller.currentBillId;
                  $.ajax({
                      type: "get",
                      url: location.href,
                      data: {
                          bill_id: Controller.currentBillId
                      },
                      success: function (data) {
                          if (data['code'] == 1) {
  
                              $('.ebill-trash').unbind('click');
                              $('.imgProd', '.ebill-list').unbind('click');
                              $('.preview-btn').unbind('click');
                              $('.ebill-edit').unbind('click');
  
                              var ebills = data['ebills'];
                              var html = Template('itemTpl', {list: ebills});
                              document.getElementById('contenedorCards').innerHTML = html;
                              ebills.length !== 0 ? $('.empty-hint').hide() : $('.empty-hint').show();
  
                              Controller.api.bindEbillTrashEvent();
                              Controller.api.bindEbillThumbnailEvent();
                              Controller.api.bindEbillEditEvent();
  
                          } else if (data['code'] == 0) {
                              Toastr.error(data['msg']);
                          }
                          layer.close(index);
                      },
                      error: function (e) {
                          layer.close(index);
                      }
                  });
              },
              screenShot: function (elementId, callback) {
                  var element = document.getElementById(elementId);
                  if (element === null) {
                      callback(null);
                      return;
                  }
                  Html2canvas(element,
                      {
                          useCORS: true,
                          scale: 1,
                          height: element.scrollHeight,
                          windowHeight: element.scrollHeight,
                      }).then(canvas => {
                      callback(canvas);
                  });
              }
          }
      };
      return Controller;
  });