<template>
  <div class="execution" style="margin-bottom: 200px;">
    <basic-container>
      <avue-crud
        ref="crud"
        :page="page"
        v-model="form"
        :data="tableData"
        :table-loading="tableLoading"
        :option="tableOption"
        @on-load="getList"
        @search-change="searchChange"
        @refresh-change="refreshChange"
        @size-change="sizeChange"
        @current-change="currentChange"
      >
        <template slot="menuLeft">
          <el-button type="primary" @click="back()">返回</el-button>
        </template>
        <template slot="menu" slot-scope="scope">
          <el-button type="text" size="small" icon="el-icon-edit" @click="showTaskInfo(scope.row, scope.index)">查看详情 </el-button>
        </template>
      </avue-crud>
      <el-dialog title="任务详情" :visible.sync="dialogView" width="30%" center :before-close="handleClose">
        <el-form :model="taskForm" ref="taskForm" label-width="100px" class="demo-ruleForm">
          <el-form-item label="任务类型" prop="taskTypeId">
            <el-input v-model="taskForm.task_type_name" :disabled="true"></el-input>
          </el-form-item>

          <el-form-item label="前端系统" v-if="this.taskForm.taskTypeId != 22 && this.taskForm.taskTypeId != 24">
            <el-input v-model="taskForm.temp1" :disabled="true"></el-input>
          </el-form-item>

          <el-form-item label="项目名称" v-if="this.taskForm.taskTypeId != 22 && this.taskForm.taskTypeId != 24">
            <el-input v-model="taskForm.temp2" :disabled="true"></el-input>
          </el-form-item>

          <el-form-item label="项目编码" v-if="this.taskForm.taskTypeId != 22 && this.taskForm.taskTypeId != 24">
            <el-input v-model="taskForm.temp3" :disabled="true"></el-input>
          </el-form-item>

          <el-form-item label="说明" v-if="this.taskForm.taskTypeId != 22 && this.taskForm.taskTypeId != 24">
            <el-input v-model="taskForm.temp4" :disabled="true"></el-input>
          </el-form-item>

          <el-form-item label="工作系统" v-if="this.taskForm.taskTypeId == 22 || this.taskForm.taskTypeId == 24">
            <el-input v-model="taskForm.temp1" :disabled="true"></el-input>
          </el-form-item>

          <el-form-item label="受试者编号" v-if="this.taskForm.taskTypeId == 22 || this.taskForm.taskTypeId == 24">
            <el-input v-model="taskForm.temp2" :disabled="true"></el-input>
          </el-form-item>

          <el-form-item label="项目编号" v-if="this.taskForm.taskTypeId == 22 || this.taskForm.taskTypeId == 24">
            <el-input v-model="taskForm.temp3" :disabled="true"></el-input>
          </el-form-item>

          <el-form-item label="上传日期" v-if="this.taskForm.taskTypeId == 22 || this.taskForm.taskTypeId == 24">
            <el-date-picker v-model="taskForm.temp8" class="w100" type="date" :disabled="true"> </el-date-picker>
          </el-form-item>

          <el-form-item label="访视阶段" v-if="this.taskForm.taskTypeId == 22 || this.taskForm.taskTypeId == 24">
            <el-input v-model="taskForm.temp4" :disabled="true"></el-input>
          </el-form-item>

          <el-form-item label="审核状态" v-if="this.taskForm.taskTypeId == 22 || this.taskForm.taskTypeId == 24">
            <el-input v-model="taskForm.temp5" :disabled="true"></el-input>
          </el-form-item>

          <el-form-item label="审核通过日期" v-if="this.taskForm.taskTypeId == 22 || this.taskForm.taskTypeId == 24">
            <el-date-picker v-model="taskForm.temp7" class="w100" type="date" :disabled="true"> </el-date-picker>
          </el-form-item>

          <el-form-item label="备注" v-if="this.taskForm.taskTypeId == 22 || this.taskForm.taskTypeId == 24">
            <el-input v-model="taskForm.temp6" :disabled="true"></el-input>
          </el-form-item>
        </el-form>

        <span slot="footer" class="dialog-footer">
          <el-button @click="cancelBtn()">关 闭</el-button>
        </span>
      </el-dialog>
      <!-- 患者教育查看 -->
      <patientEduViewDialog v-if="patientEduViewShow" :showDialog="patientEduViewShow" :dialogType="'view'" :rowData="patientEduViewForm" @handleClose="patientEduViewCloseClose" />
    </basic-container>
  </div>
</template>

<script>
import {getTaskList, getTaskInfo} from '@/api/h5';
import {tableOption} from '@/const/crud/admin/h5Task';
import Config from '@/settings';
import patientEduViewDialog from '@/views/admin/specialTask/patientEdu/components/addDialog';

export default {
  name: 'wmtask',
  data() {
    return {
      map: null,
      dialogView: false,
      getAddress: null,
      getAddCode: null,
      addressKeyword: '',
      shopInfo: {
        lng: null,
        lat: null
      },
      form: {},
      taskForm: {},
      searchForm: {},
      tableData: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      tableLoading: false,
      tableOption: tableOption,
      patientEduViewShow: false,
      patientEduViewForm: {}
    };
  },
  methods: {
    getList(page, params) {
      if (undefined == this.$route.query.id) {
        this.$message.error('积分包名称不能为空');
        return false;
      }
      this.searchForm.id = this.$route.query.id;
      this.searchForm.taskUserId = this.$route.query.userId;
      this.tableLoading = true;

      getTaskList(
        Object.assign(
          {
            current: page.currentPage,
            size: page.pageSize
          },
          params,
          this.searchForm
        )
      )
        .then(response => {
          this.tableData = response.data.data.records;
          this.page.total = response.data.data.total;
          this.tableLoading = false;
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    currentChange(current) {
      this.page.currentPage = current;
    },
    searchChange(form, done) {
      this.searchForm = form;
      this.page.currentPage = 1;
      this.getList(this.page, form);
      done();
    },
    refreshChange() {
      this.getList(this.page);
    },
    cancelBtn() {
      this.taskForm = {};
      this.dialogView = false;
    },
    handleClose() {
      this.taskForm = {};
      this.dialogView = false;
    },
    showTaskInfo(row, index) {
      if (row.type1 === '5') {
        // 患者教育
        getTaskInfo({taskId: row.id})
          .then(response => {
            this.patientEduViewForm = response.data.data.wmTaskContent;
            this.patientEduViewShow = true;
          })
          .catch(() => {});
        return;
      }
      if (row.type == '2') {
        getTaskInfo({taskId: row.id})
          .then(response => {
            this.taskForm = response.data.data.wmTaskContent;
            this.taskForm.taskTypeId = response.data.data.taskTypeId;
            this.taskForm.task_type_name = row.task_type_name;
            // this.taskForm.taskTypeId = this.taskTypeList1[0].taskTypeId;
            this.dialogView = true;
          })
          .catch(() => {});
      } else {
        window.open(
          Config.outsideUrl + '/h5/#/pages/task/task-detail/index?id=' + row.id,
          'newwindow',
          'height=750, width=400, top=200, left=300, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no'
        );
      }
    },
    back() {
      this.$router.go(-1);
    },
    patientEduViewCloseClose() {
      this.patientEduViewShow = false;
    }
  },
  components: {
    patientEduViewDialog
  }
};
</script>
