codeBar.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. <view class="uni-table">
  43. <!-- 表头行 -->
  44. <uni-tr>
  45. <uni-td width="30%" align="center">产品编码</uni-td>
  46. <uni-td width="40%" align="center">产品名称</uni-td>
  47. <uni-td width="30%" align="center">条形码</uni-td>
  48. </uni-tr>
  49. </view>
  50. <scroll-view enable-flex scroll-y="true" class="table-scroll-body" @scrolltolower="scrolltolower">
  51. <uni-table style="width: 100%;" border :loading="loading">
  52. <!-- 表格数据行 -->
  53. <uni-tr
  54. v-for="item in detailList" :key="item.id"
  55. :checkedRow="tempProduct&&tempProduct.id == item.id"
  56. @click="toEdit(item)">
  57. <uni-td width="30%" align="center">{{item.code}}</uni-td>
  58. <uni-td width="40%" align="center">{{item.name}}</uni-td>
  59. <uni-td width="30%" align="center">{{item.qrCode}}</uni-td>
  60. </uni-tr>
  61. </uni-table>
  62. </scroll-view>
  63. </view>
  64. <scanCode></scanCode>
  65. <uni-popup ref="popup" :mask-click="false" type="dialog">
  66. <view
  67. style="
  68. font-size: 30rpx;
  69. background-color: #fff;
  70. padding: 30rpx 50rpx;
  71. border-radius: 30rpx;
  72. width: 80%;
  73. margin: 0 auto;">
  74. <view style="line-height: 60rpx;width: 600rpx;" v-if="tempProduct">
  75. <view>
  76. 产品编码:{{tempProduct.code}}
  77. </view>
  78. <view>
  79. 产品名称:{{tempProduct.name}}
  80. </view>
  81. <view style="display: flex;align-items: center;padding-top: 15rpx;">
  82. <text>条形码:</text>
  83. <input
  84. :focus="true"
  85. style="width:350rpx;"
  86. class="uni-input"
  87. placeholder="扫描或输入条码"
  88. @confirm="okPop"
  89. border="surround"
  90. v-model="code">
  91. </view>
  92. </view>
  93. <view style="display: flex;padding: 50rpx 15rpx 10rpx;justify-content: center;">
  94. <button size="mini" @click="closePop" :style="{padding:'5px 20px'}">取消</button>
  95. <button size="mini" type="primary" :loading="subloading" @click="okPop" :style="{padding:'5px 20px'}">确定</button>
  96. </view>
  97. </view>
  98. </uni-popup>
  99. </view>
  100. </template>
  101. <script>
  102. import {
  103. dealerProductList,
  104. dealerProductSave
  105. } from '@/config/api.js'
  106. import scanCode from '@/libs/scan-code.vue';
  107. import { playAudio } from '@/libs/tools.js'
  108. export default {
  109. components: { scanCode },
  110. data() {
  111. return {
  112. loading: false,
  113. subloading: false,
  114. query:{
  115. qrCode:'',
  116. name:'',
  117. code:''
  118. },
  119. detailList:[],
  120. code:'',
  121. tempProduct: null,
  122. pageNo: 1,
  123. pageSize: 10,
  124. total: 0,
  125. };
  126. },
  127. onLoad(opts) {
  128. var _this = this
  129. uni.$on('scancodedate', function(content) {
  130. console.log("扫描到的内容为:", content)
  131. if(_this.tempProduct){
  132. _this.code = content||''
  133. }else{
  134. _this.query.qrCode = content||''
  135. _this.queryProduct(0)
  136. }
  137. })
  138. },
  139. onShow() {
  140. this.hideKeyborder()
  141. },
  142. onUnload() {
  143. uni.$off('scancodedate')
  144. },
  145. onBackPress() {
  146. if(this.tempProduct){
  147. this.closePop()
  148. return true
  149. }
  150. },
  151. methods: {
  152. closePop(){
  153. this.code = ''
  154. this.tempProduct = null
  155. this.$refs.popup.close()
  156. },
  157. okPop(){
  158. if(this.code){
  159. this.productSave()
  160. }else{
  161. uni.$u.toast("请输入或扫描条码!")
  162. }
  163. },
  164. hideKeyborder(){
  165. uni.hideKeyboard()
  166. },
  167. productSave(){
  168. this.subloading = true
  169. const prams = JSON.parse(JSON.stringify(this.tempProduct))
  170. prams.qrCode = this.code
  171. dealerProductSave(prams).then(res => {
  172. if(res.status == 200){
  173. this.queryProduct(1)
  174. this.closePop()
  175. }
  176. this.subloading = false
  177. })
  178. },
  179. // 查询产品
  180. queryProduct(flag){
  181. if(this.query.code==''&&this.query.qrCode==''&&this.query.name==''){
  182. if(!flag){
  183. uni.$u.toast("请输入查询条件!")
  184. playAudio('error')
  185. return
  186. }
  187. }
  188. const params = {
  189. pageNo:this.pageNo,
  190. pageSize: this.pageSize ,
  191. sysFlag: "0"
  192. }
  193. this.loading = true
  194. dealerProductList({...params,...this.query}).then(res => {
  195. console.log(res)
  196. if(res.status == 200){
  197. const list = res.data.list||[]
  198. this.total = res.data.count
  199. if(this.pageNo == 1){
  200. this.detailList = list
  201. }else{
  202. this.detailList = this.detailList.concat(list)
  203. }
  204. }
  205. this.loading = false
  206. })
  207. },
  208. scrolltolower(e){
  209. const pageNums = Math.ceil(this.total / this.pageSize)
  210. if(this.pageNo < pageNums){
  211. this.pageNo = this.pageNo + 1
  212. this.queryProduct()
  213. }else{
  214. uni.$u.toast("没有更多数据了!")
  215. }
  216. },
  217. // 编辑
  218. toEdit(item) {
  219. this.tempProduct = item
  220. this.code = item.qrCode || ''
  221. this.$refs.popup.open()
  222. this.hideKeyborder()
  223. }
  224. },
  225. }
  226. </script>
  227. <style lang="scss">
  228. $border-color:#EBEEF5;
  229. .p-content{
  230. button{
  231. line-height: 1.7;
  232. }
  233. .uni-table {
  234. position: relative;
  235. width: 100%;
  236. border-radius: 5px;
  237. background-color: #fff;
  238. /* #ifndef APP-NVUE */
  239. box-sizing: border-box;
  240. display: table;
  241. overflow-x: auto;
  242. ::v-deep .uni-table-tr:nth-child(n + 2) {
  243. &:hover {
  244. background-color: #f5f7fa;
  245. }
  246. }
  247. ::v-deep .uni-table-td{
  248. border-right: 1px $border-color solid;
  249. }
  250. /* #endif */
  251. }
  252. .table-scroll-body{
  253. height: calc(100% - 32px);
  254. width: 100%;
  255. overflow: auto;
  256. }
  257. .p-head{
  258. font-size: 32upx;
  259. color: $uni-text-color;
  260. >view{
  261. display: flex;
  262. align-items: center;
  263. padding: 15upx 20upx;
  264. justify-content: space-between;
  265. > view{
  266. display: flex;
  267. padding: 0 10upx;
  268. align-items: center;
  269. }
  270. }
  271. }
  272. .p-body{
  273. overflow: auto;
  274. flex-grow: 1;
  275. height: 50%;
  276. }
  277. .uni-input{
  278. border: 1px solid #eee;
  279. width: 100%;
  280. padding:10upx;
  281. font-size: 32rpx;
  282. }
  283. .p-footer{
  284. padding:20upx 30upx;
  285. display: flex;
  286. > button{
  287. width: 30%;
  288. }
  289. }
  290. }
  291. </style>