<template>
  <div class="project">
    <div style="margin-bottom: 15px">
      <el-button type="primary" size="small" icon="el-icon-plus" @click="addProject">新增</el-button>
    </div>
    <div>
      <el-table
        :data="dataList"
        style="width: 100%"
      >
        <el-table-column
          :resizable="false"
          prop="itemName"
          label="检查项目"
          width="200"
        />
        <el-table-column
          :resizable="false"
          label="周一"
          align="center"
        >
          <el-table-column
            :resizable="false"
            label="上午"
            align="center"
            label-class-name="checkFont"
            width="50"
          >
            <template slot-scope="scope">
              <el-checkbox disabled :value="handleIsSelected(scope.row.openVoList,'mon','am')" />
            </template>
          </el-table-column>
          <el-table-column
            :resizable="false"
            label="下午"
            align="center"
            label-class-name="checkFont"
            width="50"
          >
            <template slot-scope="scope">
              <el-checkbox disabled :value="handleIsSelected(scope.row.openVoList,'mon','pm')" />
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column
          :resizable="false"
          label="周二"
          align="center"
        >
          <el-table-column
            :resizable="false"
            label="上午"
            align="center"
            label-class-name="checkFont"
            width="50"
          >
            <template slot-scope="scope">
              <el-checkbox disabled :value="handleIsSelected(scope.row.openVoList,'tues','am')" />
            </template>
          </el-table-column>
          <el-table-column
            :resizable="false"
            label="下午"
            align="center"
            label-class-name="checkFont"
            width="50"
          >
            <template slot-scope="scope">
              <el-checkbox disabled :value="handleIsSelected(scope.row.openVoList,'tues','pm')" />
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column
          :resizable="false"
          label="周三"
          align="center"
        >
          <el-table-column
            :resizable="false"
            label="上午"
            align="center"
            label-class-name="checkFont"
            width="50"
          >
            <template slot-scope="scope">
              <el-checkbox disabled :value="handleIsSelected(scope.row.openVoList,'wed','am')" />
            </template>
          </el-table-column>
          <el-table-column
            :resizable="false"
            label="下午"
            align="center"
            label-class-name="checkFont"
            width="50"
          >
            <template slot-scope="scope">
              <el-checkbox disabled :value="handleIsSelected(scope.row.openVoList,'wed','pm')" />
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column
          :resizable="false"
          label="周四"
          align="center"
        >
          <el-table-column
            :resizable="false"
            label="上午"
            align="center"
            label-class-name="checkFont"
            width="50"
          >
            <template slot-scope="scope">
              <el-checkbox disabled :value="handleIsSelected(scope.row.openVoList,'thur','am')" />
            </template>
          </el-table-column>
          <el-table-column
            :resizable="false"
            label="下午"
            align="center"
            label-class-name="checkFont"
            width="50"
          >
            <template slot-scope="scope">
              <el-checkbox disabled :value="handleIsSelected(scope.row.openVoList,'thur','pm')" />
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column
          :resizable="false"
          label="周五"
          align="center"
        >
          <el-table-column
            :resizable="false"
            label="上午"
            align="center"
            label-class-name="checkFont"
            width="50"
          >
            <template slot-scope="scope">
              <el-checkbox disabled :value="handleIsSelected(scope.row.openVoList,'fri','am')" />
            </template>
          </el-table-column>
          <el-table-column
            :resizable="false"
            label="下午"
            align="center"
            label-class-name="checkFont"
            width="50"
          >
            <template slot-scope="scope">
              <el-checkbox disabled :value="handleIsSelected(scope.row.openVoList,'fri','pm')" />
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column
          :resizable="false"
          label="周六"
          align="center"
        >
          <el-table-column
            :resizable="false"
            label="上午"
            align="center"
            label-class-name="checkFont"
            width="50"
          >
            <template slot-scope="scope">
              <el-checkbox disabled :value="handleIsSelected(scope.row.openVoList,'sat','am')" />
            </template>
          </el-table-column>
          <el-table-column
            :resizable="false"
            label="下午"
            align="center"
            label-class-name="checkFont"
            width="50"
          >
            <template slot-scope="scope">
              <el-checkbox disabled :value="handleIsSelected(scope.row.openVoList,'sat','pm')" />
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column
          :resizable="false"
          label="周日"
          align="center"
        >
          <el-table-column
            :resizable="false"
            label="上午"
            align="center"
            label-class-name="checkFont"
            width="50"
          >
            <template slot-scope="scope">
              <el-checkbox disabled :value="handleIsSelected(scope.row.openVoList,'sun','am')" />
            </template>
          </el-table-column>
          <el-table-column
            :resizable="false"
            label="下午"
            align="center"
            label-class-name="checkFont"
            width="50"
          >
            <template slot-scope="scope">
              <el-checkbox disabled :value="handleIsSelected(scope.row.openVoList,'sun','pm')" />
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column
          :resizable="false"
          label="上班时间"
          align="center"
        >
          <el-table-column
            prop="workTimeAm"
            :resizable="false"
            label="上午"
            align="center"
          />
          <template slot-scope="scope">
            <input class="checkTime" type="checkbox" :ischecked="scope.row.workTimeAm">
          </template>
        </el-table-column>
        <el-table-column
          :resizable="false"
          label="上班时间"
          align="center"
        >
          <el-table-column
            prop="workTimePm"
            :resizable="false"
            label="下午"
            align="center"
          />
          <template slot-scope="scope">
            <input class="checkTime" type="checkbox" :ischecked="scope.row.workTimePm">
          </template>
        </el-table-column>
        <el-table-column
          :resizable="false"
          prop="timeInterval"
          label="时间间隔"
          align="center"
        />
        <el-table-column
          :resizable="false"
          prop="maxNumber"
          label="人数上限"
          align="center"
        />
        <el-table-column
          :resizable="false"
          label="操作"
          align="center"
          width="150px"
        >
          <template slot-scope="scope">
            <span
              style="color: #1890ff; padding-right: 8px;cursor: pointer"
              class="call"
              @click="editOpera(scope.row)"
            >修改</span>
            <span
              style="color: #FF4D4F; padding-right: 8px;cursor: pointer"
              class="call"
              @click="cancelClick(scope.row)"
            >取消</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <add-project
      :project-detail="projectItem"
      :title="title"
      :is-show="addShow"
      @refreshList="refreshList"
      @closeDialog="closeDialog"
    />
  </div>
