bangdingMachine.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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">扫码</button>
  22. <!-- <button type="primary" @click="tran()" >提交</button> -->
  23. </view>
  24. <view class="btn-area">
  25. <button type="primary" formType="submit">申请绑定</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. },
  63. computed: {
  64. },
  65. methods: {
  66. selectSubmit(e) {
  67. if (this.clientId != "" && this.equimentType != "" ) {
  68. var token = uni.getStorageSync("token");
  69. var globalUser = uni.getStorageSync("globalUser");
  70. uni.request({
  71. url: this.serverurl + '/TEquipment/initNew?clientId='+this.clientId+'&adminIda='+globalUser.id+
  72. '&gtClientId='+this.gtclientId+'&equimentType='+this.equimentType,
  73. // data: {
  74. // "clientId": this.clientId,
  75. // "adminIda": globalUser.id,
  76. // "gtclientId": this.gtclientId,
  77. // "equimentType": this.equimentType,
  78. // },
  79. header: {
  80. 'token': token
  81. },
  82. method: "GET",
  83. success: (res) => {
  84. console.log(res.data)
  85. uni.showModal({
  86. title: '提示',
  87. content: res.data,
  88. success: function(res) {
  89. if (res.confirm) {} else if (res.cancel) {}
  90. }
  91. });
  92. },
  93. });
  94. } else {
  95. uni.showModal({
  96. title: '提示',
  97. content: '信息不能为空',
  98. success: function(res) {
  99. if (res.confirm) {} else if (res.cancel) {}
  100. }
  101. });
  102. return;
  103. }
  104. },
  105. saomaWeixin() {
  106. var that = this;
  107. // 允许从相机和相册扫码
  108. uni.scanCode({
  109. success(res) {
  110. var message = res.result;
  111. var mes = [];
  112. mes = message.split("+");
  113. if(mes.length>0){
  114. for(var i = 0;i<mes.length;i++){
  115. if(i==0){
  116. that.clientId = mes[i];
  117. }
  118. if(i==1){
  119. that.equimentType = mes[i];
  120. }
  121. if(i==2){
  122. that.gtclientId = mes[i];
  123. }
  124. }
  125. }
  126. console.log('条码内容:' + res.result);
  127. }
  128. });
  129. },
  130. scanCodeH5() {
  131. let that = this
  132. // 调用uni提供的调用相机api
  133. uni.chooseImage({
  134. sizeType: ['original'],
  135. count: 1,
  136. success: res => {
  137. const tempFilePaths = res.tempFilePaths[0] // 获取到二维码图片的链接
  138. Qrcode.qrcode.decode(tempFilePaths); // 解析二维码图片
  139. Qrcode.qrcode.callback = res1 => {
  140. if (res1 == "error decoding QR Code") {
  141. uni.showToast({
  142. title: "识别二维码失败,请重新上传!",
  143. duration: 2000,
  144. icon: 'none'
  145. })
  146. } else {
  147. // 解析成功返回二维码链接
  148. // console.log(res1) // 这打印的是扫码扫出来的东西
  149. var mes = [];
  150. mes = res1.split("+");
  151. if(mes.length>0){
  152. for(var i = 0;i<mes.length;i++){
  153. if(i==0){
  154. that.clientId = mes[i];
  155. }
  156. if(i==1){
  157. that.equimentType = mes[i];
  158. }
  159. if(i==2){
  160. that.gtclientId = mes[i];
  161. }
  162. }
  163. }
  164. }
  165. }
  166. }
  167. });
  168. },
  169. // 扫码
  170. scanCode() {
  171. // #ifdef MP
  172. this.saomaWeixin()
  173. // #endif
  174. // #ifdef H5
  175. this.scanCodeH5()
  176. // #endif
  177. },
  178. // H5通过拉起相机拍照来识别二维码
  179. scanCodeH51() {
  180. uni.chooseImage({
  181. count: 1,
  182. success: imgRes => {
  183. Qrcode.qrcode.decode(this.getObjectURL(imgRes.tempFiles[0]))
  184. Qrcode.qrcode.callback = (codeRes) => {
  185. if (codeRes.indexOf('error') >= 0) {
  186. // 二维码识别失败
  187. this.qrCodeRes = '不合法二维码:' + codeRes
  188. } else {
  189. // 二维码识别成功
  190. let r = this.decodeStr(codeRes)
  191. this.qrCodeRes = r;
  192. var mes = [];
  193. mes = r.split("+");
  194. if(mes.length>0){
  195. for(var i = 0;i<mes.length;i++){
  196. if(i==0){
  197. that.clientId = mes[i];
  198. }
  199. if(i==1){
  200. that.equimentType = mes[i];
  201. }
  202. if(i==2){
  203. that.gtclientId = mes[i];
  204. }
  205. }
  206. }
  207. }
  208. }
  209. }
  210. })
  211. },
  212. // 获取文件地址函数
  213. getObjectURL(file) {
  214. var url = null
  215. if (window.createObjectURL !== undefined) { // basic
  216. url = window.createObjectURL(file)
  217. } else if (window.URL !== undefined) { // mozilla(firefox)
  218. url = window.URL.createObjectURL(file)
  219. } else if (window.webkitURL !== undefined) { // webkit or chrome
  220. url = window.webkitURL.createObjectURL(file)
  221. }
  222. return url
  223. },
  224. // 解码,输出:中文
  225. decodeStr(str) {
  226. var out, i, len, c;
  227. var char2, char3;
  228. out = "";
  229. len = str.length;
  230. i = 0;
  231. while (i < len) {
  232. c = str.charCodeAt(i++);
  233. switch (c >> 4) {
  234. case 0:
  235. case 1:
  236. case 2:
  237. case 3:
  238. case 4:
  239. case 5:
  240. case 6:
  241. case 7:
  242. // 0xxxxxxx
  243. out += str.charAt(i - 1);
  244. break;
  245. case 12:
  246. case 13:
  247. // 110x xxxx 10xx xxxx
  248. char2 = str.charCodeAt(i++);
  249. out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
  250. break;
  251. case 14:
  252. // 1110 xxxx 10xx xxxx 10xx xxxx
  253. char2 = str.charCodeAt(i++);
  254. char3 = str.charCodeAt(i++);
  255. out += String.fromCharCode(((c & 0x0F) << 12) |
  256. ((char2 & 0x3F) << 6) |
  257. ((char3 & 0x3F) << 0));
  258. break;
  259. }
  260. }
  261. return out;
  262. },
  263. }
  264. }
  265. </script>
  266. <style lang="scss">
  267. @import "../../static/common/selectOrder.scss";
  268. // @import "selectOrder.scss";
  269. .container{
  270. padding: 10px;
  271. }
  272. </style>