<template>
  <div class="wrap">
    <a-button type="primary" @click="sendData(20)">呼叫</a-button>
    <a-button type="primary" v-for="(item, index) in nameList" :key="index" @click="sendData(index)"> {{ item.name }} </a-button>
    <a-button type="primary" @click="sendData(21)">震动传感器</a-button>
    <a-button type="primary" @click="sendData(25)">药物剂量</a-button>
    <a-button type="primary" @click="sendData(26)">团注剂量</a-button>
    <a-button type="primary" @click="sendData(27)">维持剂量</a-button>
  </div>
</template>

<script>
import { record } from 'config/api';
export default {
  name: 'BtnPage',
  data() {
    return {
      str: '模拟按钮界面',
      nameList: [
        {
          name: '分诊区',
          value: '18',
        },
        {
          name: '急救护士',
          value: '1',
        },
        {
          name: '急救医生',
          value: '1',
        },
        {
          name: '采血车',
          value: '3',
        },
        {
          name: 'CT室',
          value: '4',
        },
        {
          name: '介入室',
          value: '8',
        },
        {
          name: '平车停放点',
          value: '19',
        },
        {
          name: '卒中中心',
          value: '20',
        },
        {
          name: '急救大楼门',
          value: '21',
        },
        {
          name: '抢救室',
          value: '22',
        },
        {
          name: '走廊',
          value: '23',
        },
        {
          name: '心电图室',
          value: '24',
        },
        {
          name: '专用电梯口（一楼）',
          value: '25',
        },
        {
          name: '专用电梯口（四楼）',
          value: '26',
        },
        {
          name: 'CCU导管室门口',
          value: '27',
        },
      ],
    };
  },
  methods: {
    async sendData(index) {
      try {
        let params = {};
        console.log(index);
        if (index === 20) {
          params = {
            param: {
              authId: '1',
              type: '0',
              value: '80000',
              time: new Date().getTime(),
            },
          };
        } else if (index === 21) {
          params = {
            param: {
              authId: '1',
              type: '7',
              value: '10,20,30',
              time: new Date().getTime(),
            },
          };
        } else if (index === 25) {
          params = {
            param: {
              authId: '1',
              type: '8',
              value: '50.2',
              time: new Date().getTime(),
            },
          };
        } else if (index === 26) {
          params = {
            param: {
              authId: '1',
              type: '9',
              value: '6.4',
              time: new Date().getTime(),
            },
          };
        } else if (index === 27) {
          params = {
            param: {
              authId: '1',
              type: '10',
              value: '60.1',
              time: new Date().getTime(),
            },
          };
        } else if (index < 20) {
          params = {
            param: {
              authId: '1',
              type: '2',
              value: this.nameList[index].value,
              time: new Date().getTime(),
            },
          };
        }
        const res = await record(params);
        const { msg, data, code } = res.data;
        console.log('data:' + data);
      } catch (error) {
        console.log(error);
      }
    },
  },
};
</script>

<style lang="stylus" scoped>
.wrap {
  button {
    margin: 10px;
    flex: 0 0 8%;
  }
}
</style>
