cylinder.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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. <<<<<<< HEAD
  113. =======
  114. // 输入钢瓶编号添加
  115. addCode() {
  116. function hasChinese(text) {
  117. var pattern = /[\u4E00-\u9FA5]/; // Unicode编码范围包含中文字符
  118. return pattern.test(text);
  119. }
  120. if (!this.frequencyCoding) {
  121. return uni.$u.toast('请先输入单位内编号')
  122. } else {
  123. if (!hasChinese(this.frequencyCoding)) {
  124. this.$api.get('/api/gas-cylinder/' + this.frequencyCoding).then(res => {
  125. if (res.code == 200) {
  126. this.codeList.push(this.frequencyCoding)
  127. this.codeList = Array.from(new Set(this.codeList));
  128. this.frequencyCoding = ''
  129. } else {
  130. uni.$u.toast(res.data.msg)
  131. }
  132. })
  133. } else {
  134. uni.$u.toast('请输入正确单位内编号')
  135. }
  136. }
  137. },
  138. >>>>>>> ec9bba9783fc5bf29c8b3276224b1ab4fab155dc
  139. // 添加一条
  140. addLine() {
  141. this.scanType = 1
  142. this.sweep()
  143. },
  144. // 连续添加
  145. continuousAddition() {
  146. this.scanType = 2
  147. this.sweep()
  148. },
  149. // 扫一扫
  150. sweep() {
  151. // 允许从相机和相册扫码
  152. uni.scanCode({
  153. scanType: ['qrCode'],
  154. autoZoom: false,
  155. success: (res) => {
  156. if (res.result) {
  157. let url = res.result;
  158. const arrf = url.split('=')
  159. this.unitCoding(arrf[1])
  160. } else {
  161. console.log('请重新扫描');
  162. return false;
  163. }
  164. },
  165. fail: (res) => {
  166. console.log('未识别到二维码1');
  167. }
  168. })
  169. },
  170. // 单位内编码获取
  171. unitCoding(qrid) {
  172. uni.showLoading({
  173. title: '加载中'
  174. });
  175. uni.request({
  176. url: 'http://qr.uinshine.com:9000/CommonAPI/product/getDetails', //仅为示例,并非真实接口地址。
  177. method: 'POST',
  178. header: {
  179. 'content-type': 'application/x-www-form-urlencoded', // 默认值
  180. },
  181. data: {
  182. qr_id: qrid,
  183. },
  184. success: (res) => {
  185. if (res.data.code == 0) {
  186. var arr = res.data.data
  187. if (this.scanType == 1) {
  188. if (this.gradatimFlag) {
  189. this.gradatimFlag = false
  190. this.fetchCylinder(arr.inner_code)
  191. }
  192. // this.codeList.push(arr.inner_code)
  193. // this.codeList = Array.from(new Set(this.codeList));
  194. } else {
  195. if (this.gradatimFlag) {
  196. this.gradatimFlag = false
  197. this.fetchCylinder(arr.inner_code, true)
  198. }
  199. // this.show = true
  200. // this.codeList.push(arr.inner_code)
  201. // this.codeList = Array.from(new Set(this.codeList));
  202. // this.scanCoding = arr.inner_code
  203. // 扫码间隔两秒
  204. // setTimeout(() => {
  205. // this.sweep()
  206. // this.show = false
  207. // }, 3000)
  208. }
  209. }
  210. uni.hideLoading();
  211. }
  212. });
  213. },
  214. // 输入钢瓶编号添加
  215. addCode() {
  216. const cnflag = hasChinese(this.frequencyCoding)
  217. if (cnflag) {
  218. uni.$u.toast('请输入正确单位内编号')
  219. } else {
  220. if (this.frequencyCoding) {
  221. if (this.gradatimFlag) {
  222. this.gradatimFlag = false
  223. this.fetchCylinder(this.frequencyCoding)
  224. }
  225. } else {
  226. uni.$u.toast('请先输入单位内编号')
  227. }
  228. }
  229. function hasChinese(text) {
  230. var pattern = /[\u4E00-\u9FA5]/; // Unicode编码范围包含中文字符
  231. return pattern.test(text);
  232. }
  233. },
  234. // 失去焦点
  235. blurInput(event, flag) {
  236. let arrEvent = event.detail.value
  237. this.firstFocus = false;
  238. const cnflag = hasChinese(arrEvent)
  239. if (cnflag) {
  240. uni.$u.toast('请输入正确单位内编号')
  241. } else {
  242. if (this.gradatimFlag && arrEvent) {
  243. if (this.clearTime) clearTimeout(this.clearTime)
  244. this.gradatimFlag = false
  245. this.fetchCylinder(arrEvent)
  246. }
  247. }
  248. function hasChinese(text) {
  249. var pattern = /[\u4E00-\u9FA5]/; // Unicode编码范围包含中文字符
  250. return pattern.test(text);
  251. }
  252. },
  253. fetchCylinder(event, flag) {
  254. this.$api.get('/api/gas-cylinder/' + event).then(res => {
  255. if (res.code == 200) {
  256. this.codeList.push(res.data.inner_code)
  257. this.codeList = Array.from(new Set(this.codeList));
  258. if (flag) {
  259. if (this.arrTime) clearTimeout(this.arrTime)
  260. this.show = true
  261. this.scanCoding = res.data.inner_code
  262. // 扫码间隔两秒
  263. this.arrTime = setTimeout(() => {
  264. this.show = false
  265. this.sweep()
  266. }, 3000)
  267. this.gradatimFlag = true
  268. return
  269. }
  270. this.clearTime = setTimeout(async () => {
  271. this.frequencyCoding = ''
  272. this.firstFocus = true;
  273. }, 100)
  274. } else if (res.data.code == 400) {
  275. this.clearTime = setTimeout(async () => {
  276. this.frequencyCoding = ''
  277. }, 100)
  278. uni.$u.toast(res.data.msg)
  279. }
  280. this.gradatimFlag = true
  281. })
  282. },
  283. // 弹窗关闭
  284. close() {
  285. this.show = false
  286. }
  287. }
  288. }
  289. </script>
  290. <style lang="scss">
  291. .title_index {
  292. margin-bottom: 10rpx;
  293. font-size: 34rpx;
  294. }
  295. .line_title {
  296. color: red;
  297. }
  298. .btn_add_card {
  299. margin-left: 20rpx;
  300. }
  301. .card_cylinder {
  302. padding: 30rpx;
  303. }
  304. .title_subhead {
  305. margin-left: 6rpx;
  306. font-size: 34rpx;
  307. font-weight: 600;
  308. }
  309. .scan_card_code {
  310. display: flex;
  311. align-items: center;
  312. justify-content: space-between;
  313. margin-top: 30rpx;
  314. padding-bottom: 30rpx;
  315. border-bottom: 1rpx solid #e4e7ed;
  316. }
  317. .card_bottle {
  318. font-size: 30rpx;
  319. span {
  320. margin: 0rpx 5rpx;
  321. color: red;
  322. }
  323. }
  324. .card_code_trac {
  325. margin-top: 30rpx;
  326. padding-bottom: 30rpx;
  327. border-bottom: 1rpx solid #e4e7ed;
  328. }
  329. .item_current {
  330. width: 40rpx;
  331. color: #82848a;
  332. }
  333. .item_title1 {
  334. margin-left: 10rpx;
  335. }
  336. .title_red {
  337. color: #fa3534;
  338. }
  339. .card_btn {
  340. position: fixed;
  341. left: 0;
  342. right: 0;
  343. bottom: 0;
  344. padding-left: 30rpx;
  345. padding-right: 30rpx;
  346. padding-top: 20rpx;
  347. background-color: #fff;
  348. padding-bottom: constant(safe-area-inset-bottom); //兼容 IOS<11.2
  349. padding-bottom: env(safe-area-inset-bottom); //兼容 IOS>11.2
  350. }
  351. .card_coding_scan {
  352. display: flex;
  353. align-items: center;
  354. flex-direction: column;
  355. width: 400rpx;
  356. padding: 30rpx;
  357. }
  358. .title_coding {
  359. font-size: 32rpx;
  360. margin: 20rpx;
  361. }
  362. .success_title {
  363. font-size: 40rpx;
  364. margin-left: 10rpx;
  365. }
  366. .coding_title1 {
  367. font-size: 60rpx;
  368. margin-bottom: 20rpx;
  369. font-weight: 600;
  370. }
  371. .card_top_input {
  372. width: 100%;
  373. font-size: 14px;
  374. color: #303133;
  375. padding: 20rpx;
  376. border-radius: 8rpx;
  377. border: 1px solid #dadbde;
  378. }
  379. </style>