<template>
  <view class="setting-container" :style="{height: `${windowHeight}px`}">
    <view class="menu-list">
      <view class="list-cell list-cell-arrow" @click="handleToPwd">
        <view class="menu-item-box">
          <view class="iconfont icon-password menu-icon"></view>
          <view>修改密码</view>
        </view>
      </view>
      <view class="list-cell list-cell-arrow" @click="handleToUpgrade">
        <view class="menu-item-box">
          <view class="iconfont icon-refresh menu-icon"></view>
          <view>检查更新</view>
        </view>
      </view>
	  <view class="list-cell list-cell-arrow" @click="handleBaseUrl">
	    <view class="menu-item-box">
	      <view class="iconfont icon-refresh menu-icon"></view>
	      <view>配置服务器地址</view>
	    </view>
	  </view>
      <view class="list-cell list-cell-arrow" @click="handleCleanTmp">
        <view class="menu-item-box">
          <view class="iconfont icon-clean menu-icon"></view>
          <view>清理缓存</view>
        </view>
      </view>
    </view>
    <view class="cu-list menu">
      <view class="cu-item item-box">
        <view class="content text-center" @click="handleLogout">
          <text class="text-black">退出登录</text>
        </view>
      </view>
    </view>
	<uni-popup ref="popup" type="dialog">
		<uni-popup-dialog mode="input" message="成功消息" :duration="2000" :before-close="true" @close="close" @confirm="confirm">
			<uni-easyinput type="text" v-model="baseUrl" placeholder="请输入服务器地址" />
			<!-- <uni-easyinput type="text" v-model="wmsUrl" placeholder="请输入WMS服务器地址" /> -->
		</uni-popup-dialog>
	</uni-popup>
  </view>
</template>

<script>
  export default {
    data() {
      return {
		// baseUrl: getApp().globalData.config.baseUrl,
		baseUrl: uni.getStorageSync('base_url'),
		// wmsUrl: uni.getStorageSync('wms_url'),
        windowHeight: uni.getSystemInfoSync().windowHeight
      }
    },
    methods: {
      handleToPwd() {
        this.$tab.navigateTo('/pages/mine/pwd/index')
      },
      handleToUpgrade() {
        this.$modal.showToast('模块建设中~')
      },
      handleCleanTmp() {
        this.$modal.showToast('模块建设中~')
      },
      handleLogout() {
        this.$modal.confirm('确定注销并退出系统吗？').then(() => {
          this.$store.dispatch('LogOut').then(() => {
            this.$tab.reLaunch('/pages/index')
          })
        })
      },
	  handleBaseUrl(){
		this.$refs.popup.open()
	  },
	  close() {
		this.$refs.popup.close()
	  },
	  confirm() {
		// 输入框的值
		uni.setStorage({
			key: 'base_url',
			data: this.baseUrl
		})
		// uni.setStorage({
		// 	key: 'wms_url',
		// 	data: this.wmsUrl
		// })
		// TODO 做一些其他的事情，手动执行 close 才会关闭对话框
		// ...
		this.$refs.popup.close()
	  },
    }
  }
</script>

<style lang="scss" scoped>
  .page {
    background-color: #f8f8f8;
  }

  .item-box {
    background-color: #FFFFFF;
    margin: 30rpx;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    padding: 10rpx;
    border-radius: 8rpx;
    color: #303133;
    font-size: 32rpx;
  }
</style>
