cylinder.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <template>
  2. <!-- 添加钢瓶 -->
  3. <view>
  4. <u-navbar :title="cylinderTitle" autoBack placeholder @leftClick="leftClick"></u-navbar>
  5. <view class="card_cylinder">
  6. <view class="title_index">单位内编号 <span class="line_title">*</span></view>
  7. <view style="display: flex;align-items: center;">
  8. <input class="card_top_input" ref="inputRef" placeholder="点击输入" v-model="frequencyCoding"
  9. :focus="firstFocus" @blur="blurInput"></input>
  10. <view class="btn_add_card">
  11. <u-button type="primary" text="添加" @click="addCode"></u-button>
  12. </view>
  13. </view>
  14. <view class="scan_card_code">
  15. <view style="display: flex;align-items: center;">
  16. <view style="display: flex;align-items: center;" @click="addLine">
  17. <u-icon name="scan" size="26"></u-icon>
  18. <view class="title_subhead">增加一条</view>
  19. </view>
  20. <view style="display: flex;align-items: center;margin-left: 30rpx;" @click="continuousAddition">
  21. <u-icon name="scan" size="26"></u-icon>
  22. <view class="title_subhead">连续扫码增加</view>
  23. </view>
  24. </view>
  25. <view class="card_bottle">已扫<span>{{codeList.length}}</span>瓶</view>
  26. </view>
  27. <view v-if="codeList.length > 0">
  28. <view class="space_between card_code_trac" v-for="(item,index) in codeList" :key="index">
  29. <view style="display: flex;align-items: center;">
  30. <view class="item_current">{{index + 1}}</view>
  31. <view class="item_title1">{{item}}</view>
  32. </view>
  33. <view class="item_title1 title_red" @click="delCode(index)">删除</view>
  34. </view>
  35. </view>
  36. <view style="margin-top: 20%;" v-else>
  37. <u-empty mode="list" text="请先扫描添加单位内编号"></u-empty>
  38. </view>
  39. </view>
  40. <view style="width: 100%;height: 120rpx;"></view>
  41. <view class="card_btn">
  42. <u-button style="margin-bottom: 20rpx;" type="primary" @click="submit">提交</u-button>
  43. </view>
  44. <u-popup :show="show" :round="10" :closeOnClickOverlay="false" mode="center" @close="close">
  45. <view class="card_coding_scan">
  46. <view class="title_coding">单位内编号</view>
  47. <view class="coding_title1">{{scanCoding}}</view>
  48. <view style="display: flex;align-items: center;">
  49. <u-icon color="#19be6b" size="30" name="checkmark-circle-fill"></u-icon>
  50. <view class="success_title">扫描成功</view>
  51. </view>
  52. <view class="title_coding">3秒后再次扫描</view>
  53. </view>
  54. </u-popup>
  55. </view>
  56. </template>
  57. <script>
  58. export default {
  59. data() {
  60. return {
  61. frequencyCoding: '',
  62. codeList: [],
  63. scanType: 1,
  64. show: false,
  65. scanCoding: '',
  66. bottleType: 1,
  67. cylinderTitle: '添加钢瓶',
  68. firstFocus: false,
  69. gradatimFlag: true,
  70. continuous: null,
  71. clearTime: null,
  72. }
  73. },
  74. onLoad(value) {
  75. this.bottleType = value.status
  76. this.cylinderTitle = value.title
  77. },
  78. methods: {
  79. // 返回
  80. leftClick() {
  81. uni.$emit('refresh');
  82. },
  83. // 添加钢瓶
  84. submit() {
  85. let arrList = []
  86. if (this.codeList.length == 0) {
  87. if (!this.frequencyCoding) {
  88. return uni.$u.toast('请先输入单位内编号')
  89. } else {
  90. arrList.push(this.frequencyCoding)
  91. }
  92. } else {
  93. arrList = this.codeList
  94. }
  95. this.$api.post('/api/gas-cylinder-status', {
  96. status: this.bottleType,
  97. innerCodeList: arrList
  98. }).then(res => {
  99. if (res.code == 200) {
  100. this.codeList = []
  101. this.frequencyCoding = ''
  102. uni.$u.toast(res.msg)
  103. } else {
  104. uni.$u.toast(res.data.msg)
  105. }
  106. })
  107. },
  108. // 删除录入钢瓶编号
  109. delCode(index) {
  110. this.codeList.splice(index, 1);
  111. },
  112. // 添加一条
  113. addLine() {
  114. this.scanType = 1
  115. this.sweep()
  116. },
  117. // 连续添加
  118. continuousAddition() {
  119. this.scanType = 2
  120. this.sweep()
  121. },
  122. // 扫一扫
  123. sweep() {
  124. // 允许从相机和相册扫码
  125. uni.scanCode({
  126. scanType: ['qrCode'],
  127. autoZoom: false,
  128. success: (res) => {
  129. console.log(res, '--------');
  130. if (res.result) {
  131. let url = res.result;
  132. const arrf = url.split('=')
  133. this.unitCoding(arrf[1])
  134. } else {
  135. console.log('请重新扫描');
  136. return false;
  137. }
  138. },
  139. fail: (res) => {
  140. console.log('未识别到二维码1');
  141. }
  142. })
  143. },
  144. // 单位内编码获取
  145. unitCoding(qrid) {
  146. uni.showLoading({
  147. title: '加载中'
  148. });
  149. uni.request({
  150. url: 'http://qr.uinshine.com:9000/CommonAPI/product/getDetails', //仅为示例,并非真实接口地址。
  151. method: 'POST',
  152. header: {
  153. 'content-type': 'application/x-www-form-urlencoded', // 默认值
  154. },
  155. data: {
  156. qr_id: qrid,
  157. },
  158. success: (res) => {
  159. if (res.data.code == 0) {
  160. var arr = res.data.data
  161. if (this.scanType == 1) {
  162. if (this.gradatimFlag) {
  163. this.gradatimFlag = false
  164. this.fetchCylinder(arr.inner_code)
  165. }
  166. // this.codeList.push(arr.inner_code)
  167. // this.codeList = Array.from(new Set(this.codeList));
  168. } else {
  169. if (this.gradatimFlag) {
  170. this.gradatimFlag = false
  171. this.fetchCylinder(arr.inner_code, true)
  172. }
  173. // this.show = true
  174. // this.codeList.push(arr.inner_code)
  175. // this.codeList = Array.from(new Set(this.codeList));
  176. // this.scanCoding = arr.inner_code
  177. // 扫码间隔两秒
  178. // setTimeout(() => {
  179. // this.sweep()
  180. // this.show = false
  181. // }, 3000)
  182. }
  183. }
  184. uni.hideLoading();
  185. }
  186. });
  187. },
  188. // 输入钢瓶编号添加
  189. addCode() {
  190. const cnflag = hasChinese(this.frequencyCoding)
  191. if (cnflag) {
  192. uni.$u.toast('请输入正确单位内编号')
  193. } else {
  194. if (this.frequencyCoding) {
  195. if (this.gradatimFlag) {
  196. this.gradatimFlag = false
  197. this.fetchCylinder(this.frequencyCoding)
  198. }
  199. } else {
  200. uni.$u.toast('请先输入单位内编号')
  201. }
  202. }
  203. function hasChinese(text) {
  204. var pattern = /[\u4E00-\u9FA5]/; // Unicode编码范围包含中文字符
  205. return pattern.test(text);
  206. }
  207. },
  208. // 失去焦点
  209. blurInput(event, flag) {
  210. let arrEvent = event.detail.value
  211. this.firstFocus = false;
  212. const cnflag = hasChinese(arrEvent)
  213. if (cnflag) {
  214. uni.$u.toast('请输入正确单位内编号')
  215. } else {
  216. if (this.gradatimFlag && arrEvent) {
  217. if (this.clearTime) clearTimeout(this.clearTime)
  218. this.gradatimFlag = false
  219. this.fetchCylinder(arrEvent)
  220. }
  221. }
  222. function hasChinese(text) {
  223. var pattern = /[\u4E00-\u9FA5]/; // Unicode编码范围包含中文字符
  224. return pattern.test(text);
  225. }
  226. },
  227. fetchCylinder(event, flag) {
  228. this.$api.get('/api/gas-cylinder/' + event).then(res => {
  229. if (res.code == 200) {
  230. this.codeList.push(res.data.inner_code)
  231. this.codeList = Array.from(new Set(this.codeList));
  232. if (flag) {
  233. if (this.arrTime) clearTimeout(this.arrTime)
  234. this.show = true
  235. this.scanCoding = res.data.inner_code
  236. // 扫码间隔两秒
  237. this.arrTime = setTimeout(() => {
  238. this.show = false
  239. this.sweep()
  240. }, 3000)
  241. this.gradatimFlag = true
  242. return
  243. }
  244. this.clearTime = setTimeout(async () => {
  245. this.frequencyCoding = ''
  246. this.firstFocus = true;
  247. }, 100)
  248. } else if (res.data.code == 400) {
  249. this.clearTime = setTimeout(async () => {
  250. this.frequencyCoding = ''
  251. }, 100)
  252. uni.$u.toast(res.data.msg)
  253. }
  254. this.gradatimFlag = true
  255. })
  256. },
  257. // 弹窗关闭
  258. close() {
  259. this.show = false
  260. }
  261. }
  262. }
  263. </script>
  264. <style lang="scss">
  265. .title_index {
  266. margin-bottom: 10rpx;
  267. font-size: 34rpx;
  268. }
  269. .line_title {
  270. color: red;
  271. }
  272. .btn_add_card {
  273. margin-left: 20rpx;
  274. }
  275. .card_cylinder {
  276. padding: 30rpx;
  277. }
  278. .title_subhead {
  279. margin-left: 6rpx;
  280. font-size: 34rpx;
  281. font-weight: 600;
  282. }
  283. .scan_card_code {
  284. display: flex;
  285. align-items: center;
  286. justify-content: space-between;
  287. margin-top: 30rpx;
  288. padding-bottom: 30rpx;
  289. border-bottom: 1rpx solid #e4e7ed;
  290. }
  291. .card_bottle {
  292. font-size: 30rpx;
  293. span {
  294. margin: 0rpx 5rpx;
  295. color: red;
  296. }
  297. }
  298. .card_code_trac {
  299. margin-top: 30rpx;
  300. padding-bottom: 30rpx;
  301. border-bottom: 1rpx solid #e4e7ed;
  302. }
  303. .item_current {
  304. width: 40rpx;
  305. color: #82848a;
  306. }
  307. .item_title1 {
  308. margin-left: 10rpx;
  309. }
  310. .title_red {
  311. color: #fa3534;
  312. }
  313. .card_btn {
  314. position: fixed;
  315. left: 0;
  316. right: 0;
  317. bottom: 0;
  318. padding-left: 30rpx;
  319. padding-right: 30rpx;
  320. padding-top: 20rpx;
  321. background-color: #fff;
  322. padding-bottom: constant(safe-area-inset-bottom); //兼容 IOS<11.2
  323. padding-bottom: env(safe-area-inset-bottom); //兼容 IOS>11.2
  324. }
  325. .card_coding_scan {
  326. display: flex;
  327. align-items: center;
  328. flex-direction: column;
  329. width: 400rpx;
  330. padding: 30rpx;
  331. }
  332. .title_coding {
  333. font-size: 32rpx;
  334. margin: 20rpx;
  335. }
  336. .success_title {
  337. font-size: 40rpx;
  338. margin-left: 10rpx;
  339. }
  340. .coding_title1 {
  341. font-size: 60rpx;
  342. margin-bottom: 20rpx;
  343. font-weight: 600;
  344. }
  345. .card_top_input {
  346. width: 100%;
  347. font-size: 14px;
  348. color: #303133;
  349. padding: 20rpx;
  350. border-radius: 8rpx;
  351. border: 1px solid #dadbde;
  352. }
  353. </style>