<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        ref="crud"
        :page="page"
        v-model="form"
        :data="tableData"
        :permission="permissionList"
        :table-loading="tableLoading"
        :option="tableOption"
        @on-load="getList"
        @search-change="searchChange"
        @size-change="sizeChange"
        @current-change="currentChange"
        @row-update="handleUpdate"
        @row-save="handleSave"
        @row-del="rowDel"
        @search-reset="searchReset"
        @refresh-change="refreshChange"
      >
        <template slot="createTimeSearch">
          <el-date-picker
            v-model="dateTime"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
            @change="startDateBtn"
            >
          </el-date-picker>
          <!-- <el-date-picker
            v-model="dateTime"
            type="date"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            placeholder="请选择提交时间"

          >
          </el-date-picker> -->
        </template>
        <template slot="menu" slot-scope="scope">
          <el-button
            v-if="scope.row.platAuditStatus == 1"
            :disabled="scope.row.platAuditStatus == 1"
            type="text"
            size="small"
            icon="el-icon-edit"
            @click="taskTj(scope.row, scope.index)"
            >已审核
          </el-button>

          <el-button
            v-if="scope.row.platAuditStatus != 1"
            type="text"
            size="small"
            icon="el-icon-edit"
            @click="taskTj(scope.row, scope.index)"
            >审核
          </el-button>
        </template>
      </avue-crud>
    </basic-container>

  </div>
</template>

<script>
import { fetchAuditList, approvalHospital, approvalDistribution, approvalPharmacy } from "@/api/wmtask";
import { tableOptionAuditCheck } from "@/const/crud/wmtask";
import { mapGetters } from "vuex";