</template>

<script>
import AddProject from '@/page-subspecialty/views/modules/nurseManagement/reservation/subSetting/addProject.vue'
import mixinViewModule from '@/mixins/view-module'

export default {
  name: 'SubSetting',
  components: { AddProject },
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/appoint/itemList',
        getDataListIsPage: true,
        createdIsNeed: false
      },
      dataForm: {
        appointStatus: '',
        searchType: '0'
      },
      addShow: false,
      title: '',
      projectItem: null
    }
  },
  created() {
    this.getDataListInitial()
  },
  methods: {
    refreshList() {
      this.addShow = false
      this.getDataListInitial()
    },
    // 展示选中
    handleIsSelected(value, week, time) {
      if (!value) {
        return false
      }
      if (time === 'am') {
        switch (week) {
          case 'mon':
            return value[0].monTime
          case 'tues':
            return value[0].tuesTime
          case 'wed':
            return value[0].wedTime
          case 'thur':
            return value[0].thurTime
          case 'fri':
            return value[0].friTime
          case 'sat':
            return value[0].satTime
          case 'sun':
            return value[0].sunTime
        }
      } else {
        switch (week) {
          case 'mon':
            return value[1].monTime
          case 'tues':
            return value[1].tuesTime
          case 'wed':
            return value[1].wedTime
          case 'thur':
            return value[1].thurTime
          case 'fri':
            return value[1].friTime
          case 'sat':
            return value[1].satTime
          case 'sun':
            return value[1].sunTime
        }
      }
    },
    // 修改
    editOpera(scopeRow) {
      this.title = '修改项目'
      this.addShow = true
      this.projectItem = scopeRow
    },
    // 取消项目预约
    cancelClick(scopeRow) {
      this.$confirmFun('确定取消该项目吗？').then(() => {
        this.$http.get('/appoint/delAppiontItem', {
          params: {
            itemId: scopeRow.itemId
          }
        }).then(() => {
          this.getDataListInitial()
          this.$message.success('删除成功')
        })
      })
    },
    // 关闭弹窗
    closeDialog(val) {
      this.addShow = val
    },
    // 新增预约项目
    addProject() {
      this.title = '新增项目'
      this.addShow = true
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-checkbox__input.is-disabled.is-checked .el-checkbox__inner{
  background: #409EFF;
  border-color: #409EFF;
}
::v-deep .el-checkbox__input.is-disabled.is-checked .el-checkbox__inner::after{
  border-color: #fff
}
::v-deep .checkFont{
  font-size: 12px !important;
}
.project{
  padding: 10px 20px;
  background: #fff;
}
</style>
