<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="仪器类型" prop="model">
        <el-select v-model="queryParams.type" @keyup.enter.native="handleQuery" style="width: 50%">
          <el-option label="全部" :value="null"></el-option>
          <el-option label="非IOT仪器" :value="1"></el-option>
          <el-option label="IOT仪器" :value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="仪器名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入仪器名称进行搜索"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="仪器ID" prop="id">
        <el-input
          v-model="queryParams.id"
          placeholder="请输入仪器ID进行搜索"
          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:instrument:add']"
        >新增
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="instrumentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" fixed="left" width="55" align="center"/>
      <el-table-column label="升序排序" align="center" prop="sortNo"/>
      <el-table-column label="仪器ID" align="center" prop="id"/>
      <el-table-column label="仪器类型" align="center" prop="type">
        <template slot-scope="scope">
          <span v-show="scope.row.type == 1">普通仪器</span>
          <span v-show="scope.row.type == 2">iot仪器</span>
        </template>
      </el-table-column>
      <el-table-column label="仪器封面" align="center" prop="banner" width="150px">
        <template slot-scope="scope">
          <el-avatar shape="square" :size="100" :src="scope.row.banner"></el-avatar>
        </template>
      </el-table-column>
      <el-table-column label="仪器LOGO" align="center" prop="logo" width="150px">
        <template slot-scope="scope">
          <el-avatar shape="square" :size="100" :src="scope.row.logo"></el-avatar>
        </template>
      </el-table-column>
      <el-table-column label="仪器名称" align="center" prop="name" width="150px"/>
      <el-table-column label="仪器型号" align="center" prop="model"/>
      <el-table-column label="保修日期" align="center" prop="guarantee">
        <template slot-scope="scope">
          <span v-show="scope.row.guarantee != null">{{ scope.row.guarantee }}年</span>
        </template>
      </el-table-column>
      <el-table-column label="小程序标签" align="center" prop="miniTagNames" width="150px">
        <template slot-scope="scope">
          <el-tag v-for="item in scope.row.miniTagNames.split(',')">
            {{ item }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="企微标签" align="center" prop="wecomTagNames" width="150px">
        <template slot-scope="scope">
          <el-tag v-for="item in scope.row.wecomTagNames.split(',')">
            {{ item }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="日常打卡奖励" align="center" prop="dailyClockCredit"/>
      <el-table-column label="额外打卡奖励" align="center" prop="extraClockCredit"/>
      <el-table-column label="操作" align="center" width="200px" fixed="right" 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:instrument:edit']"
          >编辑
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
          >设置小程序可见标签
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
          >设置微信可见标签
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
          >正品控名称配置
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
          >配置说明书
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:instrument: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="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="180px">
        <el-form-item label="排序" prop="sortNo">
          <el-input-number v-model="form.sortNo" controls-position="right" :min="0" :precision="0"
                           placeholder="请输入排序:值越大，排序越前"></el-input-number>
        </el-form-item>
        <el-form-item label="仪器封面" prop="banner" width="150px">
          <template>
            <!-- 仪器封面 -->
            <el-upload :action="uploadUrl"
                       :headers="headers"
                       :file-list="bannerFile.fileList"
                       list-type="picture-card"
                       accept=".jpg,.png"
                       :limit="1"
                       :class="{hide: bannerFile.uploadHide}"
                       :on-change="bannerUploadChange"
                       :on-remove="bannerUploadRemove"
                       :on-success="bannerUploadSuccess"
                       :on-error="uploadError"
            >
              <i slot="default" class="el-icon-plus"></i>
              <div slot="file" slot-scope="{file}">
                <img class="el-upload-list__item-thumbnail" :src="file.url" alt="">
                <span class="el-upload-list__item-actions">
                  <span class="el-upload-list__item-preview" @click="bannerPicturePreview(file)">
                    <i class="el-icon-zoom-in"></i>
                  </span>
                  <span v-if="!bannerFile.disabled" class="el-upload-list__item-delete"
                        @click="bannerUploadRemove(file)">
                    <i class="el-icon-delete"></i>
                  </span>
                </span>
              </div>
              <div slot="tip" class="el-upload__tip">只能上传jpg/png文件</div>
            </el-upload>
            <!-- 预览窗口 -->
            <el-dialog :visible.sync="bannerFile.dialogVisible" append-to-body>
              <img width="100%" :src="bannerFile.dialogImageUrl" alt="">
            </el-dialog>
          </template>
        </el-form-item>
        <!--  仪器LOGO  -->
        <el-form-item label="仪器LOGO" prop="logo">
          <template>
            <el-upload :action="uploadUrl"
                       :headers="headers"
                       :file-list="logoFile.fileList"
                       list-type="picture-card"
                       accept=".jpg,.png"
                       :limit="1"
                       :class="{hide: logoFile.uploadHide}"
                       :on-change="logoUploadChange"
                       :on-remove="logoUploadRemove"
                       :on-success="logoUploadSuccess"
                       :on-error="uploadError"
            >
              <i slot="default" class="el-icon-plus"></i>
              <div slot="file" slot-scope="{file}">
                <img class="el-upload-list__item-thumbnail" :src="file.url" alt="">
                <span class="el-upload-list__item-actions">
                  <span class="el-upload-list__item-preview" @click="logoPicturePreview(file)">
                    <i class="el-icon-zoom-in"></i>
                  </span>
                  <span v-if="!logoFile.disabled" class="el-upload-list__item-delete" @click="logoUploadRemove(file)">
                    <i class="el-icon-delete"></i>
                  </span>
                </span>
              </div>
              <div slot="tip" class="el-upload__tip">只能上传jpg/png文件</div>
            </el-upload>
            <!-- 预览窗口 -->
            <el-dialog :visible.sync="logoFile.dialogVisible" append-to-body>
              <img width="100%" :src="logoFile.dialogImageUrl" alt="">
            </el-dialog>
          </template>
        </el-form-item>
        <!--  仪器序列号  -->
        <el-form-item label="仪器序列号图片" prop="serial">
          <template>
            <el-upload :action="uploadUrl"
                       :headers="headers"
                       :file-list="serialFile.fileList"
                       list-type="picture-card"
                       accept=".jpg,.png"
                       :limit="1"
                       :class="{hide: serialFile.uploadHide}"
                       :on-change="serialUploadChange"
                       :on-remove="serialUploadRemove"
                       :on-success="serialUploadSuccess"
                       :on-error="uploadError"
            >
              <i slot="default" class="el-icon-plus"></i>
              <div slot="file" slot-scope="{file}">
                <img class="el-upload-list__item-thumbnail" :src="file.url" alt="">
                <span class="el-upload-list__item-actions">
                  <span class="el-upload-list__item-preview" @click="serialPicturePreview(file)">
                    <i class="el-icon-zoom-in"></i>
                  </span>
                  <span v-if="!serialFile.disabled" class="el-upload-list__item-delete"
                        @click="serialUploadRemove(file)">
                    <i class="el-icon-delete"></i>
                  </span>
                </span>
              </div>
              <div slot="tip" class="el-upload__tip">只能上传jpg/png文件</div>
            </el-upload>
            <!-- 预览窗口 -->
            <el-dialog :visible.sync="serialFile.dialogVisible" append-to-body>
              <img width="100%" :src="serialFile.dialogImageUrl" alt="">
            </el-dialog>
          </template>
        </el-form-item>
        <el-form-item label="手写绑定介绍视频/图片" prop="manualCodeBinding">
          <el-upload
            class="upload-demo"
            :action="uploadUrl"
            :headers="headers"
            :limit="1"
            :on-exceed="manualUploadExceed"
            :on-success="manualUploadSuccess"
            :on-error="uploadError"
            :file-list="manualFile.fileList">
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">只能上传一个文件，且视频不超过10M，图片不超过1M</div>
          </el-upload>
        </el-form-item>
        <el-form-item label="扫码绑定介绍图片" prop="scanCodeBinding">
          <el-upload
            class="upload-demo"
            :action="uploadUrl"
            :headers="headers"
            :limit="1"
            :on-exceed="scanUploadExceed"
            :on-success="scanUploadSuccess"
            :on-error="uploadError"
            :file-list="scanFile.fileList">
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">只能上传一个文件，且视频不超过10M，图片不超过1M</div>
          </el-upload>
        </el-form-item>
        <el-form-item label="仪器名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入仪器名称"/>
        </el-form-item>
        <el-form-item label="保修日期" prop="guarantee">
          <el-input-number :min="0" :precision="0" v-model="form.guarantee"></el-input-number>
        </el-form-item>
        <el-form-item label="日常打卡获得积分" prop="dailyClockCredit">
          <el-input-number :min="0" :precision="0" v-model="form.dailyClockCredit"></el-input-number>
        </el-form-item>
        <el-form-item label="开启额外打卡奖励" prop="dailyClockCredit">
          <el-switch v-model="form.isExtraClock" :active-value="1" :inactive-value="0" active-color="#13ce66"
                     inactive-color="#DCDCDC" @change="isExtraClockChange">
          </el-switch>
        </el-form-item>
        <el-form-item v-if="form.isExtraClock == 1" label="额外打卡奖励积分" prop="extraClockCredit">
          <el-input-number :min="0" :precision="0" v-model="form.extraClockCredit"></el-input-number>
        </el-form-item>
        <el-form-item v-if="form.isExtraClock == 1" label="额外打卡时间" prop="extraClockTimeRange">
          <el-date-picker
            v-model="form.extraClockTimeRange"
            clearable
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="仪器类型" prop="type">
          <el-select v-model="form.type" style="width: 50%" @change="typeChange">
            <el-option label="非IOT仪器" :value="1"></el-option>
            <el-option label="IOT仪器" :value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item v-if="form.type == 2" label="仪器型号" prop="model">
          <el-select v-model="form.model" style="width: 50%">
            <el-option label="FR200" value="FR200"></el-option>
            <el-option label="WL200" value="WL200"></el-option>
            <el-option label="FR380" value="FR380"></el-option>
            <el-option label="FR390" value="FR390"></el-option>
            <el-option label="M01" value="M01"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="模式ID" prop="sceneIds">
          <el-input v-model="form.sceneIds" placeholder="请输入模式ID"/>
        </el-form-item>
        <el-form-item label="模式名称" prop="sceneNames">
          <el-input v-model="form.sceneNames" placeholder="请输入模式名称"/>
        </el-form-item>
        <el-form-item label="生成护理记录最短时间" prop="nursingTime">
          <el-time-picker
            v-model="form.nursingTime"
            value-format="HH:mm:ss"
            placeholder="请选择护理时长">
          </el-time-picker>
        </el-form-item>
        <el-form-item label="iot版本" prop="iotVersion">
          <el-input v-model="form.iotVersion" placeholder="请输入iot版本"/>
        </el-form-item>
        <el-form-item label="iot升级数据文件" prop="iotUpgradeData">
          <el-upload
            class="upload-demo"
            :action="uploadUrl"
            :headers="headers"
            :limit="1"
            :on-exceed="iotUpgradeUploadExceed"
            :on-success="iotUpgradeUploadSuccess"
            :on-error="uploadError"
            :file-list="iotUpgradeFile.fileList">
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">只能上传一个文件</div>
          </el-upload>
        </el-form-item>
        <el-form-item label="扫机身码" prop="isScanCode">
          <el-switch v-model="form.isScanCode" active-value="1" inactive-value="0" active-color="#13ce66"
                     inactive-color="#DCDCDC">
          </el-switch>
        </el-form-item>
        <el-form-item label="是否支持购买" prop="isPurchase">
          <el-select v-model="form.isPurchase" style="width: 50%" @change="isPurchaseChang">
            <el-option label="是" :value="1"></el-option>
            <el-option label="否" :value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item v-if="form.isPurchase == 1" label="商城小程序appid" prop="shoppingAppid">
          <el-input v-model="form.shoppingAppid" placeholder="请输入商城小程序appid"/>
        </el-form-item>
        <el-form-item v-if="form.isPurchase == 1" label="商城小程序path" prop="shoppingPath">
          <el-input v-model="form.shoppingPath" placeholder="请输入商城小程序path"/>
        </el-form-item>
        <el-form-item label="蓝牙连接中图片" prop="bluetoothConnecting">
          <el-upload
            class="upload-demo"
            :action="uploadUrl"
            :headers="headers"
            :limit="1"
            :on-exceed="bluetoothConnectUploadExceed"
            :on-success="bluetoothConnectUploadSuccess"
            :on-error="uploadError"
            :file-list="bluetoothConnectFile.fileList">
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">只能上传一个文件</div>
          </el-upload>
        </el-form-item>
        <el-form-item label="蓝牙关闭图片" prop="bluetoothClosed">
          <el-upload
            class="upload-demo"
            :action="uploadUrl"
            :headers="headers"
            :limit="1"
            :on-exceed="bluetoothClosedUploadExceed"
            :on-success="bluetoothClosedUploadSuccess"
            :on-error="uploadError"
            :file-list="bluetoothClosedFile.fileList">
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">只能上传一个文件</div>
          </el-upload>
        </el-form-item>
        <el-form-item label="iot版本升级说明" prop="iotVersionUpgrade">
          <editor v-model="form.iotVersionUpgrade" placeholder="请输入内容" :min-height="192"/>
        </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>
  </div>
</template>

<script>
import {listInstrument, getInstrument, delInstrument, addInstrument, updateInstrument} from "@/api/system/instrument";
import {getToken} from "@/utils/auth";

export default {
  name: "Instrument",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 仪器列表格数据
      instrumentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        name: null,
        type: null,
      },
      /* 文件上传地址 */
      uploadUrl: process.env.VUE_APP_BASE_API + "/file/upload",
      headers: {
        Authorization: 'Bearer ' + getToken(),
      },
      /* 仪器封面 */
      bannerFile: {
        uploadHide: false,
        dialogImageUrl: '',
        dialogVisible: false,
        disabled: false,
        fileList: [],
      },
      /* 仪器logo */
      logoFile: {
        uploadHide: false,
        dialogImageUrl: '',
        dialogVisible: false,
        disabled: false,
        fileList: [],
      },
      /* 序列号图片 */
      serialFile: {
        uploadHide: false,
        dialogImageUrl: '',
        dialogVisible: false,
        disabled: false,
        fileList: [],
      },
      /* 手写绑定介绍视频/图片 */
      manualFile: {
        uploadHide: false,
        fileList: [],
      },
      /* 扫码绑定介绍视频/图片 */
      scanFile: {
        uploadHide: false,
        fileList: [],
      },
      /* iot升级数据文件 */
      iotUpgradeFile: {
        uploadHide: false,
        fileList: [],
      },
      /* 蓝牙连接文件 */
      bluetoothConnectFile: {
        uploadHide: false,
        fileList: [],
      },
      /* 蓝牙断开连接文件 */
      bluetoothClosedFile: {
        uploadHide: false,
        fileList: [],
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        sortNo: [
          {required: true, message: "排序不能为空", trigger: 'blur'}
        ],
        banner: [
          {required: true, message: "仪器封面不能为空"}
        ],
        logo: [
          {required: true, message: "仪器logo不能为空"}
        ],
        serial: [
          {required: true, message: "序列号图片不能为空"}
        ],
        name: [
          {required: true, message: "仪器名称不能为空", trigger: "blur"}
        ],
        guarantee: [
          {required: true, message: "请选择保修日期", trigger: 'blur'}
        ],
        dailyClockCredit: [
          {required: true, message: "日常打卡奖励积分不能为空", trigger: 'blur'}
        ],
        isExtraClock: [
          {required: true, message: "请选择是否开启额外打卡奖励"}
        ],
        extraClockCredit: [
          {required: true, message: "额外打卡奖励积分不能为空", trigger: 'blur'}
        ],
        extraClockTimeRange: [
          {required: true, message: "额外打卡时间段不能为空", trigger: "blur"}
        ],
        type: [
          {required: true, message: "仪器类型不能为空", trigger: 'change'}
        ],
        model: [
          {required: true, message: "仪器型号不能为空", trigger: 'change'}
        ],
        nursingTime: [
          {required: true, message: "生成护理记录最短时长不能为空", trigger: "change"}
        ],
        isPurchase: [
          {required: true, message: "是否支持购买"}
        ],
        shoppingAppid: [
          {required: true, message: "购买商城APPID不能为空", trigger: "blur"}
        ],
        shoppingPath: [
          {required: true, message: "购买商城PATH不能为空", trigger: "blur"}
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询仪器列列表 */
    getList() {
      this.loading = true;
      listInstrument(this.queryParams).then(response => {
        this.instrumentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        type: 1,
        model: "WL200",
        banner: null,
        logo: null,
        serial: null,
        guarantee: 1,
        dailyClockCredit: 0,
        isExtraClock: 0,
        extraClockCredit: 0,
        /* 额外打卡时间范围 */
        extraClockTimeRange: [],
        miniTagIds: null,
        miniTagNames: null,
        wecomTagIds: null,
        wecomTagNames: null,
        sceneIds: null,
        sceneNames: null,
        nursingTime: null,
        iotVersion: null,
        iotUpgradeData: null,
        isScanCode: 0,
        isPurchase: null,
        shoppingAppid: null,
        shoppingPath: null,
        bluetoothConnecting: null,
        bluetoothClosed: null,
        iotVersionUpgrade: null,
        sortNo: 1000,
        status: null,
        manualCodeBinding: null,
        scanCodeBinding: null,
      };
      /* 仪器封面 */
      this.bannerFile = {
        uploadHide: false,
        dialogImageUrl: '',
        dialogVisible: false,
        disabled: false,
        fileList: [],
      }
      /* 仪器logo */
      this.logoFile = {
        uploadHide: false,
        dialogImageUrl: '',
        dialogVisible: false,
        disabled: false,
        fileList: [],
      }
      /* 序列号图片 */
      this.serialFile = {
        uploadHide: false,
        dialogImageUrl: '',
        dialogVisible: false,
        disabled: false,
        fileList: [],
      }
      /* 手写绑定介绍视频/图片 */
      this.manualFile = {
        uploadHide: false,
        fileList: [],
      }
      /* 扫码绑定介绍视频/图片 */
      this.scanFile = {
        uploadHide: false,
        fileList: [],
      }
      /* iot升级数据文件 */
      this.iotUpgradeFile = {
        uploadHide: false,
        fileList: [],
      }
      /* 蓝牙连接文件 */
      this.bluetoothConnectFile = {
        uploadHide: false,
        fileList: [],
      }
      /* 蓝牙断开连接文件 */
      this.bluetoothClosedFile = {
        uploadHide: false,
        fileList: [],
      }
      // this.form.iotVersionUpgrade = 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
      getInstrument(id).then(response => {
        this.form = response.data;
        // 仪器封面回显
        this.bannerFile = {
          uploadHide: true,
          dialogImageUrl: this.form.banner,
          dialogVisible: false,
          disabled: false,
          fileList: [{name: '', url: this.form.banner}],
        }
        /* 仪器logo */
        this.logoFile = {
          uploadHide: true,
          dialogImageUrl: this.form.logo,
          dialogVisible: false,
          disabled: false,
          fileList: [{name: '', url: this.form.logo}],
        }
        /* 序列号图片 */
        this.serialFile = {
          uploadHide: true,
          dialogImageUrl: this.form.serial,
          dialogVisible: false,
          disabled: false,
          fileList: [{name: '', url: this.form.serial}],
        }
        /* 手写绑定介绍视频/图片 */
        this.manualFile = {
          uploadHide: true,
          fileList: [{name: '手写绑定介绍视频/图片', url: this.form.manualCodeBinding}],
        }
        /* 扫码绑定介绍视频/图片 */
        this.scanFile = {
          uploadHide: true,
          fileList: [{name: '扫码绑定介绍视频/图片', url: this.form.scanCodeBinding}],
        }
        /* iot升级数据文件 */
        this.iotUpgradeFile = {
          uploadHide: true,
          fileList: [{name: 'iot升级数据文件', url: this.form.iotUpgradeData}],
        }
        /* 蓝牙连接文件 */
        this.bluetoothConnectFile = {
          uploadHide: true,
          fileList: [{name: '蓝牙连接文件', url: this.form.bluetoothConnecting}],
        }
        /* 蓝牙断开连接文件 */
        this.bluetoothClosedFile = {
          uploadHide: false,
          fileList: [{name: '蓝牙断开连接文件', url: this.form.bluetoothClosed}],
        }
        // 额外打卡时间
        if (this.form.isExtraClock == 1) {
          this.form.extraClockTimeRange = [response.data.startTime, response.data.endTime];
        }
        this.open = true;
        this.title = "修改仪器列";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            this.$modal.msgSuccess("修改成功");
            // updateInstrument(this.form).then(response => {
            //   this.$modal.msgSuccess("修改成功");
            //   this.open = false;
            //   this.getList();
            // });
          } else {
            addInstrument(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 delInstrument(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /* 文件上传失败 */
    uploadError() {
      this.$message.error('文件上传失败')
    },
    /** 仪器封面操作 */
    bannerPicturePreview(file) {
      this.bannerFile.dialogImageUrl = file.url;
      this.bannerFile.dialogVisible = true;
    },
    bannerUploadRemove(file) {
      this.bannerFile.fileList = [];
      this.bannerFile.uploadHide = this.bannerFile.fileList.length >= 1;
    },
    bannerUploadChange(file, fileList) {
      this.bannerFile.fileList = fileList;
      this.bannerFile.uploadHide = this.bannerFile.fileList.length >= 1;
    },
    bannerUploadSuccess(response, file) {
      if (response.code == 200) {
        this.form.banner = response.data.url
      } else {
        this.$message.error('图片插入失败')
      }
    },
    /** logo 操作 */
    logoPicturePreview(file) {
      this.logoFile.dialogImageUrl = file.url;
      this.logoFile.dialogVisible = true;
    },
    logoUploadRemove(file) {
      this.logoFile.fileList = [];
      this.logoFile.uploadHide = this.logoFile.fileList.length >= 1;
    },
    logoUploadChange(file, fileList) {
      this.logoFile.fileList = fileList;
      this.logoFile.uploadHide = this.logoFile.fileList.length >= 1;
    },
    logoUploadSuccess(response, file) {
      if (response.code == 200) {
        this.form.logo = response.data.url
      } else {
        this.$message.error('图片插入失败')
      }
    },
    /** 序列号图片 操作 */
    serialPicturePreview(file) {
      this.serialFile.dialogImageUrl = file.url;
      this.serialFile.dialogVisible = true;
    },
    serialUploadRemove(file) {
      this.serialFile.fileList = [];
      this.serialFile.uploadHide = this.serialFile.fileList.length >= 1;
    },
    serialUploadChange(file, fileList) {
      this.serialFile.fileList = fileList;
      this.serialFile.uploadHide = this.serialFile.fileList.length >= 1;
    },
    serialUploadSuccess(response, file) {
      if (response.code == 200) {
        this.form.serial = response.data.url
      } else {
        this.$message.error('图片插入失败')
      }
    },
    /** 手写绑定介绍视频/图片 操作 */
    manualUploadExceed(files, fileList) {
      this.$message.warning(`您已上传了文件，如需更换，请先删除原上传的文件`);
    },
    manualUploadSuccess(response, file) {
      if (response.code == 200) {
        this.form.manualCodeBinding = response.data.url
      } else {
        this.$message.error('图片插入失败')
      }
    },
    /** 扫码绑定介绍视频/图片 操作 */
    scanUploadExceed(files, fileList) {
      this.$message.warning(`您已上传了文件，如需更换，请先删除原上传的文件`);
    },
    scanUploadSuccess(response, file) {
      if (response.code == 200) {
        this.form.scanCodeBinding = response.data.url
      } else {
        this.$message.error('图片插入失败')
      }
    },
    /*  iot升级数据文件 */
    iotUpgradeUploadExceed(files, fileList) {
      this.$message.warning(`您已上传了文件，如需更换，请先删除原上传的文件`);
    },
    iotUpgradeUploadSuccess(response, file) {
      if (response.code == 200) {
        this.form.iotUpgradeData = response.data.url
      } else {
        this.$message.error('图片插入失败')
      }
    },
    /*  蓝牙连接图片 */
    bluetoothConnectUploadExceed(files, fileList) {
      this.$message.warning(`您已上传了文件，如需更换，请先删除原上传的文件`);
    },
    bluetoothConnectUploadSuccess(response, file) {
      if (response.code == 200) {
        this.form.bluetoothConnecting = response.data.url
      } else {
        this.$message.error('图片插入失败')
      }
    },
    /*  蓝牙断开连接图片 */
    bluetoothClosedUploadExceed(files, fileList) {
      this.$message.warning(`您已上传了文件，如需更换，请先删除原上传的文件`);
    },
    bluetoothClosedUploadSuccess(response, file) {
      if (response.code == 200) {
        this.form.bluetoothClosed = response.data.url
      } else {
        this.$message.error('图片插入失败')
      }
    },
    /* 是否开启额外打卡奖励 */
    isExtraClockChange() {
      if (this.form.isExtraClock == 0) {
        this.form.extraClockCredit = 0;
        this.form.extraClockTimeRange = [];
      }
    },
    /* 仪器类型切换 */
    typeChange() {
      if (this.form.type == 1) {
        this.form.model = "WL200";
      }
    },
    isPurchaseChang() {
      if (this.form.isPurchase == 0) {
        this.form.shoppingAppid = null;
        this.form.shoppingPath = null;
      }
    }
  }
};
</script>

<style lang="less" scoped>
/deep/ .hide .el-upload--picture-card {
  display: none;
}
</style>
