cylinder.vue 6.6 KB

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