index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <template>
  2. <view class="scanQR">
  3. <view class="showTotal" v-if="fillOut">
  4. <view class="show">
  5. <view class="showTotal_title">
  6. 出库信息查询
  7. </view>
  8. <view style="height: 100rpx;">
  9. <input class="uni-input" v-model="dataPass" placeholder="请输入密码" @focus="tip=''" />
  10. <text class="showTotal_tip">{{ tip }}</text>
  11. </view>
  12. <view class="showTotal_btn" @click="checkDataPassword">
  13. 登录
  14. </view>
  15. </view>
  16. <view class="over"></view>
  17. </view>
  18. <view v-else class="nav">
  19. <view v-if="showImg" style="text-align: center;padding-top: 30rpx;">
  20. <image :src="images" mode="aspectFit" class="nav_saomiao" @click="chooseImgs()"></image>
  21. </view>
  22. <view class="nav_info">
  23. <view class="infoItem">
  24. <view>商品名称</view>
  25. <text>{{ info.select_good && info.select_good.good_name }}</text>
  26. </view>
  27. <view class="infoItem">
  28. <view>发货人</view>
  29. <text>{{ info.select_good_log && info.select_good_log.op_name }}</text>
  30. </view>
  31. <view class="infoItem">
  32. <view>发货时间</view>
  33. <text>{{ info.select_good_log && info.select_good_log.created_at }}</text>
  34. </view>
  35. <view class="infoItem">
  36. <view>接收者</view>
  37. <text>{{ info.select_good_log && info.select_good_log.accept_name }}</text>
  38. </view>
  39. <view class="infoItem">
  40. <view>手机号</view>
  41. <text>{{ info.select_good_log && info.select_good_log.accept_phone }}</text>
  42. </view>
  43. <view class="infoItem">
  44. <view>日志</view>
  45. <text>{{ info.select_good_log && info.select_good_log.note }}</text>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. export default {
  53. data() {
  54. return {
  55. dataPass: '',
  56. fillOut: true,
  57. tip: '',
  58. showImg: true,
  59. images: require('../../static/img/up.png'),
  60. info: {}
  61. }
  62. },
  63. onLoad() {
  64. if (this.getCookie('dataPass') && this.getCookie('dataPass') === 'lulu666') {
  65. this.fillOut = false
  66. }
  67. },
  68. methods: {
  69. checkDataPassword() {
  70. if (this.dataPass === 'lulu666') {
  71. // 密码存储日期 15天
  72. this.setCookie('dataPass', this.dataPass, 'd15')
  73. this.fillOut = false
  74. this.tip = ''
  75. } else {
  76. if (!this.dataPass) {
  77. this.tip = '请输入密码'
  78. } else {
  79. this.tip = '密码错误'
  80. this.dataPass = ''
  81. }
  82. }
  83. },
  84. setCookie(name, value, time) {
  85. var strsec = this.getsec(time)
  86. var exp = new Date()
  87. exp.setTime(exp.getTime() + strsec * 1)
  88. document.cookie = name + '=' + escape(value) + ';expires=' + exp.toGMTString()
  89. },
  90. getsec(str) {
  91. var str1 = str.substring(1, str.length) * 1
  92. var str2 = str.substring(0, 1)
  93. if (str2 === 's') {
  94. return str1 * 1000
  95. } else if (str2 === 'h') {
  96. return str1 * 60 * 60 * 1000
  97. } else if (str2 === 'd') {
  98. return str1 * 24 * 60 * 60 * 1000
  99. }
  100. },
  101. getCookie(name) {
  102. var arr = new RegExp('(^| )' + name + '=([^;]*)(;|$)')
  103. var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)')
  104. if (document.cookie.match(reg)) {
  105. arr = document.cookie.match(reg)
  106. return unescape(arr[2])
  107. } else {
  108. return null
  109. }
  110. },
  111. // 压缩图片
  112. compress(file, limit = 0.92, file_size = 50) {
  113. let _this = this
  114. return new Promise((resolve, reject) => {
  115. if (!file) {
  116. reject(new Error('不存在文件'))
  117. }
  118. const type = file.type
  119. const size = file.size
  120. const whiteType = ['image/jpeg', 'image/png']
  121. if (whiteType.indexOf(type) === -1) { // 判断文件类型
  122. reject(new Error('错误的文件类型'))
  123. }
  124. if (Math.ceil(size / 1024) < file_size) { // 判断文件大小
  125. resolve(file)
  126. }
  127. const reader = new FileReader()
  128. reader.readAsDataURL(file)
  129. reader.onload = e => {
  130. const img = new Image()
  131. img.src = e.target.result
  132. img.onload = () => {
  133. const ratio = img.naturalHeight / img.naturalWidth
  134. const canvas = document.createElement('canvas')
  135. const ctx = canvas.getContext('2d')
  136. canvas.width = img.width > 750 ? 750 : img.width // 固定宽度
  137. canvas.height = img.width * ratio
  138. ctx.drawImage(img, 0, 0, canvas.width, canvas.height)
  139. // limit: 0到1之间的取值,主要用来选定图片的质量,默认值是0.92,超出范围也会选择默认值。
  140. const newImg = canvas.toDataURL('image/jpeg', limit)
  141. // 将base64转换为filel流,
  142. let flie= _this.convertBase64UrlToFile({
  143. dataURL: newImg,
  144. type: 'image/jpeg',
  145. contentName: file.name
  146. })
  147. console.log('flie',flie)
  148. _this.uploadImage(flie)
  149. }
  150. }
  151. })
  152. },
  153. // 转base64
  154. convertBase64UrlToFile(base64) {
  155. let urlData = base64.dataURL
  156. let type = base64.type
  157. let contentName = base64.contentName
  158. let bytes = null
  159. if (urlData.split(',').length > 1) { //是否带前缀
  160. bytes = window.atob(urlData.split(',')[1]) // 去掉url的头,并转换为byte
  161. } else {
  162. bytes = window.atob(urlData)
  163. }
  164. // 处理异常,将ascii码小于0的转换为大于0
  165. let ab = new ArrayBuffer(bytes.length)
  166. let ia = new Uint8Array(ab)
  167. for (let i = 0; i < bytes.length; i++) {
  168. ia[i] = bytes.charCodeAt(i)
  169. }
  170. let result = new Blob([ab], {
  171. type: type,
  172. })
  173. let result1 = new File([result], contentName, {
  174. type: type
  175. })
  176. result1.path = window.URL.createObjectURL(result)
  177. return result1
  178. },
  179. // 查询
  180. uploadImage(img) {
  181. let that = this
  182. uni.showLoading({
  183. title: '查询中...',
  184. mask: true
  185. })
  186. uni.uploadFile({
  187. url: 'http://fangw.jiuweiyun.cn/api/authenticity/CKSelect',
  188. filePath: img.path,
  189. name: 'image',
  190. success: (res) => {
  191. uni.hideLoading()
  192. const data = JSON.parse(res.data)
  193. if (data.code == 200 && data.data) {
  194. this.info = data.data
  195. } else {
  196. this.info = {}
  197. uni.showModal({
  198. content: data.msg || '查询失败',
  199. showCancel: false,
  200. success: function (res) {
  201. if (res.confirm) {
  202. that.images = require('../../static/img/up.png')
  203. }
  204. }
  205. })
  206. }
  207. },
  208. fail: function(err) {
  209. uni.hideLoading()
  210. uni.showToast({
  211. title: '失败',
  212. icon: 'none'
  213. })
  214. }
  215. });
  216. },
  217. // 选择图片
  218. chooseImgs() {
  219. let that = this
  220. uni.chooseImage({
  221. count: 1, //默认9
  222. success: res => {
  223. this.images = res.tempFiles[0].path
  224. // 大于1M压缩
  225. console.log('压缩前', res.tempFiles[0])
  226. if (Math.ceil(res.tempFiles[0].size / 1024) > 1024) {
  227. let url = res.tempFiles[0]
  228. uni.showModal({
  229. title: '提示',
  230. content: '您选择的图片大于1M,有可能无法识别,是否继续?',
  231. confirmText: '继续',
  232. success: function (res) {
  233. if (res.confirm) {
  234. that.compress(url)
  235. } else if (res.cancel) {
  236. that.images = require('../../static/img/up.png')
  237. }
  238. }
  239. });
  240. } else {
  241. that.uploadImage(res.tempFiles[0])
  242. }
  243. }
  244. })
  245. },
  246. }
  247. }
  248. </script>
  249. <style lang="scss" scoped>
  250. .nav {
  251. &_saomiao {
  252. width: 260rpx;
  253. }
  254. .infoItem {
  255. font-size: 32rpx;
  256. padding: 10rpx 20rpx;
  257. display: flex;
  258. justify-content: space-between;
  259. text {
  260. font-size: 26rpx;
  261. font-weight: 400;
  262. width: 70%;
  263. }
  264. }
  265. }
  266. .showTotal {
  267. .uni-input {
  268. margin: 100rpx 0 0rpx;
  269. padding: 20rpx;
  270. border-bottom: 1rpx solid #999;
  271. }
  272. &_btn {
  273. width: 430rpx;
  274. height: 88rpx;
  275. background: linear-gradient(93deg, #A080FF 0%, #5D6BFF 100%);
  276. opacity: 1;
  277. border-radius: 44rpx;
  278. font-size: 32rpx;
  279. font-weight: 400;
  280. line-height: 88rpx;
  281. color: #FFFFFF;
  282. text-align: center;
  283. margin: 200rpx auto 0;
  284. }
  285. &_tip {
  286. font-size: 24rpx;
  287. color: #f44545;
  288. font-weight: 400;
  289. padding-left: 10rpx;
  290. }
  291. .show {
  292. width: 620rpx;
  293. position: fixed;
  294. left: 0;
  295. right: 0;
  296. top: 180rpx;
  297. margin: auto;
  298. z-index: 10000;
  299. background: #fff;
  300. &-image {
  301. width: 620rpx;
  302. position: relative;
  303. }
  304. &-button {
  305. width: 400rpx;
  306. line-height: 96rpx;
  307. text-align: center;
  308. color: #fff;
  309. font-size: 32rpx;
  310. border-radius: 56rpx;
  311. background: linear-gradient(90deg, #f97c55 0%, #f44545 100%);
  312. position: absolute;
  313. bottom: -40rpx;
  314. left: 110rpx;
  315. }
  316. }
  317. .over {
  318. width: 100%;
  319. height: 100%;
  320. background-color: #fff;
  321. // opacity: 0.6;
  322. position: fixed;
  323. top: 0;
  324. left: 0;
  325. z-index: 4;
  326. }
  327. .button {
  328. width: 400rpx;
  329. height: 96rpx;
  330. background: linear-gradient(90deg, #f97c55 0%, #f44545 100%);
  331. }
  332. }
  333. </style>