<!-- <template>
    <view class="home-wrap">
        <view class="amountWrap flex">
            <view class="amountLeft flex">
                <view class="amountName">库存件数</view>
                <view class="remain">190009</view>
            </view>
            <view class="amountRight flex">
                <view class="amountName">出库件数</view>
                <view class="outbound">1009</view>
            </view>
        </view>
        <view class="patientTab">
            <view :class="'notActive ft32' + (wait_type == '0' ? ' active PfScMedium' : '')"
                @click="changeWaitType('0')">库存列表</view>
            <view :class="'notActive ft32' + (wait_type == '1' ? ' active PfScMedium' : '')"
                @click="changeWaitType('1')">
                出库列表
            </view>
        </view>
        <view class="patient-type-tab1">

            <view class="bed-wait-container">
                <view class="bed-wait-list">
                    <view class="bed-wait-item" v-for="(item, index) in bedWaitList" :key="index"
                        @click="lookDetail(item)">

                        <view class="bed-wait-info">

                            <view class="bed-wait-name PfScMedium">{{ item.name }}</view>
                            <view class="bed-sex">{{ item.year }}</view>

                            <view :class="'bed-desc'">
                                {{ item.phone }}
                            </view>
                        </view>

                        <view class="bed-wait-time flex-between">
                            <view class="bed-visit-time">{{ item.time }}</view>
                            <view class="bed-checkin-time">{{ item.address }}</view>
                        </view>

                    </view>

                </view>
            </view>

            <view class="page-padding" v-show="bedWaitList && bedWaitList.length && bedWaitList.length > 0"></view>

        </view>
        <view class="qrcode_wrap">
            <img :src="cssUrl + 'qrcode_get.png'" alt="" @click="scanQrcode">
        </view>
    </view>

</template>
<script>
// import PopUpCommon from '@/components/common/popUpCommon.vue';
// import PageBottomBtn from '@/components/new/pageBottomBtn.vue'
import ListBox from '@/components/listBox.vue';
import CoinsDetail from '../coinsDetail';

