<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <!-- <el-form-item label="患者表id" prop="patientId">
        <el-input
          v-model="queryParams.patientId"
          placeholder="请输入患者表id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="签约患者管理任务节点表id" prop="manageRouteNodeId">
        <el-input
          v-model="queryParams.manageRouteNodeId"
          placeholder="请输入签约患者管理任务节点表id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="患者姓名" prop="patientName">
        <el-input
          v-model="queryParams.patientName"
          placeholder="请输入患者姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item
        label="管理路径节点名称"
        prop="routeNodeName"
        label-width="130px"
      >
        <el-input
          v-model="queryParams.routeNodeName"
          placeholder="请输入管理路径节点名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item
        label="管理任务推送时间"
        prop="taskPushDate"
        label-width="130px"
      >
        <el-date-picker
          clearable
          v-model="queryParams.taskPushDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择管理任务推送时间"
        >
        </el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="管理任务推送备注" prop="taskPushRemark">
        <el-input
          v-model="queryParams.taskPushRemark"
          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="handledetails"
          v-hasPermi="['system:taskPushRecord:add']"
          >详情</el-button
        >
      </el-col> -->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="taskPushRecordList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="患者姓名" align="center" prop="patientName" />
      <el-table-column
        label="管理路径节点名称"
        align="center"
        prop="routeNodeName"
      />
      <!-- <el-table-column label="管理任务推送方式，微信小程序：微信公众号：，短信：，IM：" align="center" prop="taskPushType" /> -->
      <el-table-column
        label="管理任务推送方式"
        align="center"
        prop="taskPushType"
      />
      <el-table-column
        label="管理任务推送时间"
        align="center"
        prop="taskPushDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.taskPushDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="管理任务推送备注"
        align="center"
        prop="taskPushRemark"
      />
      <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-document-copy"
            @click="handledetails(scope.row)"
            v-hasPermi="['system:taskPushRecord:edit']"
            >详情</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="110px"
        :inline="true"
      >
        <div class="top">
          <el-form-item label="任务内容:" prop="patientId" label-width="110px">
            <div>
              <el-radio
                v-model="form.taskType"
                label="PHONE_OUTBOUND"
                v-if="form.taskType == 'PHONE_OUTBOUND'"
                >电话外呼</el-radio
              >
              <el-radio
                v-model="form.taskType"
                label="QUESTIONNAIRE_SCALE"
                v-if="form.taskType == 'QUESTIONNAIRE_SCALE'"
                >问卷量表</el-radio
              >
              <el-radio
                v-model="form.taskType"
                label="PROPAGANDA_ARTICLE"
                v-if="form.taskType == 'PROPAGANDA_ARTICLE'"
                >宣教文章</el-radio
              >
              <el-radio
                v-model="form.taskType"
                label="TEXT_REMIND"
                v-if="form.taskType == 'TEXT_REMIND'"
                >文字提醒</el-radio
              >
              <el-radio
                v-model="form.taskType"
                label="ARTIFICIAL_FOLLOW_UP"
                v-if="form.taskType == 'ARTIFICIAL_FOLLOW_UP'"
                >人工随访</el-radio
              >
              <!-- <el-radio-group v-model="form.taskType">
                <el-radio
                class="custom-radio"
                disabled
                  v-for="(option, index) in options"
                  :key="index"
                  :label="option.value"
                  >{{ option.label }}</el-radio
                >
              </el-radio-group> -->
            </div>
          </el-form-item>
          <br />
          <!-- 电话外呼top -->
          <el-form-item
            label="电话模板:"
            prop="patientId"
            v-if="form.taskType == 'PHONE_OUTBOUND'"
          >
            <el-input
              v-model="form.phoneTemplateName"
              style="width: 260px"
              disabled
            />
          </el-form-item>

          <el-form-item
            label="电话内容:"
            prop="patientId"
            v-if="form.taskType == 'PHONE_OUTBOUND'"
          >
            <el-input
              disabled
              style="width: 635px"
              type="textarea"
              v-model="form.phoneNodeContent"
            />
          </el-form-item>
          <!-- 问卷量表top -->
          <div
            v-if="form.taskType == 'QUESTIONNAIRE_SCALE'"
            style="margin-top: -13px"
          >
            <el-form-item label="问卷模板:" prop="patientId">
              <el-input
                v-model="form.questionnaireName"
                style="width: 260px"
                disabled
              />
            </el-form-item>
            <el-form-item label="问卷有效期:" prop="patientId">
              <el-input-number
                v-model="form.questionExpirationDate"
                size="small"
                :disabled="true"
                label=""
              ></el-input-number>
              <span style="margin-left: 5px; color: #606266; font-weight: 600"
                >天</span
              >
            </el-form-item>
            <el-form-item
              label="问卷模板内容:"
              prop="patientId"
              v-if="form.taskType == 'QUESTIONNAIRE_SCALE'"
            >
              <el-input
                style="width: 635px"
                type="textarea"
                disabled
                v-model="form.questionnaireContent"
              />
            </el-form-item>
          </div>
          <!-- 宣教文章top -->
          <div
            style="margin-top: -13px"
            v-if="form.taskType == 'PROPAGANDA_ARTICLE'"
          >
            <el-form-item label="宣教模板:" prop="patientId">
              <el-input
                v-model="form.propagandaTitle"
                style="width: 260px"
                disabled
              />
            </el-form-item>

            <el-form-item label="宣教文章内容:" prop="patientId">
              <el-input
                style="width: 635px"
                type="textarea"
                disabled
                v-model="form.propagandaContent"
              />
            </el-form-item>
          </div>

          <!-- 文字提醒 -->
          <div style="margin-top: -13px" v-if="form.taskType == 'TEXT_REMIND'">
            <el-form-item
              label="提醒内容:"
              prop="patientId"
              v-if="form.taskType == 'TEXT_REMIND'"
            >
              <!-- 短信 -->
              <el-input
                v-if="form.messagePushSign == 1"
                type="textarea"
                disabled
                v-model="form.messagePreview"
                style="width: 635px"
              />
              <!-- 公众号 -->
              <el-input
                v-if="form.officialPushSign == 1"
                type="textarea"
                disabled
                v-model="form.officialRemindContent"
                style="width: 635px"
              />
              <!-- 小程序 -->
              <el-input
                v-if="form.appletPushSign == 1"
                type="textarea"
                disabled
                v-model="form.appletRemindContent"
                style="width: 635px"
              />
            </el-form-item>
          </div>
          <!-- 人工随访 -->
          <div style="margin-top: -13px">
            <el-form-item
              label-width="130px"
              label="人工随访模板:"
              prop="patientId"
              v-if="form.taskType == 'ARTIFICIAL_FOLLOW_UP'"
            >
              <el-input
                v-model="form.followTemplateName"
                style="width: 260px"
                disabled
              />
            </el-form-item>
            <el-form-item
              label-width="130px"
              label="人工随访模板内容:"
              prop="patientId"
              v-if="form.taskType == 'ARTIFICIAL_FOLLOW_UP'"
            >
              <el-input
                style="width: 600px"
                type="textarea"
                v-model="form.followContent"
              />
            </el-form-item>
          </div>
        </div>
        <!-- 电话外呼 -->
        <div v-if="form.taskType == 'PHONE_OUTBOUND'">
          <div class="topitem">
            <el-form-item label="重播次数:" prop="patientId">
              <el-input
                v-model="form.phoneRedialTimes"
                style="width: 260px"
                disabled
              />
            </el-form-item>
            <el-form-item label="时间间隔:" prop="patientId">
              <el-input-number
                v-model="form.phoneTimeInterval"
                size="small"
                :disabled="true"
                label=""
              ></el-input-number>
              <span style="margin-left: 5px; color: #606266; font-weight: 600"
                >分钟</span
              >
            </el-form-item>
          </div>
          <div class="topitem">
            <el-form-item label="电话短信提醒:" prop="patientId">
              <el-input
                v-model="form.phoneMessageRemind"
                style="width: 260px"
                disabled
              />
            </el-form-item>
            <el-form-item label="短信模板:" prop="patientId">
              <el-input
                v-model="form.phoneMessageTemplateName"
                style="width: 260px"
                disabled
              />
            </el-form-item>
          </div>
        </div>

        <!-- 问卷量表,宣教文章，文字提醒，人工随访底部 -->
        <div
          v-if="
            form.taskType == 'QUESTIONNAIRE_SCALE' ||
            form.taskType == 'PROPAGANDA_ARTICLE' ||
            form.taskType == 'TEXT_REMIND' ||
            form.taskType == 'ARTIFICIAL_FOLLOW_UP' ||
            form.taskType == 'PHONE_OUTBOUND'
          "
        >
          <div class="topitem">
            <div class="topstyle">
              <el-form-item label="推送方式:" prop="patientId">
                <!-- <span>{{form.taskPushType}}</span> -->
                <span>短信</span>
              </el-form-item>
            </div>
            <div class="topswitch">
              <el-form-item>
                <el-switch
                  v-model="form.messagePushSign"
                  disabled
                  style="position: relative; left: 33px; width: 40px"
                >
                </el-switch>
              </el-form-item>
            </div>
          </div>
          <div class="topitem">
            <div class="topstyle">
              <el-form-item label="推送方式:" prop="patientId">
                <span>公众号</span>
              </el-form-item>
            </div>
            <div class="topswitch">
              <el-form-item>
                <el-switch
                  v-model="form.officialPushSign"
                  disabled
                  style="position: relative; left: 33px; width: 40px"
                >
                </el-switch>
              </el-form-item>
            </div>
          </div>

          <div class="topitem">
            <div class="topstyle">
              <el-form-item label="推送方式:" prop="patientId">
                <span>小程序</span>
              </el-form-item>
            </div>
            <div class="topswitch">
              <el-form-item>
                <el-switch
                  v-model="form.appletPushSign"
                  disabled
                  style="position: relative; left: 33px; width: 40px"
                >
                </el-switch>
              </el-form-item>
            </div>
          </div>
          <div class="topitem">
            <div class="topstyle">
              <el-form-item label="推送方式:" prop="patientId">
                <span>电话</span>
              </el-form-item>
            </div>
            <div class="topswitch">
              <el-form-item>
                <el-switch
                  v-model="form.phonePushSign"
                  disabled
                  style="position: relative; left: 33px; width: 40px"
                >
                </el-switch>
              </el-form-item>
            </div>
          </div>
        </div>
        <div style="margin-top: 22px">
          <el-form-item
            label-width="140px"
            label="节点审核状态:"
            prop="patientId"
          >
            <el-input
              v-model="form.routeCheckStatus"
              style="width: 226px"
              disabled
            />
          </el-form-item>
          <el-form-item
            label-width="140px"
            label="任务处理人姓名:"
            prop="patientId"
          >
            <el-input
              v-model="form.routeHandlePerson"
              style="width: 226px"
              disabled
            />
          </el-form-item>
          <el-form-item
            label-width="140px"
            label="节点审核人姓名:"
            prop="patientId"
          >
            <el-input
              v-model="form.routeCheckPerson"
              style="width: 226px"
              disabled
            />
          </el-form-item>
          <el-form-item
            label-width="140px"
            label="节点审核时间:"
            prop="patientId"
          >
            <el-input
              v-model="form.routeCheckDate"
              style="width: 226px"
              disabled
            />
          </el-form-item>
          <el-form-item
            label-width="140px"
            label="节点任务执行状态:"
            prop="nodeExecuteStatus"
          >
            <el-input
              v-model="form.nodeExecuteStatus"
              style="width: 226px"
              disabled
            />
          </el-form-item>
          <el-form-item
            label-width="140px"
            label="任务处理信息:"
            prop="routeHandleRemark"
          >
            <el-input
              disabled
              v-model="form.routeHandleRemark"
              style="width: 610px"
              type="textarea"
            />
          </el-form-item>
          <el-form-item label-width="140px" label="任务链接:" prop="routeLink">
            <el-input
              v-model="form.routeLink"
              style="width: 610px"
              type="textarea"
              disabled
            />
          </el-form-item>
          <el-form-item
            label-width="140px"
            label="节点审核备注信息:"
            prop="patientId"
          >
            <el-input
              label-width="140px"
              v-model="form.routeCheckRemark"
              style="width: 610px"
              type="textarea"
              disabled
            />
          </el-form-item>
          <el-form-item
            label-width="140px"
            label="备注信息:"
            prop="routeNodeRemark"
          >
            <el-input
              v-model="form.routeNodeRemark"
              style="width: 610px"
              type="textarea"
              disabled
            />
          </el-form-item>
        </div>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { listTaskPushRecord, getManageRouteNode, delTaskPushRecord, addTaskPushRecord, updateTaskPushRecord } from "@/api/system/taskPushRecord";

