productPicture.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
  6. <meta name="apple-mobile-web-app-capable" content="yes">
  7. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  8. <!--标准mui.css-->
  9. <link rel="stylesheet" href="../../css/mui.min.css">
  10. <!-- FontAwesome字体图标 -->
  11. <link type="text/css" href="../../js/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
  12. <!--App自定义的css-->
  13. <link rel="stylesheet" type="text/css" href="../../css/common.css" />
  14. <style>
  15. .my-btn {
  16. width: 80px;
  17. height: 34px;
  18. margin: 10px auto;
  19. }
  20. </style>
  21. <style type="text/css">
  22. body {
  23. background-color: #efeff4;
  24. }
  25. .mui-content {}
  26. .mui-content a {
  27. color: #8F8F94;
  28. }
  29. .mui-content a.active {
  30. color: #007aff;
  31. }
  32. .mui-title {
  33. font-family: simhei;
  34. }
  35. .btn_2 {
  36. position: absolute;
  37. bottom: 85px;
  38. left: 10px;
  39. right: 10px;
  40. }
  41. .btn_1 {
  42. position: absolute;
  43. bottom: 10px;
  44. left: 10px;
  45. right: 10px;
  46. }
  47. .btn_3 {
  48. position: absolute;
  49. bottom: 140px;
  50. left: 10px;
  51. right: 10px;
  52. }
  53. .mui-btn-block {
  54. width: 90%;
  55. margin: 0 auto;
  56. }
  57. body {
  58. overflow: hidden;
  59. }
  60. .showimg {
  61. margin: 10px 10px auto 10px;
  62. text-align: center;
  63. }
  64. </style>
  65. </head>
  66. <body>
  67. <header class="mui-bar mui-bar-nav">
  68. <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
  69. <h1 class="mui-title">商品拍照</h1>
  70. </header>
  71. <div class="mui-content">
  72. <form class="mui-input-group" onsubmit="return false">
  73. <!--
  74. 作者:1279246617@qq.com
  75. 时间:2019-07-22
  76. 描述:form 只有一个input时 回车会变成提交form 所以加一个隐藏的input
  77. -->
  78. <input style="display: none;" id="kenghuo" />
  79. <div class="mui-input-row">
  80. <label>商品条码</label>
  81. <input type="text" class="mui-input-clear allowClear" placeholder="扫描商品条码" id="barcode" name="barcode">
  82. </div>
  83. <div class="mui-input-row">
  84. <!--
  85. 作者:1279246617@qq.com
  86. 时间:2019-07-22
  87. 描述:为了操作连贯性 不能每次提交后清空,也不能每次都选择. 只有当货主+条码不存在时才要求切换货主
  88. -->
  89. <label>货主代码</label>
  90. <select id="customerCode" name="customerCode" placeholder="选择货主" onchange="countPicture()" class="readonlyInput" style="width:60%;float: left;">
  91. </select>
  92. </div>
  93. <div class="mui-input-row" style="width:100%;font-size: 9pt;height: 25px;line-height: 10px;">
  94. <label style="width: 100%;height: 20px;padding-top: 5px;padding-bottom: 0px;text-align: left;">
  95. <span id="tips"></span>
  96. </label>
  97. </div>
  98. <div class="mui-input-row" style="min-height: 160px;overflow-y: auto;">
  99. <div class="showimg" id="showimg"></div>
  100. </div>
  101. </form>
  102. <div class="mui-content-padded " style="text-align: center;height: 50px;">
  103. <button type="button" class="mui-btn mui-btn-primary my-btn" onclick="submitUpload()"><i class="fa fa-check">&nbsp;</i>提交</button>
  104. <button type="button" class="mui-btn mui-btn-danger my-btn" onclick="cleanAll()"><i class="fa fa-times">&nbsp;</i>清空</button>
  105. </div>
  106. <button type="button" class="mui-btn mui-btn-primary mui-btn-block btn_1" onclick="galleryImgs()">从相册中选择图片</button>
  107. <br>
  108. <button type="button" class="mui-btn mui-btn-success mui-btn-block btn_2" onclick="cameraImages()">拍照</button>
  109. </div>
  110. <script src="../../js/mui.min.js"></script>
  111. <script type="text/javascript" src="../../js/jquery/jquery.min.js"></script>
  112. <script type="text/javascript" src="../../js/jquery/jquery.cookie.js"></script>
  113. <script type="text/javascript" src="../../js/wms/common.js"></script>
  114. <script type="text/javascript" src="../../js/wms/datefmt.js"></script>
  115. <script type="text/javascript" src="../../js/wms/formTransformEntity.js"></script>
  116. <script type="text/javascript" src="../../js/wms/appRequest.js"></script>
  117. <script type="text/javascript" src="../../js/other/product_picture.js"></script>
  118. <script src="../../js/photo/binaryajax.js" type="text/javascript" charset="utf-8"></script>
  119. <script src="../../js/photo/exif.js" type="text/javascript" charset="utf-8"></script>
  120. <script src="../../js/photo/canvasResize.js" type="text/javascript" charset="utf-8"></script>
  121. <script type="text/javascript" charset="utf-8">
  122. //$.noConflict()//jq 释放 $
  123. //mui初始化
  124. mui.init({
  125. swipeBack: true //启用右滑关闭功能
  126. });
  127. (function($, doc) {
  128. $.init();
  129. $.plusReady(function() {
  130. document.addEventListener("netchange", checkNetwork, false);
  131. function checkNetwork() {
  132. if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
  133. mui.toast("网络异常,请检查网络设置!");
  134. }
  135. }
  136. });
  137. }(mui, document));
  138. // 全局数组对象,添加文件,用于压缩上传使用
  139. var imgArray = new Array();
  140. //上传单张图片
  141. function galleryImg() {
  142. //每次拍摄或选择图片前清空数组对象
  143. imgArray.splice(0, imgArray.length);
  144. document.getElementsByClassName("showimg")[0].innerHTML = null;
  145. // 从相册中选择图片
  146. mui.toast("从相册中选择一张图片");
  147. plus.gallery.pick(function(path) {
  148. showImg(path);
  149. }, function(e) {
  150. mui.toast("取消选择图片");
  151. }, {
  152. filter: "image",
  153. multiple: false
  154. });
  155. }
  156. //从相册选择多张图片
  157. function galleryImgs() {
  158. //每次拍摄或选择图片前清空数组对象
  159. imgArray.splice(0, imgArray.length);
  160. document.getElementsByClassName("showimg")[0].innerHTML = null;
  161. // 从相册中选择图片
  162. mui.toast("一次最多选择6张图片");
  163. plus.gallery.pick(function(e) {
  164. if(e.files.length < 1) {
  165. mui.toast('请最少选择一张图片');
  166. return false;
  167. }
  168. if(e.files.length > 6) {
  169. mui.toast('不能超过6张图片');
  170. return false;
  171. }
  172. for(var i in e.files) {
  173. showImg(e.files[i]);
  174. }
  175. }, function(e) {
  176. mui.toast("取消选择图片");
  177. }, {
  178. filter: "image",
  179. multiple: true
  180. });
  181. }
  182. // 拍照添加文件
  183. function cameraImages() {
  184. //每次拍摄或选择图片前清空数组对象
  185. //imgArray.splice(0, imgArray.length);
  186. //document.getElementsByClassName("showimg")[0].innerHTML = null;
  187. var cmr = plus.camera.getCamera();
  188. cmr.captureImage(function(p) {
  189. plus.io.resolveLocalFileSystemURL(p, function(entry) {
  190. var localurl = entry.toLocalURL(); //把拍照的目录路径,变成本地url路径,例如file:///........之类的。
  191. showImg(localurl);
  192. });
  193. }, function(e) {
  194. mui.toast("很抱歉,调用摄像头失败 ");
  195. });
  196. }
  197. //显示预览图片
  198. function showImg(url) {
  199. // 兼容以“file:”开头的情况
  200. if(0 != url.toString().indexOf("file://")) {
  201. url = "file://" + url;
  202. }
  203. var div = document.getElementsByClassName("showimg")[0];
  204. var img = new Image();
  205. img.src = url; // 传过来的图片路径在这里用。
  206. img.onclick = function() {
  207. plus.runtime.openFile(url);
  208. };
  209. img.onload = function() {
  210. var tmph = img.height;
  211. var tmpw = img.width;
  212. var isHengTu = tmpw > tmph;
  213. var max = Math.max(tmpw, tmph);
  214. var min = Math.min(tmpw, tmph);
  215. var bili = min / max;
  216. if(max > 1200) {
  217. max = 1200;
  218. min = Math.floor(bili * max);
  219. }
  220. tmph = isHengTu ? min : max;
  221. tmpw = isHengTu ? max : min;
  222. img.style.border = "1px solid rgb(200,199,204)";
  223. img.style.margin = "10px";
  224. img.style.width = "100px";
  225. img.style.height = "100px";
  226. img.onload = null;
  227. plus.io.resolveLocalFileSystemURL(url, function(entry) {
  228. entry.file(function(file) {
  229. console.log(file.size + '--' + file.name);
  230. canvasResize(file, {
  231. width: tmpw,
  232. height: tmph,
  233. crop: false,
  234. quality: 50, //压缩质量
  235. rotate: 0,
  236. callback: function(data, width, height) {
  237. imgArray.push(data);
  238. img.src = data;
  239. div.appendChild(img);
  240. plus.nativeUI.closeWaiting();
  241. }
  242. });
  243. });
  244. },
  245. function(e) {
  246. plus.nativeUI.closeWaiting();
  247. console.log(e.message);
  248. });
  249. };
  250. };
  251. </script>
  252. </body>
  253. </html>