<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="服务方式名称" prop="serviceWayName">
        <el-input
          v-model="queryParams.serviceWayName"
          placeholder="请输入服务方式名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="服务方式编码" prop="serviceWayCode">
        <el-input
          v-model="queryParams.serviceWayCode"
          placeholder="请输入服务方式编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="所属服务方式id" prop="serviceWayId">
        <el-input
          v-model="queryParams.serviceWayId"
          placeholder="请输入所属服务方式id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属服务内容id" prop="serviceContentId">
        <el-input
          v-model="queryParams.serviceContentId"
          placeholder="请输入所属服务内容id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="服务频次文本" prop="serviceFrequencyText">
        <el-input
          v-model="queryParams.serviceFrequencyText"
          placeholder="请输入服务频次文本"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="服务频次数字起始值" prop="serviceFrequencyStart">
        <el-input
          v-model="queryParams.serviceFrequencyStart"
          placeholder="请输入服务频次数字起始值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="服务频次数字结束值" prop="serviceFrequencyEnd">
        <el-input
          v-model="queryParams.serviceFrequencyEnd"
          placeholder="请输入服务频次数字结束值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="排序" prop="serviceSort">
        <el-input
          v-model="queryParams.serviceSort"
          placeholder="请输入排序"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="serviceRemark">
        <el-input
          v-model="queryParams.serviceRemark"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['manage:servicewaycontent:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['manage:servicewaycontent:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['manage:servicewaycontent:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['manage:servicewaycontent:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-row :gutter="20">
      <el-col :span="7">
        <div class="left" ref="box">
          <div class="name">
            服务方式
            <el-button
              type="success"
              plain
              icon="el-icon-circle-plus-outline"
              size="mini"
              @click="handleUpdateserve"
              >新增</el-button
            >
            <el-button
              v-if="this.itemname"
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              @click="handleedit"
              >修改</el-button
            >
            <el-button
              v-if="this.itemname"
              type="success"
              plain
              icon="el-icon-delete"
              size="mini"
              @click="handledelete"
              >删除</el-button
            >
          </div>
          <div>
            <el-input
              v-model="name"
              placeholder="请输入服务方式"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </div>
          <div class="listitem">
            <div
              :class="itemname == null ? 'allactive' : 'all'"
              @click="itemdata()"
            >
              全部
            </div>
            <!-- <span class="count">{{ count }}</span> -->
          </div>
          <div
            class="listitem"
            v-for="(item, index) in DepartmentoList"
            :key="index"
            @click="itemdata(item)"
          >
            <div :class="itemname == item.id ? 'allactive' : 'all'">
              {{ item.serviceWayName }}
            </div>
            <span class="count">{{ item.serviceContentNum }}</span>
          </div>
        </div>
      </el-col>
      <el-col :span="17">
        <el-table
          v-loading="loading"
          :data="servicewaycontentList"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55" align="center" />
          <!-- <el-table-column label="主键id" align="center" prop="id" /> -->
          <!-- <el-table-column label="服务方式名称" align="center" prop="serviceWayName" /> -->
          <!-- <el-table-column label="服务方式编码" align="center" prop="serviceWayCode" /> -->
          <!-- <el-table-column label="服务标识，服务方式：SERVICE_WRY，服务内容：SERVICE_CONTENT，服务频次：SERVICE_FREQUENCY" align="center" prop="serviceType" /> -->
          <!-- <el-table-column label="所属服务方式id" align="center" prop="serviceWayId" /> -->
          <el-table-column
            label="服务内容"
            align="center"
            prop="serviceContent"
          />
          <!-- <el-table-column label="所属服务内容id" align="center" prop="serviceContentId" /> -->
          <el-table-column
            label="服务频次类型"
            align="center"
            prop="serviceFrequencyType"
          >
            <template slot-scope="scope">
              {{ scope.row.serviceFrequencyType == "DIGIT" ? "数字" : "" }}
              {{ scope.row.departmentType == "TEXT" ? "文本" : "" }}
            </template>
          </el-table-column>
          <!-- <el-table-column label="服务频次文本" align="center" prop="serviceFrequencyText" /> -->
          <!-- <el-table-column label="服务频次数字起始值" align="center" prop="serviceFrequencyStart" />
      <el-table-column label="服务频次数字结束值" align="center" prop="serviceFrequencyEnd" />
      <el-table-column label="排序" align="center" prop="serviceSort" />
      <el-table-column label="备注" align="center" prop="serviceRemark" /> -->
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['manage:servicewaycontent:edit']"
                >修改</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['manage:servicewaycontent:remove']"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>

    <!-- 添加或修改服务方式内容对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="550px" append-to-body>
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="70px"
        :inline="true"
      >
        <!-- <el-form-item label="服务方式名称" prop="serviceWayName">
          <el-input v-model="form.serviceWayName" placeholder="请输入服务方式名称" />
        </el-form-item>
        <el-form-item label="服务方式编码" prop="serviceWayCode">
          <el-input v-model="form.serviceWayCode" placeholder="请输入服务方式编码" />
        </el-form-item>
        <el-form-item label="所属服务方式id" prop="serviceWayId">
          <el-input v-model="form.serviceWayId" placeholder="请输入所属服务方式id" />
        </el-form-item> -->
        <el-form-item label="服务内容" prop="serviceContent">
          <el-input
            type="textarea"
            style="width: 400px"
            v-model="form.serviceContent"
          />
        </el-form-item>
        <!-- <el-form-item label="所属服务内容id" prop="serviceContentId">
          <el-input v-model="form.serviceContentId" placeholder="请输入所属服务内容id" />
        </el-form-item> -->
        <el-form-item label="服务频次">
          <el-checkbox v-model="checked">数字</el-checkbox>
        </el-form-item>

        <el-form-item
          label="起始值"
          prop="serviceFrequencyStart"
          label-width=""
        >
          <el-input
            v-model="form.serviceFrequencyStart"
            placeholder="请输入服务频次数字起始值"
          />
        </el-form-item>

        <el-form-item
          label="结束值"
          prop="serviceFrequencyEnd"
          label-width="200px"
        >
          <el-input
            v-model="form.serviceFrequencyEnd"
            placeholder="请输入服务频次数字结束值"
          />
        </el-form-item>
        <!-- </> -->

        <el-form-item
          label="服务频次文本"
          prop="serviceFrequencyText"
          label-width="90x"
        >
          <el-checkbox v-model="TEXT">文本</el-checkbox>
        </el-form-item>

        <el-form-item label="" prop="serviceFrequencyText" label-width="90x">
          <el-input
            v-model="form.serviceFrequencyText"
            placeholder="请输入服务频次文本"
          />
        </el-form-item>
        <!-- <el-form-item label="排序" prop="serviceSort">
          <el-input v-model="form.serviceSort" placeholder="请输入排序" />
        </el-form-item>
        <el-form-item label="备注" prop="serviceRemark">
          <el-input v-model="form.serviceRemark" placeholder="请输入备注" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 服务方式 -->
    <el-dialog
      :title="titles"
      :visible.sync="opens"
      width="500px"
      append-to-body
    >
      <el-form
        ref="form"
        :model="format"
        :rules="rules"
        label-width="120px"
        :inline="true"
      >
        <el-form-item label="服务方式名称" prop="serviceWayName">
          <el-input
            v-model="format.serviceWayName"
            placeholder="请输入服务方式名称"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForms">确 定</el-button>
        <el-button @click="cancels">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listServicewaycontent,
  getServicewaycontent,
  delServicewaycontent,
  addServicewaycontent,
  editServiceWay,
  updateServicewaycontent,
  addServiceWay,
  serviceWayList,
  removeServiceWay,
  serviceWay,
} from "@/api/manage/servicewaycontent";

export default {
  name: "Servicewaycontent",
  data() {
    return {
      disabled: "",
      titles: "",
      checked: true,
      TEXT: true,
      DepartmentoList: [], //左侧数组
      format: {
        serviceWayName: "",
        id:'',
      },
      // 遮罩层
      loading: true,
      opens: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 服务方式内容表格数据
      servicewaycontentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      name: "",

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        serviceWayName: null,
        serviceWayCode: null,
        serviceType: null,
        serviceWayId: null,
        serviceContent: null,
        serviceContentId: null,
        serviceFrequencyType: null,
        serviceFrequencyText: null,
        serviceFrequencyStart: null,
        serviceFrequencyEnd: null,
        serviceSort: null,
        serviceRemark: null,
      },
      count: "", //全部

      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      itemname: null,
      querydepartmen: {
        serviceWayName: "",
      },
    };
  },
  watch: {
    name(val) {
      // console.log(val,'55')
      this.querydepartmen.serviceWayName = val;
      this.mentlist();
    },
  },
  created() {
    this.getList();
    this.mentlist();

    // listMessage(this.queryParams).then(response => {
    //   this.count = response.total;
    // });
  },
  methods: {
    // 左侧服务方式提交
    submitForms() {
      // console.log(this.itenname,'5252')
      this.$refs["form"].validate((valid) => {
        if (valid) {
          console.log(this.format)

          if (this.format.id) {
            editServiceWay(this.format).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.opens = false;
              this.mentlist();
            });
          } else {
            addServiceWay(this.format).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.opens = false;
              this.mentlist();
            });
          }
        }
      });
    },
    cancels() {
      this.opens = false;
    },
    // 左侧服务方式列表
    mentlist() {
      this.loading = true;
      serviceWayList(this.querydepartmen).then((response) => {
        this.DepartmentoList = response.data;
        // this.count=this.DepartmentoList.length
        console.log(this.DepartmentoList);

        // this.total = response.total;
        this.loading = false;
      });
    },
    // 左侧科室
    itemdata(item) {
      if (item) {
        console.log(item, "9999");
        // if(item.id==5){
        //   this.disabled=false
        // }else{
        //   this.disabled=true
        // }
        this.itemname = item.id;
        // this.departmentName = item.serviceWayName;
        this.loading = true;
        this.queryParams.serviceWayId = item.id;
        this.getList();
      } else {
        this.queryParams.serviceWayId = "";
        this.itemname = null;
        this.getList();
      }
    },
    /** 查询服务方式内容列表 */
    getList() {
      this.loading = true;
      listServicewaycontent(this.queryParams).then((response) => {
        this.servicewaycontentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        serviceWayName: null,
        serviceWayCode: null,
        serviceType: null,
        serviceWayId: null,
        serviceContent: null,
        serviceContentId: null,
        serviceFrequencyType: null,
        serviceFrequencyText: null,
        serviceFrequencyStart: null,
        serviceFrequencyEnd: null,
        serviceSort: null,
        serviceRemark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加服务方式内容";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // this.reset();
      console.log(row)
      // const id = row.serviceContentId 
      getServicewaycontent(row.serviceContentId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改服务方式内容";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateServicewaycontent(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addServicewaycontent(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    // 修改服务方式
    handleedit() {
      console.log(this.itemname);
      this.format.id=this.itemname
      if (this.itemname) {
        
        serviceWay(this.itemname).then((res) => {
          this.format.serviceWayName = res.msg;
          this.opens = true;
          this.title = "修改服务方式内容";
        });
      } 
      // else {
      //   this.$message.error("请先选择一种服务方式");
      // }
      this.format.serviceWayName = "";
      this.titles = "修改服务方式";
    },
    handledelete() {
        const id = this.itemname 
        console.log(id,'111111111')
        this.$modal
          .confirm("是否确认删除此服务方式？")
          .then(function () {
            return removeServiceWay(id);
          })
          .then(() => {
            this.mentlist();
            this.$modal.msgSuccess("删除成功");
          })
          .catch(() => {});
   
    },
    // },
    handleUpdateserve() {
      this.titles = "新增服务方式";
      this.format.serviceWayName = "";
      this.opens = true;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      console.log(row)
      const id = row.serviceFrequencyId 
      const serviceContentId = row.serviceContentId 

      this.$modal
        .confirm('是否确认删除服务方式内容编号为"' + serviceContentId + '"的数据项？')
        .then(function () {
          return delServicewaycontent(serviceContentId,id);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "manage/servicewaycontent/export",
        {
          ...this.queryParams,
        },
        `servicewaycontent_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style lang="scss">
.left {
  height: 530px;
  overflow: auto;
  .name {
    font-weight: 700;
    margin-bottom: 10px;
  }
  .listitem {
    width: 100%;
    height: 50px;
    border-bottom: 1px solid #dcdfe6;
    .count {
      display: inline-block;
      position: relative;
      // right: -172px;
      left: 325px;
      color: #a4a6aa;
      top: -35px;
      font-size: 13px;
    }
    .all {
      height: 50px;
      line-height: 50px;
      padding-left: 13px;
    }
    .allactive {
      background: #e8f4ff;
      height: 50px;
      line-height: 50px;
      padding-left: 13px;
      border-left: 3px solid #4d9de7;
    }
  }
}
.button {
  display: inline-block;
  position: relative;
  left: 20px;
  top: -11px;
}
.dotClass {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: block;
  // margin-left: 10px;  //这个用于圆点居中
  position: relative;
  top: 16px;
  left: 12px;
}
</style>