<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="任务标题" prop="workTitle">
        <el-input
          v-model="queryParams.workTitle"
          placeholder="请输入任务标题"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="任务类型" prop="workType">
        <el-select v-model="queryParams.workType" placeholder="请选择任务类型" clearable size="small">
          <el-option label="入户安检" value="1" />
          <el-option label="巡检" value="2" />
          <el-option label="报警巡查" value="3" />
          <el-option label="其他" value="4" />
        </el-select>
      </el-form-item>
      <el-form-item label="任务状态" prop="workStatus">
        <el-select v-model="queryParams.workStatus" placeholder="请选择任务状态" clearable size="small">
          <el-option label="派发中" value="0" />
          <el-option label="已接单" value="1" />
          <el-option label="已反馈" value="2" />
          <el-option label="已归档" value="3" />
        </el-select>
      </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:order:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:order:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:order:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
		  :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['system:order:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="任务标题" align="center" prop="workTitle" />
      <el-table-column label="任务类型" align="center" prop="workType">
        <template slot-scope="scope">
          <span v-if="scope.row.workType == 1">入户安检</span>
          <span v-if="scope.row.workType == 2">巡检</span>
          <span v-if="scope.row.workType == 3">报警巡查</span>
          <span v-if="scope.row.workType == 4">其他</span>
        </template>
      </el-table-column>
     <!-- <el-table-column label="任务内容" align="center" prop="workContent" />-->
      <el-table-column label="创建单位" align="center" prop="workCreateEnterpriseName" />
      <el-table-column label="指派单位" align="center" prop="workAssignEnterproseName" />
      <el-table-column label="指派人" align="center" prop="workAssignMan" />
      <el-table-column label="任务状态" align="center" prop="workStatus">
        <template slot-scope="scope">
          <span v-if="scope.row.workStatus == 0" style='color: #ff4949'>派发中</span>
          <span v-if="scope.row.workStatus == 1" style="color: mediumblue">已接单</span>
          <span v-if="scope.row.workStatus == 2" style='color: #1890ff'>已反馈</span>
          <span v-if="scope.row.workStatus == 3" style='color: #30B46B'>已归档</span>
        </template>
      </el-table-column>>
      <!--<el-table-column label="巡检时间" align="center" prop="inspectionDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.inspectionDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="巡检路线" align="center" prop="inspectionRoute" />-->
      <!--<el-table-column label="问题描述" align="center" prop="problemDescription" />
      <el-table-column label="问题图片" align="center" prop="pictureUrl" style="text-align:center;">
        <template slot-scope="scope">
          <img :src="scope.row.iconUrl" style="width: 20%;vertical-align:middle;cursor:pointer;" @click="showPicture(scope.row)"/>
          <el-image :ref="'a'+scope.row.workId" :src="scope.row.iconUrl" v-show="false" :preview-src-list="[scope.row.iconUrl]" v-if="scope.row.iconUrl != '' && scope.row.iconUrl != null"></el-image>
        </template>
      </el-table-column>-->
      <!--<el-table-column label="图片路径" align="center" prop="iconUrl" />-->
     <!-- <el-table-column label="整改方案" align="center" prop="rectificationPlan" />
      <el-table-column label="整改结果" align="center" prop="rectificationResult" />-->
      <el-table-column label="责任单位" align="center" prop="responsibleUnit" />
      <el-table-column label="责任人员" align="center" prop="responsiblePerson" />
      <el-table-column label="截止日期" align="center" prop="expiryDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.expiryDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="150%">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="workDetail(scope.row)"
            v-hasPermi="['system:order:edit']"
          >详情</el-button>
          <el-button v-if="scope.row.workStatus == '0' || scope.row.workStatus == '1'"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:order:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:order:remove']"
          >删除</el-button>
          <el-button v-if=" (('enterprise'== roleType && (scope.row.workAssignManId == '' || scope.row.workAssignManId == null)) || ('zhengfu'== roleType && (scope.row.workAssignEnterproseId == '' || scope.row.workAssignEnterproseId == null))) && scope.row.workStatus == '0'"
                     size="mini"
                     type="text"
                     icon="el-icon-edit"
                     @click="workIssue(scope.row)"
                     v-hasPermi="['system:order:edit']"
          >任务下发</el-button>
          <el-button v-if=" 'inpector'== roleType && scope.row.workStatus == '0'"
                     size="mini"
                     type="text"
                     icon="el-icon-edit"
                     @click="takingOrder(scope.row)"
                     v-hasPermi="['system:order:edit']"
          >接单</el-button>
          <el-button v-if="'zhengfu'!= roleType && (scope.row.workStatus == '0' || scope.row.workStatus == '1')"
                     size="mini"
                     type="text"
                     icon="el-icon-edit"
                     @click="feedbookWork(scope.row)"
                     v-hasPermi="['system:order:edit']"
          >反馈</el-button>
          <el-button v-if="'zhengfu'!= roleType && scope.row.workStatus == '2'"
                     size="mini"
                     type="text"
                     icon="el-icon-edit"
                     @click="sortWork(scope.row)"
                     v-hasPermi="['system:order:edit']"
          >归档</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="900px" @closed="dialogClose" @open="dialogOpen" :close-on-click-modal="false">
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="任务标题" prop="workTitle">
            <el-input v-model="form.workTitle" placeholder="请输入任务标题" :disabled="isDetail"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="任务类型" prop="workType">
            <el-select v-model="form.workType" placeholder="请选择任务类型" style="width: 350px" :disabled="isDetail">
              <el-option label="入户安检" value="1" />
              <el-option label="巡检" value="2" />
              <el-option label="报警巡查" value="3" />
              <el-option label="其他" value="4" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="任务内容" prop="workContent">
          <!--<editor v-model="form.workContent" :min-height="192" :readOnly="!s"/>-->
        <editor v-if="isOpen" v-model="form.workContent" :min-height="192" :readOnly="isDetail"/>

      </el-form-item>
      <el-row>
        <el-col :span="12">
          <el-form-item label="指派单位" prop="workAssignEnterproseName">
            <!--<el-input v-model="form.workAssignEnterproseName" placeholder="请输入指派单位名称" />-->
            <el-select v-model="form.workAssignEnterproseId" placeholder="请选择指派单位名称" style="width: 350px" @change="selectworkAssignEnterprose($event)" :disabled="isDetail">
              <el-option
                v-for="item in enterprises"
                :key="item.enterpriseId"
                :label="item.enterpriseName"
                :value="item.enterpriseId"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="指派人" prop="workAssignMan">
            <!--<el-input v-model="form.workAssignManId" placeholder="请输入指派人" />-->
            <el-select v-model="form.workAssignManId" placeholder="请输入指派人" style="width: 350px" @change="selectInspection($event,'edit')" :disabled="isDetail" clearable>
              <el-option
                v-for="item in inspectors"
                :key="item.userId "
                :label="item.userName"
                :value="item.userId "
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12" v-show="isDetail">
          <el-form-item label="创建单位" prop="inspectionDate">
            <el-input v-model="form.workCreateEnterpriseName" placeholder="请输入创建单位名称" :disabled="isDetail"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="巡检时间" prop="inspectionDate" v-show="form.workType=='2'">
            <el-date-picker clearable size="small"
                            v-model="form.inspectionDate"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="选择巡检时间" style="width: 350px" :disabled="isDetail">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item label="巡检路线" prop="inspectionRoute" v-show="form.workType=='2'">
        <el-input v-model="form.inspectionRoute" type="textarea" placeholder="请输入巡检路线" :disabled="isDetail"/>
      </el-form-item>
      <el-form-item label="问题描述" prop="problemDescription" v-show="form.workType=='3'">
        <el-input v-model="form.problemDescription" type="textarea" placeholder="请输入问题描述" :disabled="isDetail"/>
      </el-form-item>
      <el-form-item label="整改方案" prop="rectificationPlan" v-show="form.workType=='3' && isDetail && (form.workStatus =='2' || form.workStatus =='3')">
         <el-input v-model="form.rectificationPlan" type="textarea" placeholder="请输入整改方案" :disabled="isDetail"/>
       </el-form-item>
      <el-form-item label="反馈图片" prop="iconUrl" v-show="isDetail && (form.workStatus =='2' || form.workStatus =='3')">
        <MyFileUpload
          listType="picture-card"
          @resFun="getFileInfo"
          @remove="listRemove"
          :fileArr="fileList"
          :readOnly= "isDetail"
        />
        <el-input v-show="false" disabled v-model="form.iconUrl"></el-input>
      </el-form-item>
       <el-form-item label="反馈信息" prop="rectificationResult" v-show="isDetail && (form.workStatus =='2' || form.workStatus =='3')">
         <el-input v-model="form.rectificationResult" type="textarea" placeholder="请输入整改结果" :disabled="isDetail"/>
       </el-form-item>
      <el-row>
        <el-col :span="12">
          <el-form-item label="责任单位" prop="responsibleUnit">
            <el-input v-model="form.responsibleUnit" placeholder="请输入责任单位" :disabled="isDetail"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="责任人员" prop="responsiblePerson">
            <el-input v-model="form.responsiblePerson" placeholder="请输入责任人员" :disabled="isDetail"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item label="截止日期" prop="expiryDate">
        <el-date-picker clearable size="small"
                        v-model="form.expiryDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择截止日期" style="width: 350px" :disabled="isDetail">
        </el-date-picker>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm" v-show="!isDetail">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
    <!-- 任务下发 -->
    <el-dialog :title="title" :visible.sync="workOpen" width="900px" append-to-body>
      <el-form ref="workForm" :model="workForm" :rules="workRules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="任务标题" prop="workTitle">
             <!-- <el-input v-model="workForm.workTitle" placeholder="请输入任务标题"/>-->
              <span>{{ workForm.workTitle }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="任务类型" prop="workType">
              <span v-if="workForm.workType == '1'">入户安检</span>
              <span v-if="workForm.workType == '2'">巡检</span>
              <span v-if="workForm.workType == '3'">报警巡查</span>
              <span v-if="workForm.workType == '4'">其他</span>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="指派单位" prop="workAssignEnterproseName">
              <!--<el-input v-model="form.workAssignEnterproseName" placeholder="请输入指派单位名称" />-->
              <el-select v-model="workForm.workAssignEnterproseId" placeholder="请选择指派单位名称" style="width: 350px" @change="selectworkAssignEnterprose($event)">
                <el-option
                  v-for="item in enterprises"
                  :key="item.enterpriseId"
                  :label="item.enterpriseName"
                  :value="item.enterpriseId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="指派人" prop="workAssignMan">
              <!--<el-input v-model="form.workAssignManId" placeholder="请输入指派人" />-->
              <el-select v-model="workForm.workAssignManId" placeholder="请输入指派人" style="width: 350px" @change="selectInspection($event,'work')">
                <el-option
                  v-for="item in inspectors"
                  :key="item.userId "
                  :label="item.userName"
                  :value="item.userId "
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitWorkForm">确 定</el-button>
        <el-button @click="cancelWorkForm">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 反馈 -->
    <el-dialog :title="title" :visible.sync="feedBookOpen" width="900px" append-to-body>
      <el-form ref="feedBookForm" :model="feedBookForm" :rules="feedBookRules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="任务标题" prop="workTitle">
              <!--<el-input v-model="feedBookForm.workTitle" placeholder="请输入任务标题"/>-->
              <span>{{feedBookForm.workTitle}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="任务类型" prop="workType">
              <span v-if="feedBookForm.workType == '1'">入户安检</span>
              <span v-if="feedBookForm.workType == '2'">巡检</span>
              <span v-if="feedBookForm.workType == '3'">报警巡查</span>
              <span v-if="feedBookForm.workType == '4'">其他</span>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="整改方案" prop="rectificationPlan" v-if="feedBookForm.workType=='3'">
          <el-input v-model="feedBookForm.rectificationPlan" type="textarea" placeholder="请输入整改方案" />
        </el-form-item>

        <el-form-item label="反馈图片" prop="iconUrl">
          <MyFileUpload
            listType="picture-card"
            @resFun="getFileInfo"
            @remove="listRemove"
            :fileArr="fileList"
          />
          <el-input v-show="false" disabled v-model="feedBookForm.iconUrl"></el-input>
        </el-form-item>

         <el-form-item label="反馈信息" prop="rectificationResult">
           <el-input v-model="feedBookForm.rectificationResult" type="textarea" placeholder="反馈信息" />
         </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFeedBookForm">确 定</el-button>
        <el-button @click="cancelFeedBook">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOrder, getOrder, delOrder, addOrder, updateOrder, exportOrder } from "@/api/operationMonitor/order";
import Editor from '@/components/Editor';
import MyFileUpload from '@/components/MyFileUpload';
import { enterpriseLists } from "@/api/regulation/info";
import { getInspectionUsers } from "@/api/system/user";
import ScrollPane from "../../../layout/components/TagsView/ScrollPane";
export default {
  name: "Order",
  components: {
    ScrollPane,
    Editor,
    MyFileUpload
  },
  data() {
    return {
      isOpen:false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      detailDialogVisible: false,
      workForm: {},
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 燃气任务表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //企业选项
      enterprises: [],
      //巡检员
      inspectors:[],
      // 上传文件列表
      fileList: [],
      //详情
      isDetail: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        workTitle: null,
        workType: null,
        workContent: null,
        workCreateEnterpriseName: null,
        workCreateEnterpriseId: null,
        workAssignEnterproseName: null,
        workAssignEnterproseId: null,
        workAssignManId: null,
        workAssignMan: null,
        workStatus: null,
        inspectionDate: null,
        inspectionRoute: null,
        problemDescription: null,
        iconUrl: null,
        rectificationPlan: null,
        rectificationResult: null,
        responsibleUnit: null,
        responsiblePerson: null,
        expiryDate: null,
        isDel: null,
        remarks: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        workTitle: [
          { required: true, message: "任务标题", trigger: "blur" }
        ],
        workType: [
          { required: true, message: "任务类型", trigger: "blur" }
        ],
        workContent: [
          { required: true, message: "任务内容", trigger: "blur" }
        ],
        workAssignEnterproseName: [
          { required: true, message: "指派单位", trigger: "blur" }
        ],
        expiryDate: [
          { required: true, message: "截止时间", trigger: "blur" }
        ]
      },
      //任务下发表单校验
      workRules: {
        workAssignEnterproseName: [
          { required: true, message: "指派单位", trigger: "blur" }
        ],
        workAssignMan: [
          { required: true, message: "指派人", trigger: "blur" }
        ]
      },
      //反馈校验
      feedBookRules: {
        iconUrl: [
          { required: true, message: "反馈图片", trigger: "change" }
        ],
        rectificationResult:[
          { required: true, message: "反馈信息", trigger: "blur" }
        ]
      },
      roleType: "zhengfu",
      workForm:{},
      workOpen: false,
      feedBookForm: {
        iconUrl: ""
      },
      feedBookOpen: false
    };
  },
  created() {
    window.func=()=>{
      this.isDetail =!this.isDetail;
    }
    this.getList();
    let enterpriseId = this.$store.state.user.enterpriseId;
    let post = this.$store.state.user.posts.find(item => item.postCode === "se");
    if(-2 != enterpriseId){
      if(post){
        this.roleType = "inpector";
      }else{
        this.roleType = "enterprise";
      }
    }

  },
  methods: {

    dialogClose(){
      this.isOpen=false;
    },
    dialogOpen(){
      this.isOpen=true;
    },
    /** 查询燃气任务列表 */
    getList() {
      this.loading = true;
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        workId: null,
        workTitle: null,
        workType: null,
        workContent: null,
        workCreateEnterpriseName: null,
        workCreateEnterpriseId: null,
        workAssignEnterproseName: null,
        workAssignEnterproseId: null,
        workAssignManId: null,
        workAssignMan: null,
        workStatus: "0",
        inspectionDate: null,
        inspectionRoute: null,
        problemDescription: null,
        iconUrl: null,
        rectificationPlan: null,
        rectificationResult: null,
        responsibleUnit: null,
        responsiblePerson: null,
        expiryDate: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        isDel: null,
        remarks: 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.workId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.isDetail = false;
      this.title = "添加燃气任务";
      this.getEnterpriseLists();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const workId = row.workId || this.ids
      this.isDetail = false;
      getOrder(workId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改燃气任务";
        this.getEnterpriseLists();
        this.getInspectionUserList(response.data.workAssignEnterproseId);
      });

    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.workId != null) {
            updateOrder(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrder(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const workIds = row.workId || this.ids;
      this.$confirm('是否确认删除燃气任务编号为"' + workIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delOrder(workIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有燃气任务数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportOrder(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    },
    getFileInfo(res){
      this.feedBookForm.iconUrl = res.url;
      //this.$set(this.feedBookForm,'iconUrl',res.url)
    },
    listRemove(e) {
      this.form.iconUrl = "";
      this.fileList = [];
    },
    showPicture(row){
      this.$refs['a'+row.workId].showViewer = true;
    },
    //指派单位
    getEnterpriseLists(){
      enterpriseLists().then(response => {
        this.enterprises = response.rows;
      });
    },
    //获取巡检员
    getInspectionUserList(enterpriseId){
      getInspectionUsers(enterpriseId,"se").then(response =>{
        this.inspectors = response.data;
      })
    },
    //选择指派单位
    selectworkAssignEnterprose(enterpriseId){
      this.form.workAssignManId = "";
      this.workForm.workAssignManId = "";
      this.workForm.workAssignMan="";
      this.form.workAssignMan = "";
      this.getInspectionUserList(enterpriseId);
      let enterpriseName = this.enterprises.find(val=>val.enterpriseId == enterpriseId).enterpriseName;
      this.form.workAssignEnterproseName = enterpriseName;
    },
    //获取指派人
    selectInspection(userId,type){
      if(userId){
        let userName = this.inspectors.find(val=>val.userId == userId).userName;
        if("edit" == type){
          this.form.workAssignMan = userName;
        }else{
          this.workForm.workAssignMan = userName;
        }
      }else{
        if("edit" == type){
          this.form.workAssignMan = "";
        }else{
          this.workForm.workAssignMan = "";
        }
      }
    },
    /*//选择任务类型
    selectWorkType(workType){
      if("2" == workType){
        this.inspectorInfoIsShow = true;
      }else{
        this.inspectorInfoIsShow = false;
      }
    },*/
    //详情
    workDetail(row){
      getOrder(row.workId).then(response => {
        this.isDetail=true;
        this.open = true;
        this.title = "燃气任务详情";
        this.form = response.data;
        this.getEnterpriseLists();
        this.getInspectionUserList(response.data.workAssignEnterproseId);
      });
    },
    //任务下发
    workIssue(row){
      this.title = "任务下发";
      this.workForm = {};
      this.workForm.workId = row.workId;
      this.workForm.workTitle = row.workTitle;
      this.workForm.workType = row.workType;
      if(row.workAssignEnterproseId){
        this.workForm.workAssignEnterproseId = row.workAssignEnterproseId;
        this.workForm.workAssignEnterproseName = row.workAssignEnterproseName;
      }
     /* if(row.workAssignManId){
        this.workForm.workAssignManId =  row.workAssignManId;
        this.workForm.workAssignMan = row.workAssignMan;
      }*/
      //this.workForm = row;
      this.workForm.workStatus = '1';
      this.workOpen = true;
      this.getEnterpriseLists();
      this.getInspectionUserList(row.workAssignEnterproseId);
    },
    //接单
    takingOrder(row){
      this.$confirm('是否确认接单?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
        this.workForm = {};
        this.workForm.workId = row.workId;
        this.workForm.workStatus = '1';
        if (this.workForm.workId != null) {
          updateOrder(this.workForm);
        }
      }).then(response => {
        this.getList();
        this.msgSuccess("接单成功");
      }).catch(() => {});
    },
    //反馈
    feedbookWork(row){
      this.title = "反馈信息";
      this.feedBookOpen = true;
      //this.feedBookForm = {};
      this.feedBookForm.workId = row.workId;
      this.feedBookForm.workTitle = row.workTitle;
      this.feedBookForm.workType = row.workType;
      /*if(row.iconUrl){
        this.feedBookForm.iconUrl = row.iconUrl;
      }*/
      /*if(row.rectificationPlan){
        this.feedBookForm.rectificationPlan =  row.rectificationPlan;
      }
      if(row.rectificationResult){
        this.feedBookForm.rectificationResult =  row.rectificationResult;
      }*/
      //this.feedBookForm = row;
      this.getEnterpriseLists();
    },
    //归档
    sortWork(row){
      this.$confirm('是否确认归档?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.workForm = {};
      this.workForm.workId = row.workId;
      this.workForm.workStatus = '3';
      if (this.workForm.workId != null) {
        updateOrder(this.workForm);
      }
      }).then(response => {
        this.getList();
        this.msgSuccess("归档成功");
      }).catch(() => {});
    },
    //任务下发提交
    submitWorkForm() {
      this.$refs["workForm"].validate(valid => {
        if (valid) {
          if (this.workForm.workId != null) {
            updateOrder(this.workForm).then(response => {
              this.msgSuccess("任务下发成功");
              this.workOpen = false;
              this.getList();
            });
          }
        }
      });
    },
    //任务下发取消
    cancelWorkForm(){
      this.workOpen = false;
      this.workForm = {};
    },
    //反馈提交
    submitFeedBookForm(){
      this.$refs["feedBookForm"].validate(valid => {
        if (valid) {
          if (this.feedBookForm.workId != null) {
            //this.feedBookForm.workStatus = '2';
            updateOrder(this.feedBookForm).then(response => {
              this.msgSuccess("反馈成功");
              this.feedBookOpen = false;
              this.getList();
          });
          }
        }
      });
    },
    //反馈取消
    cancelFeedBook(){
      this.feedBookOpen = false;
      this.feedBookForm = {};
    },
  }
};
</script>
