cylinder.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <!-- 添加钢瓶 -->
  3. <view>
  4. <u-navbar title="添加钢瓶" autoBack placeholder @leftClick="leftClick"></u-navbar>
  5. <view class="card_cylinder">
  6. <view class="title_index">钢瓶编号</view>
  7. <view style="display: flex;align-items: center;">
  8. <u-input border="surround" placeholder="点击输入" v-model="frequencyCoding"></u-input>
  9. <view class="btn_add_card">
  10. <u-button type="primary" text="添加" @click="addCode"></u-button>
  11. </view>
  12. </view>
  13. <view class="scan_card_code">
  14. <view style="display: flex;align-items: center;" @click="addLine">
  15. <u-icon name="scan" size="26"></u-icon>
  16. <view class="title_subhead">增加一条</view>
  17. </view>
  18. <view style="display: flex;align-items: center;margin-left: 30rpx;" @click="continuousAddition">
  19. <u-icon name="scan" size="26"></u-icon>
  20. <view class="title_subhead">连续扫码增加</view>
  21. </view>
  22. </view>
  23. <view v-if="codeList.length > 0">
  24. <view class="space_between card_code_trac" v-for="(item,index) in codeList" :key="index">
  25. <view style="display: flex;align-items: center;">
  26. <view class="item_current">{{index + 1}}</view>
  27. <view class="item_title1">{{item}}</view>
  28. </view>
  29. <view class="item_title1 title_red" @click="delCode(index)">删除</view>
  30. </view>
  31. </view>
  32. <view style="margin-top: 20%;" v-else>
  33. <u-empty mode="list" text="请先扫描添加钢瓶编号"></u-empty>
  34. </view>
  35. </view>
  36. <view style="width: 100%;height: 120rpx;"></view>
  37. <view class="card_btn">
  38. <u-button style="margin-bottom: 20rpx;" type="primary" @click="submit">提交</u-button>
  39. </view>
  40. <u-popup :show="show" :round="10" mode="center" @close="close">
  41. <view class="card_coding_scan">
  42. <view class="title_coding">钢瓶编号</view>
  43. <view class="coding_title1">{{scanCoding}}</view>
  44. <view style="display: flex;align-items: center;">
  45. <u-icon color="#19be6b" size="30" name="checkmark-circle-fill"></u-icon>
  46. <view class="success_title">扫描成功</view>
  47. </view>
  48. <view class="title_coding">3秒后再次扫描</view>
  49. </view>
  50. </u-popup>
  51. </view>
  52. </template>
  53. <script>
  54. export default {
  55. data() {
  56. return {
  57. frequencyCoding: '',
  58. codeList: [],
  59. scanType: 1,
  60. show: false,
  61. scanCoding: '',
  62. bottleType: 1,
  63. }
  64. },
  65. onLoad(value) {
  66. this.bottleType = value.status
  67. },
  68. methods: {
  69. // 返回
  70. leftClick(){
  71. uni.$emit('refresh');
  72. },
  73. // 添加钢瓶
  74. submit() {
  75. let arrList = []
  76. if (this.codeList.length == 0) {
  77. if (!this.frequencyCoding) {
  78. return uni.$u.toast('请先输入钢瓶编号')
  79. } else {
  80. arrList.push(this.frequencyCoding)
  81. }
  82. } else {
  83. arrList = this.codeList
  84. }
  85. this.$api.post('/api/gas-cylinder-status', {
  86. status: Number(this.bottleType),
  87. innerCodeList: arrList
  88. }).then(res => {
  89. if (res.code == 200) {
  90. this.codeList = []
  91. this.frequencyCoding = ''
  92. uni.$u.toast(res.msg)
  93. }
  94. })
  95. },
  96. // 删除录入钢瓶编号
  97. delCode(index) {
  98. this.codeList.splice(index, 1);
  99. },
  100. // 输入钢瓶编号添加
  101. addCode() {
  102. this.codeList.push(this.frequencyCoding)
  103. this.codeList = Array.from(new Set(this.codeList));
  104. this.frequencyCoding = ''
  105. },
  106. // 添加一条
  107. addLine() {
  108. this.scanType = 1
  109. this.sweep()
  110. },
  111. // 连续添加
  112. continuousAddition() {
  113. this.scanType = 2
  114. this.sweep()
  115. },
  116. // 扫一扫
  117. sweep() {
  118. // 允许从相机和相册扫码
  119. uni.scanCode({
  120. scanType: ['qrCode'],
  121. autoZoom: false,
  122. success: (res) => {
  123. console.log(res, '--------');
  124. if (res.result) {
  125. let url = res.result;
  126. const arrf = url.split('=')
  127. this.unitCoding(arrf[1])
  128. } else {
  129. console.log('请重新扫描');
  130. return false;
  131. }
  132. },
  133. fail: (res) => {
  134. console.log('未识别到二维码1');
  135. }
  136. })
  137. },
  138. // 单位内编码获取
  139. unitCoding(qrid) {
  140. uni.showLoading({
  141. title: '加载中'
  142. });
  143. uni.request({
  144. url: 'http://qr.uinshine.com:9000/CommonAPI/product/getDetails', //仅为示例,并非真实接口地址。
  145. method: 'POST',
  146. header: {
  147. 'content-type': 'application/x-www-form-urlencoded', // 默认值
  148. },
  149. data: {
  150. qr_id: qrid,
  151. },
  152. success: (res) => {
  153. if (res.data.code == 0) {
  154. var arr = res.data.data
  155. if (this.scanType == 1) {
  156. this.codeList.push(arr.inner_code)
  157. this.codeList = Array.from(new Set(this.codeList));
  158. } else {
  159. this.show = true
  160. this.codeList.push(arr.inner_code)
  161. this.codeList = Array.from(new Set(this.codeList));
  162. this.scanCoding = arr.inner_code
  163. // 扫码间隔两秒
  164. setTimeout(() => {
  165. this.sweep()
  166. this.show = false
  167. }, 3000)
  168. }
  169. uni.hideLoading();
  170. }
  171. }
  172. });
  173. },
  174. // 弹窗关闭
  175. close() {
  176. this.show = false
  177. }
  178. }
  179. }
  180. </script>
  181. <style lang="scss">
  182. .title_index {
  183. margin-bottom: 10rpx;
  184. font-size: 34rpx;
  185. }
  186. .btn_add_card {
  187. margin-left: 20rpx;
  188. }
  189. .card_cylinder {
  190. padding: 30rpx;
  191. }
  192. .title_subhead {
  193. margin-left: 6rpx;
  194. font-size: 34rpx;
  195. font-weight: 600;
  196. }
  197. .scan_card_code {
  198. display: flex;
  199. align-items: center;
  200. margin-top: 20rpx;
  201. padding-bottom: 20rpx;
  202. border-bottom: 1rpx solid #d7d7d7;
  203. }
  204. .card_code_trac {
  205. margin-top: 30rpx;
  206. padding-bottom: 30rpx;
  207. border-bottom: 1rpx solid #d7d7d7;
  208. }
  209. .item_current {
  210. width: 40rpx;
  211. color: #82848a;
  212. }
  213. .item_title1 {
  214. margin-left: 10rpx;
  215. }
  216. .title_red {
  217. color: #fa3534;
  218. }
  219. .card_btn {
  220. position: fixed;
  221. left: 0;
  222. right: 0;
  223. bottom: 0;
  224. padding-left: 30rpx;
  225. padding-right: 30rpx;
  226. padding-top: 20rpx;
  227. background-color: #fff;
  228. padding-bottom: constant(safe-area-inset-bottom); //兼容 IOS<11.2
  229. padding-bottom: env(safe-area-inset-bottom); //兼容 IOS>11.2
  230. }
  231. .card_coding_scan {
  232. display: flex;
  233. align-items: center;
  234. flex-direction: column;
  235. width: 400rpx;
  236. padding: 30rpx;
  237. }
  238. .title_coding {
  239. font-size: 32rpx;
  240. margin: 20rpx;
  241. }
  242. .success_title {
  243. font-size: 40rpx;
  244. margin-left: 10rpx;
  245. }
  246. .coding_title1 {
  247. font-size: 60rpx;
  248. margin-bottom: 20rpx;
  249. font-weight: 600;
  250. }
  251. </style>