<template>
  <div id="medicalunion-management">
    <div class="top-btn">
      <el-select v-model="selectType" @change="getArticleList">
        <el-option
          v-for="item in selectList"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>
      <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
      :visible.sync="addVisible"
      width="520px"
      :show-close="true"
      @closed="resetForm"
    >
      <div class="title">{{ readOnly ? "查看" : "添加" }}</div>
      <el-form
        ref="form"
        :model="form"
        :label-position="'right'"
        label-width="110px"
        label-suffix=":"
        :disabled="readOnly"
      >
        <el-form-item
          v-for="(item, index) in formList"
          :key="index"
          :label="item.label"
          :prop="item.prop"
          :rules="[{ required: true, message: item.label + '不能为空' }]"
        >
          <!-- <template v-if="!readOnly"> -->
          <template>
            <!-- 输入框 -->
            <el-input
              v-if="item.type == 'input'"
              v-model="form[item.prop]"
              autocomplete="off"
              :placeholder="'请填写' + item.label"
            ></el-input>
            <!-- 下拉选 -->
            <el-select
              v-else-if="item.type == 'select'"
              v-model="form[item.prop]"
              :placeholder="'请选择' + item.label"
              style="width: 100%"
            >
              <el-option
                v-for="e in item.selectGroup"
                :key="e.value"
                :label="e.label"
                :value="e.value"
              ></el-option>
            </el-select>
            <!-- 上传 -->
            <el-upload-self
              v-else-if="item.type === 'upload'"
              v-model="form[item.prop]"
              :btn-type="'text'"
              v-bind="item"
              :list-type="item.listType"
              :accept="item.accept"
              :limit="item.limit"
              :disabled="readOnly"
            ></el-upload-self>
            <!-- switch -->
            <!-- switch切换  启用 -->
            <el-switch
              v-else-if="item.type === 'switch'"
              v-model="form[item.prop]"
              :active-value="1"
              :inactive-value="0"
            >
            </el-switch>
          </template>
          <!-- <template v-else>
            <span>{{ form[item.prop] || "--" }}</span>
          </template> -->
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button class="f-btn" type="primary" @click="submitForm('4')"
          >保存</el-button
        >
      </span>
    </el-dialog>
    <!-- 删除提示框 -->
    <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>
  </div>
</template>
<script>
import CustomsTable from "@/components/CustomsTable"
import paginationMixin from "@/components/TabComponents/mixin"
import ElUploadSelf from "@/components/UploadForOperation"
import mixin from "./mixin"
import { articleList } from "@/api/operation-management"
export default {
  components: {
    CustomsTable,
    ElUploadSelf,
  },
  mixins: [paginationMixin, mixin],
  data() {
    return {
      // readOnly: true,
      // addVisible: false,
      // deleteVisible: false,
      selectList: [
        {
          label: "筛查",
          value: "0",
        },
        {
          label: "生活",
          value: "1",
        },
        {
          label: "医学知识",
          value: "2",
        },
        {
          label: "其他",
          value: "3",
        },
      ],
      selectType: "0",
      listLoading: false,
      columns: [
        {
          label: "标题",
          minWidth: 120,
          value: "articleTitle",
        },
        {
          label: "图片",
          type: "img",
          minWidth: 120,
          value: "imgPath",
        },
        {
          label: "文件",
          minWidth: 120,
          type: "file",
          value: "filePath",
        },
        {
          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.viewMedical,
              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: "select",
          label: "类型",
          prop: "articleType",
          selectGroup: [
            {
              label: "筛查",
              value: "1",
            },
            {
              label: "生活",
              value: "2",
            },
            {
              label: "医学知识",
              value: "3",
            },
            {
              label: "其他",
              value: "4",
            },
          ],
        },
        {
          type: "input",
          label: "标题",
          prop: "articleTitle",
        },
        {
          type: "upload",
          label: "图片",
          prop: "imgPath",
          listType: "picture-card",
        },
        {
          type: "upload",
          label: "PDF",
          prop: "filePath",
          accept: "application/pdf",
        },
        {
          type: "switch",
          label: "启用状态",
          prop: "status",
        },
      ],
      // form: {
      //   status: 1,
      // },
    }
  },
  watch: {},
  mounted() {
    this.getArticleList()
  },
  methods: {
    // 获取健康科普
    getArticleList() {
      this.listLoading = true
      let params = {
        size: this.pageSize,
        current: this.pageIndex,
        moduleType: "4",
        articleType: this.selectType - 0 + 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
        })
    },
  },
}
</script>
<style lang="scss" scoped>
#medicalunion-management {
  padding: 20px 0;
  .top-btn {
    .btn {
      width: 80px;
      height: 32px;
      background: #4e68ff;
      border-radius: 4px;
      margin-left: 20px;
    }
  }
  .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>