export default {
  name: "TaskPushRecord",
  data() {
    return {
      selectedOption: '', // 选中的选项值

      num: '',
      value1: true,
      options: [
        { value: 'PHONE_OUTBOUND', label: '电话外呼' },
        { value: 'QUESTIONNAIRE_SCALE', label: '问卷量表' },
        { value: 'PROPAGANDA_ARTICLE', label: '宣教文章' },
        { value: 'TEXT_REMIND', label: '文字提醒' },
        { value: 'ARTIFICIAL_FOLLOW_UP', label: '人工随访' },
      ],// 循环的数据源
      // 遮罩层
      // loading: false,
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 患者管理任务推送方式记录表格数据
      taskPushRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        patientId: null,
        manageRouteNodeId: null,
        patientName: null,
        routeNodeName: null,
        taskPushType: null,
        taskPushDate: null,
        taskPushRemark: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleChange(value) {
      console.log('选中的值：', value);
      this.form.taskType = value
      // 在这里可以处理选中值的变化，例如发送请求或更新数据等操作
    },
    /** 查询患者管理任务推送方式记录列表 */
    getList() {
      this.loading = true;
      listTaskPushRecord(this.queryParams).then(response => {
        this.taskPushRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        taskType: null,
        questionExpirationDate: undefined,
        routeCheckStatus: null,
        id: null,
        patientId: null,
        manageRouteNodeId: null,
        patientName: null,
        routeNodeName: null,
        taskPushType: null,
        taskPushDate: null,
        taskPushRemark: 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
    },
    // 详情按钮
    handledetails(row) {
      this.reset();
      console.log(this.form)

      const id = row.manageRouteNodeId || this.ids
      var obj = {
        manageRouteNodeId: id
      }
      getManageRouteNode(obj).then(response => {
        this.form = response.data;
        if (this.form.phoneMessageRemind == 'NOT_SEND_MESSAGE') {
          this.form.phoneMessageRemind = '不发送短信'
        } else if (this.form.phoneMessageRemind == 'NOT_CONNECTED_SEND_MESSAGE') {
          this.form.phoneMessageRemind = '未接通发短信'
        }
        else if (this.form.phoneMessageRemind == 'CONNECTED_SEND_MESSAGE') {
          this.form.phoneMessageRemind = '接通后发短信'
        }
        else if (this.form.phoneMessageRemind == 'EVERYONE_SEND_MESSAGE') {
          this.form.phoneMessageRemind = '所有人发短信'
        } else {
          this.form.phoneMessageRemind = ''

        }

        if (this.form.phoneRedialTimes == 'REDIAL_ONCE') {
          this.form.phoneRedialTimes = '重拨一次'
        }
        else if (this.form.phoneRedialTimes == 'REDIAL_TWICE') {
          this.form.phoneRedialTimes = '重拨二次'
        }
        else if (this.form.phoneRedialTimes == 'NOT_REPLAY') {
          this.form.phoneRedialTimes = '不重播'
        } else {
          this.form.phoneRedialTimes = ''
        }
        if (this.form.questionExpirationDate == null) {
          this.form.questionExpirationDate = undefined
        }
        // 短信
        if (this.form.messagePushSign == null || this.form.messagePushSign == 0) {
          this.form.messagePushSign = false
        } else if (this.form.messagePushSign == 1) {
          this.form.messagePushSign = true
        }
        // 公众号
        if (this.form.officialPushSign == null || this.form.officialPushSign == 0) {
          this.form.officialPushSign = false
        } else if (this.form.officialPushSign == 1) {
          this.form.officialPushSign = true
        }

        // 小程序
        if (this.form.appletPushSign == null || this.form.appletPushSign == 0) {
          this.form.appletPushSign = false
        } else if (this.form.appletPushSign == 1) {
          this.form.appletPushSign = true
        }
        // 电话

        if (this.form.phonePushSign == null || this.form.phonePushSign == 0) {
          this.form.phonePushSign = false
        } else if (this.form.phonePushSign == 1) {
          this.form.phonePushSign = true
        }
        // 节点审核

        if (this.form.routeCheckStatus == 'AGREE') {
          this.form.routeCheckStatus = '同意'
        } else if (this.form.routeCheckStatus == 'DISAGREE') {
          this.form.routeCheckStatus = '不同意'
        }


        if (this.form.nodeExecuteStatus == 'EXECUTED') {
          this.form.nodeExecuteStatus = '已执行'
        } else if (this.form.nodeExecuteStatus == 'UNEXECUTED') {
          this.form.nodeExecuteStatus = '未执行'
        }



        console.log(this.form)
        this.open = true;
        this.titleup = "详情";
      });
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTaskPushRecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTaskPushRecord(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
  }
};
</script>
<style lang="scss" scoped>
::v-deep .el-input.is-disabled .el-input__inner {
  background: #fff;
  color: #606266;
}
::v-deep .el-textarea.is-disabled .el-textarea__inner {
  color: #606266;
  background: #fff;
}
.top {
  width: 100%;
  border-bottom: 1px solid #dfe4ed;
}
.topitem {
  display: flex;
  width: 100%;
  border-bottom: 1px solid #dfe4ed;
  height: 64px;
  padding-top: 16px;
  .topswitch {
    position: absolute;
    right: 69px;
  }
}
</style>
