codeBar.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. class="uni-input"
  9. placeholder="扫描或输入条码"
  10. border="surround"
  11. @confirm="queryProduct(0)"
  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. class="uni-input"
  20. placeholder="请输入产品编码"
  21. @confirm="queryProduct(0)"
  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. class="uni-input"
  31. placeholder="请输入产品名称"
  32. @confirm="queryProduct(0)"
  33. border="surround"
  34. v-model="query.name">
  35. </view>
  36. </view>
  37. <view>
  38. <button type="primary" size="mini" @click="queryProduct(0)" :style="{padding:'5px 30px'}">查询</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="30%" align="center">{{item.code}}</uni-td>
  55. <uni-td width="40%" align="center">{{item.name}}</uni-td>
  56. <uni-td width="30%" align="center">{{item.qrCode}}</uni-td>
  57. </uni-tr>
  58. </uni-table>
  59. <view v-if="noMore" style="padding: 30upx;text-align: center;color:#999;font-size: 24rpx;">{{noMore}}</view>
  60. </view>
  61. <scanCode></scanCode>
  62. <uni-popup ref="popup" :mask-click="false" type="dialog">
  63. <view
  64. style="
  65. font-size: 30rpx;
  66. background-color: #fff;
  67. padding: 30rpx 50rpx;
  68. border-radius: 30rpx;
  69. width: 80%;
  70. margin: 0 auto;">
  71. <view style="line-height: 60rpx;width: 600rpx;" v-if="tempProduct">
  72. <view>
  73. 产品编码:{{tempProduct.code}}
  74. </view>
  75. <view>
  76. 产品名称:{{tempProduct.name}}
  77. </view>
  78. <view style="display: flex;align-items: center;padding-top: 15rpx;">
  79. <text>条形码:</text>
  80. <input
  81. :focus="true"
  82. style="width:350rpx;"
  83. class="uni-input"
  84. placeholder="扫描或输入条码"
  85. @confirm="okPop"
  86. border="surround"
  87. v-model="code">
  88. </view>
  89. </view>
  90. <view style="display: flex;padding: 50rpx 15rpx 10rpx;justify-content: center;">
  91. <button size="mini" @click="closePop" :style="{padding:'5px 20px'}">取消</button>
  92. <button size="mini" type="primary" :loading="subloading" @click="okPop" :style="{padding:'5px 20px'}">确定</button>
  93. </view>
  94. </view>
  95. </uni-popup>
  96. </view>
  97. </template>
  98. <script>
  99. import {
  100. dealerProductList,
  101. dealerProductSave
  102. } from '@/config/api.js'
  103. import scanCode from '@/libs/scan-code.vue';
  104. import { playAudio } from '@/libs/tools.js'
  105. export default {
  106. components: { scanCode },
  107. data() {
  108. return {
  109. loading: false,
  110. subloading: false,
  111. query:{
  112. qrCode:'',
  113. name:'',
  114. code:''
  115. },
  116. detailList:[],
  117. code:'',
  118. tempProduct: null,
  119. noMore: ''
  120. };
  121. },
  122. onLoad(opts) {
  123. var _this = this
  124. uni.$on('scancodedate', function(content) {
  125. console.log("扫描到的内容为:", content)
  126. if(_this.tempProduct){
  127. _this.code = content||''
  128. }else{
  129. _this.query.qrCode = content||''
  130. _this.queryProduct(0)
  131. }
  132. })
  133. },
  134. onShow() {
  135. this.hideKeyborder()
  136. },
  137. onUnload() {
  138. uni.$off('scancodedate')
  139. },
  140. onBackPress() {
  141. if(this.tempProduct){
  142. this.closePop()
  143. return true
  144. }
  145. },
  146. methods: {
  147. closePop(){
  148. this.code = ''
  149. this.tempProduct = null
  150. this.$refs.popup.close()
  151. },
  152. okPop(){
  153. if(this.code){
  154. this.productSave()
  155. }else{
  156. uni.$u.toast("请输入或扫描条码!")
  157. }
  158. },
  159. hideKeyborder(){
  160. uni.hideKeyboard()
  161. },
  162. productSave(){
  163. this.subloading = true
  164. const prams = JSON.parse(JSON.stringify(this.tempProduct))
  165. prams.qrCode = this.code
  166. dealerProductSave(prams).then(res => {
  167. if(res.status == 200){
  168. this.queryProduct(1)
  169. this.closePop()
  170. }
  171. this.subloading = false
  172. })
  173. },
  174. // 查询产品
  175. queryProduct(flag){
  176. if(this.query.code==''&&this.query.qrCode==''&&this.query.name==''){
  177. if(!flag){
  178. uni.$u.toast("请输入查询条件!")
  179. playAudio('error')
  180. return
  181. }
  182. }
  183. const params = {
  184. pageNo:1,
  185. pageSize:10 ,
  186. sysFlag: "0"
  187. }
  188. this.loading = true
  189. dealerProductList({...params,...this.query}).then(res => {
  190. console.log(res)
  191. if(res.status == 200){
  192. this.detailList = res.data && res.data.list || []
  193. }
  194. if(res.data.count > 10){
  195. this.noMore = '最多显示前10条匹配产品!'
  196. }else{
  197. this.noMore = ''
  198. }
  199. this.loading = false
  200. })
  201. },
  202. // 编辑
  203. toEdit(item) {
  204. this.tempProduct = item
  205. this.code = this.tempProduct.qrCode
  206. this.$refs.popup.open()
  207. this.hideKeyborder()
  208. }
  209. },
  210. }
  211. </script>
  212. <style lang="scss">
  213. .p-content{
  214. button{
  215. line-height: 1.7;
  216. }
  217. .p-head{
  218. font-size: 32upx;
  219. color: $uni-text-color;
  220. >view{
  221. display: flex;
  222. align-items: center;
  223. padding: 15upx 20upx;
  224. justify-content: space-between;
  225. > view{
  226. display: flex;
  227. padding: 0 10upx;
  228. align-items: center;
  229. }
  230. }
  231. }
  232. .p-body{
  233. overflow: auto;
  234. flex-grow: 1;
  235. height: 50%;
  236. }
  237. .uni-input{
  238. border: 1px solid #eee;
  239. width: 100%;
  240. padding:10upx;
  241. font-size: 32rpx;
  242. }
  243. .p-footer{
  244. padding:20upx 30upx;
  245. display: flex;
  246. > button{
  247. width: 30%;
  248. }
  249. }
  250. }
  251. </style>