<template>
  <!-- 提示音设置 -->
  <view class="tips-root">
    <view class="title-tip">通知</view>
  </view>

  <!-- 订单拣货提醒 -->
  <view class="picking-root">
    <picker
      :value="smsNotify"
      :range="smsNotifyData"
      @change="bindMultiPickerChange"
    >
      <view class="item">
        <view>未拣货提醒</view>
        <view class="text">
          {{ smsNotifyData[+smsNotify] || '请选择' }}
        </view>
      </view>
    </picker>
  </view>

  <!-- 默认使用打印机设备 -->
  <view class="picking-root">
    <picker
      :value="defaultPrinterValue"
      :range="defaultPrinter"
      @change="defaultPrinterChange"
    >
      <view class="item">
        <view>选择默认使用打印机</view>
        <view class="text">
          {{ defaultPrinter[+defaultPrinterValue] || '请选择' }}
        </view>
      </view>
    </picker>
  </view>

  <!-- 网络打印机设置 -->
  <view class="inter-printer">
    <view class="title-tip">网络打印机</view>
    <!-- <view class="item" @tap="bindPrinter(printerName)">
      <text>网络打印机</text>
      <text class="printer-name">{{ printerName || '未绑定' }}</text>
    </view> -->
    <picker
      :value="defultNetPrinterValue"
      :range="netPrinterData"
      @change="updateNetPrinter"
    >
      <view class="item">
        <view>网络打印机</view>
        <view class="printer-name">
          {{ netPrinterData[+defultNetPrinterValue] || '未绑定' }}
        </view>
      </view>
    </picker>
    <view class="item">
      <view>禁用网络打印机设置</view>
      <switch
        :checked="printerDisabled"
        @change="switchprinterDisabled"
        color="#4EB331"
        style="zoom: 0.85"
      />
    </view>
    <view class="item" @tap="DeletePrinterSeq">
      <text>清空打印队列</text>
      <jx-icon icon="gengduo" color="rgb(220, 220, 220)"></jx-icon>
    </view>
  </view>

  <!-- 蓝牙打印机设置 -->
  <view class="bluetooth-printer">
    <view class="title-tip">蓝牙打印机设置</view>
    <view class="item" @tap="bluetoothPrinterSetUp">
      <view>蓝牙打印机</view>
      <text class="printer-name">{{ newPrinterName }}</text>
    </view>
    <picker :value="retryActive" :range="printerFontSize" @change="changeRetry">
      <view class="item">
        <view>打印模板</view>
        <text class="text">{{
          printerFontSize[+retryActive] ? printerFontSize[+retryActive] : '请选择'
        }}</text>
      </view>
    </picker>
    <view class="item">
      <view>兼容模式</view>
      <switch
        :checked="getStorage('printerCompatible')"
        @change="switchCompatible"
        color="#4EB331"
        style="zoom: 0.85"
      />
    </view>
    <view class="item">
      <view>不打印商品价格</view>
      <switch
        :checked="getStorage('printerGoodsMoney')"
        @change="switchgoodsMoney"
        color="#4EB331"
        style="zoom: 0.85"
      />
    </view>
    <view class="item">
      <view>是否打印UPC码</view>
      <switch
        :checked="getStorage('isPrinterUpc')"
        @change="switchUpc"
        color="#4EB331"
        style="zoom: 0.85"
      />
    </view>
  </view>

  <!-- 消息设置 -->
  <view class="inter-printer" v-show="isExistMtStore || isExistEbStore">
    <view class="title-tip">消息设置</view>
    <view class="item" v-if="isExistMtStore">
      <view>美团IM单聊状态</view>
      <switch
        v-if="!store.getters['storeInfo/imMtStatus'][0].errMsg"
        :checked="imMtStoreStatus"
        @change="switchImMtStoreStatus($event, 1)"
        color="#4EB331"
        style="zoom: 0.85"
      />
      <text v-else class="printer-name">未知状态</text>
    </view>
    <view class="item"  v-if="isExistEbStore">
      <view>淘宝闪购IM单聊状态</view>
      <switch
        v-if="!store.getters['storeInfo/imEbStatus'][0].errMsg"
        :checked="imEbStoreStatus"
        @change="switchImMtStoreStatus($event, 3)"
        color="#4EB331"
        style="zoom: 0.85"
      />
      <text v-else class="printer-name">未知状态</text>
    </view>
  </view>

  <!-- 其它设置 -->
  <view class="inter-printer">
    <view class="title-tip">其它设置</view>
    <view class="item" @tap="jumpBusinessStatus">
      <view>营业状态设置</view>
      <jx-icon icon="gengduo" color="rgb(220, 220, 220)"></jx-icon>
    </view>
    <view class="item" @tap="setTime">
      <view>营业时间设置</view>
      <jx-icon icon="gengduo" color="rgb(220, 220, 220)"></jx-icon>
    </view>
    <view class="item"  v-if="isExistEbStore" @tap="jumpInvoiceSet">
      <view>发票设置（淘宝闪购）</view>
      <jx-icon icon="gengduo" color="rgb(220, 220, 220)"></jx-icon>
    </view>
  </view>

  <!-- 版权设置 -->
  <view class="copyRight-root">
    <view class="title-tip">关于</view>
    <view
      class="item"
      v-for="item in copyRight"
      :key="item.id"
      @tap="copyRightFn(item.url)"
    >
      <text>{{ item.title }}</text>
      <jx-icon icon="gengduo" color="rgb(220, 220, 220)"></jx-icon>
    </view>
  </view>

  <!-- 绑定网络打印机弹框 -->
  <uni-popup ref="popup" type="top">
    <view class="jx-popup-update">
      <view class="text">{{ netPrinterData[+defultNetPrinterValue] }}</view>
        <input
          class="ipt"
          type="digit"
          :placeholder="'请输入' + currentNetPrinter[1]"
          v-model="bindNetPrinter.printerSN"
          />
        <input
          v-if="currentNetPrinter[2]!=='不填'"
          style="margin-top:20rpx;"
          class="ipt"
          type="digit"
          :placeholder="'请输入' + currentNetPrinter[2]"
          v-model="bindNetPrinter.printerKey"
        />

        <view class="scan-code" v-if="netPrinterData[+defultNetPrinterValue] === '易联云打印机'" @tap="scanCode">扫码绑定</view>

        <view class="btn-root">
          <view class="btn-esc"  @tap="cancelPopup">取消</view>
          <view class="btn-ok" @tap="handleConfirm">确定</view>
        </view>
    </view>
  </uni-popup>

  <!-- 退出登录 -->
  <view class="outLogin-root">
    <text class="outLogin" @tap="outLogin">退出登录</text>
  </view>

  <!-- 公共组件 -->
  <jx-loading />
