<template>
  <at-table
    @load="loadData"
    :data="data"
    :page-result="pageResult"
    ref="AtTable"
    :dialogTitle="dialogTitle"
    :dialogVisible="dialogVisible"
    @select-all="handleSelect"
    @select="handleSelect"
    @handleDialogCancel="handleDialogCancel"
    @handleDialogClose="handleDialogClose"
    @handleDialogSubmit="handleDialogSubmit"
    @row-dblclick="handleRowDBClick"
  >
    <template v-slot:searchInput>
      <el-form
        ref="searchForm"
        :model="searchForm"
        label-width="80px"
        class="search-top"
        @submit.native.prevent
      >
        <el-input
          v-model="searchForm.theme"
          placeholder="请输入会议主题"
          @keyup.enter.native="handleSearch"
          clearable
          @input="handleSearch"
        />
        <dict-select
          v-model="searchForm.meetingType"
          :dict-code="'hylx'"
          placeholder="请选择会议类型"
          clearable
          style="width: 100%"
          @keyup.enter.native="handleSearch"
          @input="handleSearch"
        ></dict-select>
        <el-date-picker
          v-model="searchForm.startTime"
          type="date"
          placeholder="选择会议时间"
          format="yyyy-MM-dd"
          clearable
          style="width: 100%"
          value-format="yyyy-MM-dd"
          @keyup.enter.native="handleSearch"
          @change="handleSearch"
        >
        </el-date-picker>
        <el-input
          v-model="searchForm.host"
          placeholder="请输入主持人"
          @keyup.enter.native="handleSearch"
          clearable
          @input="handleSearch"
        />
        <el-button
          size="small"
          @click="handleSearch"
          type="primary"
          class="el-icon-search search-btn"
        >
          查询
        </el-button>
        <el-button
          size="small"
          @click="handleReset"
          type="primary"
          plain
          class="el-icon-refresh"
        >
          重置
        </el-button>
      </el-form>
    </template>
    <template v-slot:operationBtn>
      <ht-delete-button :url="deleteUrl" :htTable="$refs.AtTable">
        删除会议
      </ht-delete-button>
    </template>
    <template>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" width="55" align="center" />
      <el-table-column
        prop="theme"
        label="会议主题"
        align="center"
        :show-overflow-tooltip="true"
      >
        <template v-slot="{row}">
          <el-link type="primary" @click="handleRowDBClick(row)">
            {{ row.theme }}
          </el-link>
        </template>
      </el-table-column>
      <el-table-column
        prop="meetingType"
        label="会议类型"
        align="center"
        :show-overflow-tooltip="true"
      >
        <template v-slot="{row}">
          {{ getDictName('hylx', row.meetingType) || '-' }}
        </template>
      </el-table-column>
      <el-table-column
        prop="startTime"
        label="开始时间"
        align="center"
        :show-overflow-tooltip="true"
      >
      <template v-slot="{row}">
        {{ row.startTime || '-' }}
      </template>
      </el-table-column>
      <el-table-column
        prop="endTime"
        label="结束时间"
        align="center"
        :show-overflow-tooltip="true"
      >
       <template v-slot="{row}">
        {{ row.endTime || '-' }}
      </template>
      </el-table-column>
      <el-table-column
        prop="places"
        label="地点"
        align="center"
        :show-overflow-tooltip="true"
      >
        <template v-slot="{row}">
          {{
            row.places.length > 0
              ? row.places.map((item) => item.name).join(',')
              : '-'
          }}
        </template>
      </el-table-column>
      <el-table-column
        prop="host"
        label="主持人"
        align="center"
        :show-overflow-tooltip="true"
      >
        <template v-slot="{row}">
          {{ row.host ? row.host : '-' }}
        </template>
      </el-table-column>
      <el-table-column
        prop="meetingStatus"
        label="会议状态"
        align="center"
        :show-overflow-tooltip="true"
      >
        <template v-slot="{row}">
          {{ getDictName('hyzt', row.meetingStatus) }}
        </template>
      </el-table-column>
    </template>
    <template v-slot:dialogContent>
      <el-form
        ref="ruleForm"
        data-vv-scope="form"
        :model="form"
        label-width="100px"
        v-if="dialogVisible"
        disabled
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="会议主题" prop="theme">
              <el-input
                v-model="form.theme"
                placeholder="请输入会议主题"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="会议类型" prop="meetingType">
              <dict-select
                v-model="form.meetingType"
                :dict-code="'hylx'"
                placeholder="请选择会议类型"
                clearable
                style="width: 100%"
              ></dict-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="开始时间" prop="startTime">
              <el-input v-model="form.startTime"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="结束时间" prop="endTime">
              <el-input v-model="form.endTime"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="参会人">
            <el-tag
              v-for="(tag, index) in form.users"
              :key="index"
              :disable-transitions="false"
            >
              {{ tag.userName }}
            </el-tag>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="会议室">
            <el-tag
              v-for="(tag, index) in form.places"
              :key="index"
              :disable-transitions="false"
            >
              {{ tag.placeName }}
            </el-tag>
          </el-form-item>
        </el-row>
      </el-form>

      <div class="collapse-box">
        <el-collapse v-model="activeNames">
          <el-collapse-item title="更多设置" name="1">
            <el-form :model="form" label-width="160px" disabled>
              <el-row>
                <el-form-item label="提醒时间">
                  <dict-select
                    v-model="form.remindTime"
                    :dict-code="'tx'"
                    style="width: 100%"
                  ></dict-select>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="主持人">
                  <el-input v-model="form.host"></el-input>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="开会密码">
                  <el-input v-model="form.password"></el-input>
                </el-form-item>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="开启等候室">
                    <el-switch
                      v-model="form.isWaitRoom"
                      active-value="1"
                      inactive-value="0"
                    ></el-switch>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item
                    label-width="220px"
                    label="允许成员在主持人进会前加入"
                  >
                    <el-switch
                      v-model="form.isOpen"
                      active-value="1"
                      inactive-value="0"
                    ></el-switch>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-form-item label="会议开始时来电提醒">
                  <dict-select
                    v-model="form.remindUser"
                    :dict-code="'hykssldtx'"
                    style="width: 100%"
                  ></dict-select>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="成员入会时静音">
                  <dict-select
                    v-model="form.mute"
                    :dict-code="'cyrhsjy'"
                    style="width: 100%"
                  ></dict-select>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="入会成员限制">
                  <dict-select
                    v-model="form.limitUser"
                    :dict-code="'rhcyxz'"
                    style="width: 100%"
                  ></dict-select>
                </el-form-item>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="开启屏幕水印">
                    <el-switch
                      v-model="form.isWatermark"
                      active-value="1"
                      inactive-value="0"
                    ></el-switch>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </el-collapse-item>
        </el-collapse>
      </div>
    </template>
  </at-table>
