bangdingMachine.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <view class="content">
  3. <form @submit="selectSubmit" class="form">
  4. <view class="select-input">
  5. <input class="input" style="display:none;" />
  6. <text>{{$t('bangdingMachine.clientId')}}:{{clientId}}</text>
  7. </view>
  8. <view class="select-input">
  9. <input class="input" style="display:none;" />
  10. <text>{{$t('bangdingMachine.equimentType')}}:{{equimentType}}</text>
  11. <!-- <button type="primary" @click="saoma()" class="button1">
  12. <p class="p">扫码</p>
  13. </button> -->
  14. </view>
  15. <!-- <view class="select-input">
  16. <input class="input" style="display:none;" />
  17. <text>状态:{{status}}</text>
  18. </view> -->
  19. <view class="btn-area">
  20. <!-- <button type="primary" @click="saoma()">扫码</button> -->
  21. <button type="default" @click="scanCode">{{$t('bangdingMachine.QR')}}</button>
  22. <!-- <button type="primary" @click="tran()" >提交</button> -->
  23. </view>
  24. <view class="btn-area">
  25. <button type="primary" formType="submit">{{$t('bangdingMachine.binding')}}</button>
  26. <!-- <button type="primary" @click="tran()" >提交</button> -->
  27. </view>
  28. </form>
  29. </view>
  30. </template>
  31. <script>
  32. let Qrcode = require('../../utils/reqrcode.js')
  33. import MxDatePicker from '../../components/mx-datepicker/mx-datepicker.vue';
  34. import {
  35. dateUtils
  36. } from '@/common/util.js';
  37. // import uniCollapse from '@/components/uni-collapse/uni-collapse.vue';
  38. // import uniCollapseItem from '@/components/uni-collapse-item/uni-collapse-item.vue';
  39. // import uniList from '../../uni_modules/uni-list/components/uni-list/uni-list.vue';
  40. // import uniListItem from '../../uni_modules/uni-list/components/uni-list-item/uni-list-item.vue';
  41. // import uniIcons from '../../uni_modules/uni-icons/components/uni-icons/uni-icons.vue';
  42. export default {
  43. components: {
  44. MxDatePicker
  45. // uniCollapse,
  46. // uniCollapseItem,
  47. // uniList,
  48. // uniListItem,
  49. // uniIcons
  50. },
  51. data() {
  52. return {
  53. //时间选择器
  54. clientId:'',
  55. status:'',
  56. equimentType:'',
  57. gtclientId:'123456'
  58. };
  59. },
  60. onShow() {
  61. var date = new Date();
  62. uni.setNavigationBarTitle({
  63. title: this.$t('user.bangji')
  64. });
  65. },
  66. computed: {
  67. },
  68. methods: {
  69. selectSubmit(e) {
  70. if (this.clientId != "" && this.equimentType != "" ) {
  71. var token = uni.getStorageSync("token");
  72. var globalUser = uni.getStorageSync("globalUser");
  73. uni.request({
  74. url: this.serverurl + '/TEquipment/initNew?clientId='+this.clientId+'&adminIda='+globalUser.id+
  75. '&gtClientId='+this.gtclientId+'&equimentType='+this.equimentType,
  76. // data: {
  77. // "clientId": this.clientId,
  78. // "adminIda": globalUser.id,
  79. // "gtclientId": this.gtclientId,
  80. // "equimentType": this.equimentType,
  81. // },
  82. header: {
  83. 'token': token
  84. },
  85. method: "GET",
  86. success: (res) => {
  87. console.log(res.data)
  88. uni.showModal({
  89. title: this.$t('common.tip'),
  90. content: res.data,
  91. success: function(res) {
  92. if (res.confirm) {} else if (res.cancel) {}
  93. }
  94. });
  95. },
  96. });
  97. } else {
  98. uni.showModal({
  99. title: this.$t('common.tip'),
  100. content: this.$t('bangdingMachine.noMessage'),
  101. success: function(res) {
  102. if (res.confirm) {} else if (res.cancel) {}
  103. }
  104. });
  105. return;
  106. }
  107. },
  108. saomaWeixin() {
  109. var that = this;
  110. // 允许从相机和相册扫码
  111. uni.scanCode({
  112. success(res) {
  113. var message = res.result;
  114. var mes = [];
  115. mes = message.split("+");
  116. if(mes.length>0){
  117. for(var i = 0;i<mes.length;i++){
  118. if(i==0){
  119. that.clientId = mes[i];
  120. }
  121. if(i==1){
  122. that.equimentType = mes[i];
  123. }
  124. if(i==2){
  125. that.gtclientId = mes[i];
  126. }
  127. }
  128. }
  129. console.log('条码内容:' + res.result);
  130. }
  131. });
  132. },
  133. scanCodeH5() {
  134. let that = this
  135. // 调用uni提供的调用相机api
  136. uni.chooseImage({
  137. sizeType: ['original'],
  138. count: 1,
  139. success: res => {
  140. const tempFilePaths = res.tempFilePaths[0] // 获取到二维码图片的链接
  141. Qrcode.qrcode.decode(tempFilePaths); // 解析二维码图片
  142. Qrcode.qrcode.callback = res1 => {
  143. if (res1 == "error decoding QR Code") {
  144. uni.showToast({
  145. title: this.$t('bangdingMachine.failed'),
  146. duration: 2000,
  147. icon: 'none'
  148. })
  149. } else {
  150. // 解析成功返回二维码链接
  151. // console.log(res1) // 这打印的是扫码扫出来的东西
  152. var mes = [];
  153. mes = res1.split("+");
  154. if(mes.length>0){
  155. for(var i = 0;i<mes.length;i++){
  156. if(i==0){
  157. that.clientId = mes[i];
  158. }
  159. if(i==1){
  160. that.equimentType = mes[i];
  161. }
  162. if(i==2){
  163. that.gtclientId = mes[i];
  164. }
  165. }
  166. }
  167. }
  168. }
  169. }
  170. });
  171. },
  172. // 扫码
  173. scanCode() {
  174. // #ifdef MP
  175. this.saomaWeixin()
  176. // #endif
  177. // #ifdef H5
  178. this.scanCodeH5()
  179. // #endif
  180. },
  181. // H5通过拉起相机拍照来识别二维码
  182. scanCodeH51() {
  183. uni.chooseImage({
  184. count: 1,
  185. success: imgRes => {
  186. Qrcode.qrcode.decode(this.getObjectURL(imgRes.tempFiles[0]))
  187. Qrcode.qrcode.callback = (codeRes) => {
  188. if (codeRes.indexOf('error') >= 0) {
  189. // 二维码识别失败
  190. this.qrCodeRes = this.$t('bangdingMachine.illegal') + codeRes
  191. } else {
  192. // 二维码识别成功
  193. let r = this.decodeStr(codeRes)
  194. this.qrCodeRes = r;
  195. var mes = [];
  196. mes = r.split("+");
  197. if(mes.length>0){
  198. for(var i = 0;i<mes.length;i++){
  199. if(i==0){
  200. that.clientId = mes[i];
  201. }
  202. if(i==1){
  203. that.equimentType = mes[i];
  204. }
  205. if(i==2){
  206. that.gtclientId = mes[i];
  207. }
  208. }
  209. }
  210. }
  211. }
  212. }
  213. })
  214. },
  215. // 获取文件地址函数
  216. getObjectURL(file) {
  217. var url = null
  218. if (window.createObjectURL !== undefined) { // basic
  219. url = window.createObjectURL(file)
  220. } else if (window.URL !== undefined) { // mozilla(firefox)
  221. url = window.URL.createObjectURL(file)
  222. } else if (window.webkitURL !== undefined) { // webkit or chrome
  223. url = window.webkitURL.createObjectURL(file)
  224. }
  225. return url
  226. },
  227. // 解码,输出:中文
  228. decodeStr(str) {
  229. var out, i, len, c;
  230. var char2, char3;
  231. out = "";
  232. len = str.length;
  233. i = 0;
  234. while (i < len) {
  235. c = str.charCodeAt(i++);
  236. switch (c >> 4) {
  237. case 0:
  238. case 1:
  239. case 2:
  240. case 3:
  241. case 4:
  242. case 5:
  243. case 6:
  244. case 7:
  245. // 0xxxxxxx
  246. out += str.charAt(i - 1);
  247. break;
  248. case 12:
  249. case 13:
  250. // 110x xxxx 10xx xxxx
  251. char2 = str.charCodeAt(i++);
  252. out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
  253. break;
  254. case 14:
  255. // 1110 xxxx 10xx xxxx 10xx xxxx
  256. char2 = str.charCodeAt(i++);
  257. char3 = str.charCodeAt(i++);
  258. out += String.fromCharCode(((c & 0x0F) << 12) |
  259. ((char2 & 0x3F) << 6) |
  260. ((char3 & 0x3F) << 0));
  261. break;
  262. }
  263. }
  264. return out;
  265. },
  266. }
  267. }
  268. </script>
  269. <style lang="scss">
  270. @import "../../static/common/selectOrder.scss";
  271. // @import "selectOrder.scss";
  272. .container{
  273. padding: 10px;
  274. }
  275. </style>