<template>
  <div>
    <el-dialog
      title="透析上机"
      class="newDialog"
      :visible.sync="visible"
      width="854px"
      :modal-append-to-body="false"
    >
      <div class="warnTxt" v-if="showTxt != ''">{{ showTxt }}</div>

      <multi-select-box
        :propsForm="InnerDialogProps"
        v-on:dialog-comfirm="innerDialogComfirm"
        v-on:dialog-cancle="innerDialogCancle"
      ></multi-select-box>

      <el-form :model="form" ref="form" label-width="100px">
        <el-form-item
          label="班次"
          v-if="isShowFiled('班次')"
          :prop="isName('班次')"
          :rules="isCheckmust('班次')"
        >
          <el-select
            v-model="form.schedual_type"
            placeholder="请选择班次"
            @change="changeSchedualType"
          >
            <el-option
              v-for="(item, index) in schedules_type"
              :key="index"
              :value="item.id"
              :label="item.name"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item
          label="上机床位"
          v-if="isShowFiled('上机床位')"
          :prop="isName('上机床位')"
          :rules="isCheckmust('上机床位')"
        >
          <el-select v-model="form.bed_id" placeholder="请选择上机床位">
            <el-option
              v-for="(bed, index) in zone_beds"
              :key="index"
              :value="bed.id"
              :label="bed.number"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="上机护士"
          v-if="isShowFiled('上机护士')"
          prop="nurse_id"
          :rules="isCheckmust('上机护士')"
        >
          <el-select v-model="form.nurse_id" placeholder="请选择上机护士">
            <el-option
              v-for="(admin, index) in adminRoles"
              :key="index"
              :value="admin.id"
              :label="admin.name"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="穿刺者"
          v-if="isShowFiled('穿刺者')"
          prop="puncture_nurse_id"
          :rules="isCheckmust('穿刺者')"
        >
          <el-select
            v-model="form.puncture_nurse_id"
            placeholder="请选择穿刺护士"
          >
            <el-option
              v-for="(admin, index) in adminRoles"
              :key="index"
              :value="admin.id"
              :label="admin.name"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item
          label="质控护士"
          v-if="isShowFiled('质控护士')"
          prop="quality_nurse_id"
          :rules="isCheckmust('质控护士')"
        >
        <!--  -->
          <el-select
            v-model="form.quality_nurse_id"
            placeholder="请选择质控护士"
          >
            <el-option
              v-for="(admin, index) in adminRoles"
              :key="index"
              :value="admin.id"
              :label="admin.name"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item
          label="换药护士"
          v-if="isShowFiled('换药护士')"
          :prop="isName('换药护士')"
          :rules="isCheckmust('换药护士')"
        >
        <!--  -->
          <el-select v-model="form.change_nurse" placeholder="请选择换药护士">
            <el-option
              v-for="(admin, index) in adminRoles"
              :key="index"
              :value="admin.id"
              :label="admin.name"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item
          label="冲管护士"
          v-if="isShowFiled('冲管护士')"
          :prop="isName('冲管护士')"
          :rules="isCheckmust('冲管护士')"
        >
          <el-select v-model="form.washpipe_nurse" placeholder="请选择冲管护士">
            <el-option
              v-for="(admin, index) in adminRoles"
              :key="index"
              :value="admin.id"
              :label="admin.name"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item
          label="疑难穿刺护士"
          v-if="isShowFiled('疑难穿刺护士')"
          :prop="isName('疑难穿刺护士')"
          :rules="isCheckmust('疑难穿刺护士')"
        >
          <el-select
            v-model="form.difficult_puncture_nurse"
            placeholder="请选择疑难穿刺护士"
          >
            <el-option
              v-for="(admin, index) in adminRoles"
              :key="index"
              :value="admin.id"
              :label="admin.name"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item
          label="新开瘘护士"
          v-if="isShowFiled('新开瘘护士')"
          :prop="isName('新开瘘护士')"
          :rules="isCheckmust('新开瘘护士')"
        >
          <el-select
            v-model="form.new_fistula_nurse"
            placeholder="请选择新开瘘护士"
          >
            <el-option
              v-for="(admin, index) in adminRoles"
              :key="index"
              :value="admin.id"
              :label="admin.name"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item
          label="引血(ml/min)"
          v-if="isShowFiled('引血')"
          :prop="isName('引血')"
          :rules="isCheckmust('引血')"
        >
          <el-input
            type="number"
            v-model="form.blood_drawing"
            style="width: 200px"
          ></el-input>
        </el-form-item>

        <el-form-item
          label="穿刺针"
          v-if="isShowFiled('穿刺针')"
          :prop="isName('穿刺针')"
          :rules="isCheckmust('穿刺针')"
        >
          <el-input
            v-model="form.puncture_needle"
            @focus="showInnerDialog('11')"
            style="width: 200px"
          ></el-input>
        </el-form-item>

        <el-form-item
          label="穿刺方式： "
          v-if="isShowFiled('穿刺方式')"
          :prop="isName('穿刺方式')"
          :rules="isCheckmust('穿刺方式')"
        >
          <el-input
            v-model="form.puncture_way"
            readonly
            style="width: 200px"
            @focus="showInnerDialog('13')"
          >
          </el-input>
        </el-form-item>

        <el-form-item
          label="透析器:"
          v-if="isShowFiled('透析器')"
          :prop="isName('透析器')"
          :rules="isCheckmust('透析器')"
        >
          <el-input
            v-model="form.dialysis_dialyszers"
            style="width: 200px"
            @focus="showInnerDialog('7')"
          ></el-input>
        </el-form-item>

        <el-form-item
          label="灌流器:"
          v-if="isShowFiled('灌流器')"
          :prop="isName('灌流器')"
          :rules="isCheckmust('灌流器')"
        >
          <el-input
            v-model="form.dialysis_irrigation"
            style="width: 200px"
            @focus="showInnerDialog('8')"
          ></el-input>
        </el-form-item>

        <el-form-item
          label="血管通路："
          v-if="isShowFiled('血管通路')"
          prop="blood_access_id"
          :rules="isCheckmust('血管通路')"
        >
          <el-select v-model="form.blood_access_id" placeholder="请选择" @change="changeBloodAccessOpion">
            <el-option :key="0" label="请选择" :value="0"></el-option>
            <el-option
              v-for="(option, index) in blood_access_option"
              :key="index + 'i'"
              :label="option.name"
              :value="option.id"
            ></el-option>
          </el-select>
        </el-form-item>

       
          <el-form-item
            label="导管备注："
            :prop="isName('导管备注')"
            :rules="isCheckmust('导管备注')"
            v-if="isShowFiled('导管备注') && blood_access_option_name!=undefined&&blood_access_option_name.indexOf('置管') !== -1"
          >
            <el-select @change="dialysisSummarySelectChange" v-model="value2">
              <el-option
                v-for="(item, index) in summary"
                :label="item.text"
                :value="item.value"
                :key="index"
              ></el-option>
            </el-select>
          </el-form-item>
       
    
          <el-form-item
            :prop="isName('导管备注')"
            :rules="isCheckmust('导管备注')"
            v-if="isShowFiled('导管备注') && blood_access_option_name!=undefined&&blood_access_option_name.indexOf('置管') !== -1"
          >
            <el-input
              type="textarea"
              v-model="form.catheter_operation"
              :rows="4"
            ></el-input>
          </el-form-item>
    

        <el-form-item
          label="核酸检测日期:"
          style="width: 300px"
          :prop="isName('核酸检测日期')"
          :rules="isCheckmust('核酸检测日期')"
          v-if="isShowFiled('核酸检测日期')"
        >
          <el-date-picker
            type="date"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            placeholder="选择时间"
            v-model="form.nuclein_date"
            style="width: 100%"
          ></el-date-picker>
        </el-form-item>

        <el-form-item
          label="上机时间 :"
          style="width: 300px"
          :prop="isName('上机时间')"
          :rules="isCheckmust('上机时间')"
          v-if="isShowFiled('上机时间')"
        >
          <el-date-picker
            type="datetime"
            format="yyyy-MM-dd HH:mm"
            value-format="yyyy-MM-dd HH:mm"
            placeholder="选择时间"
            v-model="form.start_time"
            style="width: 100%"
          ></el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button
            v-if="dialysis_order.id == 0"
            @click="submit('form')"
            type="primary"
            :loading="loading"
            >执行上机</el-button
          >
          <el-button v-else type="info" :disabled="true">已上机</el-button>
          <el-button
            v-if="dialysis_order.id > 0"
            type="primary"
            @click="editOrder('form')"
            >修改上机
          </el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  

     <el-dialog
          title="提示"
          :visible.sync="infoDialogVisible"
          width="30%">
          <span>
           <el-form>
             <el-row>
               <span>申请日期:</span>
                <span>
                    <el-date-picker
                      type="datetime"
                      format="yyyy-MM-dd HH:mm"
                      value-format="yyyy-MM-dd HH:mm"
                      placeholder="选择时间"
                      v-model="selected_date"
                  ></el-date-picker>
                </span>
             </el-row>
             <el-row>
               <span>备注:</span>
                <span>
                   <el-input v-model="remark" style="width:200px"></el-input>
                </span>
             </el-row>
           </el-form>
         
          </span>
          <span slot="footer" class="dialog-footer">
            <el-button @click="infoDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="saveInformation">确 定</el-button>
          </span>
        </el-dialog>

  </div>
