123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- <template>
- <view class="content">
- <form @submit="selectSubmit" class="form">
- <view class="select-input">
- <input class="input" style="display:none;" />
- <text>{{$t('bangdingMachine.clientId')}}:{{clientId}}</text>
- </view>
- <view class="select-input">
- <input class="input" style="display:none;" />
- <text>{{$t('bangdingMachine.equimentType')}}:{{equimentType}}</text>
- <!-- <button type="primary" @click="saoma()" class="button1">
- <p class="p">扫码</p>
- </button> -->
- </view>
- <!-- <view class="select-input">
- <input class="input" style="display:none;" />
- <text>状态:{{status}}</text>
- </view> -->
- <view class="btn-area">
- <!-- <button type="primary" @click="saoma()">扫码</button> -->
- <button type="default" @click="scanCode">扫码</button>
- <!-- <button type="primary" @click="tran()" >提交</button> -->
- </view>
- <view class="btn-area">
- <button type="primary" formType="submit">申请绑定</button>
- <!-- <button type="primary" @click="tran()" >提交</button> -->
- </view>
- </form>
- </view>
- </template>
- <script>
- let Qrcode = require('../../utils/reqrcode.js')
- import MxDatePicker from '../../components/mx-datepicker/mx-datepicker.vue';
- import {
- dateUtils
- } from '@/common/util.js';
- // import uniCollapse from '@/components/uni-collapse/uni-collapse.vue';
- // import uniCollapseItem from '@/components/uni-collapse-item/uni-collapse-item.vue';
- // import uniList from '../../uni_modules/uni-list/components/uni-list/uni-list.vue';
- // import uniListItem from '../../uni_modules/uni-list/components/uni-list-item/uni-list-item.vue';
- // import uniIcons from '../../uni_modules/uni-icons/components/uni-icons/uni-icons.vue';
- export default {
- components: {
- MxDatePicker
- // uniCollapse,
- // uniCollapseItem,
- // uniList,
- // uniListItem,
- // uniIcons
- },
- data() {
- return {
- //时间选择器
- clientId:'',
- status:'',
- equimentType:'',
- gtclientId:'123456'
- };
- },
- onShow() {
- var date = new Date();
- },
- computed: {
- },
- methods: {
-
- selectSubmit(e) {
- if (this.clientId != "" && this.equimentType != "" ) {
- var token = uni.getStorageSync("token");
- var globalUser = uni.getStorageSync("globalUser");
- uni.request({
- url: this.serverurl + '/TEquipment/initNew?clientId='+this.clientId+'&adminIda='+globalUser.id+
- '>ClientId='+this.gtclientId+'&equimentType='+this.equimentType,
- // data: {
- // "clientId": this.clientId,
- // "adminIda": globalUser.id,
- // "gtclientId": this.gtclientId,
- // "equimentType": this.equimentType,
- // },
- header: {
- 'token': token
- },
- method: "GET",
- success: (res) => {
- console.log(res.data)
- uni.showModal({
- title: '提示',
- content: res.data,
- success: function(res) {
- if (res.confirm) {} else if (res.cancel) {}
- }
- });
- },
- });
- } else {
- uni.showModal({
- title: '提示',
- content: '信息不能为空',
- success: function(res) {
- if (res.confirm) {} else if (res.cancel) {}
- }
- });
- return;
- }
- },
- saomaWeixin() {
- var that = this;
- // 允许从相机和相册扫码
- uni.scanCode({
- success(res) {
- var message = res.result;
- var mes = [];
- mes = message.split("+");
- if(mes.length>0){
- for(var i = 0;i<mes.length;i++){
- if(i==0){
- that.clientId = mes[i];
- }
- if(i==1){
- that.equimentType = mes[i];
- }
- if(i==2){
- that.gtclientId = mes[i];
- }
- }
- }
- console.log('条码内容:' + res.result);
- }
- });
- },
-
- scanCodeH5() {
- let that = this
- // 调用uni提供的调用相机api
- uni.chooseImage({
- sizeType: ['original'],
- count: 1,
- success: res => {
- const tempFilePaths = res.tempFilePaths[0] // 获取到二维码图片的链接
- Qrcode.qrcode.decode(tempFilePaths); // 解析二维码图片
- Qrcode.qrcode.callback = res1 => {
- if (res1 == "error decoding QR Code") {
- uni.showToast({
- title: "识别二维码失败,请重新上传!",
- duration: 2000,
- icon: 'none'
- })
- } else {
- // 解析成功返回二维码链接
- // console.log(res1) // 这打印的是扫码扫出来的东西
- var mes = [];
- mes = res1.split("+");
- if(mes.length>0){
- for(var i = 0;i<mes.length;i++){
- if(i==0){
- that.clientId = mes[i];
- }
- if(i==1){
- that.equimentType = mes[i];
- }
- if(i==2){
- that.gtclientId = mes[i];
- }
- }
- }
- }
- }
- }
- });
- },
- // 扫码
- scanCode() {
- // #ifdef MP
- this.saomaWeixin()
- // #endif
-
- // #ifdef H5
- this.scanCodeH5()
- // #endif
- },
- // H5通过拉起相机拍照来识别二维码
- scanCodeH51() {
- uni.chooseImage({
- count: 1,
- success: imgRes => {
- Qrcode.qrcode.decode(this.getObjectURL(imgRes.tempFiles[0]))
- Qrcode.qrcode.callback = (codeRes) => {
- if (codeRes.indexOf('error') >= 0) {
- // 二维码识别失败
- this.qrCodeRes = '不合法二维码:' + codeRes
- } else {
- // 二维码识别成功
- let r = this.decodeStr(codeRes)
- this.qrCodeRes = r;
- var mes = [];
- mes = r.split("+");
- if(mes.length>0){
- for(var i = 0;i<mes.length;i++){
- if(i==0){
- that.clientId = mes[i];
- }
- if(i==1){
- that.equimentType = mes[i];
- }
- if(i==2){
- that.gtclientId = mes[i];
- }
- }
- }
- }
- }
- }
- })
- },
- // 获取文件地址函数
- getObjectURL(file) {
- var url = null
- if (window.createObjectURL !== undefined) { // basic
- url = window.createObjectURL(file)
- } else if (window.URL !== undefined) { // mozilla(firefox)
- url = window.URL.createObjectURL(file)
- } else if (window.webkitURL !== undefined) { // webkit or chrome
- url = window.webkitURL.createObjectURL(file)
- }
- return url
- },
- // 解码,输出:中文
- decodeStr(str) {
- var out, i, len, c;
- var char2, char3;
- out = "";
- len = str.length;
- i = 0;
- while (i < len) {
- c = str.charCodeAt(i++);
- switch (c >> 4) {
- case 0:
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- // 0xxxxxxx
- out += str.charAt(i - 1);
- break;
- case 12:
- case 13:
- // 110x xxxx 10xx xxxx
- char2 = str.charCodeAt(i++);
- out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
- break;
- case 14:
- // 1110 xxxx 10xx xxxx 10xx xxxx
- char2 = str.charCodeAt(i++);
- char3 = str.charCodeAt(i++);
- out += String.fromCharCode(((c & 0x0F) << 12) |
- ((char2 & 0x3F) << 6) |
- ((char3 & 0x3F) << 0));
- break;
- }
- }
- return out;
- },
- }
- }
- </script>
- <style lang="scss">
- @import "../../static/common/selectOrder.scss";
- // @import "selectOrder.scss";
- .container{
- padding: 10px;
- }
- </style>
|