<template>
  <!-- 设备信息修改 -->
  <div class="deviceSetPage page flex-col">
    <s-header :name="$t('device.deviceInformation')" :noback="false"></s-header>
    <van-form @submit="updateDeviceFun">
      <div class="bd1 flex-col">
        <div class="bd3 flex-col">
          <div class="mod1 flex-col">
            <span class="word2">{{$t('device.essentialInformation')}}</span>
            <img
              class="pic1"
              referrerpolicy="no-referrer"
              src="https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng8947935ab81635fdedd8124b11e305eef66286421b69c84fef22233014a3fa9a"
            />
          </div>
          <div class="mod2 flex-col"></div>
        </div>
        <span class="word3">{{$t('device.equipmentCode')}}：{{deviceDetal ? deviceDetal.clientId : ''}}</span>
        <van-field
          v-model="deviceDetal.name"
          name="name"
          :label="`${$t('device.equipmentNameLabel')}:`"
          :placeholder="$t('device.equipmentNamePlaceholder')"
        />
        <van-field
          v-model="deviceDetal.selfName"
          name="name"
          :label="`${$t('device.equipmentRemarksLabel')}:`"
          :placeholder="$t('device.equipmentRemarksPlaceholder')"
        />
        <span class="txt3">{{$t('device.affiliatedMerchant')}}：{{deviceDetal ? deviceDetal.adminUserName : ''}}</span>
        <div class="bd7 flex-row justify-between">
          <span class="word6"
            >{{$t('device.affiliatedArea')}}：{{deviceDetal ? deviceDetal.fullName : ''}}</span
          >
          <div class="mod3 flex-col"></div>
        </div>
        <div class="bd8 flex-col"></div>
        <span class="txt4">{{$t('device.machineType')}}：{{deviceDetal ? deviceDetal.equimentType : ''}}</span>
        <span class="word7">{{$t('device.expirationTime')}}：{{deviceDetal ? deviceDetal.lastUseDate : ''}}</span>
        <div class="bd9 flex-row">
          <span class="txt5">{{$t('device.equipmentLabel')}}：</span>
          <div class="box2 flex-col"><span class="word8">标签一</span></div>
          <div class="ImageText1 flex-col">
            <div class="box3 flex-row justify-between">
              <div class="bd10 flex-col"></div>
              <div class="TextGroup1 flex-col">
                <span class="word9">{{$t('device.edit')}}</span>
              </div>
            </div>
          </div>
        </div>
        <van-field
          v-model="deviceDetal.operationalName"
          name="name"
          :label="`${$t('device.nameOfOperatorLabel')}:`"
          :placeholder="$t('device.nameOfOperatorPlaceholder')"
        />
        <van-field
          v-model="deviceDetal.operationalPhone"
          name="name"
          :label="`${$t('device.operatorTelephoneLabel')}:`"
          :placeholder="$t('device.operatorTelephonePlaceholder')"
        />
        <van-field
          v-model="deviceDetal.timeRuleId"
          name="name"
          :label="`${$t('device.advertisingRulesLabel')}:`"
          :placeholder="$t('device.advertisingRulesPlaceholder')"
        />
        <div class="van-cell van-field">
          <div class="van-cell__title van-field__label"><span>{{$t('device.paymentMethod')}}:</span></div>
          <div class="van-cell__value van-field__value radioBox">
            <van-radio-group v-model="deviceDetal.payType" direction="horizontal">
              <van-radio name="0" icon-size="18px">{{$t('device.onlinePayment')}}</van-radio>
              <van-radio name="1" icon-size="18px">{{$t('device.offlinePayment')}}</van-radio>
              <van-radio name="2" icon-size="18px">{{$t('device.onlineAndOfflinePayment')}}</van-radio>
            </van-radio-group>
          </div>
        </div>
        <div class="bd18 flex-col">
          <van-button round type="primary" class="register info7" native-type="submit">{{$t('device.submitAndPushDeviceUpdates')}}</van-button>
        </div>
      </div>
    </van-form>
    <nav-bar></nav-bar>
  </div>
</template>
<script>
import { onMounted, ref } from 'vue';
import sHeader from "@/components/SimpleHeader";
import navBar from '@/components/NavBar';
import { useRoute, useRouter } from "vue-router";
import { getDeviceDetal, updateDevice } from '@/service/device/index';
import { Toast } from 'vant';
import { useI18n } from 'vue-i18n';

