<template>
  <div class="father_box">
    <el-row style="height: 500px">
      <el-col :span="9">
        <!--        <el-row
                  class="box_left"
                  v-for="(item, index) in basicInfosettingList"
                  :key="index"
                >
                  <div class="text_left" v-if="index==0">{{ item.infoName }}:</div>
                  <div class="text_left" v-if="index==1">{{ item.infoName }}:</div>
                  <div class="text_left" v-if="index==2">{{ item.infoName }}:</div>
                  <div class="text_left" v-if="index==3">{{ item.infoName }}:</div>
                  <div class="text_left" v-if="index==4">{{ item.infoName }}:</div>
                  <div class="text_left" v-if="index==5">{{ item.infoName }}:</div>
                  <div class="text_left" v-else>{{ item.infoName }}:</div>
                </el-row>-->
        <el-row v-if="autoCancelTime.id" class="box_left">
          <div class="text_left">交费等待时间</div>
        </el-row>
        <el-row v-if="isEmptyStomachItemExamTime.id" class="box_left none">
          <div class="text_left">空腹检查时间限定</div>
        </el-row>
        <el-row v-if="isEmptyStomachItemRatio.id" class="box_left none">
          <div class="text_left">空腹检查号源比例</div>
        </el-row>
        <el-row v-if="itemIntervalTime.id" class="box_left none">
          <div class="text_left">预约项目间隔时间</div>
        </el-row>
        <el-row v-if="advancedRegisterTime.id" class="box_left">
          <div class="text_left">提前登记时间</div>
        </el-row>
        <el-row v-if="isReserveMsg.id" class="box_left">
          <div class="text_left">预约成功短信通知</div>
        </el-row>
        <el-row v-if="isAutoCancelMsg.id" class="box_left">
          <div class="text_left">自动取消预约短信通知</div>
        </el-row>
        <el-row v-if="isArtificalCancelMsg.id" class="box_left">
          <div class="text_left">手动取消预约短信通知</div>
        </el-row>
        <el-row v-if="isForcedCancelMsg.id" class="box_left">
          <div class="text_left">强制取消预约短信通知</div>
        </el-row>
        <el-row v-if="isChangeMsg.id" class="box_left">
          <div class="text_left">改约短信通知</div>
        </el-row>
        <el-row v-if="reservationQueryDays.id" class="box_left">
          <div class="text_left">手动预约患者申请单查询天数</div>
        </el-row>
      </el-col>
      <el-col :span="14">
        <el-row v-if="autoCancelTime.id" class="box_right">
          <div class="text_right">
            <div class="input_box_right">
              <el-input
                v-model="autoCancelTime.infoValue"
                placeholder="该项为必填项"
                @blur="UInfoValue(autoCancelTime),Updateinfo($event)"
              />
            </div>
            <div>分钟</div>
          </div>
        </el-row>
        <el-row v-if="isEmptyStomachItemExamTime.id" class="box_right none">
          <div class="text_right">
            <div class="input_box_right">
              <el-time-picker
                v-model="isEmptyStomachItemExamTime.infoValue"
                format="HH:mm"
                placeholder="请选择时间"
                value-format="HH:mm"
                @blur="UInfoValue(isEmptyStomachItemExamTime),Updateinfo($event)"
              />
            </div>
            <div>之前</div>
          </div>
        </el-row>
        <el-row v-if="isEmptyStomachItemRatio.id" class="box_right none">
          <div class="text_right">
            <div class="input_box_right">
              <el-input
                v-model="isEmptyStomachItemRatio.infoValue"
                placeholder="该项为必填项"
                @blur="UInfoValue(isEmptyStomachItemRatio),Updateinfo($event)"
              />
            </div>
            <div>%</div>
          </div>
        </el-row>
        <el-row v-if="itemIntervalTime.id" class="box_right none">
          <div class="text_right">
            <div class="input_box_right">
              <el-input
                v-model="itemIntervalTime.infoValue"
                placeholder="该项为必填项"
                @blur="UInfoValue(itemIntervalTime),Updateinfo($event)"
              />
            </div>
            <div>分钟</div>
          </div>
        </el-row>
        <el-row v-if="advancedRegisterTime.id" class="box_right">
          <div class="text_right">
            <div class="input_box_right">
              <el-input
                v-model="advancedRegisterTime.infoValue"
                placeholder="该项为必填项"
                @blur="UInfoValue(advancedRegisterTime),Updateinfo($event)"
              />
            </div>
            <div>分钟</div>
          </div>
        </el-row>
        <el-row v-if="isReserveMsg.id" class="box_right">
          <div class="text_right">
            <div class="input_box_right" style="margin-left: 20px">
              <el-radio-group v-model="isReserveMsg.infoValue" @change="queueSmsChange(isReserveMsg)">
                <el-radio :key="1" :label="'1'" :value="'1'">通知</el-radio>
                <el-radio :key="0" :label="'0'" :value="'0'">不通知</el-radio>
              </el-radio-group>
            </div>
          </div>
        </el-row>
        <el-row v-if="isAutoCancelMsg.id" class="box_right">
          <div class="text_right">
            <div class="input_box_right" style="margin-left: 20px">
              <el-radio-group v-model="isAutoCancelMsg.infoValue" @change="queueSmsChange(isAutoCancelMsg)">
                <el-radio :key="1" :label="'1'" :value="'1'">通知</el-radio>
                <el-radio :key="0" :label="'0'" :value="'0'">不通知</el-radio>
              </el-radio-group>
            </div>
          </div>
        </el-row>
        <el-row v-if="isArtificalCancelMsg.id" class="box_right">
          <div class="text_right">
            <div class="input_box_right" style="margin-left: 20px">
              <el-radio-group v-model="isArtificalCancelMsg.infoValue" @change="queueSmsChange(isArtificalCancelMsg)">
                <el-radio :key="1" :label="'1'" :value="'1'">通知</el-radio>
                <el-radio :key="0" :label="'0'" :value="'0'">不通知</el-radio>
              </el-radio-group>
            </div>
          </div>
        </el-row>
        <el-row v-if="isForcedCancelMsg.id" class="box_right">
          <div class="text_right">
            <div class="input_box_right" style="margin-left: 20px">
              <el-radio-group v-model="isForcedCancelMsg.infoValue" @change="queueSmsChange(isForcedCancelMsg)">
                <el-radio :key="1" :label="'1'" :value="'1'">通知</el-radio>
                <el-radio :key="0" :label="'0'" :value="'0'">不通知</el-radio>
              </el-radio-group>
            </div>
          </div>
        </el-row>
        <el-row v-if="isChangeMsg.id" class="box_right">
          <div class="text_right">
            <div class="input_box_right" style="margin-left: 20px">
              <el-radio-group v-model="isChangeMsg.infoValue" @change="queueSmsChange(isChangeMsg)">
                <el-radio :key="1" :label="'1'" :value="'1'">通知</el-radio>
                <el-radio :key="0" :label="'0'" :value="'0'">不通知</el-radio>
              </el-radio-group>
            </div>
          </div>
        </el-row>
        <el-row v-if="reservationQueryDays.id" class="box_right">
          <div class="text_right">
            <div class="input_box_right">
              <el-input v-model="reservationQueryDays.infoValue" :min="1" :precision="0"
                        :type="number"
                        @blur="UInfoValue(reservationQueryDays)"
              />
            </div>
            <div>天</div>
          </div>
        </el-row>

      </el-col>
    </el-row>
  </div>
