<template>
  <div id="medicalunion-management">
    <div class="top-btn">
      <el-button type="primary" class="btn" @click="addMedical">添加</el-button>
    </div>
    <div class="bot-table">
      <customs-table
        ref="table"
        :table-data="tableData"
        :columns="columns"
        :header-class="'newHeader'"
        :list-loading="listLoading"
        :current-page="pageIndex"
        :total-count="total"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        @pageSizeChange="handleSizeChange"
        @currentPageChange="handleCurrentChange"
      />
    </div>
    <!-- 删除提示框 -->
    <el-dialog title="提示" :visible.sync="deleteVisible" width="30%">
      <span>确定删除吗？</span>
      <span slot="footer" class="dialog-footers">
        <el-button @click="deleteVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirmDelete">确 定</el-button>
      </span>
    </el-dialog>
    <!-- <el-dialog :visible.sync="addVisible" width="520px" :show-close="true">
      <div class="title">添加医联体</div>
      <el-form
        :model="form"
        :label-position="'right'"
        label-width="110px"
        label-suffix=":"
      >
        <el-form-item
          v-for="(item, index) in formList"
          :key="index"
          :label="item.label"
        >
          <el-input
            v-if="item.type == 'input'"
            v-model="form[item.prop]"
            autocomplete="off"
            :placeholder="'请填写' + item.label"
          ></el-input>
          <el-select
            v-if="item.type == 'select'"
            v-model="form[item.prop]"
            :placeholder="'请选择' + item.label"
          >
            <el-option
              v-for="e in item.selectGroup"
              :key="e.value"
              :label="e.label"
              :value="e.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="addVisible = false">保存</el-button>
      </span>
    </el-dialog> -->
  </div>
</template>
<script>
import CustomsTable from "@/components/CustomsTable"
import paginationMixin from "@/components/TabComponents/mixin"
import {
  articleList,
  articleEnable,
  deleteArticle,
} from "@/api/operation-management"
export default {
  components: {
    CustomsTable,
  },
  mixins: [paginationMixin],
  data() {
    return {
      addVisible: false,
      listLoading: false,
      deleteVisible: false,
      columns: [
        {
          label: "标题",
          minWidth: 120,
          value: "articleTitle",
        },
        {
          label: "文件",
          minWidth: 120,
          value: "fileCode",
        },
        {
          label: "上传时间",
          minWidth: 120,
          value: "uploadTime",
        },
        {
          label: "最新修改时间",
          minWidth: 120,
          value: "updateTime",
        },
        {
          label: "上传人姓名",
          minWidth: 120,
          value: "uploadUserName",
        },
        {
          label: "启用状态",
          minWidth: 120,
          type: "switch",
          value: "status",
          func: this.openChage,
        },
        {
          label: "操作",
          width: 220,
          fixed: "right",
          operType: "button",
          operations: [
            {
              func: this.editMedical,
              formatter(row) {
                return {
                  label: "查看",
                  type: "text",
                }
              },
            },
            {
              func: this.editMedical,
              formatter(row) {
                return {
                  label: "编辑",
                  type: "text",
                }
              },
            },
            {
              func: this.deleteFunc,
              style: {
                color: "#FA6400",
              },
              formatter(row) {
                return {
                  label: "删除",
                  type: "text",
                }
              },
            },
          ],
        },
      ],
      tableData: [
        // {
        //   title: "第一个",
        //   isOpen: true,
        // },
      ],
      formList: [
        {
          type: "input",
          label: "医联体名称",
          prop: "medicalName",
        },
        {
          type: "input",
          label: "医联体编号",
          prop: "medicalId",
        },
        {
          type: "select",
          label: "省",
          prop: "province",
          selectGroup: [{ label: "北京市", value: "001" }],
        },
        {
          type: "select",
          label: "市",
          prop: "city",
          selectGroup: [{ label: "北京市", value: "001" }],
        },
      ],
      form: {},
      deleteId: "",
    }
  },
  watch: {},
  mounted() {
    this.getArticleList()
  },
  methods: {
    // 删除
    deleteFunc(data) {
      console.log(data)
      this.deleteVisible = true
      this.deleteId = data.id
    },
    // 确认删除
    confirmDelete() {
      this.deleteVisible = false
      deleteArticle(this.deleteId)
        .then((res) => {
          if (res.code == 1) {
            this.$message.success("删除成功")
            this.getArticleList()
          }
        })
        .catch(() => {})
    },
    // 获取新闻会议
    getArticleList() {
      this.listLoading = true
      let params = {
        size: this.pageSize,
        current: this.pageIndex,
        moduleType: "1",
      }
      articleList(params)
        .then((res) => {
          if (res.code == 1) {
            this.tableData = [...res.data.records]
            this.total = res.data.total
            this.listLoading = false
          }
        })
        .catch((e) => {
          this.listLoading = false
        })
    },
    // 添加医联体
    addMedical() {
      this.addVisible = true
    },
    // 编辑医联体
    editMedical(data) {
      console.log(data)
      this.form = {
        medicalName: "黑乎乎",
        medicalId: "123",
        province: "001",
        city: "001",
      }
      this.addVisible = true
    },
    // 启用状态
    openChage(data, index) {
      console.log(data, index)
      let params = {
        id: data.id,
        status: data.status ? 1 : 0,
      }
      articleEnable(params).then((res) => {
        if (res.code == 1) {
          // this.$message.success("保存成功")
          this.getArticleList()
        }
      })
    },
  },
}
</script>
<style lang="scss" scoped>
#medicalunion-management {
  padding: 20px 0;

  .top-btn {
    .btn {
      width: 80px;
      height: 32px;
      background: #4e68ff;
      border-radius: 4px;
    }
  }
  .bot-table {
    margin-top: 20px;
  }
  .title {
    text-align: center;
    height: 26px;
    font-size: 22px;
    font-family: AlibabaPuHuiTiM;
    color: rgba(0, 0, 0, 0.8);
    line-height: 26px;
    margin-bottom: 30px;
  }
}
::v-deep .el-dialog__body {
  padding: 0 40px;
  border-top: none;
}
::v-deep .el-dialog__footer {
  border-top: none;
  text-align: center;
  .f-btn {
    width: 100px;
    height: 32px;
    background: #4e68ff;
  }
}
</style>
