<template>
  <fullscreen :fullscreen.sync="fullscreen" class="container">
    <div class="container-box">
      <toolList @iconCli="iconCli" :tooltit="tooltit"></toolList>
      <div style="overflow: hidden">
        <div class="search" style="float: left">
          <mySearch
            :searchList="searchList"
            @searchInfo="searchInfo"
          ></mySearch>
          <el-button
            class="btn-check"
            size="large"
            type="primary"
            style="background-color: white; color: #4a5562"
            @click="resetSearch()"
            >重置
          </el-button>
        </div>
        <div style="margin-top: 20px; float: right" class="bigbtns">
          <el-button
            style="margin-left: 20px"
            class="btn-check"
            size="medium"
            type="primary"
            @click="addNew(1)"
            >新建
          </el-button>
        </div>
      </div>
      <div class="tabbox">
        <el-table
          height="calc(100% - 40px)"
          class="com-table"
          ref="multipleTable"
          :data="tableData"
          tooltip-effect="dark"
          size="small"
          border
          style="width: 100%"
          v-loading="loading"
        >
          <el-table-column prop="appName" label="应用名称"> </el-table-column>
          <el-table-column prop="type" label="类型"> </el-table-column>
          <el-table-column prop="addUserName" label="发起人"> </el-table-column>
          <el-table-column prop="opTime" label="发起时间"> </el-table-column>
          <el-table-column prop="stateString" label="状态"> </el-table-column>
          <el-table-column
            label="操作"
            width="180px"
            align="center"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="primary"
                @click="watchInfo(1, scope.row)"
                >查看
              </el-button>
              <el-button
                size="mini"
                type="primary"
                @click="processInfo(1, scope.row)"
                v-if="scope.row.changeState == 1"
                >处理
              </el-button>
              <el-button
                size="mini"
                type="primary"
                @click="changeInfo(1, scope.row)"
                v-if="scope.row.updateState == 1"
                >修改
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          class="pageBox"
          @current-change="currchange"
          layout="prev, pager, next"
          background
          :total="total"
        >
        </el-pagination>
      </div>

      <el-dialog
        :title="dialogString"
        :visible.sync="addStatus"
        width="60%"
        :destroy-on-close="true"
        :modal-append-to-body="false"
        :close-on-click-modal="false"
        :fullscreen="true"
      >
        <div v-loading="loading">
          <el-form :model="addInfoList" ref="addInfoList" :rules="addInfoRules">
            <div class="info-line">
              <el-form-item prop="appName">
                <span>应用名称</span>
                <el-input
                  v-model="addInfoList.appName"
                  placeholder="应用名称"
                  :disabled="addType != 1"
                ></el-input>
              </el-form-item>
              <el-form-item prop="version">
                <span>版本号</span>
                <el-input
                  v-model="addInfoList.version"
                  placeholder="版本号"
                  :disabled="addType != 1"
                ></el-input>
              </el-form-item>
            </div>
            <div class="info-line">
              <el-form-item prop="type">
                <span>类型</span>
                <el-select
                  :popper-append-to-body="false"
                  v-model="addInfoList.type"
                  placeholder="类型"
                  :disabled="addType != 1"
                  @change="typeChange"
                >
                  <el-option
                    v-for="items in apkType"
                    :key="items.dataCode"
                    :label="items.dataName"
                    :value="items.dataCode"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item prop="processTime">
                <span>要求处理时长（天）</span>
                <el-input
                  v-model="addInfoList.processTime"
                  placeholder="要求处理时长（天）"
                  :disabled="addType != 1 || addInfoList.type != 'Launcher'"
                  type="number"
                  min="0"
                  oninput="value=value.replace('-','')"
                ></el-input>
              </el-form-item>
            </div>
            <div class="info-line">
              <el-form-item prop="taskName">
                <span>本次任务</span>
                <el-input
                  v-model="addInfoList.taskName"
                  placeholder="本次任务"
                  :disabled="addType != 1"
                ></el-input>
              </el-form-item>
              <el-form-item prop="taskInfo">
                <span>任务要素</span>
                <el-input
                  v-model="addInfoList.taskInfo"
                  placeholder="任务要素"
                  :disabled="addType != 1"
                ></el-input>
              </el-form-item>
            </div>
            <!--申请人上传文件筐-->
            <div style="padding-left: 80px" v-if="addType == 1">
              <myUpload
                @uploadBack="uploadBack"
                :fileInfo="fileInfo"
                :fileList="fileInfo.fileList"
              ></myUpload>
            </div>
            <!--申请人下载文件筐-->
            <div
              style="padding: 0 0 10px 100px"
              v-if="this.datalist.attList.length > 0 && addType == 2"
            >
              <uploadDown
                :datalist="datalist"
                :dialogStatus="uploadstatus"
              ></uploadDown>
            </div>
            <div v-if="addType == 2 && addInfoList.type == 'Launcher'">
              <div class="info-line" v-if="addInfoList.state == 1">
                <span
                  style="
                    color: blue;
                    font-size: 16px;
                    margin-left: 15px;
                    margin-bottom: 10px;
                  "
                  >网络部需填：</span
                >
                <br />
              </div>
              <div class="info-line">
                <el-form-item prop="testState">
                  <span>测试是否通过</span>
                  <el-select
                    :popper-append-to-body="false"
                    v-model="addInfoList.testState"
                    placeholder="是否通过"
                    :disabled="addInfoList.state != 1"
                  >
                    <el-option
                      v-for="items in testState"
                      :key="items.dataCode"
                      :label="items.dataName"
                      :value="items.dataCode"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </div>
              <div class="info-line">
                <el-form-item prop="testInfo">
                  <span>测试说明</span>
                  <el-input
                    v-model="addInfoList.testInfo"
                    placeholder="测试说明"
                    :disabled="addInfoList.state != 1"
                  ></el-input>
                </el-form-item>
              </div>
              <div class="info-line" v-if="addInfoList.state == 1">
                <span
                  style="color: blue; margin-left: 85px; cursor: pointer"
                  @click="getTemple()"
                  >下载模板</span
                >
              </div>
              <!--网络部上传文件筐-->
              <div style="padding-left: 80px" v-if="addInfoList.state == 1">
                <myUpload
                  @uploadBack="uploadBack"
                  :fileInfo="fileInfo"
                  :fileList="fileInfo.fileList"
                ></myUpload>
              </div>
              <!--网络部下载文件筐-->
              <div
                style="padding: 0 0 10px 100px"
                v-if="this.netDataList.attList.length > 0 && addType == 2"
              >
                <uploadDown
                  :datalist="netDataList"
                  :dialogStatus="uploadstatus"
                ></uploadDown>
              </div>
              <div v-if="addType == 2 && addInfoList.state != 1">
                <div class="info-line">
                  <el-form-item prop="applicantInfo">
                    <span>申请人审核意见</span>
                    <el-input
                      v-model="addInfoList.applicantInfo"
                      placeholder="申请人审核意见"
                      :disabled="addInfoList.state != 2"
                    ></el-input>
                  </el-form-item>
                </div>
              </div>
            </div>
            <div v-if="addType == 2 && addInfoList.state == 6">
              <div class="info-line">
                <el-form-item prop="onlineTime">
                  <span>上线日期</span>
                  <el-date-picker
                    :disabled="disableStatus"
                    v-model="addInfoList.onlineTime"
                    type="date"
                  >
                  </el-date-picker>
                </el-form-item>
              </div>
              <div class="info-line">
                <el-form-item prop="onlineResult">
                  <span>上线结果</span>
                  <el-input
                    v-model="addInfoList.onlineResult"
                    placeholder="上线结果"
                    :disabled="disableStatus"
                  ></el-input>
                </el-form-item>
              </div>
            </div>
          </el-form>
          <div slot="footer" class="dialog-footer myfooter">
            <el-button
              v-if="addType == 1 && addInfoList.type == 'Launcher'"
              @click="processExa()"
              type="primary"
              >提交网络部
            </el-button>
            <el-button
              v-if="addType == 1 && addInfoList.type == 'APK'"
              @click="processExa()"
              type="primary"
              >提交室主任审批
            </el-button>
            <el-button
              v-if="addType == 2 && addInfoList.state == 1"
              @click="beforeSubmit()"
              type="primary"
            >
              回 复
            </el-button>
            <el-button
              v-if="
                addType == 2 &&
                (addInfoList.state == 3 || addInfoList.state == 4)
              "
              @click="deniedSubmit()"
              type="primary"
              >驳回至申请人
            </el-button>
            <el-button
              v-if="addType == 2 && addInfoList.state == 2"
              @click="processExa()"
              type="primary"
            >
              提交室主任审批
            </el-button>
            <el-button
              v-if="addType == 2 && addInfoList.state == 3"
              @click="processExa()"
              type="primary"
            >
              提交领导审批
            </el-button>
            <el-button
              v-if="addType == 2 && addInfoList.state == 4"
              @click="beforeSubmit()"
              type="primary"
            >
              通 过
            </el-button>
            <el-button
              v-if="addType == 2 && addInfoList.state == 6"
              @click="beforeSubmit()"
              type="primary"
            >
              确定上线
            </el-button>
            <el-button @click="addStatus = false">取 消</el-button>
          </div>
        </div>
      </el-dialog>

      <el-dialog
        title="查看"
        :visible.sync="watchStatus"
        width="60%"
        :destroy-on-close="true"
        :modal-append-to-body="false"
        :close-on-click-modal="false"
        :fullscreen="true"
      >
        <div v-loading="loading">
          <el-form
            :model="watchInfoList"
            ref="watchInfoList"
            style="height: calc(100vh - 180px); overflow-y: scroll"
          >
            <div class="info-line">
              <el-form-item prop="appName">
                <span>应用名称</span>
                <el-input
                  v-model="watchInfoList.appName"
                  placeholder="应用名称"
                  :disabled="true"
                ></el-input>
              </el-form-item>
              <el-form-item prop="version">
                <span>版本号</span>
                <el-input
                  v-model="watchInfoList.version"
                  placeholder="版本号"
                  :disabled="true"
                ></el-input>
              </el-form-item>
            </div>
            <div class="info-line">
              <el-form-item prop="type">
                <span>类型</span>
                <el-select
                  :popper-append-to-body="false"
                  v-model="watchInfoList.type"
                  placeholder="类型"
                  :disabled="true"
                >
                  <el-option
                    v-for="items in apkType"
                    :key="items.dataCode"
                    :label="items.dataName"
                    :value="items.dataCode"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item prop="processTime">
                <span>要求处理时长（天）</span>
                <el-input
                  v-model="watchInfoList.processTime"
                  placeholder="要求处理时长（天）"
                  :disabled="true"
                  type="number"
                ></el-input>
              </el-form-item>
            </div>
            <div class="info-line">
              <el-form-item prop="taskName">
                <span>本次任务</span>
                <el-input
                  v-model="watchInfoList.taskName"
                  placeholder="本次任务"
                  :disabled="true"
                ></el-input>
              </el-form-item>
              <el-form-item prop="taskInfo">
                <span>任务要素</span>
                <el-input
                  v-model="watchInfoList.taskInfo"
                  placeholder="任务要素"
                  :disabled="true"
                ></el-input>
              </el-form-item>
            </div>
            <!--申请人下载文件筐-->
            <div
              style="padding: 0 0 10px 100px"
              v-if="this.datalist.attList.length > 0"
            >
              <uploadDown
                :datalist="datalist"
                :dialogStatus="uploadstatus"
              ></uploadDown>
            </div>
            <div v-if="watchInfoList.type == 'Launcher'">
              <div class="info-line">
                <el-form-item prop="testState">
                  <span>测试是否通过</span>
                  <el-select
                    :popper-append-to-body="false"
                    v-model="watchInfoList.testState"
                    placeholder="是否通过"
                    :disabled="true"
                  >
                    <el-option
                      v-for="items in testState"
                      :key="items.dataCode"
                      :label="items.dataName"
                      :value="items.dataCode"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </div>
              <div class="info-line">
                <el-form-item prop="testInfo">
                  <span>测试说明</span>
                  <el-input
                    v-model="watchInfoList.testInfo"
                    placeholder="测试说明"
                    :disabled="true"
                  ></el-input>
                </el-form-item>
              </div>
              <!--网络部下载文件筐-->
              <div
                style="padding: 0 0 10px 100px"
                v-if="this.netDataList.attList.length > 0"
              >
                <uploadDown
                  :datalist="netDataList"
                  :dialogStatus="uploadstatus"
                ></uploadDown>
              </div>
              <div>
                <div class="info-line">
                  <el-form-item prop="applicantInfo">
                    <span>申请人审核意见</span>
                    <el-input
                      v-model="watchInfoList.applicantInfo"
                      placeholder="申请人审核意见"
                      :disabled="true"
                    ></el-input>
                  </el-form-item>
                </div>
              </div>
            </div>
            <div v-if="watchInfoList.state == 7">
              <div class="info-line">
                <el-form-item prop="onlineTime">
                  <span>上线日期</span>
                  <el-date-picker
                    :disabled="true"
                    v-model="watchInfoList.onlineTime"
                    type="date"
                  >
                  </el-date-picker>
                </el-form-item>
              </div>
              <div class="info-line">
                <el-form-item prop="onlineResult">
                  <span>上线结果</span>
                  <el-input
                    v-model="watchInfoList.onlineResult"
                    placeholder="上线结果"
                    :disabled="true"
                  ></el-input>
                </el-form-item>
              </div>
            </div>
            <div style="margin-bottom: 20px; padding: 0 20px">
              <el-table
                class="com-table"
                ref="multipleTable"
                :data="stepList"
                tooltip-effect="dark"
                size="small"
                border
                style="width: 100%"
              >
                <el-table-column prop="processName" label="流程环节">
                </el-table-column>
                <el-table-column prop="processUserName" label="处理人">
                </el-table-column>
                <el-table-column prop="processTime" label="处理时间">
                </el-table-column>
                <el-table-column prop="processResult" label="处理意见">
                </el-table-column>
              </el-table>
            </div>
          </el-form>

          <div slot="footer" class="dialog-footer myfooter">
            <el-button @click="closeWatchInfo()">关 闭</el-button>
          </div>
        </div>
      </el-dialog>

      <el-dialog
        title="选择审批人"
        :visible.sync="checkexa"
        width="100%"
        style="height: 100%"
        :fullscreen="true"
        :destroy-on-close="true"
        :modal-append-to-body="false"
        :close-on-click-modal="false"
      >
        <div style="height: 100%">
          <el-form :model="addInfoList" ref="addInfoList" style="height: 100%">
            <el-form-item prop="processUserId" style="height: 100%">
              <!-- <span style="width: 80px">审批人员</span> -->
              <deptTreeOnly
                @treeCheck="treeCheckonly"
                :defaultList="defaultList"
                :type="depttype"
                :closeList="closeList"
              ></deptTreeOnly>
              <div style="text-align: center; margin-top: 30px">
                <el-button type="primary" @click="checkProcessUser()"
                  >确 定</el-button
                >
                <el-button @click="checkexa = false">取 消</el-button>
              </div>
              <!-- <div class="tree treeUser">
                <p>
                  {{ treeListonly.leaderAuditName }}
                  <i
                    v-if="treeListonly.leaderAuditName"
                    @click="treeDelete()"
                    class="el-icon-error"
                  ></i>
                </p>
              </div> -->
            </el-form-item>
          </el-form>
        </div>
      </el-dialog>
    </div>
    <myMessage
      :messTit="messTit"
      @closeMessage="closeMessage"
      :centerDialogVisible="centerDialogVisible"
      v-if="centerDialogVisible"
    ></myMessage>
  </fullscreen>