export default {
    options: { styleIsolation: "shared" },
    components: {
        // PopUpCommon,
        // PageBottomBtn,
        ListBox,
        CoinsDetail
    },
    data() {
        return {
            cssUrl: this.cssUrl,
            wait_type: '0',
            bedWaitList: [
                {
                    name: '机制光绪通宝',
                    year: '1889年',
                    phone: '1310684212',
                    id: 1,
                    time: '2025.12.21 13:23',
                    address: '北京公博二部'
                },
                {
                    name: '机制光绪通宝',
                    year: '1889年',
                    phone: '1310684212',
                    id: 2,
                    time: '2025.12.21 13:23',
                    address: '北京公博二部'
                },
                {
                    name: '机制光绪通宝',
                    year: '1889年',
                    phone: '1310684212',
                    id: 3,
                    time: '2025.12.21 13:23',
                    address: '北京公博二部'
                },
                {
                    name: '机制光绪通宝',
                    year: '1889年',
                    phone: '1310684212',
                    id: 1,
                    time: '2025.12.21 13:23',
                    address: '北京公博二部'
                },
                {
                    name: '机制光绪通宝',
                    year: '1889年',
                    phone: '1310684212',
                    id: 2,
                    time: '2025.12.21 13:23',
                    address: '北京公博二部'
                },
                {
                    name: '机制光绪通宝',
                    year: '1889年',
                    phone: '1310684212',
                    id: 3,
                    time: '2025.12.21 13:23',
                    address: '北京公博二部'
                },
                {
                    name: '机制光绪通宝',
                    year: '1889年',
                    phone: '1310684212',
                    id: 1,
                    time: '2025.12.21 13:23',
                    address: '北京公博二部'
                },
                {
                    name: '机制光绪通宝',
                    year: '1889年',
                    phone: '1310684212',
                    id: 2,
                    time: '2025.12.21 13:23',
                    address: '北京公博二部'
                },
                {
                    name: '机制光绪通宝',
                    year: '1889年',
                    phone: '1310684212',
                    id: 3,
                    time: '2025.12.21 13:23',
                    address: '北京公博二部'
                },
                {
                    name: '机制光绪通宝',
                    year: '1889年',
                    phone: '1310684212',
                    id: 1,
                    time: '2025.12.21 13:23',
                    address: '北京公博二部'
                },
                {
                    name: '机制光绪通宝',
                    year: '1889年',
                    phone: '1310684212',
                    id: 2,
                    time: '2025.12.21 13:23',
                    address: '北京公博二部'
                },
                {
                    name: '机制光绪通宝',
                    year: '1889年',
                    phone: '1310684212',
                    id: 3,
                    time: '2025.12.21 13:23',
                    address: '北京公博二部'
                },
            ],
            titleType:{
                '1':'扫码入库',
                '2':'扫码出库',
                '3':'出库信息',
            },
            btnText:{
                '1':'入库',
                '2':'出库',
            },
            coinsType:'1',//钱币信息
            detailItem:{
                name:'北京公博二部',
                num:'1310684212',
                count:'AU 58',
                size:'24.0*1.1mm，3.5g',
                operate:'泅渡'
            },
            code:'',
            state:''
        }
    },
    onLoad(option) {
        // var token = uni.getStorageSync("u_token");
        // if(option.code && option.state) {
        //     this.code = option.code
        //     this.state = option.state
        // }
        // 初始化情求
        this.getCoinsList()
    },
    methods: {
         getCoinsList(){
            // 获取列表信息
            // const res = await this.$request({
            //     url: '/getlist',
            //     method: 'POST',
            //     data: {
            //         type:this.wait_type
            //     }
            // });
            // if (res.code !== 0) {
            //     this.$pop.modelShow(res.msg)
            //     return;
            // }
            this.$http.req('api/getlist',{status:'1',page:1,pagesize:10}, 'POST').then(data=>{
                console.log(data,'====');
            });
            // this.bedWaitList = res.data;
        },
        lookDetail(item){
            let url = `/pages/coinsDetail/index?id=${item.id}`
			this.$nav.navToPath(url)
        },
        changeWaitType(type){
            this.wait_type = type;
            // 调用列表查询接口
            this.getCoinsList()
        },
        async scanQrcode() {
				// #ifdef MP-WEIXIN
				uni.scanCode({
					success: (res) => {
                        console.log(res,'====---');
                        let url = res.path;
						// if(res.path) {
						
						// }
                        // const res = await this.$request({
                        //     url: '/get_scan_code_detail',
                        //     method: 'POST',
                        //     data: {
                        //         url
                        //     }
                        // });
                        // if(res.code == 0){
                        //     // this.scanCodeDetail = res.data
                        //     // this.$refs.coinsPopup.openPop()
                        // }
					},
					complete(res) {
						if (res.errMsg === 'scanCode:ok') {
							console.log('扫码成功:', res.result);
						} else if (res.errMsg === 'scanCode:fail cancel') {
							console.log('用户取消扫码');
						} else {
							uni.showToast({
								title: '扫码失败'+JSON.stringify(res.errMsg),
								icon: 'none'
							})
						}
					}
				})
				// #endif
			},
        async onConfirm(){
            // 确认入库
            let url = '/'//入库
            // 根据当前钱币状态，切换url 或者 参数信息

            // 确认出库
            const res = await this.$request({
                url: '/get_scan_code_detail',
                method: 'POST',
                data: {
                    url
                }
            });

            if(res.code == 0){
                // 根据当前列表状态-切换状态
                if(this.scanCodeDetail.type == '为入库'){
                    if (this.wait_type != '0') this.wait_type = '0'
                }else{
                    if (this.wait_type != '1') this.wait_type = '1'
                }
                // 更新数据
                this.getCoinsList()
                // this.$refs.coinsPopup.closePop()
            }

        },
        cancelClick(){
            this.$refs.coinsPopup.closePop()
        },
    }
}
</script>
<style lang="scss" scoped>
.home-wrap {
    display: flex;
    flex-direction: column;
    height: 100%;
    .amountWrap {
        gap: 16rpx;
        padding: 36rpx 24rpx;
        box-sizing: border-box;
        background: #fff;

        .amountName {
            display: flex;
            align-items: center;
            gap: 12rpx;
            color: #666;
            font-size: 26rpx;
        }

        img {
            width: 20rpx;
            height: 32rpx;
        }

        .amountLeft,
        .amountRight {
            flex: 1;
            padding: 18px;
            align-items: center;
            justify-content: center;
            flex-direction: column;
            border-radius: 12px;
            background: #F8FFF7;

            .add,
            .use {
                font-size: 40rpx;
            }
        }

        .amountLeft {
            background: #F0F7FD;
        }

    }

    .patientTab {
        width: 100%;
        display: flex;
        justify-content: center;
        height: 120rpx;
        align-items: center;
        margin-top: 20rpx;
        padding: 0 62rpx;
        box-sizing: border-box;
        justify-content: space-between;
        background: white;
        border-radius: 12rpx 12rpx 0rpx 0rpx;
        box-shadow: 0px 1rpx 0rpx 0rpx rgba(0, 0, 0, 0.15);

        .notActive {
            width: 269rpx;
            height: 100%;
            text-align: center;
            font-weight: 400;
            color: #666666;
            font-size: 32rpx;
            line-height: 120rpx;
            display: flex;
            justify-content: center;
            align-items: center;

            .wait-bed-num {
                padding: 0px 14rpx;
                box-sizing: border-box;
                width: auto;
                height: 38rpx;
                min-width: 60rpx;
                display: flex;
                justify-content: center;
                align-items: center;
                border-radius: 60rpx;
                background: #FFEBEB;
                font-size: 28rpx;
                color: #FF1818;
                margin-left: 10rpx;
            }
        }

        .active {
            font-weight: 500;
            color: #4DC56D;
            box-sizing: border-box;
            border-bottom: 4rpx solid #4DC56D;
        }
    }

    .remain,.outbound {
        font-weight: 500;
        color: #00A2E2;
        line-height: 56rpx;
        font-size: 40rpx;
    }

    .outbound {
        color: #FF7D17;
    }

    .patient-type-tab1 {
        height: auto;
        width: 100%;
        background: white;
        overflow-y: auto;
        flex: 1;
        .bed-wait-container {
            padding: 0rpx 42rpx;
            background: white;
            box-sizing: border-box;
        }

        .bed-wait-item {
            padding: 36rpx 0rpx;
            border-bottom: 2rpx solid #F1F1F1;
            position: relative;
        }

        .bed-wait-info {
            display: flex;

            .bed-wait-name {
                font-size: 32rpx;
                color: #000000;
                margin-right: 24rpx;
            }

            .bed-visit-type-desc {
                padding: 0 18rpx;
                height: 40rpx;
                box-sizing: border-box;
                display: flex;
                align-items: center;
                justify-content: center;
                font-size: 26rpx;
                line-height: normal;
                border-radius: 6rpx;
                margin-left: 24rpx;
                background: #F7FCFF;
                color: #007FD0;
                border: 1rpx solid #5FA1CB;

                &.ml-auto {
                    margin-left: auto;
                }
            }

            .bed-desc {
                color: #999999;
                font-size: 28rpx;
                margin-left: auto;

                &.active {
                    color: #4DC56D;
                }
            }

            .bed-sex,
            .bed-age {
                font-size: 28rpx;
                font-weight: normal;
                line-height: 44rpx;
                color: #242833;
            }

            .bed-age {
                margin-left: 24rpx;
            }
        }

        .bed-wait-time {
            display: flex;
            column-gap: 24rpx;
            margin-top: 16rpx;

            view {
                font-size: 24rpx;
                color: #999999;
            }
        }
    }
    .list-wrap{
        padding: 20rpx 18rpx;
    }
    .qrcode_wrap{
        position: relative;
        background: #fff;
        height: 166rpx;
        box-shadow: 0px -2rpx 116rpx 0px rgba(181, 181, 181, 0.26);
        img{
            width: 122rpx;
            height: 142rpx;
            position: absolute;
            top: -42rpx;
            left: 50%;
            transform: translateX(-50%);
        }
    }
    .content{
        margin-bottom: 145rpx;
    }

    .pop-title{
		height: 40rpx;
		text-align: center;
		margin:42rpx 0 22rpx 0;
        font-size: 36rpx;
        font-weight: 500;
        line-height: 50rpx;
        text-align: center;
        letter-spacing: 2rpx;
        color: #000000;
		// background: #F6F6F8;
	}

    .cancle-button {
        font-weight: 500;
        font-size: 32rpx;
        color: #ffffff;
        line-height: 92rpx;
        text-align: center;
        width: 100%;
        height: 92rpx;
        background: #F1F2F3;
        border-radius: 12rpx;
    }


}
</style> -->

