<script>
export default {
    data() {
        return {
            plateNo: "",
            // 省份简写
            provinces: [
                ['京', '沪', '粤', '津', '冀', '晋', '蒙', '辽', '吉', '黑',
                    '苏', '浙', '皖', '闽', '赣', '鲁', '豫', '鄂', '湘',
                    '桂', '琼', '渝', '川', '贵', '云', '藏',
                    '陕', '甘', '青', '宁', '新'],
            ],
            // 车牌输入
            numbers: [
                ["A", "B", "C", "D", "E", "F", "G", "H", "J", "K",
                    "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V",
                    "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5",
                    "6", "7", "8", "9"]
            ],
            carnum: [],
            showNewPower: true,
            KeyboardState: true,
        };
    },
    onShareAppMessage(res) {
        return {
            title: 'xxx',
            path: '/pages/pages/home'
        }
    },
    onShow() {
        let memberPlateNo = comm.getCache("memberPlateNo")
        if (memberPlateNo) {
            this.plateNo = memberPlateNo;
            this.carnum = memberPlateNo.split('', 8);
            if (this.carnum.length == 7) {
                this.showNewPower = false;
            } else if (this.carnum.length == 8) {
                this.showNewPower = true;
            }

        }
    },
    methods: {
        bindChoose(e) {

            if (!this.carnum[7]) {
                var arr = [];
                arr[0] = e.target.dataset.val;
                this.carnum = this.carnum.concat(arr)

            }
        },
        bindDelChoose() {
            if (this.carnum.length != 0) {
                if (this.carnum.length > 0) {
                    let p = this.carnum.length - 1;
                    let carArr = [];
                    for (var i = 0; i < p; i++) {
                        carArr.push(this.carnum[i]);
                    }
                    this.carnum = carArr;
                }
            }
        },
        showPowerBtn() {
            this.showNewPower = true;
            this.KeyboardState = true;
        },
        closeKeyboard() {
            this.KeyboardState = false;
        },
        openKeyboard() {
            this.KeyboardState = true;
        },
        importPlateNo(e) {
            this.plateNo = e.detail.value
        },
        submitNumber() {
            var that = this;
            if (that.carnum[6]) {
                wx.showLoading();
                var number;
                if (!that.showNewPower) {
                    if (that.carnum[6]) {
                        number = that.carnum[0] + that.carnum[1] + that.carnum[2] + that.carnum[3] + that.carnum[4] +
                            that.carnum[5] + that.carnum[6];
                        that.plateNo = number;
                        that.summit();
                    } else {
                        wx.showToast({
                            title: '请填写完整的车牌号码',
                            duration: 2000
                        })
                    }
                } else {
                    if (that.carnum[7]) {
                        number = that.carnum[0] + that.carnum[1] + that.carnum[2] + that.carnum[3] + that.carnum[4] +
                            that.carnum[5] + that.carnum[6] + that.carnum[7];
                        that.plateNo = number;
                        that.summit();
                    } else {
                        wx.showToast({
                            title: '请填写完整的车牌号码',
                            duration: 2000
                        })
                    }
                }
            } else {
                wx.showToast({
                    title: '请填写完整的车牌号码',
                    duration: 2000
                })
            }
        },
        summit() {
            let plateNo = this.plateNo;
            let data = {
                plateNo: plateNo
            }
            // 调用后台，需要根据实际情况替换。
            comm.request("POST", "/xxx/xxx", data, (res) => {
                wx.hideLoading();
                if (res.data.ret_code == 200) {
                    comm.setCache("memberPlateNo", plateNo);
                    wx.showModal({
                        content: '绑定成功',
                        showCancel: false,
                        success() {
                            wx.navigateBack()
                        }
                    })
                } else {
                    wx.showModal({
                        content: res.data.ret_msg,
                        showCancel: false,
                        success() {

                        }
                    })
                }

            })

        }
    }
}
</script>换成语法糖的形式