</template>

<script>
import mySearch from "../../../components/search.vue";
import myUpload from "../../../components/upload";
import toolList from "../../../components/toolList";
import myMessage from "../../../components/myMessage.vue";
import deptTreeOnly from "../../../components/newTree.vue";
import uploadDown from "../../../components/uploadDown";

export default {
  components: {
    myUpload,
    mySearch,
    toolList,
    myMessage,
    deptTreeOnly,
    uploadDown,
  },
  data() {
    const appName = (rule, value, callback) => {
      if (!this.addInfoList.appName) {
        callback(new Error("不能为空"));
      } else {
        callback();
      }
    };
    const version = (rule, value, callback) => {
      if (!this.addInfoList.version) {
        callback(new Error("不能为空"));
      } else {
        callback();
      }
    };
    // const type = (rule, value, callback) => {
    //     if (!this.addInfoList.type) {
    //         callback(new Error('不能为空'))
    //     } else {
    //         callback()
    //     }
    // }
    const taskName = (rule, value, callback) => {
      if (!this.addInfoList.taskName) {
        callback(new Error("不能为空"));
      } else {
        callback();
      }
    };
    const taskInfo = (rule, value, callback) => {
      if (!this.addInfoList.taskInfo) {
        callback(new Error("不能为空"));
      } else {
        callback();
      }
    };
    // const processTime = (rule, value, callback) => {
    //     if (this.addInfoList.type == 'Launcher' && !this.addInfoList.processTime) {
    //         callback(new Error('不能为空'))
    //     } else {
    //         callback()
    //     }
    // }

    const testState = (rule, value, callback) => {
      if (this.addInfoList.state == 1 && !this.addInfoList.testState) {
        callback(new Error("不能为空"));
      } else {
        callback();
      }
    };

    const testInfo = (rule, value, callback) => {
      if (this.addInfoList.state == 1 && !this.addInfoList.testInfo) {
        callback(new Error("不能为空"));
      } else {
        callback();
      }
    };

    const applicantInfo = (rule, value, callback) => {
      if (this.addInfoList.state == 2 && !this.addInfoList.applicantInfo) {
        callback(new Error("不能为空"));
      } else {
        callback();
      }
    };

    const onlineTime = (rule, value, callback) => {
      if (this.addInfoList.state == 6 && !this.addInfoList.onlineTime) {
        callback(new Error("不能为空"));
      } else {
        callback();
      }
    };

    const onlineResult = (rule, value, callback) => {
      if (this.addInfoList.state == 6 && !this.addInfoList.onlineResult) {
        callback(new Error("不能为空"));
      } else {
        callback();
      }
    };

    return {
      addInfoRules: {
        appName: [
          {
            required: true,
            trigger: "blur",
            validator: appName,
          },
        ],
        version: [
          {
            required: true,
            trigger: "blur",
            validator: version,
          },
        ],
        // type: [{
        //     required: true,
        //     trigger: 'change',
        //     validator: type
        // }],
        taskInfo: [
          {
            required: true,
            trigger: "blur",
            validator: taskInfo,
          },
        ],
        taskName: [
          {
            required: true,
            trigger: "blur",
            validator: taskName,
          },
        ],
        // processTime: [{
        //     required: true,
        //     trigger: 'blur',
        //     validator: processTime
        // }],
        testState: [
          {
            required: true,
            trigger: "change",
            validator: testState,
          },
        ],
        testInfo: [
          {
            required: true,
            trigger: "change",
            validator: testInfo,
          },
        ],
        applicantInfo: [
          {
            required: true,
            trigger: "blur",
            validator: applicantInfo,
          },
        ],
        onlineTime: [
          {
            required: true,
            trigger: "blur",
            validator: onlineTime,
          },
        ],
        onlineResult: [
          {
            required: true,
            trigger: "blur",
            validator: onlineResult,
          },
        ],
      },
      tooltit: "魔百和APK版本升级和应用上线测试",
      searchList: [
        {
          type: "input",
          tit: "应用名称",
          value: "",
          width: "100%",
        },
      ],
      fullscreen: false,
      loading: false,
      total: 0,
      pageSize: 1,
      tableData: [{}],
      dialogStatus: false,
      disableStatus: false,
      infolist: {},
      userInfo: {},
      params: {},
      centerDialogVisible: false,
      addStatus: false,
      addInfoList: {},
      watchInfoList: {},
      attList: [],
      uploadstatus: false,
      fileInfo: {
        limit: 50,
        url: "/market/cMkApkTestMain/upload",
        fileList: [],
      },
      //控制下载文件筐
      datalist: {
        url: "/market/cMkApkTestMain/downFile",
        type: 1,
        attList: [],
      },
      netDataList: {
        url: "/market/cMkApkTestMain/downFile",
        type: 1,
        attList: [],
      },
      apkType: [
        {
          dataCode: "APK",
          dataName: "APK",
        },
        {
          dataCode: "Launcher",
          dataName: "Launcher",
        },
      ],
      testState: [
        {
          dataCode: "是",
          dataName: "是",
        },
        {
          dataCode: "否",
          dataName: "否",
        },
      ],
      //是添加还是修改
      addType: 0,
      //选择审批人
      checkexa: false,
      //审批人用到的
      treeListonly: {},
      defaultList: [],
      closeList: false,
      depttype: 0,
      //是否是修改
      changeState: false,
      watchStatus: false,
      dialogString: "",
      stepList: [],
    };
  },
  methods: {
    clickTree() {
      this.checkexa = true;
    },
    typeChange(v) {
      if (v == "APK") {
        this.addInfoList.processTime = "";
      }
    },
    resetSearch() {
      this.searchList = [
        {
          type: "input",
          tit: "应用名称",
          value: "",
          width: "100%",
        },
      ];
      this.params = {};
      this.getList(this.params, 1);
    },
    treeDelete() {
      this.treeListonly = {};
      this.closeList = !this.closeList;
    },
    //功能栏
    iconCli(v) {
      if (v === 1) {
        this.getList(this.params, this.pageSize);
      }
      if (v === 2) {
        this.fullscreen = !this.fullscreen;
      }
    },
    //搜索数据
    searchInfo(v) {
      this.params = {};
      v[0] ? (this.params.appName = v[0]) : "";
      this.getList(this.params, this.pageSize);
    },
    //获取列表
    getList(v, n) {
      this.pageSize = n;
      this.loading = true;
      this.tableData = [];
      let _this = this;
      this.$http({
        url: "/market/cMkApkTestMain/queryPage",
        method: "post",
        headers: {
          "Content-Type": "application/json",
          page: '{"pageNo":"' + n + '","pageSize":"10"}',
        },
        data: v,
      }).then((res) => {
        this.tableData = res.data.data;
        this.total = res.data.totalRecord;
        this.loading = false;
      });
    },
    getAuditStep(appId) {
      this.loading = true;
      this.stepList = [];
      this.$http({
        url: "/market/cMkApkTestMain/queryAuditStepList",
        method: "post",
        headers: {
          "Content-Type": "application/json",
        },
        data: {
          appId: appId,
        },
      }).then((res) => {
        this.stepList = res.data;
        this.loading = false;
      });
    },
    // 分页
    currchange(v) {
      this.pageSize = v;
      this.getList(this.params, this.pageSize);
    },
    addNew(v, n) {
      this.dialogString = "新建";
      this.changeState = false;
      this.attList = [];
      this.fileInfo.fileList = [];
      this.addStatus = true;
      this.disableStatus = false;
      this.addInfoList = Object.assign({}, n); //拷贝
      this.addInfoList.opNo = this.userInfo.loginNo;
      this.addInfoList.opName = this.userInfo.loginName;
      this.loading = false;
      this.addType = 1;
      //this.addInfoList.state = 2
    },
    processInfo(v, n) {
      this.dialogString = "处理";
      this.datalist.attList = [];
      this.netDataList.attList = [];
      this.addInfoList = {};
      //获取文件
      let _this = this;
      this.$http({
        url: "/market/cMkApkTestMain/queryFiles",
        method: "post",
        headers: {
          "Content-Type": "application/json",
        },
        data: {
          testMainId: n.id,
        },
      }).then((res) => {
        if (res.data.result === 1) {
          _this.$message({
            message: res.data.desc,
            type: "error",
          });
        } else {
          console.log(res.data);
          //显示文件列表
          this.datalist.attList = res.data[0];
          this.netDataList.attList = res.data[1];
          this.attList = [];
          this.fileInfo.fileList = [];
          console.log(this.datalist);
          this.changeState = false;
          this.addType = 2;
          this.addInfoList = Object.assign({}, n); //拷贝
          this.addStatus = true;
          this.disableStatus = false;
          this.loading = false;
        }
      });
    },
    watchInfo(v, n) {
      this.datalist.attList = [];
      this.netDataList.attList = [];
      //获取文件
      let _this = this;
      this.$http({
        url: "/market/cMkApkTestMain/queryFiles",
        method: "post",
        headers: {
          "Content-Type": "application/json",
        },
        data: {
          testMainId: n.id,
        },
      }).then((res) => {
        if (res.data.result === 1) {
          _this.$message({
            message: res.data.desc,
            type: "error",
          });
        } else {
          this.getAuditStep(n.id);
          //显示文件列表
          this.datalist.attList = res.data[0];
          this.netDataList.attList = res.data[1];
          this.attList = [];
          this.fileInfo.fileList = [];
          console.log(this.datalist);
          this.changeState = false;
          this.addType = 2;
          this.watchInfoList = Object.assign({}, n); //拷贝
          this.watchStatus = true;
          this.disableStatus = false;
          this.loading = false;
        }
      });
    },
    closeWatchInfo() {
      this.checkexa = false;
      this.addStatus = false;
      this.addInfoList = {};
      this.fileInfo.fileList = [];
      this.attList = [];
      this.treeListonly = {};
      this.closeList = !this.closeList;
      this.getList({}, 1);
      this.watchStatus = false;
    },
    changeInfo(v, n) {
      this.dialogString = "修改";
      //获取文件
      let _this = this;
      this.$http({
        url: "/market/cMkApkTestMain/queryFiles",
        method: "post",
        headers: {
          "Content-Type": "application/json",
        },
        data: {
          testMainId: n.id,
        },
      }).then((res) => {
        if (res.data.result === 1) {
          _this.$message({
            message: res.data.desc,
            type: "error",
          });
        } else {
          console.log(res.data);
          //显示文件列表
          this.attList = [];
          this.fileInfo.fileList = [];
          res.data[0].forEach((item) => {
            this.fileInfo.fileList.push({
              name: item.fileName,
              id: item.id,
              fileName: item.fileName,
              fileCode: item.fileCode,
              opName: item.opName,
              opNo: item.opNo,
              opTime: item.opTime,
            });
            this.attList.push({
              name: item.fileName,
              id: item.id,
              fileName: item.fileName,
              fileCode: item.fileCode,
              opName: item.opName,
              opNo: item.opNo,
              opTime: item.opTime,
            });
          });
          this.changeState = true;
          this.addType = 1;
          this.addInfoList = Object.assign({}, n); //拷贝
          this.addStatus = true;
          this.disableStatus = false;
          this.loading = false;
        }
      });
    },
    processExa() {
      this.$refs.addInfoList.validate((valid) => {
        if (valid) {
          if (
            this.attList.length == 0 &&
            (this.addInfoList.state == 1 || this.addType == 1)
          ) {
            this.$message({
              message: "请上传附件",
              type: "error",
            });
            return;
          }
          if (this.addType == 1 && !this.addInfoList.appName) {
            this.$message({
              message: "应用名称不能为空",
              type: "error",
            });
            return;
          }
          if (this.addType == 1 && !this.addInfoList.version) {
            this.$message({
              message: "版本号不能为空",
              type: "error",
            });
            return;
          }
          if (this.addType == 1 && !this.addInfoList.taskName) {
            this.$message({
              message: "本次任务不能为空",
              type: "error",
            });
            return;
          }
          if (this.addType == 1 && !this.addInfoList.taskInfo) {
            this.$message({
              message: "任务要素不能为空",
              type: "error",
            });
            return;
          }
          if (
            this.addType == 1 &&
            this.addInfoList.type == "Launcher" &&
            !this.addInfoList.processTime
          ) {
            this.$message({
              message: "要求处理时长不能为空",
              type: "error",
            });
            return;
          }
          if (this.addInfoList.state == 2 && !this.addInfoList.version) {
            this.$message({
              message: "申请人审核意见不能为空",
              type: "error",
            });
            return;
          }
          this.checkexa = true;
        }
      });
    },
    //提交前准备
    checkProcessUser() {
      let _this = this;
      if (!_this.treeListonly.length > 1) {
        _this.$message({
          message: "只能选择一个人",
          type: "error",
        });
      } else {
        _this.beforeSubmit();
      }
    },
    beforeSubmit() {
      let _this = this;
      console.log(_this.addInfoList);
      console.log(_this.defaultList);
      console.log(_this.treeListonly);
      console.log(_this.closeList);
      let u = "";
      let d = {};
      this.$refs.addInfoList.validate((valid) => {
        if (valid) {
          if (
            _this.attList.length == 0 &&
            (_this.addInfoList.state == 1 || _this.addType == 1)
          ) {
            _this.$message({
              message: "请上传附件",
              type: "error",
            });
            return;
          }
          if (_this.addInfoList.state == 1 && !_this.addInfoList.testState) {
            _this.$message({
              message: "测试结果不能为空",
              type: "error",
            });
            return;
          }
          if (_this.addInfoList.state == 1 && !_this.addInfoList.testInfo) {
            _this.$message({
              message: "测试说明不能为空",
              type: "error",
            });
            return;
          }
          if (_this.addInfoList.state == 6 && !_this.addInfoList.onlineTime) {
            _this.$message({
              message: "上线日期不能为空",
              type: "error",
            });
            return;
          }
          if (_this.addInfoList.state == 6 && !_this.addInfoList.onlineResult) {
            _this.$message({
              message: "上线结果不能为空",
              type: "error",
            });
            return;
          }
          if (_this.addType == 1) {
            _this.addInfoList.processUserId = _this.treeListonly[0].key;
            _this.addInfoList.opTime = _this.$formatDate(
              new Date(),
              "YYYY-MM-DD HH:mm:ss"
            );
            //新增，或被驳回了修改
            u = "/market/cMkApkTestMain/addMkApkTestMain";
            if (_this.changeState) {
              u = "/market/cMkApkTestMain/updateMkApkTestMain";
            }
            d = {
              mkApkTestMain: _this.addInfoList,
              filesList: _this.attList,
            };
            _this.submitInfo(u, "", d);
          } else if (_this.addType == 2) {
            _this.addInfoList.processUserId = _this.treeListonly[0].key;
            //提审
            u = "/market/cMkApkTestMain/processTest";
            d = {
              mkApkTestMain: _this.addInfoList,
              filesList: _this.attList,
            };
            _this.submitInfo(u, "", d);
          }
        }
      });
    },
    deniedSubmit() {
      let _this = this;
      let u = "";
      let d = {};
      //提审
      u = "/market/cMkApkTestMain/deniedTest";
      d = _this.addInfoList;
      _this.submitInfo(u, "", d);
    },
    //提交
    submitInfo(u, v, d) {
      let _this = this;
      this.$refs.addInfoList.validate((valid) => {
        if (valid) {
          this.$http({
            url: u,
            method: "post",
            headers: {
              "Content-Type": "application/json",
            },
            data: d,
          }).then((res) => {
            if (res.data.result === 1) {
              _this.$message({
                message: res.data.desc,
                type: "error",
              });
            } else {
              _this.$message({
                message: "成功",
                type: "success",
              });
              _this.checkexa = false;
              _this.addStatus = false;
              _this.addInfoList = {};
              _this.fileInfo.fileList = [];
              _this.attList = [];
              _this.treeListonly = {};
              _this.closeList = !_this.closeList;
              _this.getList({}, 1);
            }
          });
        }
      });
    },
    //文件返回值
    uploadBack(v) {
      this.attList = v;
    },
    getUser() {
      this.userInfo = JSON.parse(window.sessionStorage.userInfo);
      this.infolist = {
        opNo: "",
        opName: "",
      };
      this.infolist.opNo = this.userInfo.loginNo;
      this.infolist.opName = this.userInfo.loginName;
    },
    treeCheckonly(v) {
      this.treeListonly = v;
    },
    getTemple() {
      let _this = this;
      _this
        .$http({
          url: "/market/cMkApkTestMain/downTemple",
          method: "post",
          responseType: "blob",
          headers: {
            "Content-Type": "application/json",
          },
        })
        .then((res) => {
          if (window.navigator && window.navigator.msSaveOrOpenBlob) {
            let blob = new Blob([res.data], {
              type: "application/x-msdownload",
            });
            window.navigator.msSaveOrOpenBlob(
              blob,
              // this.wo.bizName + ".xlsx"
              "【黑龙江移动】XX产品（XX合作方）-最终上线验收测试报告v1.2(1).docx"
            );
          } else {
            /* 火狐谷歌的文件下载方式 */
            var blob = new Blob([res.data]);
            var downloadElement = document.createElement("a");
            var href = window.URL.createObjectURL(blob);
            downloadElement.href = href;
            downloadElement.download =
              "【黑龙江移动】XX产品（XX合作方）-最终上线验收测试报告v1.2(1).docx";
            document.body.appendChild(downloadElement);
            downloadElement.click();
            document.body.removeChild(downloadElement);
            window.URL.revokeObjectURL(href);
          }
        });
    },
  },
  mounted() {
    this.getList({}, 1);
    this.getUser();
  },
  created() {},
};
</script>
<style>
.info-line .el-input.is-disabled .el-input__inner {
  background-color: #f5f7fa;
  border-color: #e4e7ed;
  color: #66686c;
  cursor: not-allowed;
}
</style>
<style scoped lang="scss">
::v-deep .el-checkbox.el-transfer-panel__item {
  display: block !important;
}
::v-deep .el-form-item__content {
  height: 100% !important;
}
::v-deep .el-dialog__body {
  max-height: calc(100vh - 170px) !important;
  min-height: 100px;
  height: 100%;
  overflow-y: hidden;
}
.img-box {
  height: calc(100vh - 240px);
  overflow-y: scroll;

  .boximg {
    display: flex;
    flex-wrap: wrap;
    margin-top: 20px;

    div {
      display: inline-block;
      width: 18%;
      margin-right: 2%;
      margin-bottom: 20px;
      overflow: hidden;
      border: 1px solid #ddd;
      border-radius: 3px;
      background: #fff;
      position: relative;
      height: 100px;

      img {
        width: 100%;
        position: absolute;
        top: 0;
        bottom: 0;
        margin: auto;
        // height: 100%;
      }
    }
  }
}