</template>

<script>
export default {
  name: 'HistoricalConference',
  data() {
    return {
      data: [],
      searchForm: {
        theme: '',
        meetingType: '',
        startTime: '',
        host: '',
      },
      dialogTitle: '',
      dialogVisible: false,
      pageResult: {
        page: 1,
        pageSize: 10,
        total: 0,
      },
      form: {},
      activeNames: [],
    }
  },
  computed: {
    deleteUrl: function () {
      return `${window.context.xqhk}/meeting/v1/removes`
    },
  },
  methods: {
    loadData(param, cb) {
      let query = [
        {
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'meeting_status_',
          relation: 'AND',
          value: 3,
        },
        {
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'meeting_status_',
          relation: 'OR',
          value: 4,
        },
      ]
      let search = {
        theme_: this.searchForm.theme,
        meeting_type_: this.searchForm.meetingType,
        start_time_: this.searchForm.startTime,
        host_: this.searchForm.host,
      }
      for (let i in search) {
        if (search[i]) {
          query.push({
            group: 'advance',
            operation: 'LIKE',
            property: i,
            relation: 'AND',
            value: search[i],
          })
        }
      }
      if (param.querys && param.querys.length) {
        param.querys.push(...query)
      } else {
        param.querys = query
      }
      this.$http
        .post('${xqhk}/meeting/v1/getJson', param)
        .then(
          (resp) => {
            let response = resp.data.value
            this.data = response.rows
            this.pageResult = {
              page: response.page,
              pageSize: response.pageSize,
              total: response.total,
            }
          },
          (error) => {
            reject(error)
          }
        )
        .finally(() => cb())
    },
    handleSearch() {
      this.$refs.AtTable.load()
    },
    handleReset() {
      this.searchForm = {
        theme: '',
        meetingType: '',
        startTime: '',
        host: '',
      }
      this.$refs.AtTable.load()
    },
    handleSelect(selection) {},
    handleDialogCancel() {
      this.dialogVisible = false
    },
    handleDialogClose() {
      this.dialogVisible = false
    },
    handleDialogSubmit() {
      this.dialogVisible = false
    },
    handleRowDBClick(row) {
      this.form = row
      this.dialogTitle = '修改'
      this.dialogVisible = true
    },
    handleAdd() {
      this.dialogTitle = '新增'
      this.dialogVisible = true
    },
  },
}
</script>

<style lang="scss" scoped>
@import '@/assets/css/common.scss';
</style>
