codeBar.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <view class="p-content">
  3. <view class="p-head">
  4. <view>
  5. <text>条形码:</text>
  6. <view style="flex-grow: 1;display: flex;align-items: center;">
  7. <input
  8. style="width: 100%;text-align: left;font-size: 32rpx;padding: 6rpx 0 6rpx 7rpx;"
  9. class="uni-input"
  10. placeholder="扫描或输入条码"
  11. border="surround"
  12. v-model="query.qrCode">
  13. </view>
  14. </view>
  15. <view>
  16. <text>产品编码:</text>
  17. <view style="flex-grow: 1;display: flex;align-items: center;">
  18. <input
  19. style="width: 100%;text-align: left;font-size: 32rpx;padding: 6rpx 0 6rpx 7rpx;"
  20. class="uni-input"
  21. placeholder="请输入产品编码"
  22. border="surround"
  23. v-model="query.code">
  24. </view>
  25. </view>
  26. <view>
  27. <text>产品名称:</text>
  28. <view style="flex-grow: 1;display: flex;align-items: center;">
  29. <input
  30. style="width: 100%;text-align: left;font-size: 32rpx;padding: 6rpx 0 6rpx 7rpx;"
  31. class="uni-input"
  32. placeholder="请输入产品名称"
  33. border="surround"
  34. v-model="query.name">
  35. </view>
  36. </view>
  37. <view>
  38. <button type="primary" size="mini" @click="queryProduct" :style="{padding:'5px 20px'}">查询</button>
  39. </view>
  40. </view>
  41. <view class="p-body">
  42. <uni-table border emptyText="暂无数据" :loading="loading" >
  43. <!-- 表头行 -->
  44. <uni-tr>
  45. <uni-td align="center">条形码</uni-td>
  46. <uni-td align="center">产品编码</uni-td>
  47. <uni-td align="center">产品名称</uni-td>
  48. </uni-tr>
  49. <!-- 表格数据行 -->
  50. <uni-tr
  51. v-for="item in detailList" :key="item.id"
  52. :checkedRow="tempProduct&&tempProduct.id == item.id"
  53. @click="toEdit(item)">
  54. <uni-td width="40%" align="center">{{item.qrCode}}</uni-td>
  55. <uni-td width="30%" align="center">{{item.code}}</uni-td>
  56. <uni-td width="30%" align="center">{{item.name}}</uni-td>
  57. </uni-tr>
  58. </uni-table>
  59. </view>
  60. <scanCode></scanCode>
  61. <uni-popup ref="popup" :mask-click="false" type="dialog">
  62. <view
  63. style="
  64. font-size: 30rpx;
  65. background-color: #fff;
  66. padding: 30rpx 50rpx;
  67. border-radius: 30rpx;
  68. width: 80%;
  69. margin: 0 auto;">
  70. <view style="line-height: 60rpx;" v-if="tempProduct">
  71. <view>
  72. 产品编码:{{tempProduct.code}}
  73. </view>
  74. <view>
  75. 产品名称:{{tempProduct.name}}
  76. </view>
  77. <view style="display: flex;align-items: center;padding-top: 15rpx;">
  78. 条形码:
  79. <input
  80. :focus="true"
  81. style="width: 70%;text-align: left;border: 1px solid #eee;font-size: 32rpx;padding: 6rpx 0 6rpx 7rpx;"
  82. class="uni-input"
  83. placeholder="扫描或输入条码"
  84. border="surround"
  85. v-model="code">
  86. </view>
  87. </view>
  88. <view style="display: flex;padding: 50rpx 15rpx 10rpx;justify-content: center;">
  89. <button size="mini" @click="closePop" :style="{padding:'5px 20px'}">取消</button>
  90. <button size="mini" type="primary" :loading="subloading" @click="okPop" :style="{padding:'5px 20px'}">确定</button>
  91. </view>
  92. </view>
  93. </uni-popup>
  94. </view>
  95. </template>
  96. <script>
  97. import {
  98. dealerProductList,
  99. dealerProductSave
  100. } from '@/config/api.js'
  101. import scanCode from '@/libs/scan-code.vue';
  102. import { playAudio } from '@/libs/tools.js'
  103. export default {
  104. components: { scanCode },
  105. data() {
  106. return {
  107. loading: false,
  108. subloading: false,
  109. query:{
  110. qrCode:'',
  111. name:'',
  112. code:''
  113. },
  114. detailList:[],
  115. code:'',
  116. tempProduct: null
  117. };
  118. },
  119. onLoad(opts) {
  120. var _this = this
  121. uni.$on('scancodedate', function(content) {
  122. console.log("扫描到的内容为:", content)
  123. _this.code = content||''
  124. })
  125. },
  126. onShow() {
  127. this.hideKeyborder()
  128. },
  129. onUnload() {
  130. uni.$off('scancodedate')
  131. },
  132. methods: {
  133. closePop(){
  134. this.$refs.popup.close()
  135. },
  136. okPop(){
  137. if(this.code){
  138. this.productSave()
  139. }else{
  140. uni.$u.toast("请输入或扫描条码!")
  141. }
  142. },
  143. hideKeyborder(){
  144. uni.hideKeyboard()
  145. },
  146. productSave(){
  147. this.subloading = true
  148. this.tempProduct.qrCode = this.code
  149. dealerProductSave(this.tempProduct).then(res => {
  150. if(res.status == 200){
  151. this.queryProduct()
  152. this.code == ''
  153. this.closePop()
  154. }
  155. this.subloading = false
  156. })
  157. },
  158. // 查询产品
  159. queryProduct(){
  160. if(this.query.code==''&&this.query.qrCode==''&&this.query.name==''){
  161. uni.$u.toast("请输入查询条件!")
  162. playAudio('error')
  163. return
  164. }
  165. const params = {
  166. pageNo:1,
  167. pageSize:10 ,
  168. sysFlag: "0"
  169. }
  170. console.log(params)
  171. dealerProductList({...params,...this.query}).then(res => {
  172. console.log(res)
  173. if(res.status == 200){
  174. this.detailList = res.data && res.data.list || []
  175. }
  176. })
  177. },
  178. // 编辑
  179. toEdit(item) {
  180. this.tempProduct = item
  181. this.$refs.popup.open()
  182. this.hideKeyborder()
  183. }
  184. },
  185. }
  186. </script>
  187. <style lang="scss">
  188. .p-content{
  189. button{
  190. line-height: 1.7;
  191. }
  192. .p-head{
  193. font-size: 32upx;
  194. color: $uni-text-color;
  195. >view{
  196. display: flex;
  197. align-items: center;
  198. padding: 15upx 20upx;
  199. border-bottom: 1px solid #eee;
  200. justify-content: space-between;
  201. > view{
  202. display: flex;
  203. padding: 0 10upx;
  204. align-items: center;
  205. }
  206. }
  207. .uni-input{
  208. border: 1px solid #eee;
  209. width: 150upx;
  210. text-align: center;
  211. }
  212. }
  213. .p-body{
  214. overflow: auto;
  215. flex-grow: 1;
  216. height: 50%;
  217. }
  218. .p-footer{
  219. padding:20upx 30upx;
  220. display: flex;
  221. > button{
  222. width: 30%;
  223. }
  224. }
  225. }
  226. </style>