<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="90px"
    >
      <el-form-item
        label="护理站名称"
        prop="nurseStationId"
        label-width="100px"
      >
        <el-button type="" class="stationbtn" @click="ParamsStation(true)">{{
          queryParams.nurseStationName
        }}</el-button>
      </el-form-item>
      <!-- <el-form-item label="护理站id" prop="nurseStationId">
        <el-input
          v-model="queryParams.nurseStationId"
          placeholder="请输入护理站id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="护理项目id" prop="nurseItemId">
        <el-input
          v-model="queryParams.nurseItemId"
          placeholder="请输入护理项目id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item
        label="护理项目"
        prop="nurseItemId"
        label-width="100px"
      >
        <el-button type="" class="stationbtn" @click="ParamsStationxm(true)">{{
          queryParams.nurseItemName
        }}</el-button>
      </el-form-item>
      <el-form-item label="海报名称" prop="poserName">
        <el-input
          v-model="queryParams.poserName"
          placeholder="请输入海报名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="海报模块" prop="moduleType">
        <el-input
          v-model="queryParams.moduleType"
          placeholder="请输入海报名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="海报编号" prop="poserCode">
        <el-input
          v-model="queryParams.poserCode"
          placeholder="请输入海报编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="海报图片存放路径" prop="posterPictureUrl">
        <el-input
          v-model="queryParams.posterPictureUrl"
          placeholder="请输入海报图片存放路径"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="海报视频存放路径" prop="posterVideoUrl">
        <el-input
          v-model="queryParams.posterVideoUrl"
          placeholder="请输入海报视频存放路径"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="海报显示顺序" prop="poserSort">
        <el-input
          v-model="queryParams.poserSort"
          placeholder="请输入海报显示顺序"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="海报图片跳转链接" prop="jumpLink">
        <el-input
          v-model="queryParams.jumpLink"
          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="['system:poser: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="['system:poser: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="['system:poser: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="['system:poser:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="poserList"
      @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="护理机构id，用于区分哪个护理站"
        align="center"
        prop="nurseStationId"
      />
      <el-table-column
        label="护理项目id，用于区分是哪个服务项目"
        align="center"
        prop="nurseItemId"
      /> -->
      <el-table-column label="海报名称" align="center" prop="poserName" />
      <el-table-column label="海报编号" align="center" prop="poserCode" />
      <el-table-column label="海报简介" align="center" prop="posterIntroduce" />
      <el-table-column
        label="海报图片存放路径"
        align="center"
        prop="posterPictureUrl"
      />
      <el-table-column
        label="海报视频存放路径"
        align="center"
        prop="posterVideoUrl"
      />
      <!-- <el-table-column
        label="海报模块标识，护理机构模块：NURSE_AGENCY_MODULE，护理项目模块：NURSE_ITEM_MODULE，健康咨询模块：HEALTH_CONSUTION_MODULE，首页模块：HOME_PAGE_MODULE"
        align="center"
        prop="moduleType"
      /> -->
      <el-table-column label="海报显示顺序" align="center" prop="poserSort" />
      <el-table-column
        label="海报图片跳转链接"
        align="center"
        prop="jumpLink"
      />
      <!-- <el-table-column
        label="海报图片跳转标识，新人福利：NEW_PEOPLE_WELFARE，首页：HOME_PAGE，商城：SHOPPING"
        align="center"
        prop="jumpType"
      /> -->
      <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="['system:poser:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:poser: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-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="140px">
        <!-- <el-form-item
          label="护理机构id，用于区分哪个护理站"
          prop="nurseStationId"
        >
          <el-input
            v-model="form.nurseStationId"
            placeholder="请输入护理机构id，用于区分哪个护理站"
          />
        </el-form-item>
        <el-form-item
          label="护理项目id，用于区分是哪个服务项目"
          prop="nurseItemId"
        >
          <el-input
            v-model="form.nurseItemId"
            placeholder="请输入护理项目id，用于区分是哪个服务项目"
          />
        </el-form-item> -->
        <el-form-item label="海报名称" prop="poserName">
          <el-input v-model="form.poserName" placeholder="请输入海报名称" />
        </el-form-item>
        <el-form-item label="海报编号" prop="poserCode">
          <el-input v-model="form.poserCode" placeholder="请输入海报编号" />
        </el-form-item>
        <el-form-item label="海报简介" prop="posterIntroduce">
          <editor
            @imgs="imgs"
            :min-height="100"
            v-model="form.posterIntroduce"
          ></editor>
          <!-- <el-input
            v-model="form.posterIntroduce"
            type="textarea"
            placeholder="请输入内容"
          /> -->
        </el-form-item>
        <el-form-item label="海报图片" prop="posterPictureUrl">
          <stationAcatar
            @imgUrl="imgUrl"
            :img="form.posterPictureUrl"
            :type="'posterPictureUrl'"
          />
        </el-form-item>
        <!-- <el-form-item label="海报图片存放路径" prop="posterPictureUrl">
          <el-input
            v-model="form.posterPictureUrl"
            placeholder="请输入海报图片存放路径"
          />
        </el-form-item> -->
        <el-form-item label="海报视频存放路径" prop="posterVideoUrl">
          <el-input
            v-model="form.posterVideoUrl"
            placeholder="请输入海报视频存放路径"
          />
        </el-form-item>
        <el-form-item label="海报显示顺序" prop="poserSort">
          <el-input v-model="form.poserSort" placeholder="请输入海报显示顺序" />
        </el-form-item>
        <el-form-item label="海报图片跳转链接" prop="jumpLink">
          <el-input
            v-model="form.jumpLink"
            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="选择护理站"
      :visible.sync="nurseStationshow"
      width="1100px"
      append-to-body
      :before-close="clicknurseStationshow"
    >
      <el-form
        ref="form"
        :model="getListByUserquery"
        label-width="110px"
        :inline="true"
      >
        <el-form-item label="护理站编码" prop="nurseStationCode">
          <el-input
            v-model="getListByUserquery.nurseStationCode"
            placeholder="请输入护理站编码"
          />
        </el-form-item>
        <el-form-item label="护理站名称" prop="nurseStationName">
          <el-input
            v-model="getListByUserquery.nurseStationName"
            placeholder="请输入护理站名称"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="info"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="stationcancel"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
      <el-table
        v-loading="loading"
        :data="nurseStationlist"
        @cell-dblclick="choicestationid"
      >
        <el-table-column label="请选择" width="70" align="center">
          <template slot-scope="scope">
            <el-button
              type="primary"
              style="width: 15px; height: 15px"
              circle
              @click="choicestationid(scope.row)"
              v-if="stationid == scope.row.id"
            ></el-button>

            <el-button
              style="width: 15px; height: 15px"
              circle
              v-else
              @click="choicestationid(scope.row)"
            >
            </el-button>
          </template>
        </el-table-column>
        <el-table-column
          property="nurseStationCode"
          label="护理站编码"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="nurseStationName"
          label="护理站名称"
          align="center"
        >
        </el-table-column>
        <el-table-column property="phone" label="联系电话" align="center">
        </el-table-column>
        <el-table-column
          property="address"
          label="护理站地址"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
      </el-table>

      <pagination
        v-show="total4 > 0"
        :total="total4"
        :page.sync="getListByUserquery.pageNum"
        :limit.sync="getListByUserquery.pageSize"
        @pagination="info"
      />
    </el-dialog>
   
     <!-- 护理项目分类 -->
     <el-dialog
      title="选择护理项目分类"
      :visible.sync="Classifyshow"
      width="1100px"
      append-to-body
      :before-close="cancelClassifyshow"
    >
      <el-form :model="classifyquery" label-width="150px" :inline="true">
        <el-form-item label="护理项目分类编码" prop="classifyCode">
          <el-input
            v-model="classifyquery.classifyCode"
            placeholder="请输入护理项目分类编码"
          />
        </el-form-item>
        <el-form-item label="护理项目分类名称" prop="classifyName">
          <el-input
            v-model="classifyquery.classifyName"
            placeholder="请输入护理项目分类名称"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="classifylistInfo"
            >搜索</el-button
          >
          <el-button
            icon="el-icon-refresh"
            size="mini"
            @click="classifylistcancel"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
      <el-table
        v-loading="loading"
        :data="classifylist"
        @cell-dblclick="choiceclassify"
      >
        <el-table-column label="请选择" width="70" align="center">
          <template slot-scope="scope">
            <el-button
              type="primary"
              style="width: 15px; height: 15px"
              circle
              @click="choiceclassify(scope.row)"
              v-if="form.nurseStationItem.nurseClassifyId == scope.row.id"
            ></el-button>

            <el-button
              style="width: 15px; height: 15px"
              circle
              v-else
              @click="choiceclassify(scope.row)"
            >
            </el-button>
          </template>
        </el-table-column>
        <el-table-column
          property="classifyCode"
          label="护理项目分类编码"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="classifyName"
          label="护理项目分类名称"
          align="center"
        >
        </el-table-column>
      </el-table>
      <pagination
        v-show="classifytotal > 0"
        :total="classifytotal"
        :page.sync="classifyquery.pageNum"
        :limit.sync="classifyquery.pageSize"
        @pagination="classifylistInfo"
      />
    </el-dialog>
  </div>
</template>

<script>
import {
  listPoser,
  getPoser,
  delPoser,
  addPoser,
  listInfo,
  getListByUser,
  updatePoser,
  updatePicture,
} from "@/api/system/poser";
import stationAcatar from "../stationAvatar/index.vue";

import editor from "@/components/Editor";

export default {
  name: "Poser",
  components: { stationAcatar, editor },
  data() {
    return {
      // 遮罩层
      loading: true,

      getListByUserquery: {
        pageNum: 1,
        pageSize: 10,
      },
           // 查询参数
           StationConsumablequeryParams: {
                pageNum: 1,
                pageSize: 10,
                nurseStationId: null,
                consumableDetail: null,
            },
      nurseStationlist: [],
      nurseStationshow:false,
      imgone: "",
      imgsurl: { pictureUrlList: [] },
      imageUrl: "", //商品图片
      // 选中数组
      ids: [],

      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      Classifyshow: false,
      // 总条数
      total: 0,
      total2: 0,
      total4: 0,
      classifytotal:0,
      classifylist: [],
      // 泉医到家系统海报模块信息（包含咨询简介信息）表格数据
      poserList: [],
      nurseItemList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      classifyquery: {
                pageNum: 1,
                pageSize: 10,
                classifyCode: null,
                classifyName: null,
            },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nurseStationId: null,
        nurseItemId: null,
        nurseClassifyId:null,
        poserName: null,
        poserCode: null,
        posterIntroduce: null,
        posterPictureUrl: null,
        posterVideoUrl: null,

        moduleType: null,
        poserSort: null,
        jumpLink: null,
        jumpType: null,
      },
      // 表单参数
      form: {
        nurseStationItem: {
                    nurseStationId: null,
                    nurseTypeId: null,
                    nurseItemName: "",
                    nurseItemContent: "",
                    advanceAppointDuration: "",
                    itemPictureUrl: "",
                    sort: "",
                    nurseStationName: "请选择所属护理站",
                    classifyName: '请选择护理项目分类',
                    nurseClassifyId: "",
                },
      },
      // 表单校验
      rules: {
        poserName: [
          { required: true, message: "请输入海报名称", trigger: "blur" },
        ],
        poserCode: [
          { required: true, message: "请输入海报编号", trigger: "blur" },
        ],
        posterIntroduce: [
          { required: true, message: "请输入海报简介", trigger: "blur" },
        ],
        posterPictureUrl: [
          { required: true, message: "请输入海报图片", trigger: "blur" },
        ],
        posterVideoUrl: [
          {
            required: true,
            message: "请输入海报视频存放路径",
            trigger: "blur",
          },
        ],
        poserSort: [
          { required: true, message: "请输入海报顺序", trigger: "blur" },
        ],
        jumpLink: [
          {
            required: true,
            message: "请输入海报图片跳转链接",
            trigger: "blur",
          },
        ],
      },
    };
  },
  created() {
    this.getList();
     this.classifylistInfo();
  },
  methods: {
      //打开遮罩层
      clickClassifyshow() {
            this.Classifyshow = true
            this.classifylistcancel()
        },
        //关闭遮罩层
        cancelClassifyshow() {
            this.Classifyshow = false
        },
        //选中
        choiceclassify(e) {
            this.form.nurseStationItem.nurseClassifyId = e.id
            this.form.nurseStationItem.classifyName = e.classifyName
            this.Classifyshow = false
        },
        //重置
        classifylistcancel() {
            this.classifyquery = {
                pageNum: 1,
                pageSize: 10,
                classifyCode: null,
                classifyName: null,
            }
            this.classifylistInfo();
        },
        //搜索
        classifylistInfo() {
            listInfo(this.classifyquery).then(res => {
                this.classifylist = res.rows
                this.classifytotal = res.total
            })
        },
    //页面所属护理站
    ParamsStation(item) {
      this.info();
      this.nurseStationshow = true;
      this.homenumber = item;
      this.stationid = this.queryParams.nurseStationId;
    },
    ParamsStationxm() {
      this.classifylistInfo();
      this.Classifyshow = true;
      this.form.nurseStationItem.nurseClassifyId = this.queryParams.nurseItemId;
      // this.homenumber = item;
      // this.stationid = this.queryParams.nurseStationId;
    },
    //护理站list
    info() {
      getListByUser(this.getListByUserquery).then((res) => {
        this.nurseStationlist = res.rows;
        this.total4 = res.total;
      });
    },
       //打开护理站列表
       nurseStationshowclick() {
            this.stationcancel();
            this.stationid = this.form.nurseStationItem.nurseStationId
            this.nurseStationshow = true
        },
          //护理站重置
          stationcancel() {
            this.getListByUserquery = {
                pageNum: 1,
                pageSize: 10,
            };
            this.info();
        },
        //护理站页面选择护理站
        choicestationid(item) {
            if (this.homenumber) {
                this.queryParams.nurseStationName = item.nurseStationName;
                this.queryParams.nurseStationId = item.id;
            } else {
                this.stationid = item.id
                this.form.nurseStationItem.nurseStationId = item.id;
                this.form.nurseStationItem.nurseStationName = item.nurseStationName;
                this.StationConsumablequeryParams.nurseStationId = item.id;
            }
            this.nurseStationshow = false;
            this.stationcancel();
        },
        //关闭护理站页面
        clicknurseStationshow() {
            this.nurseStationshow = false;
        },
    imgs(item) {
      this.imgsurl.posterIntroduce.push(item);
    },
    imgUrl(imgUrl) {
      this.form.posterPictureUrl = imgUrl;
    },
    /** 查询泉医到家系统海报模块信息（包含咨询简介信息）列表 */
    getList() {
      this.loading = true;
      listPoser(this.queryParams).then((response) => {
        this.poserList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
       
    // 取消按钮
    cancel() {
      var obj = { pictureUrlList: [] };
      if (this.imgone != this.form.posterPictureUrl) {
        obj.pictureUrlList.push(this.form.posterPictureUrl);
      }
      if (obj.pictureUrlList.length > 0) {
        updatePicture(obj).then((res) => {});
      }
      if (this.imgsurl.pictureUrlList.length > 0) {
        updatePicture(this.imgsurl).then((res) => {});
      }
      this.imgsurl = { pictureUrlList: [] };
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        nurseStationId: null,
        nurseItemId: null,
        poserName: null,
        poserCode: null,
        posterIntroduce: null,
        posterPictureUrl: null,
        posterVideoUrl: null,
        moduleType: null,
        poserSort: null,
        jumpLink: null,
        jumpType: 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();
      const id = row.id || this.ids;
      getPoser(id).then((response) => {
        this.form = response.data;
        this.imgone = this.form.posterPictureUrl;
        if (response.data.goodAttributeDetailsLists) {
          this.goodDetailsLists = response.data.goodAttributeDetailsLists;
        }
        this.open = true;
        this.title = "修改泉医到家系统海报模块信息（包含咨询简介信息）";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updatePoser(this.form).then((response) => {
              var obj = { pictureUrlList: [] };
              if (this.imgone != this.form.posterPictureUrl) {
                obj.pictureUrlList.push(this.imgone);
              }
              this.imgsurl = { pictureUrlList: [] };
              if (obj.pictureUrlList.length > 0) {
                updatePicture(obj).then((res) => {});
              }

              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPoser(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm(
          '是否确认删除泉医到家系统海报模块信息（包含咨询简介信息）编号为"' +
            ids +
            '"的数据项？'
        )
        .then(function () {
          return delPoser(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/poser/export",
        {
          ...this.queryParams,
        },
        `poser_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style  lang="scss" scoped>
.stationbtn {
  width: 208px;
  text-align: left;
  height: 32px;
  overflow: hidden;
  font-size: 14px;
}</style>