</template>

<script>
import {
  listBasicInfosetting,
  getBasicInfosetting,
  delBasicInfosetting,
  addBasicInfosetting,
  updateBasicInfosetting,
  exportBasicInfosetting
} from '@/api/basis/basicInfosetting'

export default {
  name: 'BasisInfo',
  data() {
    return {
      // 基础信息设置表格数据
      basicInfosettingList: [],
      val: '',
      e: '',
      number: '',
      queueSmsList: [], // 队列短信规则设置

      autoCancelTime: {}, // 交费等待时间
      isEmptyStomachItemExamTime: {}, //空腹检查时间限定
      isEmptyStomachItemRatio: {}, // 空腹检查号源比例
      itemIntervalTime: {}, // 预约项目间隔时间
      advancedRegisterTime: {}, // 提前登记时间
      isReserveMsg: {}, // 预约成功短信通知
      isAutoCancelMsg: {}, // 自动取消预约短信通知
      isArtificalCancelMsg: {}, // 手动取消预约短信通知
      isForcedCancelMsg: {},// 强制取消预约短信通知
      isChangeMsg: {}, // 改约短信通知,
      reservationQueryDays: {} // 手动预约患者申请单查询天数
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询基础信息设置列表 */
    getList() {
      // console.log("查询所有");
      listBasicInfosetting().then((response) => {
        this.basicInfosettingList = response.rows.filter(item => !['intervalTime', 'inVisitRatio'].includes(item.infoId))
        this.queueSmsList = response.rows.filter(item => item.infoType === '队列短信规则设置')
        response.rows.forEach(item => {
          switch (item.infoId) {
            case 'autoCancelTime':
              this.autoCancelTime = item
              break
            case 'isEmptyStomachItemExamTime':
              this.isEmptyStomachItemExamTime = item
              break
            case 'isEmptyStomachItemRatio':
              this.isEmptyStomachItemRatio = item
              break
            case 'itemIntervalTime':
              this.itemIntervalTime = item
              break
            case 'advancedRegisterTime':
              this.advancedRegisterTime = item
              break
            case 'isReserveMsg':
              this.isReserveMsg = item
              break
            case 'isAutoCancelMsg':
              this.isAutoCancelMsg = item
              break
            case 'isArtificalCancelMsg':
              this.isArtificalCancelMsg = item
              break
            case 'isForcedCancelMsg':
              this.isForcedCancelMsg = item
              break
            case 'isChangeMsg':
              this.isChangeMsg = item
              break
            case 'reservationQueryDays':
              this.reservationQueryDays = item
              break
            default:
              break
          }
        })
      })
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getBasicInfosetting(id).then((response) => {
        this.form = response.data
      })
    },
    Updateinfo(e) {
      let boolean = new RegExp('^[1-9][0-9]*$').test(e.target.value)
      if (!boolean) {
        this.$message.warning('请输入十位以内的阿拉伯数字！')
        e.target.value = ''
      }
    },
    UInfoValue(val) {
      /*获取id,infoValue的操作*/
      let ids = val.id
      let value = val.infoValue
      updateBasicInfosetting({ id: ids, infoValue: value }).then((response) => {
        this.$message.success('修改成功！')
      })
    },
    // 短信设置修改
    queueSmsChange(val) {
      updateBasicInfosetting({ id: val.id, infoValue: val.infoValue })
        .then(({ code, msg }) => {
          if (code !== 200) {
            this.$message.error(`修改失败:${msg}`)
          }
        })
    }
  }
}
</script>
<style>
.father_box {
  padding-top: 20px;
}

.box_left {
  border: 1px solid #ffffff;
  background-color: #F7F7F8;
  height: 52px;
  margin-right: 1px;
}

.text_left {
  line-height: 52px;
  text-align: right;
  margin-right: 5px;
  font-weight: normal;
}

.box_right {
  border: 1px solid #ffffff;
  height: 52px;
  background-color: #F7F7F8;
}

.text_right {
  display: flex;
  flex-direction: row;
  line-height: 52px;
  text-align: left;
  margin-left: 5px;
}

.input_box_right {
  width: 219px;
  margin-right: 5px;
  font-family: "Times New Roman", Times, serif;
  font-size: 14px;
  font-weight: normal;
}

.none {
  display: none;
}

</style>
