<template>
    <!-- pages/entryWrite/page/Entry/prescription/handlePrescAudit/handlePrescAudit.wxml -->
    <view class="body" :style="'height:' + winHeight * 2 + 'rpx'">
        <van-cell title-class="titleClass" title="处理意见" />
        <view class="radioGroup">
            <van-radio-group :value="radio" @change="onChange">
                <van-cell-group>
                    <block v-for="(item, index) in items" :key="index">
                        <van-cell title-class="radioGroup-cell-title" :title="item.name" clickable :data-name="item.value" @click="onClick($event, { name: item.value })">
                            <van-radio slot="right-icon" :name="item.value" />
                        </van-cell>
                    </block>
                </van-cell-group>
            </van-radio-group>
            <!-- <radio-group bindchange="radioChange">
      <label class="weui-cell weui-check__label" wx:for="{{items}}" wx:key="{{item.value}}">
        <view class="weui-cell__hd">
        <radio value="{{item.value}}" checked="true"/>
        </view>
          <view class="weui-cell__bd">{{item.name}}</view>
      </label>
    </radio-group> -->
        </view>
        <view>
            <van-cell title-class="titleClass" title="备注" />
            <view class="field-input">
                <van-field
                    input-class="field-input-class"
                    :value="mark"
                    v-model="value"
                    placeholder=" 请输入（不超过100字）"
                    maxlength="100"
                    type="textarea"
                    rows="7"
                    @change="fieldChange"
                    show-word-limit
                    autosize
                />
            </view>
        </view>

        <!-- <van-button  class="btn" type="info" size="large" bindtap="handlePrescAudit">提交</van-button> -->
        <button class="handle-btn" :disabled="btnVisable" @tap="handlePrescAudit">提交</button>
    </view>
</template>

<script>
import { $http } from '../../../../../../config/https.js';
import Util from '../../../../../../utils/util.js';
export default {
    data() {
        return {
            btnVisable: true,
            radio: '',
            value: '',
            mark: '',

            items: [
                {
                    value: 'auditRec',
                    name: '接受拒绝'
                },
                {
                    value: 'apply',
                    name: '申诉'
                }
            ],

            prescNo: '',
            winWidth: '',
            winHeight: ''
        };
    },
    onLoad: function (options) {
        var that = this;
        let winWidth;
        let winHeight;
        uni.getSystemInfo({
            success: function (res) {
                winWidth = res.windowWidth;
                winHeight = res.windowHeight;
            }
        });
        this.setData({
            prescNo: options.prescNo,
            winWidth,
            winHeight
        });
        console.log('options:', this);
    },
    /** 页面卸载 */
    onUnload: function () {
        // var that=this;
        // if (getCurrentPages().length>2){
        //   let pages=getCurrentPages()
        //   let curPage=pages[pages.length-2];
        //   // let data=curPage.data;
        //   // curPage.setData('isBack',true);
        // }
    },
    methods: {
        /**
         * 组件的方法列表
         */
        handlePrescAudit: Util.debounce(function () {
            let { prescNo, radio, mark } = this;
            let httpsCode = radio == 'apply' ? '02030023' : '02030024';
            let data = {
                params: [
                    {
                        ordPrescNo: prescNo,
                        remark: mark
                    }
                ]
            };
            $http.post('urlDeault', this, {
                code: httpsCode,
                data: data,
                success: function (res) {
                    let icon = 'none';
                    if (res.errorCode == '0') {
                        icon = 'success';
                    }
                    uni.showToast({
                        title: res.errorMessage,
                        icon: icon
                    });
                    uni.navigateBack({
                        delta: 2
                    });
                }
            });
        }),

        fieldChange: function (event) {
            this.setData({
                mark: event.detail
            });
        },

        onChange: function (event) {
            this.setData({
                radio: event.detail,
                btnVisable: false
            });
        },

        onClick: function (event, _dataset) {
            /* ---处理dataset begin--- */
            this.handleDataset(event, _dataset);
            /* ---处理dataset end--- */
            const { name } = event.currentTarget.dataset;
            this.setData({
                radio: name,
                btnVisable: false
            });
        },

        radioChange: function (e) {
            const items = this.items;
            for (let i = 0, len = items.length; i < len; ++i) {
                items[i].checked = items[i].value === e.detail.value;
            }
            this.setData({
                items
            });
        }
    }
};
</script>
<style>
/* pages/entryWrite/page/Entry/prescription/handlePrescAudit/handlePrescAudit.wxss */
.body {
    background-color: #f5f4f4;
}
.titleClass {
    font-size: 32rpx;
    font-weight: 900;
}
.radioGroup-cell-title {
    font-size: 32rpx;
    margin-left: 30rpx !important;
}
.field-input {
    height: 300rpx;
    border: 4rpx solid #f5f4f4;
}
.field-input-class {
    font-size: 28rpx;
}
.handle-btn {
    background-color: #0079fe;
    color: #ffffff;
    border-radius: 30px;
    margin: 20px 10px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
}
</style>
