<template>
	<view class="body">
		<view class="header">
			<view class="container">
				<view class="icon">
					<u-image v-if="false" height="60" width="60"
						src="https://yuledui.oss-cn-qingdao.aliyuncs.com/merch_manage/img/credit_card_icon.png"></u-image>
				</view>
				<view class="title " @click='showInfo = !showInfo'>
					扫码付款 <text style="font-weight:bold;">[金豆抵扣]</text>设置<u-icon name="info-circle
" size="28"></u-icon>
				</view>
			</view>
		</view>
		<!-- <view class="payinfo"  v-if="showInfo">
      <view>开启金豆抵扣后,
	  <text style="font-weight:bold;">将同时开启随机立减功能;</text></view>
      <view style="color:red;">请注意:提现时将扣除订单金豆赠送比例金额</view> -->
		<!-- 0.0038平台手续费 -->
		<!-- <view style="color:red;">例如:金豆赠送比例为0.01(百分之一),那消费者付款100元后,您将得到100*(1-0.0038)-(0.01*100)=98.62元</view>
      <view style="color:#999999;">随机立减费用由余乐兑平台方承担,不会从商家提现中扣除</view>

    </view> -->
		<!--  <view class="content">
      <u--form :model="form" ref="uForm">
        <u-form-item label="是否开启金豆抵扣" label-width="280" prop="redirect">
          <u-switch size='50'  v-model="openCreditGive" @change="openCreditGiveChange" slot="right"></u-switch>
        </u-form-item>
      </u--form>
    </view> -->

		<view class="content" v-if="openCreditGive">
			<u--form :model="form" ref="uForm">
				<u-form-item label-width="300" :label-position="labelPosition" label="当前金豆抵扣比例(%):" prop="credit_give">
					<u-input :border="border" type="number" placeholder="请输入金豆抵扣比例"
						v-model="form.deduction_ratio"></u-input>
				</u-form-item>
				<u-form-item label-width="300" :label-position="labelPosition" label="输入金豆抵扣比例(%):" prop="credit_give">
					<u-input :border="border" type="number" placeholder="请输入金豆抵扣比例"
						v-model="form.credit_give"></u-input>
				</u-form-item>
				<u-form-item label-width="300" :label-position="labelPosition" label="确认金豆抵扣比例(%):" prop="credit_give2">
					<u-input :border="border" type="number" placeholder="请再次输入金豆抵扣比例"
						v-model="form.credit_give2"></u-input>
				</u-form-item>
			</u--form>
		</view>


		<view style="margin-top: 60rpx;">
			<u-button :disabled="false" class="button" @click="submit">保存设置</u-button>
		</view>

	</view>
</template>

<script>
	import {
		update_deduction
	} from '@/utils/api.js'
	let that = {}
	export default {
		data() {
			return {
				showInfo: false,
				form: {
				},
				bankImgUp: 'http://yuledui.oss-cn-qingdao.aliyuncs.com/merch_manage/img/bank_card_setting/take_photo.png', // 银行卡照片OCR
				openCreditGive: true,
				border: 'none',
				showPayType: false,
				labelPosition: 'left',
				modifyCreditMoneyEg: function() {
					let resNum = parseFloat(parseFloat(that.form.credit_give) * 100).toFixed(2)
					if (parseInt(resNum) == resNum) {
						resNum = parseInt(resNum)
					}
					return resNum
				},
			};
		},
		onLoad() {
			this.init()
		},
		methods: {
			init() {
				if (uni.getStorageSync('shopManage').deduction_ratio > 0) {
					this.openCreditGive = true
				} else {
					this.openCreditGive = false
				}
				this.form.deduction_ratio = uni.getStorageSync('shopManage').deduction_ratio
			},
			submit() {
				var that=this
				// if (!that.openCreditGive) {
				// 	that.form.credit_give = 0
				// }
				// if (that.form.credit_give >= 1) {
				// 	uni.showModal({
				// 		title: '提示',
				// 		content: '抵现比例必须小于1'
				// 	})
				// 	return
				// }
				if (that.form.credit_give !== that.form.credit_give2) {
					uni.showModal({
						title: '提示',
						content: '两次输入的抵现比例不一致'
					})
					return
				}
				update_deduction({
					shop_admin_id: uni.getStorageSync('shopManage').shop_admin_id,
					deduction_ratio: this.form.credit_give
				}).then(res => {
					if(res.code==200){
						this.$u.toast('修改成功')
					}
				})
			},
			openCreditGiveChange(selectValue) {
				console.log(selectValue);
			},
			creditGiveInputChange(inputValue) {
				console.log(inputValue)
			},
		}
	}
</script>


<style lang="scss" scoped>
	@import "./creditadd.scss";
</style>