.boximgc {
  display: flex;
  flex-wrap: wrap;
  width: calc(100% - 80px) !important;
  margin-left: 80px;

  div {
    display: inline-block;
    width: 18% !important;
    margin-right: 2%;
    margin-bottom: 20px;
    overflow: hidden;
    border: 1px solid #ddd;
    border-radius: 3px;
    background: #fff;
    position: relative;
    height: 100px;

    img {
      width: 100%;
      position: absolute;
      top: 0;
      bottom: 0;
      margin: auto;
      // height: 100%;
    }
  }
}

.typebox {
  div {
    border: 1px solid #ddd;
    border-top: transparent;

    span {
      display: inline-block;
      width: 20%;
      line-height: 30px;
      padding: 10px;
      vertical-align: top;
    }

    .big {
      width: 35%;
      // background: #f4f4f4;
    }

    .small {
      width: 5%;
      text-align: center;
      // border-right: 1px solid #ddd;
    }

    .gys {
      width: 40%;
    }
  }
}

.t-footer {
  text-align: right;
  padding-right: 20px;
  margin-top: 20px;
}

.onetab {
  padding: 20px;
  height: calc(100% - 180px);
}

.titbox {
  div {
    float: right;

    i {
      font-size: 22px;
      margin-left: 20px;
      cursor: pointer;
    }
  }
}