<template>
    <view>
      <button @click="handleLogin">登录</button>
  
      <button v-if="hasLogin" @click="handleAuth">授权获取用户信息</button>
    </view>
  </template>
  
  <script>
  export default {
    data() {
      return {
        hasLogin: false,
        code: '',
        openid: ''
      };
    },
    onLoad(){
        this.getCoinsList()
    },
    methods: {
        getCoinsList(){
            // 获取列表信息
            // const res = await this.$request({
            //     url: '/getlist',
            //     method: 'POST',
            //     data: {
            //         type:this.wait_type
            //     }
            // });
            // if (res.code !== 0) {
            //     this.$pop.modelShow(res.msg)
            //     return;
            // }
            this.$http.req('api/getlist',{status:'1',page:1,pagesize:10}, 'POST').then(data=>{
                console.log(data,'====');
            });
            // this.bedWaitList = res.data;
        },
      // 1. 先执行登录（获取 code → openid）
      async handleLogin() {
        try {
          const res = await wx.login({ provider: 'weixin' });
          console.log(res,'====----');
          this.code = res.code;
  
          // 发送 code 到后端换取 openid
          const { data } = await uni.request({
            url: 'http://coin.checkcopy.com/api/login',
            method: 'POST',
            data: { code: this.code }
          });
  
          if (data.success) {
            this.openid = data.openid;
            this.hasLogin = true; // 登录成功，显示授权按钮
            uni.showToast({ title: '登录成功', icon: 'none' });
          }
        } catch (err) {
          console.error('登录失败:', err);
        }
      },
  
    }
  };
  </script>
