let that = {}
export default {
	data() {
		return {
			showInfo: false,
			form: {
				payType: '提现到银行',
				payTypeValue: 2,
			},
			bankImgUp: 'http://yuledui.oss-cn-qingdao.aliyuncs.com/merch_manage/img/bank_card_setting/take_photo.png',// 银行卡照片OCR
			openAutoPay: true,
			border: false,
			showPayType: false,
			labelPosition: 'left',
			errorType: ['message'],
			rules: {
				bank_name: [
					{
						required: true,
						message: '请输入姓名',
						trigger: 'blur',
					},
					{
						min: 3,
						max: 5,
						message: '姓名长度在3到5个字符',
						trigger: ['change', 'blur'],
					},
					{
						// 此为同步验证，可以直接返回true或者false，如果是异步验证，稍微不同，见下方说明
						validator: (rule, value, callback) => {
							return this.$u.test.chinese(value);
						},
						message: '姓名必须为中文',
						trigger: ['change', 'blur'],
					},
				]
			}
		};
	},
	onLoad: function () {
		that = this
		that.init();
	},
	methods: {
		init() {
			getApp().globalData.util.request({
				s: 'Merch.Mershop_Bank.getBankCard',
			}).then(res => {
				if (res.data.ret == 200) {
					that.form = res.data.data;
					that.form.bank_no2 = res.data.data.bank_no
				}
			})
		},
		submit() {
			if (that.form.bank_no !== that.form.bank_no2) {
				uni.showModal({
					title: '提示',
					content: '两次输入的卡号不一致'
				});
				return
			}
			getApp().globalData.util.request({
				s: 'Merch.Mershop_Bank.updateBankCard',
				bank_com: that.form.bank_com,
				bank_no: that.form.bank_no,
				bank_name: that.form.bank_name,
			}).then(res => {
				uni.showModal({
					title: '提示',
					content: res.data.data.res_msg,
					showCancel:false,
					success: function (res) {
						if (res.confirm) {
							console.log('用户点击确定');
						}
					}
				})
			})
		},
		selectColor(items) {
			if (items[0].value == 'no') {
				that.openAutoPay = false
			} else {
				that.openAutoPay = true
			}
		},
		bankUpImg() {			
			 getApp().globalData.util.upload().then(success=>{
				that.bankImgUp = success
				that.getBankOCR(that.bankImgUp)
			})
		},
		// 银行卡识别OCR
		getBankOCR: function (fileUrl) {
			uni.showLoading({
				title: '识别中'
			})
			uni.request({
				url: 'https://yld.angyakeji.com/www/src/tools/aliyun/ocr.php',
				data: {
					fileUrl: fileUrl,
					type: 'bankcard'
				},
				complete: (res) => {
					uni.hideLoading()
					if (res.data && res.data.Data) {
						let fres = res.data.Data
						that.$set(that.form, 'bank_com', fres.BankName)
						that.$set(that.form, 'bank_no', fres.CardNumber)
						that.$set(that.form, 'bank_no2', fres.CardNumber)
					}
				},
			})
		},
	}
}