.tabbox {
  margin-top: 15px;
}

.pageBox {
  text-align: right;
  margin-top: 10px;
}

.info-line {
  width: 100%;
  display: block;
  padding-left: 20px;

  div {
    width: 50%;
    display: inline-block;
  }

  span {
    width: 130px;
    display: inline-block;
    text-align: left;

    i {
      color: red;
      display: inline-block;
      padding-right: 5px;
    }
  }

  .el-select,
  .el-input {
    width: calc(100% - 150px);
  }
}

.online {
  width: 100%;

  .el-select {
    width: calc(100% - 100px);
  }

  span {
    vertical-align: top;
  }

  .el-textarea {
    width: calc(100% - 100px);
  }

  .tree {
    width: calc(50% - 60px);
    display: inline-block;
    margin-right: 20px;
    height: 300px;
    overflow-y: scroll;

    .el-icon-error {
      float: right;
      font-size: 20px;
      margin-top: 9px;
      cursor: pointer;
    }
  }

  .treeUser {
    margin: 0;
    border: 1px solid #ddd;

    p {
      background: #f4f4f4;
      padding: 0 20px;
      margin-bottom: 5px;
    }
  }

  .treeUserb {
    width: calc(100% - 100px);
    border: 1px solid #ddd;
    background: #f4f4f4;
    border-radius: 3px;
    height: auto;
    overflow: hidden;

    p {
      display: inline-block;
      padding: 0 20px;
      margin-bottom: 5px;
    }
  }
}
</style>