export default {
  name: "wmtask",

  data() {
    return {
      form: {},
      searchForm: {},
      tableData: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 20, // 每页显示多少条
      },
      tableLoading: false,
      tableOption: tableOptionAuditCheck,
      toexamineForm: {},
      atypismData: [],
      wmTaskData: {},
      newInfoData: {},
      dateTime: "",
      startDate: "",
      endData:""
    };
  },
  created(){
      if(this.$route.query.current){
          let current = this.$route.query.current
          this.page.currentPage = Number(current)
      }
  },
  mounted() {

  },
  computed: {
    ...mapGetters(["permissions"]),
    permissionList() {},
  },

  methods: {
    getList(page, params) {
      this.tableLoading = true;
      console.log(1,page)
      console.log(2,this.page)
      fetchAuditList(
        Object.assign(
          {
            current: page.currentPage,
            size: page.pageSize,
          },
          params,
          this.searchForm
        )
      )
        .then((response) => {
          location.replace('/#/admin/wmtask/auditCheck')
          this.tableData = response.data.data.records;
          this.page.total = response.data.data.total;
          this.tableLoading = false;

        })
        .catch(() => {
          this.tableLoading = false;
        });

    },
    rowDel: function (row, index) {
      this.$confirm("是否确认删除ID为" + row.id, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delObj(row.id);
        })
        .then((data) => {
          this.$message.success("删除成功");
          this.getList(this.page);
        });
    },
    handleUpdate: function (row, index, done, loading) {
      row.address = this.addressKeyword;
      putObj(row)
        .then((data) => {
          this.$message.success("修改成功");
          done();
          this.getList(this.page);
        })
        .catch(() => {
          loading();
        });
    },
    handleSave: function (row, done, loading) {
      row.address = this.addressKeyword;
      addObj(row)
        .then((data) => {
          this.$message.success("添加成功");
          done();
          this.getList(this.page);
        })
        .catch(() => {
          loading();
        });
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    currentChange(current) {
      this.page.currentPage = current;
    },
    // 提交时间获取值
    startDateBtn(date,done){
      this.startDate = date[0],
      this.endData = date[1]
    },
    searchChange(form, done) {
      this.searchForm = form;
      this.searchForm.startDate = this.startDate;
      this.searchForm.endDate =  this.endData;
      this.page.currentPage = 1;
      this.getList(this.page, form);
      done();
    },
    searchReset(){
      this.dateTime = "";
      this.startDate = "";
      this.endData = "";
      this.searchForm = {};
    },
    refreshChange() {
      this.getList(this.page);
		},

		// 审核获取数据
    taskTj(row, index) {

      let arg = {
        taskId: row.id,
      };
      if("15"==row.taskTypeId||"30"==row.taskTypeId){
        // 审核-医院信息
            approvalHospital(arg).then(response => {
              if(response.data.code == "0"){

                this.atypismData = response.data.data.compareList;
                this.toexamineForm = response.data.data.info;
                this.toexamineForm.compareResult= response.data.data.wmTask.compareResult;
                this.wmTaskData = response.data.data.wmTask;
                this.newInfoData = response.data.data.newinfo;


                this.$router.push({ path: '/admin/wmdahospital/indexAudit',query:{
                  atypismData: this.atypismData,
                  toexamineForm: this.toexamineForm,
                  wmTaskData: this.wmTaskData,
                  newInfoData:  this.newInfoData,
                  current: this.page.currentPage,
                  arg: arg
                }})
              }else{
                this.$message.error(response.data.msg);
              }
              }).catch(() => {
                this.$message.error(response.data.msg);
              })

          }else if("16"==row.taskTypeId){
            // 审核-商业公司信息
            approvalDistribution(arg).then(response => {

              console.log(response.data)
              if(response.data.code == "0"){

                let businessInfo = {};
                let businessWmTask = {};
                let businessCompareList = [];
                let businessNewInfo ={};
                businessInfo = response.data.data.info;
                businessWmTask = response.data.data.wmTask;
                businessCompareList = response.data.data.compareList;
                businessNewInfo = response.data.data.newinfo;

                this.$router.push({ path: '/admin/wmdadistribution/indexAudit',query:{
                  businessInfo: businessInfo,
                  businessWmTask:businessWmTask,
                  businessCompareList:businessCompareList,
                  current: this.page.currentPage,
                  arg: arg,
                  businessNewInfo: businessNewInfo
                }})

              }else{
                this.$message.error(response.data.msg);
              }
            }).catch(() => {
              this.$message.error(response.data.msg);
            })

          }else{
            // 审核-药店信息
            approvalPharmacy(arg).then(response => {

              if(response.data.code == "0"){
                let pharmacyInfo = {};
                let pharmacyWmTask = {};
                let pharmacyNewInfo = {};
                pharmacyInfo = response.data.data.info;
                pharmacyInfo.compareResult = response.data.data.compareResult;

                pharmacyInfo.temp3 =  response.data.data.wmTask.temp3;
                pharmacyInfo.temp4 =  response.data.data.wmTask.temp4;
                pharmacyInfo.temp5 =  response.data.data.wmTask.temp5;
                pharmacyInfo.temp6 =  response.data.data.wmTask.temp6;
                pharmacyInfo.temp7 =  response.data.data.wmTask.temp7;
                pharmacyInfo.temp8 =  response.data.data.wmTask.temp8;
                pharmacyInfo.temp9 =  response.data.data.wmTask.temp9;
                pharmacyWmTask = response.data.data.wmTask;



                this.$router.push({ path: '/admin/wmdapharmacy/indexAudit',query:{
                  pharmacyInfo: pharmacyInfo,
                  pharmacyWmTask:pharmacyWmTask,
                  current: this.page.currentPage,
                  arg: arg,

                }})

              }else{
                this.$message.error(response.data.msg);
              }

            }).catch(() => {
              this.$message.error(response.data.msg);
            })
          }


        // if("15"==row.taskTypeId)
        // {
        //   this.$router.push({ path: '/admin/wmdahospital/indexAudit?taskId='+row.id+'&taskUser='+row.$taskUserId+'&date='+ row.createTime+'&phone='+row.$updateUser})
        // }
        // if("18"==row.taskTypeId){
        //   this.$router.push({ path: '/admin/wmdapharmacy/indexAudit?updateUser='+row.id+'&taskId='+row.id+'&taskUser='+row.$taskUserId+'&date='+ row.createTime+'&phone='+row.$updateUser})
        // }

        // if("16"==row.taskTypeId){
        //   this.$router.push({ path: '/admin/wmdadistribution/indexAudit?taskId='+row.id+'&taskUser='+row.$taskUserId+'&date='+ row.createTime+'&phone='+row.$updateUser})
        // }
    }
  }
};
</script>

<style lang="scss" scoped>
.title {
  width: 100%;
  height: 20px;
  line-height: 20px;
  border-bottom: 1px solid black;
  margin-bottom: 20px;
}
.atypismStyle {
  margin-bottom: 10px;
}
</style>
