<template>
    <view>
        <!-- pages/oneselfCenter/page/replyTemplate/replyTemplate.wxml -->
        <!-- <view class="replyTemplate-wrapper" wx:for='{{array}}' wx:key="key" wx:for-index="index" wx:for-item="item" > -->
        <view class="replyTemplate-wrapper">
            <view class="replyTemplate-content">
                <view v-if="array.length > 0">
                    <block v-for="(item, idx) in array" :key="idx">
                        <view class="picker-border">
                            <mp-cell
                                @tap.native="onClickSelect($event, { value: item.templet, id: item.ID, index: idx })"
                                :data-value="item.templet"
                                :data-id="item.ID"
                                :data-index="idx"
                            >
                                <text class="textalign">{{ item.templet }}</text>
                            </mp-cell>
                        </view>
                    </block>
                </view>
                <view v-else class="nodata">
                    <cover-image :src="imgDomain + '/images/icon/doctor/nothing.png'"></cover-image>
                    暂无回复模板
                </view>
            </view>
        </view>

        <!-- <view wx:if="{{array.length <= 0}}" class="nodata">
	<cover-image src="https://chis.e24health.com/images/icon/doctor/nothing.png"></cover-image>
	暂无回复模板
</view> -->
        <button class="handle-btn" @tap="addChange">添加回复模板</button>
    </view>
</template>

<script>
import Cache from '../../../../utils/cache';
import { httpconfig } from '../../../../config/httpconfig';
import { $http } from '../../../../config/https';
export default {
    components: {},
    data() {
        return {
            imgDomain: httpconfig.imgDomain,
            array: [],
            select: ''
        };
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.listData(); // 获取 下拉框数据
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.listData();
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {
        onClickSelect: function (e, _dataset) {
            /* ---处理dataset begin--- */
            this.handleDataset(e, _dataset);
            /* ---处理dataset end--- */
            let { value, id, index } = e.currentTarget.dataset;
            console.log('e', e);
            uni.navigateTo({
                //目的页面地址
                url: '../replyTemplateHand/replyTemplateHand?type=edit&value=' + value + '&id=' + id + '&idx=' + index
            });
        },

        // 列表数据
        listData: function (e) {
            let userData = Cache.get('userData');
            let { userID, locID, hospID } = userData;
            $http.post('urlDeault', this, {
                code: '03100028',
                data: {
                    params: [
                        {
                            userID: userID || '',
                            // 用户ID session 中获取
                            locID: locID || '',
                            // 科室ID session 中获取
                            hospID: hospID || ''
                        }
                    ]
                },
                success: function (res) {
                    // console.log('逻辑', res);
                    let errorCode = res.errorCode;
                    if (errorCode === '0') {
                        this.setData({
                            array: res.result.data //诊断数据列表
                        });
                    }
                }
            });
        },

        // 点击添加
        addChange: function (event) {
            let pages = getCurrentPages(); //获取当前页面js里面的pages里的所有信息。
            let prevPage = pages[pages.length - 1];
            prevPage.setData(
                {
                    // 将我们想要传递的参数在这里直接setData。上个页面就会执行这里的操作。
                    select: -1
                },
                () => {
                    uni.navigateTo({
                        //目的页面地址
                        url: '../replyTemplateHand/replyTemplateHand?type=add' // 添加按钮名称,
                    });
                }
            );
        }
    }
};
</script>
<style>
/* pages/oneselfCenter/page/replyTemplate/replyTemplate.wxss */
.replyTemplate-wrapper {
    width: 100%;
    min-height: 100vh;
    position: relative;
    background-color: #ffffff;
    padding-bottom: 120rpx;
    box-sizing: border-box;
}

.replyTemplate-content {
    width: 100%;
    overflow: auto;
    background-color: #ffffff;
}

.picker-border {
    border-bottom: 1px solid #e5e5e5;
    padding: 15rpx 30rpx;
}

.detail-input .weui-cell > .weui-cell__bd {
    text-align: right;
}

.handle-btn {
    background-color: #0079fe;
    color: #ffffff;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(env(safe-area-inset-bottom) + 100rpx);
    line-height: 100rpx;
}

.picker-times .weui-cell {
    color: #333333;
    font-weight: bold;
    height: 100rpx;
    background-color: #f5f4f4;
    line-height: 100rpx;
    margin: 0;
    padding: 0 16px;
}

button {
    border-radius: initial;
}

.nodata {
    text-align: center;
    color: #666;
}
/*文字两端对齐*/
.textalign {
    text-align: justify;
    text-justify: inter-ideograph;
    word-wrap: break-word;
    word-break: break-all;
}
</style>