</template>

<script>
import axios from "axios";
import {
  GetSchedualNumber,
  PostModifyStartDialysis,
  startDialysis,
} from "@/api/dialysis_record";
  import { saveInformation } from '@/api/dialysis'
import { uParseTime } from "@/utils/tools";
import { getDataConfig } from "@/utils/data";
import { parseTime } from "@/utils";
import store from "@/store";
import multiSelectBox from "./MultiSelectBox";
import request from "@/utils/request";
const moment = require("moment");
export default {
  name: "ComputerDialog",
  components: {
    multiSelectBox,
  },
  data() {
    return {
      showTxt: "",
      hasPermission: true,
      zone_beds: [],
      visible: false,
      loading: false,
      template_id: 0,
      patient_id: 0,
      schedule_date: 0,
      start_time: 0,
      creator: 0,
      form: {
        washpipe_nurse: "",
        bed_id: "",
        nurse_id: "",
        start_time: "",
        puncture_nurse_id: "",
        blood_drawing: 100,
        change_nurse: "",
        difficult_puncture_nurse: "",
        new_fistula_nurse: "",
        quality_nurse_id: "",
        puncture_needle: "",
        puncture_way: "",
        dialysis_dialyszers: "",
        dialysis_irrigation: "",
        blood_access_id: "",
        nuclein_date: moment(new Date()).add("year", 0).format("YYYY-MM-DD"),
        catheter_operation:""
      },
      blood_access_option: [],
      schedual_type: 0,
      schedules_type: [
        { id: 1, name: "上午" },
        { id: 2, name: "下午" },
        { id: 3, name: "晚上" },
      ], // 该排班的区里的床位
      isPremission: false,
      adminRoles: [{ id: 0, name: "请选择" }],
      org_id: 0,
      punctureNeedleOptions: [],
      puncture_ways: [],
      InnerDialogProps: {
        values: [],
        visibility: false,
        isShowTextArea: true,
        customContent: "",
        titles: "",
        type: "", // 不同弹框类型，用来匹配数据
      },
      dialyzers: [],
      irrigations: [],
      summary:[],
      blood_access_option_name:"",
      value2:"",
      infoDialogVisible:false,
      selected_date:"",
      remark:""
    };
  },
  props: {
    dialysis_order: {
      type: Object,
    },
    schedule: {
      type: Object,
    },
    admins: {
      type: Array,
    },
    device_numbers: {
      type: Array,
    },
    special_premission: {
      type: Array,
    },
    patient: {
      type: Object,
    },
    stockType: {
      type: Array,
      default: () => {
        return [];
      },
    },
    lastOrder: {
      type: Object,
    },
  },
  mounted() {},
  created() {
    this.template_id = this.$store.getters.xt_user.template_info.template_id;
    this.org_id = this.$store.getters.xt_user.template_info.org_id;
    this.patient_id = this.$route.query.patient_id;
    this.schedule_date = this.$route.query.date;
    this.form.nurse_id =
      this.dialysis_order.id == 0
        ? this.$store.getters.xt_user.user.id
        : this.dialysis_order.start_nurse;
    this.form.puncture_nurse_id =
      this.dialysis_order.id == 0
        ? this.$store.getters.xt_user.user.id
        : this.dialysis_order.puncture_nurse;
    this.form.washpipe_nurse =
      this.dialysis_order.id == 0
        ? this.$store.getters.xt_user.user.id
        : this.dialysis_order.washpipe_nurse;

    if (this.form.puncture_nurse_id == 0) {
      this.form.puncture_nurse_id = this.$store.getters.xt_user.user.id;
    }

    if (this.form.change_nurse == 0) {
      this.form.change_nurse = this.$store.getters.xt_user.user.id;
    }

    if (this.form.washpipe_nurse == 0) {
      this.form.washpipe_nurse = this.$store.getters.xt_user.user.id;
    }
    if (this.form.difficult_puncture_nurse == 0) {
      this.form.difficult_puncture_nurse = this.$store.getters.xt_user.user.id;
    }
    if (this.form.new_fistula_nurse == 0) {
      this.form.new_fistula_nurse = this.$store.getters.xt_user.user.id;
    }
    // console.log("dialysis_order9999999999wo", this.dialysis_order);
    this.form.puncture_needle = this.dialysis_order.puncture_needle;
    this.form.puncture_way = this.dialysis_order.puncture_way;
    this.form.dialysis_dialyszers = this.dialysis_order.dialysis_dialyszers;
    this.form.dialysis_irrigation = this.dialysis_order.dialysis_irrigation;
    this.form.blood_access_id = this.dialysis_order.blood_access_id;
    this.blood_access_option_name = this.changeBloodAccessOpion(this.dialysis_order.blood_access_id)
    // this.form.schedual_type = this.dialysis_order.schedule_type
    // this.schedual_type = this.dialysis_order.schedule_type
    // console.log("班次",this.form.schedual_type)
    this.punctureNeedleOptions = getDataConfig(
      "hemodialysis",
      "puncture_needle"
    );
    this.puncture_ways = getDataConfig("hemodialysis", "puncture_method");
    this.blood_access_option = getDataConfig(
      "hemodialysis",
      "vascular_access_desc"
    );
    this.summary = getDataConfig('catheter_operation', 'catheter_operation')
  },
  watch: {
    patient: {
      handler(newVal) {
        this.patient_id = newVal.id;
      },
      deep: true,
    },
    "schedule.id": function () {},
    "dialysis_order.id": function () {
      this.form.nurse_id =
        this.dialysis_order.id == 0
          ? this.$store.getters.xt_user.user.id
          : this.dialysis_order.start_nurse;
      this.form.puncture_nurse_id =
        this.dialysis_order.id == 0
          ? this.$store.getters.xt_user.user.id
          : this.dialysis_order.puncture_nurse;
      this.form.washpipe_nurse =
        this.dialysis_order.id == 0
          ? this.$store.getters.xt_user.user.id
          : this.dialysis_order.washpipe_nurse;
      this.form.change_nurse =
        this.dialysis_order.id == 0
          ? this.$store.getters.xt_user.user.id
          : this.dialysis_order.change_nurse;
      this.form.difficult_puncture_nurse =
        this.dialysis_order.id == 0
          ? this.$store.getters.xt_user.user.id
          : this.dialysis_order.difficult_puncture_nurse;
      this.form.new_fistula_nurse =
        this.dialysis_order.id == 0
          ? this.$store.getters.xt_user.user.id
          : this.dialysis_order.new_fistula_nurse;
      this.form.quality_nurse_id =
        this.dialysis_order.id == 0
          ? this.$store.getters.xt_user.user.id
          : this.dialysis_order.quality_nurse_id;
      this.form.puncture_needle = this.dialysis_order.puncture_needle;
      this.form.puncture_way = this.dialysis_order.puncture_way;
      this.form.dialysis_dialyszers = this.dialysis_order.dialysis_dialyszers;
      this.form.dialysis_irrigation = this.dialysis_order.dialysis_irrigation;
      this.form.blood_access_id = this.dialysis_order.blood_access_id;
     
      var blood_access_option_name = this.changeBloodAccessOpionOne(this.dialysis_order.blood_access_id)
      // this.form.schedual_type = this.dialysis_order.schedule_type
      // console.log("8823832323223",this.form.schedual_type)
      this.blood_access_option_name = blood_access_option_name
      this.form.catheter_operation = this.dialysis_order.catheter_operation
      this.form.nuclein_date =
        this.dialysis_order.id == 0
          ? this.getTimeOne(this.lastOrder.nuclein_date)
          : this.getTimeOne(this.dialysis_order.nuclein_date);
      var nowDate = new Date();
      var nowYear = nowDate.getFullYear();
      var nowMonth = nowDate.getMonth() + 1;
      var nowDay = nowDate.getDate();
      var nowHours = nowDate.getHours();
      var nowMinutes = nowDate.getMinutes();
      var nowSeconds = nowDate.getSeconds();
      var time =
        nowYear +
        "-" +
        (nowMonth < 10 ? "0" + nowMonth : nowMonth) +
        "-" +
        (nowDay < 10 ? "0" + nowDay : nowDay) +
        " " +
        (nowHours < 10 ? "0" + nowHours : nowHours) +
        ":" +
        (nowMinutes < 10 ? "0" + nowMinutes : nowMinutes);
      this.form.start_time =
        this.dialysis_order.id == 0
          ? time
          : this.getTime(this.dialysis_order.start_time, "{y}-{m}-{d} {h}:{i}");
    },
    admins: function () {
      // console.log("admins", this.admins);
      if (this.admins.length > 0) {
        for (let i = 0; i < this.admins.length; i++) {
          if(this.admins[i].status == 1){
            this.adminRoles.push(this.admins[i]);
          }
        }
      }
     console.log("人员", this.adminRoles);
    },
    stockType: function () {
      console.log("stockType", this.stockType);
      var arr = [];
      var arrTwo = [];
      for (let i = 0; i < this.stockType.length; i++) {
        if (this.stockType[i].stock_attribute == 2) {
          arr.push(this.stockType[i]);
        }
        if (this.stockType[i].stock_attribute == 3) {
          arrTwo.push(this.stockType[i]);
        }
      }
      var dialyzator = [];
      var irrigation = [];
      for (let i = 0; i < arr.length; i++) {
        for (let j = 0; j < arr[i].GoodInfo.length; j++) {
          dialyzator.push(arr[i].GoodInfo[j]);
        }
      }
      this.dialyzers = dialyzator;

      for (let i = 0; i < arrTwo.length; i++) {
        for (let j = 0; j < arrTwo[i].GoodInfo.length; j++) {
          irrigation.push(arrTwo[i].GoodInfo[j]);
        }
      }
      this.irrigations = irrigation;
    },
  },
  computed: {},
  methods: {
    isName(name) {
      let filedList = store.getters.xt_user.fileds;
      for (let i = 0; i < filedList.length; i++) {
        if (filedList[i].module == 7 && filedList[i].filed_name_cn == name) {
          return filedList[i].filed_name;
        }
      }
    },

    isCheckmust(name) {
      let filedList = store.getters.xt_user.fileds;
      for (let i = 0; i < filedList.length; i++) {
        if (
          filedList[i].module == 7 &&
          filedList[i].filed_name_cn == name &&
          filedList[i].is_show == 1&&
          filedList[i].is_write == 1
        ) {
          if (
          name == "穿刺者" ||
          name == "质控护士" ||
          name == "换药护士" ||
          name == "血管通路" 
        ) {
          
          return [
            { required: true, message: `请输入${name}`,trigger: ['blur','change'] },
            { required: true, pattern: /^[1-9]\d*$/, message: `请输入${name}`,trigger: ['blur','change'] },
          ];
        }
          return [{ required: true, message: `请输入${name}` }];
        } 
                

      }
    },
    isShowFiled(name) {
      var filedList = store.getters.xt_user.fileds;
      for (let i = 0; i < filedList.length; i++) {
        if (
          filedList[i].module == 7 &&
          filedList[i].filed_name_cn == name &&
          filedList[i].is_show == 1
        ) {
          return true;
        }
      }
      return false;
    },
    changeSchedualType: function (schedual_type) {
      let ParamsQuery = {};
      ParamsQuery["schedual_type"] = schedual_type;
      ParamsQuery["record_date"] = this.$route.query.date;
      GetSchedualNumber(ParamsQuery).then((response) => {
        if (response.data.state == 0) {
          return false;
        } else {
          this.temp_device_numbers = response.data.data.number;
          for (
            let index = 0;
            index < this.temp_device_numbers.length;
            index++
          ) {
            const device_number = this.temp_device_numbers[index];
            this.temp_device_numbers[index]["number"] =
              device_number["zone_name"] + "-" + device_number["number"];
          }
          this.zone_beds = this.temp_device_numbers;
          this.form.bed_id = this.zone_beds[0].id;
        }
      });
    },
    GetSchedualNumber: function () {
      let ParamsQuery = {};
      ParamsQuery["schedual_type"] = this.schedual_type;
      ParamsQuery["record_date"] = this.$route.query.date;
      console.log("列表33333333333333333333", ParamsQuery);
      // console.log("路由",this.$route.query.date)

      GetSchedualNumber(ParamsQuery).then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg);
          return false;
        } else {
          this.temp_device_numbers = response.data.data.number;
          for (
            let index = 0;
            index < this.temp_device_numbers.length;
            index++
          ) {
            const device_number = this.temp_device_numbers[index];
            this.temp_device_numbers[index]["number"] =
              device_number["zone_name"] + "-" + device_number["number"];
          }
          this.zone_beds = this.temp_device_numbers;

          this.form.bed_id =
            this.dialysis_order.id == 0
              ? this.schedule.bed_id
              : this.dialysis_order.bed_id;
          if (this.dialysis_order.id == 0) {
            let isFilter = true;
            for (let i = 0; i < this.zone_beds.length; i++) {
              if (this.zone_beds[i].id == this.schedule.bed_id) {
                isFilter = false;
              }
            }
            if (isFilter) {
              this.form.bed_id = this.zone_beds[0].id;
            }
          } else {
            for (let i = 0; i < this.device_numbers.length; i++) {
              if (this.device_numbers[i].id == this.dialysis_order.bed_id) {
                let obj = {};
                obj = this.device_numbers[i];
                if (
                  obj["number"].indexOf(this.device_numbers[i]["zone_name"]) ==
                  -1
                ) {
                  obj["number"] =
                    this.device_numbers[i]["zone_name"] +
                    "-" +
                    this.device_numbers[i]["number"];
                }
                this.zone_beds.unshift(obj);
                this.zone_beds.sort((a, b) => a.id - b.id);
              }
            }
          }
        }
      });
    },
    getTime(value, temp) {
      if (value != undefined) {
        return parseTime(value, temp);
      }
      return "";
    },
    getTimeOne(val) {
      if (val == "") {
        return "";
      } else {
        return uParseTime(val, "{y}-{m}-{d}");
      }
    },
    show: function (dialysis, lastOrder) {
      this.record = dialysis;

      this.getPermission();
      this.visible = true;

      var nowDate = new Date();
      var nowYear = nowDate.getFullYear();
      var nowMonth = nowDate.getMonth() + 1;
      var nowDay = nowDate.getDate();
      var nowHours = nowDate.getHours();
      var nowMinutes = nowDate.getMinutes();
      var nowSeconds = nowDate.getSeconds();
      this.form.nuclein_date =
        this.dialysis_order.id == 0
          ? this.getTimeOne(lastOrder.nuclein_date)
          : this.getTimeOne(this.dialysis_order.nuclein_date);
      if (this.dialysis_order.id != 0) {
        this.form.start_time = this.getTime(
          this.dialysis_order.start_time,
          "{y}-{m}-{d} {h}:{i}"
        );
      } else {
        this.form.start_time =
          nowYear +
          "-" +
          (nowMonth < 10 ? "0" + nowMonth : nowMonth) +
          "-" +
          (nowDay < 10 ? "0" + nowDay : nowDay) +
          " " +
          (nowHours < 10 ? "0" + nowHours : nowHours) +
          ":" +
          (nowMinutes < 10 ? "0" + nowMinutes : nowMinutes);
      }
      console.log("hhahhahahahaha",this.dialysis_order)
      if (this.dialysis_order.id == 0) {
        let now = new Date();
        let hour = now.getHours();
        if (hour >= 6 && hour < 12) {
          this.schedual_type = 1;
        } else if (hour >= 12 && hour < 18) {
          this.schedual_type = 2;
        } else if (hour >= 18) {
          this.schedual_type = 3;
        }
      } else {
        this.form.schedual_type = this.dialysis_order.schedual_type;
        this.schedual_type = this.dialysis_order.schedual_type;
      }

      if (this.dialysis_order.id > 0) {
        if (this.dialysis_order.creator == 0) {
          this.creator = this.dialysis_order.start_nurse;
        } else {
          this.creator = this.dialysis_order.creator;
        }
      }

      this.GetSchedualNumber();
    },
    hide: function () {
      this.visible = false;
    },
    submit: function (formName) {
      console.log(this.form,'this.form')
      this.$refs.form.validate((valid) => {
        if (valid) {
          if (this.form.start_time == "" || this.form.start_time == null) {
            this.$message.error("开始时间不能为空");
            return;
          }
          console.log(this.dialysis_order);
          this.loading = true;
          let mode = "1";
          var blood_drawing = this.form.blood_drawing.toString();
          console.log("质控护士", this.form.quality_nurse_id);
          console.log("this.form.nuclein_date", this.form.nuclein_date);

          startDialysis(
            this.patient_id,
            this.schedule_date
              ? parseTime(this.schedule_date, "{y}-{m}-{d}")
              : parseTime(new Date(), "{y}-{m}-{d}"),
            this.form.nurse_id,
            this.form.bed_id,
            this.form.lood_drawing,
            this.form.puncture_nurse_id,
            this.form.start_time,
            this.schedual_type,
            mode,
            this.form.washpipe_nurse,
            this.form.change_nurse,
            this.form.difficult_puncture_nurse,
            this.form.new_fistula_nurse,
            blood_drawing,
            this.form.quality_nurse_id,
            this.form.puncture_needle,
            this.form.puncture_way,
            this.form.dialysis_dialyszers,
            this.form.dialysis_irrigation,
            this.form.blood_access_id,
            this.form.nuclein_date,
            this.form.catheter_operation
          ).then((rs) => {
            this.loading = false;
            var resp = rs.data;
            if (resp.state == 1) {
              var resp_dialysis_order = resp.data.dialysis_order;
              var this_order = this.dialysis_order;
              for (const key in resp_dialysis_order) {
                this.$set(this_order, key, resp_dialysis_order[key]);
              }
              let orgId = parseInt(sessionStorage.getItem("org_id"));
              // axios.get('/api/index/uppatient?org_id='+ orgId + '&admin_user_id='+ this.form.nurse_id + '&patient_id=' + this.patient_id + '&up_time=' + (new Date(this.form.start_time).getTime() / 1000)).then((res) => {
              //   console.log('res',res.data)

              // })
              this.hide();
              this.$emit("monitor", resp.data.monitor);
              this.$message.success("上机成功");
            } else {

              this.$message.error(resp.msg);
              if(resp.code == 600000008){
                this.infoDialogVisible = true
              }
            }
          });
        } else {
          return false;
        }
      });
    },
    editOrder() {
      let ParamsQuery = {};
      ParamsQuery["schedual_type"] = this.schedual_type;
      ParamsQuery["id"] = this.dialysis_order.id;
      ParamsQuery["nurse"] = this.form.nurse_id;
      ParamsQuery["bed"] = this.form.bed_id;
      ParamsQuery["start_time"] = this.form.start_time;
      ParamsQuery["puncture_nurse"] = this.form.puncture_nurse_id;
      ParamsQuery["washpipe_nurse"] = this.form.washpipe_nurse;
      ParamsQuery["change_nurse"] = this.form.change_nurse;
      ParamsQuery["difficult_puncture_nurse"] =
        this.form.difficult_puncture_nurse;
      ParamsQuery["new_fistula_nurse"] = this.form.new_fistula_nurse;
      ParamsQuery["blood_drawing"] = this.form.blood_drawing;
      ParamsQuery["quality_nurse"] = this.form.quality_nurse_id;
      ParamsQuery["puncture_needle"] = this.form.puncture_needle;
      ParamsQuery["puncture_way"] = this.form.puncture_way;
      ParamsQuery["dialysis_dialyszers"] = this.form.dialysis_dialyszers;
      ParamsQuery["dialysis_irrigation"] = this.form.dialysis_irrigation;
      ParamsQuery["blood_access_id"] = this.form.blood_access_id;
      ParamsQuery["nuclein_date"] = this.form.nuclein_date;
      ParamsQuery["mode"] = "2";
      ParamsQuery['catheter_operation'] = this.form.catheter_operation
      if (this.dialysis_order.creator != this.$store.getters.xt_user.user.id) {
        ParamsQuery["mode"] = "3";
      }
        console.log(this.form,'this.form')
        this.$refs.form.validate((valid) => {
        if (valid) {
        PostModifyStartDialysis(ParamsQuery).then((rs) => {
        var resp = rs.data;
        if (resp.state == 1) {
          this.$message.success("修改成功");
          this.hide();
          var resp_dialysis_order = resp.data.dialysis_order;
          var this_order = this.dialysis_order;
          for (const key in resp_dialysis_order) {
            this.$set(this_order, key, resp_dialysis_order[key]);
            this.$emit("assessmentAfterDislysis", resp.data.after);
          }
        } else {
          this.$message.error(resp.msg);
          if(response.data.code == 600000008){
            this.infoDialogVisible = true
          }
        }
      });
        }else{
          return false;
        }
      })

    },
    getPermission() {
      request
        .get("/api/func_per/get", {
          params: {
            create_url: "/api/dialysis/start_record?mode=1",
            modify_url: "/api/start_dialysis/modify?mode=2",
            modify_other_url: "/api/start_dialysis/modify?mode=3",
            module: 0,
          },
        })
        .then((res) => {
          console.log(res);
          console.log("上机", this.record);
          if (res.data.state == 0) {
            this.hasPermission = false;
          } else if (res.data.state == 1) {
            if (this.record.id != "" && this.record.creater != 0) {
              //有数据
              if (this.record.creater == this.$store.getters.xt_user.user.id) {
                //创建人是自己
                if (res.data.data.is_has_modify == false) {
                  this.hasPermission = false;
                  this.showTxt = "你没有修改执行上机权限";
                }
              } else {
                //创建人不是自己
                if (res.data.data.is_has_modify_other == false) {
                  this.hasPermission = false;
                  this.showTxt = "你没有修改他人执行上机权限";
                }
              }
            } else if (this.record.id == "" || this.record.creater == 0) {
              if (res.data.data.is_has_create == false) {
                this.hasPermission = false;
                this.showTxt = "你没有执行上机权限";
              }
            }
          }
        });
    },
    showInnerDialog: function (val) {
      console.log("val32323223232323wi", val);
      this.InnerDialogProps.visibility = true;
      switch (val) {
        case "7": // 透析器
          for (let i = 0; i < this.dialyzers.length; i++) {
            this.dialyzers[i].name = this.dialyzers[i].specification_name;
          }
          this.InnerDialogProps.values = this.dialyzers;
          this.InnerDialogProps.titles = "透析器";
          this.InnerDialogProps.type = "dialyzers";
          this.InnerDialogProps.selected = this.form.dialysis_dialyszers;
          this.InnerDialogProps.isShowTextArea = false;
          break;
        case "8":
          for (let i = 0; i < this.irrigations.length; i++) {
            this.irrigations[i].name = this.irrigations[i].specification_name;
          }
          this.InnerDialogProps.values = this.irrigations;
          this.InnerDialogProps.titles = "灌流器";
          this.InnerDialogProps.type = "irrigations";
          this.InnerDialogProps.selected = this.form.dialysis_irrigation;
          this.InnerDialogProps.isShowTextArea = false;
          break;
        case "11": //穿刺针
          this.InnerDialogProps.values = this.punctureNeedleOptions;
          this.InnerDialogProps.titles = "穿刺针";
          this.InnerDialogProps.type = "puncture_needle";
          this.InnerDialogProps.selected = this.form.puncture_needle;
          this.InnerDialogProps.isShowTextArea = false;
          break;
        case "13": // 穿刺方式
          this.InnerDialogProps.values = this.puncture_ways;
          this.InnerDialogProps.titles = "穿刺方式";
          this.InnerDialogProps.type = "puncture_way";
          this.InnerDialogProps.selected = this.form.puncture_way;
          this.InnerDialogProps.isShowTextArea = false;

          break;
      }
    },
    innerDialogComfirm: function (val) {
      this.InnerDialogProps.visibility = false;
      switch (val.type) {
        case "puncture_needle":
          this.form.puncture_needle = val.value.join(",");
          break;
        case "puncture_way":
          this.form.puncture_way = val.value.join(",");
          break;
        case "dialyzers":
          this.form.dialysis_dialyszers = val.value.join(",");
          break;
        case "irrigations":
          this.form.dialysis_irrigation = val.value.join(",");
          break;
      }
    },
    innerDialogCancle: function () {
      this.InnerDialogProps.visibility = false;
    },
   
    dialysisSummarySelectChange: function (values) {
      if (this.form.catheter_operation == "") {
        this.form.catheter_operation = values;
      } else {
       
        if (this.form.catheter_operation.indexOf(values) == -1) {
          if (
            this.form.catheter_operation
              .charAt(this.form.catheter_operation.length - 1)
              .indexOf("。") == -1
          ) {
            this.form.catheter_operation =
              this.form.catheter_operation+ "," + values;
          } else {
            this.form.catheter_operation =
              this.form.catheter_operation + "," + values;
            this.form.catheter_operation =
              this.form.catheter_operation+ values;
          }
        }
      }
    },
    changeBloodAccessOpion(id){
      var name = ""
      for(let i=0;i<this.blood_access_option.length;i++){
        // console.log("id9999",this.blood_access_option[i].id)
        if(id == this.blood_access_option[i].id){
           name = this.blood_access_option[i].name
        }
      }

      this.blood_access_option_name = name
    },
    changeBloodAccessOpionOne(id){
      var name = ""
      for(let i=0;i<this.blood_access_option.length;i++){
        // console.log("id9999",this.blood_access_option[i].id)
        if(id == this.blood_access_option[i].id){
           name = this.blood_access_option[i].name
        }
      }

      return name
    },
    saveInformation(){
        var params = {
          selected_date:this.selected_date,
          patient_id:this.$route.query.patient_id,
          record_date:this.$route.query.date,
          module:6,
          remark:this.remark,
        }
        saveInformation(params).then(response=>{
           if(response.data.state == 1){
             var information = response.data.data.information
             this.$message.success("提交成功!")
             this.infoDialogVisible = false
           }
        })
      }
  },
};
</script>

<style scoped>
.txsj {
  text-align: center;
  margin-bottom: 20px;
}
.warnTxt {
  text-align: center;
  margin: 0 auto;
  background: #faa331;
  max-width: 240px;
  padding: 10px 20px;
  border-radius: 4px;
  margin-bottom: 10px;
  color: #fff;
}
</style>
<style lang="scss">
.newDialog {
  .el-dialog__body {
    padding: 10px 20px 30px;
  }
}
</style>