export default {
  setup() {
    const { t } = useI18n();
    const route = useRoute();
    const router = useRouter();
    const deviceDetal = ref({
      name: '',
      selfName: '',
      operationalName: '',
      operationalPhone: '',
      timeRuleId: '',
      payType: ''
    });
    // 初始化页面获取列表
    onMounted(async () => { console.log('onMounted'); getDeviceDetalFun(); });

    // 获取设备列表数据
    const getDeviceDetalFun = async () => {
      const { data } = await getDeviceDetal({id: route.query.deviceId});
      if (data.code === '00000') {
        deviceDetal.value = data.data;
      } else { Toast.fail(data.message); }
    }
    // 修改设备详情
    const updateDeviceFun = async () => {
      let params =  Object.assign({}, deviceDetal.value);
      params = [params].map((item) => {
        return {
          id: item.id,
          name: item.name,
          selfName: item.selfName,
          areaId: item.areaId,
          channel: item.channel,
          contactName: item.contactName,
          contactPhone: item.contactPhone,
          flowers: item.flowers,
          operationalName: item.operationalName,
          operationalPhone: item.operationalPhone,
          timeRuleId: item.timeRuleId
        }
      })[0];
      const { data } = await updateDevice(params);
      if (data.code === '00000') {
        Toast.success(t('device.modificationSucceeded'));
        router.push({ path: '/device' });
      } else { Toast.fail(data.message); }
    }
    return { deviceDetal, updateDeviceFun };
  },
  components: { sHeader, navBar },
};
</script>
<style lang="less" scoped>
@import "../../common/style/common";
.deviceSetPage {
  .van-field__label {
    display: flex;
    align-items: center;
    margin-right: 0;
  }
  .van-field__control {
    line-height: 2.5;
    border: 0.01333rem solid #b9bad0;
    border-radius: 0.05333rem;
    text-indent: 0.16rem;
    font-size: 0.34667rem;
  }
  .van-cell:after { display: none; }
} 
.page {
  background-color: rgba(255, 255, 255, 1);
  position: relative;
  width: 375px;
  height: calc(100vh - 50px);
  overflow: hidden;
  overflow-y: auto;
  .bd1 {
    width: 375px;
    .bd2 {
      z-index: 3;
      height: 64px;
      background: url(https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPnged210ff8540d1e20d828b0758e650612a9ea018b41f720bede87fea0f933d8d8)
        100% no-repeat;
      width: 375px;
      position: relative;
      .block1 {
        width: 364px;
        height: 20px;
        margin: 1px 0 0 7px;
        .group1 {
          width: 34px;
          height: 6px;
          background: url(https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPnga64b2ae35561e96115c75cc6dfc235eedb108ecf95df957be1ef364417a9806e)
            100% no-repeat;
          margin-top: 7px;
        }
        .txt1 {
          width: 38px;
          height: 17px;
          overflow-wrap: break-word;
          color: rgba(81, 84, 106, 1);
          font-size: 12px;
          font-family: PingFangSC-Semibold;
          text-align: right;
          white-space: nowrap;
          line-height: 17px;
          margin-left: 21px;
          display: block;
        }
        .group2 {
          width: 30px;
          height: 17px;
          overflow-wrap: break-word;
          font-size: 0;
          font-family: PingFangSC-Semibold;
          text-align: right;
          white-space: nowrap;
          line-height: 17px;
          margin: 3px 0 0 73px;
          .info1 {
            width: 30px;
            height: 17px;
            overflow-wrap: break-word;
            color: rgba(81, 84, 106, 1);
            font-size: 12px;
            font-family: PingFangSC-Semibold;
            text-align: left;
            white-space: nowrap;
            line-height: 17px;
          }
          .word1 {
            width: 30px;
            height: 17px;
            overflow-wrap: break-word;
            color: rgba(81, 84, 106, 1);
            font-size: 12px;
            font-family: PingFangSC-Medium;
            text-align: left;
            white-space: nowrap;
            line-height: 17px;
          }
        }
        .group3 {
          width: 26px;
          height: 10px;
          background: url(https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng2e68dee6e62554db0f6ac40572f41b7be9cc24d35fc06b24c556fed2b7b18626)
            100% no-repeat;
          margin: 5px 0 0 142px;
        }
      }
      .block2 {
        width: 210px;
        height: 22px;
        margin: 9px 0 12px 10px;
        .icon1 {
          width: 10px;
          height: 18px;
          margin-top: 4px;
        }
        .info2 {
          width: 64px;
          height: 22px;
          overflow-wrap: break-word;
          color: rgba(64, 77, 116, 1);
          font-size: 16px;
          font-family: PingFangSC-Medium;
          text-align: center;
          white-space: nowrap;
          line-height: 22px;
          display: block;
        }
      }
      .img1 {
        z-index: 22;
        position: absolute;
        left: 0;
        top: 63px;
        width: 375px;
        height: 2px;
      }
    }
    .bd3 {
      background-color: rgba(255, 255, 255, 1);
      z-index: 24;
      height: 54px;
      margin-top: 1px;
      width: 375px;
      position: relative;
      .mod1 {
        width: 375px;
        height: 38px;
        margin-top: 16px;
        .word2 {
          width: 65px;
          height: 14px;
          overflow-wrap: break-word;
          color: rgba(64, 77, 116, 1);
          font-size: 15px;
          font-family: PingFangSC-Semibold;
          text-align: left;
          white-space: nowrap;
          line-height: 15px;
          display: block;
          margin: 1px 0 0 43px;
        }
        .pic1 {
          width: 375px;
          height: 2px;
          margin-top: 18px;
        }
      }
      .mod2 {
        z-index: 28;
        position: absolute;
        left: 17px;
        top: 18px;
        width: 19px;
        height: 20px;
        background: url('../../assets/device/baseMssage.png')
          100% no-repeat;
        background-size: 100%;
        background-position: top center;
      }
    }
    .word3 {
      width: 242px;
      height: 20px;
      overflow-wrap: break-word;
      color: rgba(64, 77, 116, 1);
      font-size: 14px;
      text-align: left;
      white-space: nowrap;
      line-height: 20px;
      display: block;
      margin: 14px 0 0 15px;
    }
    .bd4 {
      width: 345px;
      height: 38px;
      margin: 10px 0 0 15px;
      .info3 {
        width: 65px;
        height: 13px;
        overflow-wrap: break-word;
        color: rgba(64, 77, 116, 1);
        font-size: 13px;
        text-align: left;
        white-space: nowrap;
        line-height: 13px;
        margin-top: 13px;
        display: block;
      }
      .box1 {
        background-color: rgba(255, 255, 255, 1);
        border-radius: 2px;
        height: 38px;
        border: 0.5px solid rgba(185, 186, 208, 1);
        width: 254px;
        .word4 {
          width: 74px;
          height: 13px;
          overflow-wrap: break-word;
          color: rgba(168, 168, 197, 1);
          font-size: 13px;
          text-align: left;
          white-space: nowrap;
          line-height: 13px;
          display: block;
          margin: 13px 0 0 6px;
        }
      }
    }
    .bd5 {
      width: 345px;
      height: 38px;
      margin: 10px 0 0 15px;
      .word5 {
        width: 65px;
        height: 13px;
        overflow-wrap: break-word;
        color: rgba(64, 77, 116, 1);
        font-size: 13px;
        text-align: left;
        white-space: nowrap;
        line-height: 13px;
        margin-top: 13px;
        display: block;
      }
      .bd6 {
        background-color: rgba(255, 255, 255, 1);
        border-radius: 2px;
        height: 38px;
        border: 0.5px solid rgba(185, 186, 208, 1);
        width: 254px;
        .txt2 {
          width: 152px;
          height: 13px;
          overflow-wrap: break-word;
          color: rgba(168, 168, 197, 1);
          font-size: 13px;
          text-align: left;
          white-space: nowrap;
          line-height: 13px;
          display: block;
          margin: 13px 0 0 6px;
        }
      }
    }
    .txt3 {
      width: 225px;
      height: 18px;
      overflow-wrap: break-word;
      color: rgba(64, 77, 116, 1);
      font-size: 13px;
      text-align: left;
      white-space: nowrap;
      line-height: 18px;
      display: block;
      margin: 10px 0 0 15px;
    }
    .bd7 {
      width: 224px;
      height: 18px;
      margin: 10px 0 0 15px;
      .word6 {
        width: 208px;
        height: 18px;
        overflow-wrap: break-word;
        color: rgba(64, 77, 116, 1);
        font-size: 13px;
        text-align: left;
        white-space: nowrap;
        line-height: 18px;
        display: block;
      }
      .mod3 {
        width: 4px;
        height: 10px;
        background: url(https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng6ec57f29fd34229f6aceb7ad67da85c2372fbdbe5a590a5b5bda6e58eff803a5) -1px
          0px no-repeat;
        margin-top: 4px;
      }
    }
    .bd8 {
      width: 100%;
      height: 1px;
      background: url(https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng699372cef543e7a77f69ee4b13e1e8fd3969dbac13a75ca8bfd596af7891e8b5) -1px
        0px no-repeat;
      margin: 16px 0 0 15px;
      background-size: 100%;
    }
    .txt4 {
      width: 110px;
      height: 18px;
      overflow-wrap: break-word;
      color: rgba(64, 77, 116, 1);
      font-size: 13px;
      text-align: left;
      white-space: nowrap;
      line-height: 18px;
      display: block;
      margin: 19px 0 0 15px;
    }
    .word7 {
      width: 143px;
      height: 18px;
      overflow-wrap: break-word;
      color: rgba(64, 77, 116, 1);
      font-size: 13px;
      text-align: left;
      white-space: nowrap;
      line-height: 18px;
      display: block;
      margin: 10px 0 0 15px;
    }
    .bd9 {
      width: 204px;
      height: 27px;
      margin: 10px 0 0 15px;
      .txt5 {
        width: 65px;
        height: 18px;
        overflow-wrap: break-word;
        color: rgba(64, 77, 116, 1);
        font-size: 13px;
        text-align: left;
        white-space: nowrap;
        line-height: 18px;
        display: block;
      }
      .box2 {
        background-color: rgba(229, 154, 109, 1);
        border-radius: 2px;
        height: 24px;
        width: 65px;
        margin: 3px 0 0 6px;
        .word8 {
          width: 39px;
          height: 18px;
          overflow-wrap: break-word;
          color: rgba(255, 255, 255, 1);
          font-size: 13px;
          text-align: left;
          white-space: nowrap;
          line-height: 18px;
          display: block;
          margin: 3px 0 0 13px;
        }
      }
      .ImageText1 {
        height: 17px;
        width: 40px;
        margin: 6px 0 0 28px;
        .box3 {
          width: 40px;
          height: 17px;
          .bd10 {
            width: 11px;
            height: 15px;
            background: url(https://lanhu-dds-backend.oss-cn-beijing.aliyuncs.com/merge_image/imgs/954cd8f1feea46dc8d798320da0ce881_mergeImage.png)
              100% no-repeat;
            margin-top: 1px;
          }
          .TextGroup1 {
            height: 17px;
            width: 24px;
            .word9 {
              width: 24px;
              height: 17px;
              overflow-wrap: break-word;
              color: rgba(77, 106, 221, 1);
              font-size: 12px;
              text-align: left;
              white-space: nowrap;
              line-height: 17px;
              display: block;
            }
          }
        }
      }
    }
    .bd11 {
      width: 345px;
      height: 38px;
      margin: 32px 0 0 15px;
      .word10 {
        width: 78px;
        height: 13px;
        overflow-wrap: break-word;
        color: rgba(64, 77, 116, 1);
        font-size: 13px;
        text-align: left;
        white-space: nowrap;
        line-height: 13px;
        margin-top: 13px;
        display: block;
      }
      .bd12 {
        background-color: rgba(255, 255, 255, 1);
        border-radius: 2px;
        height: 38px;
        border: 0.5px solid rgba(185, 186, 208, 1);
        width: 253px;
        .word11 {
          width: 74px;
          height: 13px;
          overflow-wrap: break-word;
          color: rgba(168, 168, 197, 1);
          font-size: 13px;
          text-align: left;
          white-space: nowrap;
          line-height: 13px;
          display: block;
          margin: 13px 0 0 6px;
        }
      }
    }
    .bd13 {
      width: 345px;
      height: 38px;
      margin: 10px 0 0 15px;
      .info4 {
        width: 91px;
        height: 13px;
        overflow-wrap: break-word;
        color: rgba(64, 77, 116, 1);
        font-size: 13px;
        text-align: left;
        white-space: nowrap;
        line-height: 13px;
        margin-top: 13px;
        display: block;
      }
      .main1 {
        background-color: rgba(255, 255, 255, 1);
        border-radius: 2px;
        height: 38px;
        border: 0.5px solid rgba(185, 186, 208, 1);
        width: 254px;
        .txt6 {
          width: 86px;
          height: 13px;
          overflow-wrap: break-word;
          color: rgba(168, 168, 197, 1);
          font-size: 13px;
          text-align: left;
          white-space: nowrap;
          line-height: 13px;
          display: block;
          margin: 13px 0 0 6px;
        }
      }
    }
    .bd14 {
      width: 345px;
      height: 38px;
      margin: 10px 0 0 15px;
      .info5 {
        width: 65px;
        height: 13px;
        overflow-wrap: break-word;
        color: rgba(64, 77, 116, 1);
        font-size: 13px;
        text-align: left;
        white-space: nowrap;
        line-height: 13px;
        margin-top: 13px;
        display: block;
      }
      .bd15 {
        background-color: rgba(255, 255, 255, 1);
        border-radius: 2px;
        height: 38px;
        border: 0.5px solid rgba(185, 186, 208, 1);
        width: 254px;
        .word12 {
          width: 52px;
          height: 13px;
          overflow-wrap: break-word;
          color: rgba(168, 168, 197, 1);
          font-size: 13px;
          text-align: left;
          white-space: nowrap;
          line-height: 13px;
          display: block;
          margin: 13px 0 0 6px;
        }
      }
    }
    .bd16 {
      width: 348px;
      height: 18px;
      margin: 20px 0 0 15px;
      .txt7 {
        width: 65px;
        height: 18px;
        overflow-wrap: break-word;
        color: rgba(64, 77, 116, 1);
        font-size: 13px;
        text-align: left;
        white-space: nowrap;
        line-height: 18px;
        display: block;
      }
      .section1 {
        width: 12px;
        height: 12px;
        background: url(https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng5e3fac6de0c7dcaa42c48ad9495ff6feeaa9cdab9afc41f6b5ceac1719f3fd50)
          100% no-repeat;
        margin: 4px 0 0 6px;
      }
      .info6 {
        width: 52px;
        height: 18px;
        overflow-wrap: break-word;
        color: rgba(64, 77, 116, 1);
        font-size: 13px;
        text-align: left;
        white-space: nowrap;
        line-height: 18px;
        margin-left: 4px;
        display: block;
      }
      .ImageText2 {
        height: 18px;
        margin-left: 20px;
        width: 68px;
        .group4 {
          width: 68px;
          height: 18px;
          .outer1 {
            border-radius: 50%;
            width: 12px;
            height: 12px;
            border: 1px solid rgba(77, 106, 221, 1);
            margin-top: 4px;
          }
          .TextGroup2 {
            height: 18px;
            width: 52px;
            .word13 {
              width: 52px;
              height: 18px;
              overflow-wrap: break-word;
              color: rgba(64, 77, 116, 1);
              font-size: 13px;
              text-align: left;
              white-space: nowrap;
              line-height: 18px;
              display: block;
            }
          }
        }
      }
      .ImageText3 {
        height: 18px;
        margin-left: 20px;
        width: 101px;
        .bd17 {
          width: 101px;
          height: 18px;
          .outer2 {
            border-radius: 50%;
            width: 12px;
            height: 12px;
            border: 1px solid rgba(77, 106, 221, 1);
            margin-top: 4px;
          }
          .TextGroup3 {
            height: 18px;
            width: 85px;
            .word14 {
              width: 85px;
              height: 18px;
              overflow-wrap: break-word;
              color: rgba(64, 77, 116, 1);
              font-size: 13px;
              text-align: left;
              white-space: nowrap;
              line-height: 18px;
              display: block;
            }
          }
        }
      }
    }
    .bd18 {
      background-color: rgba(77, 106, 221, 1);
      border-radius: 17px;
      height: 34px;
      width: 220px;
      margin: 42px 0 42px 78px;
      .info7 {
        width: 150px;
        height: 13px;
        overflow-wrap: break-word;
        color: rgba(255, 255, 255, 1);
        font-size: 15px;
        font-family: PingFangSC-Medium;
        text-align: center;
        white-space: nowrap;
        line-height: 15px;
        display: block;
        margin: 11px 0 0 35px;
      }
    }
  }
}
</style>
