index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <view class="content">
  3. <view class="vercode_content">
  4. <view class="vontent_boby" @click="warehous">
  5. <view class="uicon-volume_text">
  6. <text>物料名称:原料</text>
  7. </view>
  8. <view class="uicon-volume_text">
  9. <text>规格:FESA-02131-345K</text>
  10. </view>
  11. </view>
  12. </view>
  13. <view class="border-buttons">
  14. <view class="buttons" @click="Material">
  15. <text>新增物料</text>
  16. </view>
  17. <view class="buttons2">
  18. <text>新增入库</text>
  19. </view>
  20. </view>
  21. <xw-scan></xw-scan>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. data() {
  27. return {
  28. recshow: false,
  29. value: "",
  30. placeholder: "请输入入库单位",
  31. //logo图片 base64
  32. };
  33. },
  34. onLoad(option) {
  35. // this.$broadcastScan.init(this.getScancode);
  36. },
  37. onUnload() {
  38. // 移除监听事件
  39. uni.$off("xwscan");
  40. },
  41. onHide() {
  42. // this.$broadcastScan.stop();
  43. },
  44. onShow() {
  45. // this.$broadcastScan.start();
  46. let that = this;
  47. let pages = getCurrentPages();
  48. let currPage = pages[pages.length - 1]; //当前页面
  49. if (currPage.testdata != undefined) {
  50. console.log("$attrs", currPage.testdata);
  51. this.value = currPage.testdata.name;
  52. }
  53. },
  54. created() {
  55. // 抓取扫描枪数据
  56. document.onkeydown = (e) => {
  57. this.startScan();
  58. };
  59. },
  60. watch: {
  61. scanCodeValue(value) {
  62. if (!!value) {
  63. document.onkeydown = null;
  64. } else {
  65. this.placeholder = "扫码失败,请重新扫码...";
  66. }
  67. },
  68. },
  69. mounted() {
  70. let _this = this;
  71. },
  72. onHide() {
  73. this.recshow = false;
  74. },
  75. methods: {
  76. Material() {
  77. uni.navigateTo({
  78. url: "/pages/Warehousing/selectMaterial/index",
  79. });
  80. },
  81. focusFn(e) {
  82. this.recshow = true;
  83. uni.$off("xwscan"); // 每次进来先 移除全局自定义事件监听器
  84. uni.$on("xwscan", (res) => {
  85. console.log("扫码结果:", res.code);
  86. this.value = res.code;
  87. });
  88. console.log("focus事件");
  89. },
  90. startScan() {
  91. this.$nextTick(() => {
  92. this.focusState = true;
  93. });
  94. // 自动获取input输入框焦点
  95. if (e.which === 13) {
  96. // 安卓版PDA扫描枪扫描完后完成键的keycode=229
  97. // 其他类型可根据keycode值来确认哪一个是完成值,我的是13
  98. setTimeout(() => {
  99. if (this.value.length < 3) return;
  100. this.value = "";
  101. }, 500);
  102. return;
  103. }
  104. },
  105. getScancode(code) {
  106. console.log("进", code);
  107. // 有些PDA会自带换行符,trim函数处理下
  108. code = code.trim();
  109. this.value = code;
  110. //code就是扫描获取的值
  111. console.log(code);
  112. uni.showLoading({
  113. title: code,
  114. });
  115. setTimeout(() => {
  116. uni.hideLoading();
  117. }, 3000);
  118. },
  119. goto(data) {
  120. uni.navigateTo({
  121. url: data,
  122. });
  123. },
  124. },
  125. };
  126. </script>
  127. <style scoped>
  128. /deep/.is-input-border {
  129. display: flex;
  130. box-sizing: border-box;
  131. flex-direction: row;
  132. align-items: center;
  133. border-radius: 4px;
  134. background-color: rgb(245 245 245) !important;
  135. /* background: #24bdbd; */
  136. }
  137. /deep/uni-button {
  138. color: #000;
  139. border: 1px solid #ff0000;
  140. border-radius: 31px;
  141. width: 21%;
  142. background-color: #f5f5f5;
  143. height: 42px;
  144. font-size: 16px;
  145. color: #ff0000;
  146. }
  147. /deep/.uni-easyinput__content-input[data-v-abe12412] {
  148. width: auto;
  149. position: relative;
  150. overflow: hidden;
  151. flex: 1;
  152. line-height: 1;
  153. font-size: 14px;
  154. height: 35px;
  155. /* border-bottom: 1px solid #ff0000 !important; */
  156. }
  157. /deep/.is-input-border {
  158. display: flex;
  159. box-sizing: border-box;
  160. flex-direction: row;
  161. align-items: center;
  162. border: none !important;
  163. border-radius: 4px;
  164. }
  165. </style>
  166. <style lang="scss" scoped>
  167. .content {
  168. .vontent_boby {
  169. padding: 0 15px;
  170. background: #fff;
  171. border-top: 1px solid #dbdbdb;
  172. display: flex;
  173. justify-content: space-between;
  174. font-size: 15px;
  175. color: #838383;
  176. border-bottom: 1px solid #dbdbdb;
  177. height: 55px;
  178. align-items: center;
  179. }
  180. .border-buttons {
  181. display: flex;
  182. position: absolute;
  183. button: 0;
  184. bottom: 32px;
  185. justify-content: space-between;
  186. /* width: 91%; */
  187. left: 0;
  188. text-align: center;
  189. right: 0;
  190. padding: 0 15px;
  191. .buttons {
  192. width: 46%;
  193. border: 1px solid #f00;
  194. border-radius: 34px;
  195. height: 42px;
  196. display: flex;
  197. justify-content: center;
  198. align-items: center;
  199. font-size: 18px;
  200. color: red;
  201. font-weight: 500;
  202. }
  203. .buttons2 {
  204. width: 46%;
  205. border: 1px solid #ff0505;
  206. border-radius: 34px;
  207. height: 42px;
  208. background: red;
  209. display: flex;
  210. justify-content: center;
  211. align-items: center;
  212. font-size: 18px;
  213. color: white;
  214. font-weight: 500;
  215. }
  216. }
  217. }
  218. </style>