<template>
  <view class="operation">
    <view
      class="operation__header"
      :class="
        dourceData.local_model == '0'
          ? 'operation__header--info'
          : 'operation__header--warn'
      "
      >{{ dourceData.name }}
      <view
        :class="
          dourceData.local_model == '0'
            ? 'operation__header--infoing'
            : 'operation__header--warning'
        "
      >
        {{ dourceData.local_model == '0' ? '本地' : '远程' }}
      </view>
    </view>
    <view class="operation__model">
      模式
      <view class="operation__model--container">
        <view
          class="hand"
          @click="changeClick('hand')"
          :class="{ active: dourceData.local_model == '0' }"
          >手动</view
        >
        <view
          class="auto"
          @click="changeClick('auto')"
          :class="{ active: dourceData.local_model == '1' }"
          >自动</view
        >
      </view>
    </view>
    <view class="operation__body">
      <view class="operation__body-content">
        <view class="operation__body-content--title">展开</view>
        <view class="operation__body-content--desc">
          <u-switch
            :disabled="this.dourceData.local_model == '0'"
            v-model="runStatus"
            active-color="#14A478"
            inactive-color="#C3CAD8"
            size="36"
          ></u-switch>
        </view>
      </view>
      <view class="operation__body-content">
        <view class="operation__body-content--title">收拢</view>
        <view class="operation__body-content--desc">
          <u-switch
            :disabled="this.dourceData.local_model == '0'"
            v-model="closeStatus"
            active-color="#14A478"
            inactive-color="#C3CAD8"
            size="36"
          ></u-switch>
        </view>
      </view>
    </view>
  </view>
</template>
<script>
export default {
  name: 'OperationCard',
  props: {
    dourceData: {
      type: Object,
      default: () => ({}),
    },
  },
  computed: {
    runStatus: {
      get() {
        // 展开
        return this.dourceData.down_status == '1';
      },
      set(val) {
        this.$emit('run-status', this.dourceData);
      },
    },
    closeStatus: {
      get() {
        // 收拢
        return this.dourceData.up_status == '1';
      },
      set(val) {
        this.$emit('close-status', this.dourceData);
      },
    },
  },
  data() {
    return {
      info: 'https://webstaticimg.oss-cn-hangzhou.aliyuncs.com/bigdata_app/image/zhongshui/info.png',
      warning:
        'https://webstaticimg.oss-cn-hangzhou.aliyuncs.com/bigdata_app/image/zhongshui/warning.png',
    };
  },
  methods: {
    changeClick(type) {
      if (this.dourceData.local_model == '0') {
        return;
      }
      this.$emit('change-click', {
        type,
        dourceData: this.dourceData,
      });
    },
  },
};
</script>
<style scoped lang="scss">
.operation {
  justify-content: center;
  border-radius: 4px;
  background: #eff2fa;
  margin-bottom: 32rpx;
  position: relative;
  &__header {
    height: 64rpx;
    line-height: 64rpx;
    color: #333333;
    font-family: 'Source Han Sans CN VF';
    font-size: 28rpx;
    font-weight: 500;
    padding: 0 32rpx;
    position: relative;
    &--infoing {
      width: 150rpx;
      height: 56rpx;
      line-height: 50rpx;
      position: absolute;
      right: 0rpx;
      top: 0rpx;
      background: url('https://webstaticimg.oss-cn-hangzhou.aliyuncs.com/bigdata_app/image/zhongshui/info.png')
        no-repeat center center;
      background-size: 100%;
      color: #0085ff;
      text-align: center;
      font-family: 'Source Han Sans CN VF';
      font-size: 28rpx;
      font-weight: 400;
    }
    &--warning {
      width: 150rpx;
      height: 56rpx;
      line-height: 50rpx;
      position: absolute;
      right: 0rpx;
      top: 0rpx;
      background: url('https://webstaticimg.oss-cn-hangzhou.aliyuncs.com/bigdata_app/image/zhongshui/warning.png')
        no-repeat center center;
      background-size: 100%;
      text-align: center;
      font-family: 'Source Han Sans CN VF';
      font-size: 28rpx;
      font-weight: 400;
      color: #eeac19;
    }
  }
  &__header--info {
    background: linear-gradient(180deg, #eff4ff 20.24%, #eff2fa 100%);
  }
  &__header--warn {
    background: linear-gradient(180deg, #fffaef 20.24%, #eff2fa 100%);
  }
  &__model {
    display: flex;
    height: 80rpx;
    align-items: center;
    justify-content: space-between;
    border-radius: 16rpx;
    background: #e4ebf6;
    color: #333333;
    font-family: 'Source Han Sans CN VF';
    font-size: 28rpx;
    font-weight: 500;
    padding: 0 32rpx;
    color: #333333;
    font-family: 'Source Han Sans CN VF';
    font-size: 28rpx;
    margin: 0 24rpx;
    margin-top: 16rpx;
    &--container {
      display: flex;
      align-items: center;
      justify-content: space-between;
      width: 164rpx;
      height: 48rpx;
      background: #ffffff;
      border-radius: 8rpx;
      padding: 0 4rpx;
      .hand {
        width: 50%;
        border-radius: 8rpx;
        text-align: center;
        height: 40rpx;
        font-family: 'Source Han Sans CN VF';
        font-size: 24rpx;
        font-weight: 400;
        color: #687a74;
      }
      .auto {
        width: 50%;
        border-radius: 8rpx;
        text-align: center;
        height: 40rpx;
        font-family: 'Source Han Sans CN VF';
        font-size: 24rpx;
        font-weight: 400;
        color: #687a74;
      }
      .active {
        background: #14a478;
        color: #ffffff;
      }
    }
  }
  &__body {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-gap: 24rpx;
    padding: 30rpx;
    padding-top: 24rpx;
    &-content {
      height: 72rpx;
      background: #ffffff;
      border-radius: 16rpx;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 16rpx;
    }
  }
}
</style>