</template>

<script lang="ts" setup>
import { getStorage } from '@/utils/storage'
import { computed } from 'vue'
import setUp from './setUp'
const {
  copyRight,              // 京西版权信息
  smsNotifyData,          // 未拣货选项
  defaultPrinter,         // 选择默认打印设备
  defaultPrinterChange,   // 切换打印设备
  smsNotify,              // 选中提醒方式
  bindMultiPickerChange,  // 未拣货选择提醒方式
  defaultPrinterValue,    // 默认选中设备
  copyRightFn,            // 京西协议
  // printerName,            // 绑定的打印机品牌
  // bindPrinter,            // 绑定打印机
  bluetoothPrinterSetUp,  // 蓝牙打印机设置
  switchUpc,              // 是否打印Upc
  newPrinterName,         // 当前绑定打印机名字
  DeletePrinterSeq,       // 清空打印队列
  printerDisabled,        // 是否禁用网络打印机
  switchprinterDisabled,  // 网络打印机禁用开关
  imMtStoreStatus,        // IM单聊状态是否开启
  imEbStoreStatus,        // IM单聊状态是否开启 饿百
  switchImMtStoreStatus,  // 更改IM单聊门店状态
  isExistMtStore,         // 是否绑定美团门店
  isExistEbStore,         // 是否绑定饿百门店
  printerFontSize,        // 蓝牙打印机字体大小
  retryActive,            // 默认选中重试次数
  changeRetry,            // 选择重试次数
  switchCompatible,       // 打印机兼容模式
  outLogin,               // 退出登录
  switchgoodsMoney,       // 是否打印商品价格
  netPrinterData,         // 网络打印机
  defultNetPrinterValue,  // 默认选中的网络打印机
  updateNetPrinter,       // 选择网络打印机
  popup,                  // 弹框实例
  scanCode,               // 易联云 扫码绑定打印机
  cancelPopup,            // 取消绑定打印机弹框
  currentNetPrinter,      // 当前选中的网络打印机需填写的数据
  bindNetPrinter,         // 绑定的网络打印机的值 v-model
  handleConfirm,          // 绑定网络打印机
  setTime,                // 去修改营业时间
  jumpBusinessStatus,     // 跳转到营业状态页面
  jumpInvoiceSet,         // 跳转到发票设置页面
  store
} = setUp()
</script>

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

<style>
page {
  background-color: rgb(247, 247, 247);
}
</style>