<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true" v-show="showSearch" label-width="68px">
      <!--      <el-form-item label="任务编号" prop="taskCode">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.taskCode"-->
      <!--          placeholder="请输入任务编号"-->
      <!--          clearable-->
      <!--          size="small"-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item label="任务名称" prop="taskName">
        <el-input
          v-model="queryParams.taskName"
          placeholder="请输入任务名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="任务类型" prop="taskType">
        <el-select v-model="queryParams.taskType" clearable placeholder="任务类型" @change="onInput()" >
          <el-option
            v-for="item in taskTypeOptions"
            :key="item.dictValue"
            :label="item.dictLabel"
            :value="item.dictValue">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="显示周期" prop="displayCycle">
        <el-select v-model="queryParams.displayCycle" clearable placeholder="显示周期" @change="onInput()">
          <el-option
            v-for="item in displayCycleOptions"
            :key="item.dictValue"
            :label="item.dictLabel"
            :value="item.dictValue">
          </el-option>
        </el-select>
      </el-form-item>
        <el-form-item label="流程类型" prop="processKey">
          <el-select v-model="queryParams.processKey" clearable placeholder="流程类型" style="width: 178px;" @change="onInput()">
            <el-option
              v-for="item in listModeler"
              :key="item.key"
              :label="item.name"
              :value="item.key">
            </el-option>
          </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="['sfa:task: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="['sfa:task: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="['sfa:task:softRemove']"
        >删除</el-button>
      </el-col>
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="warning"-->
      <!--          plain-->
      <!--          icon="el-icon-download"-->
      <!--          size="mini"-->
      <!--          @click="handleExport"-->
      <!--          v-hasPermi="['sfa:task:export']"-->
      <!--        >导出</el-button>-->
      <!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-select size="mini" v-model="sortVal" placeholder="排序方式" style="width: 100px;">-->
<!--          <el-option-->
<!--            v-for="item in storeOptions"-->
<!--            :key="item.value"-->
<!--            :label="item.label"-->
<!--            :value="item.value">-->
<!--          </el-option>-->
<!--        </el-select>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="taskList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!--      <el-table-column label="任务id" align="center" prop="taskId" />-->
      <el-table-column label="任务编号" align="center" prop="taskCode" width="90" />
      <el-table-column label="任务名称" align="center" prop="taskName"  :show-overflow-tooltip="true" />
      <el-table-column label="任务类型" align="center" prop="taskType" width="80" >
        <template slot-scope="scope">
          <span>{{taskTypeFormat(scope.row,scope.column)}}</span>
        </template>
      </el-table-column>
      <el-table-column label="流程类型" align="center" prop="processName" width="160" :show-overflow-tooltip="true" />
      <el-table-column label="是否必填" align="center" prop="isMust" width="80">
        <template slot-scope="scope">
          <span>{{isMustFormat(scope.row,scope.column)}}</span>
        </template>
      </el-table-column>
      <el-table-column label="显示周期" align="center" prop="displayCycle" width="80" >
        <template slot-scope="scope">
          <span>{{displayCycleFormat(scope.row,scope.column)}}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否有效" align="center" prop="isValid" width="90" >
        <template slot-scope="scope">
          <span>{{isValidFormat(scope.row,scope.column)}}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createBy" width="140"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="150" />
<!--      <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >编辑</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="previewFn(scope.row)"
            v-show="scope.row.taskType != '2'"
          >预览</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            class="text-danger"
          >删除</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="editVisible" width="90%" append-to-body>
      <el-form ref="editForm" :model="editForm"  :inline="true" :rules="editFormRules" size="mini" label-width="98px">
        <el-row :gutter="10">
          <el-col :span="6">
            <el-form-item label="任务编号" prop="taskCode" v-show="title=='新增任务'?false:true">
              <el-input v-model="editForm.taskCode" placeholder="请输入任务编号" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="任务名称" prop="taskName" >
              <el-input v-model="editForm.taskName" placeholder="请输入任务名称" @input="onInput()" />
            </el-form-item>
          </el-col>
<!--          <el-col :span="8">-->
<!--            <el-form-item label="是否必填" prop="isMust" style="height: 29px;">-->
<!--              <el-radio-group v-model="editForm.isMust">-->
<!--                <el-radio :label="item.dictValue" :key="index" v-for="(item,index) in isNotOptions">{{item.dictLabel}}</el-radio>-->
<!--              </el-radio-group>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
          <el-col :span="6">
            <el-form-item label="是否有效" prop="isValid" style="height: 29px;">
              <el-radio-group v-model="editForm.isValid">
                <el-radio :label="item.dictValue" :key="index" v-for="(item,index) in isNotOptions">{{item.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="显示周期" prop="displayCycle">
              <el-select v-model="editForm.displayCycle" clearable placeholder="显示周期" style="width: 178px;" @change="onInput()">
                <el-option
                  v-for="item in displayCycleOptions"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="任务类型" prop="taskType">
              <el-select v-model="editForm.taskType" placeholder="任务类型" @change="taskTypeChange" :disabled="taskTypeDisabled" style="width: 178px;">
                <el-option
                  v-for="item in taskTypeOptions"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="照片类型" prop="photoType">
              <el-select v-model="editForm.photoType" clearable placeholder="照片类型" style="width: 178px;" @change="onInput()">
                <el-option
                  v-for="item in photoTypeOptions"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="图片识别类型" prop="photoIdentifyType">
              <el-select v-model="editForm.photoIdentifyType" clearable placeholder="图片识别类型" style="width: 178px;" @change="onInput()">
                <el-option
                  v-for="item in photoIdentifyTypeOptions"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6" v-if="editForm.taskType==2||editForm.taskType==3">
            <el-form-item label="是否必填" prop="isMust" style="height: 29px;" >
              <el-radio-group v-model="editForm.isMust">
                <el-radio label="1" >否</el-radio>
                <el-radio label="0" >是(全部)</el-radio>
                <el-radio label="2" >是(至少一项)</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="6" v-if="editForm.taskType==2">
            <el-form-item label="不经营选项" prop="unManage" style="height: 29px;" >
              <el-radio-group v-model="editForm.unManage">
                <el-radio label="0" >展示</el-radio>
                <el-radio label="1" >隐藏</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="巡检类型" prop="inspectionType">
              <el-select v-model="editForm.inspectionType" clearable placeholder="巡检类型" style="width: 178px;" @change="onInput()">
                <el-option
                  v-for="item in sfataskOptions"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        <el-col :span="6">
          <el-form-item label="流程类型" prop="processKey">
            <el-select v-model="editForm.processKey" :disabled="title=='新增任务'?false:true" clearable placeholder="流程类型" style="width: 178px;" @change="onInput()">
              <el-option
                v-for="item in listModeler"
                :key="item.id"
                :label="item.name"
                :value="item.key">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        </el-row>
        <!--        <el-form-item label="删除标记" prop="delFlag">-->
        <!--          <el-input v-model="form.delFlag" placeholder="请输入删除标记" />-->
        <!--        </el-form-item>-->
      </el-form>
      <el-row :gutter="10" class="mb8">
<!--        <el-col :span="22">-->
<!--          <div class="info">【竞品新品调查】明细</div>-->
<!--        </el-col>-->
        <el-col :span="2">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="addCJXVisiableFn"
            v-hasPermi="['sfa:task:add']"
          >添加</el-button>
        </el-col>
      </el-row>
      <el-table v-show="editForm.taskType =='1'" v-loading="loading" :data="editForm.collectionItemList">
        <el-table-column label="采集项编号" align="center" prop="collectionCode" />
        <el-table-column label="采集项名称" align="center" prop="collectionName" />
        <el-table-column label="采集项类型" align="center" >
          <template slot-scope="scope">
            <span>{{collectionTypeFormat(scope.row,scope.column)}}</span>
          </template>
        </el-table-column>
        <el-table-column label="回答类型" align="center" >
          <template slot-scope="scope">
            <span>{{answerTypeFormat(scope.row,scope.column)}}</span>
          </template>
        </el-table-column>
        <el-table-column label="是否必填" align="center"  >
          <template slot-scope="scope">
            <span>{{isMustFormat(scope.row,scope.column)}}</span>
          </template>
        </el-table-column>
        <el-table-column label="是否支持图片" align="center" prop="isValid" >
          <template slot-scope="scope">
            <span>{{isPictureFormat(scope.row,scope.column)}}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="collectionItemDelete(scope.row)"
            >删除</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="previewFnC(scope.row)"
            >预览</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-top"
              @click="updateTaskCollectionItemSortFn(scope.row,scope.$index,'u')"
              :disabled="scope.$index == 0"
            >上移</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-bottom"
              @click="updateTaskCollectionItemSortFn(scope.row,scope.$index,'d')"
              :disabled="scope.$index == editForm.collectionItemList.length-1"
            >下移</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-table v-show="editForm.taskType =='2'" v-loading="loading" :data="editForm.productsList">
        <el-table-column label="产品编号" align="center" prop="code" />
        <el-table-column label="产品名称" align="center" prop="name" />
        <el-table-column label="品牌" align="center">
          <template slot-scope="scope">
            <span>{{brandIdFormat(scope.row,scope.column)}}</span>
          </template>
        </el-table-column>
        <el-table-column label="层次一" align="center">
          <template slot-scope="scope">
            <span>{{level1Format(scope.row,scope.column)}}</span>
          </template>
        </el-table-column>
        <el-table-column label="规格" align="center" prop="spec" width="80" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="productsDelete(scope.row)"
              class="text-danger"
            >删除</el-button>
<!--            <el-button-->
<!--              size="mini"-->
<!--              type="text"-->
<!--              icon="el-icon-view"-->
<!--              @click="previewFnC(scope.row)"-->
<!--              v-hasPermi="['sfa:collectionItem:edit']"-->
<!--            >预览</el-button>-->
            <el-button
              size="mini"
              type="text"
              icon="el-icon-top"
              @click="updateTaskProductsSortFn(scope.row,scope.$index,'u')"
              :disabled="scope.$index == 0"
            >上移</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-bottom"
              @click="updateTaskProductsSortFn(scope.row,scope.$index,'d')"
              :disabled="scope.$index == editForm.collectionItemList.length-1"
            >下移</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-table v-show="editForm.taskType =='3'" v-loading="loading" :data="editForm.signDictypeList">
<!--        <el-table-column label="产品编号" align="center" prop="code" />-->
        <el-table-column label="物料名称" align="center" prop="signName" />
        <el-table-column label="物料品类" align="center" prop="signType">
<!--          <template slot-scope="scope">-->
<!--            <span>{{brandIdFormat(scope.row,scope.column)}}</span>-->
<!--          </template>-->
        </el-table-column>

        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="WLDelete(scope.row)"
              class="text-danger"
            >删除</el-button>
            <!--            <el-button-->
            <!--              size="mini"-->
            <!--              type="text"-->
            <!--              icon="el-icon-view"-->
            <!--              @click="previewFnC(scope.row)"-->
            <!--              v-hasPermi="['sfa:collectionItem:edit']"-->
            <!--            >预览</el-button>-->
            <el-button
              size="mini"
              type="text"
              icon="el-icon-top"
              @click="updateWLProductsSortFn(scope.row,scope.$index,'u')"
              :disabled="scope.$index == 0"
            >上移</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-bottom"
              @click="updateWLProductsSortFn(scope.row,scope.$index,'d')"
              :disabled="scope.$index == editForm.collectionItemList.length-1"
            >下移</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="editSubmitForm">确 定</el-button>
        <el-button @click="editVisible=false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 编辑弹窗中的添加采集项对话框 -->
    <el-dialog title="添加采集项" :visible.sync="addCJXVisible" width="90%" append-to-body>
      <el-form ref="addCJXForm" :model="addCJXForm"  :inline="true" size="mini" v-show="showSearchCJX" label-width="90px">
        <el-form-item label="采集项编号" prop="collectionCode">
          <el-input v-model="addCJXForm.collectionCode" clearable placeholder="请输入采集项编号" @input="onInput()" />
        </el-form-item>
        <el-form-item label="采集项名称" prop="collectionName">
          <el-input v-model="addCJXForm.collectionName" clearable placeholder="请输入采集项名称" @input="onInput()"/>
        </el-form-item>
        <el-form-item label="采集项分类" prop="collectionType">
          <el-select size="mini" v-model="addCJXForm.collectionType" clearable placeholder="请选择采集项类型" @change="onInput()">
            <el-option
              v-for="item in collectionTypeOptions"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="cjxQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQueryCJX">重置</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"
            :disabled="multipleCJX"
            @click="addCJX"
          >批量添加</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearchCJX" @queryTable="cjxQuery"></right-toolbar>
      </el-row>
      <el-table v-loading="loadingCJX" :data="cjxList" @selection-change="handleSelectionChangeCJX">
        <el-table-column type="selection" width="55" align="center" />
        <!--      <el-table-column label="任务id" align="center" prop="taskId" />-->
        <el-table-column label="采集项编号" align="center" prop="collectionCode" />
        <el-table-column label="采集项名称" align="center" prop="collectionName" />
        <el-table-column label="采集项类型" align="center">
          <template slot-scope="scope">
            <span>{{collectionTypeFormat(scope.row,scope.column)}}</span>
          </template>
        </el-table-column>
        <el-table-column label="回答类型" align="center" width="80">
          <template slot-scope="scope">
            <span>{{answerTypeFormat(scope.row,scope.column)}}</span>
          </template>
        </el-table-column>
        <el-table-column label="使用频次" align="center" prop="useFrequency" width="80" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-plus"
              @click="addCJX(scope.row)"
            >添加</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="previewFnC(scope.row)"
            >预览</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="totalCJX>0"
        :total="totalCJX"
        :page.sync="addCJXForm.pageNum"
        :limit.sync="addCJXForm.pageSize"
        @pagination="getListCollectionItem"
      />
<!--      <div slot="footer" class="dialog-footer">-->
<!--        <el-button type="primary" @click="addCJXSubmitForm">确 定</el-button>-->
<!--        <el-button @click="addCJXVisible = false">取 消</el-button>-->
<!--      </div>-->
    </el-dialog>
    <!-- 编辑弹窗中的添加产品对话框 -->
    <el-dialog title="添加产品" :visible.sync="addCPVisible" width="90%" append-to-body>
      <el-form ref="addCPForm" :model="addCPForm"  :inline="true" size="mini" v-show="showSearchCP" label-width="90px">
        <el-form-item label="产品编号" prop="code">
          <el-input v-model="addCPForm.code" clearable placeholder="请输入产品编号" />
        </el-form-item>
        <el-form-item label="产品名称" prop="name">
          <el-input v-model="addCPForm.name" clearable placeholder="请输入产品名称" />
        </el-form-item>
        <el-form-item label="品牌" prop="brandCode">
          <el-select v-model="addCPForm.brandCode" clearable placeholder="请选择品牌">
            <el-option
              v-for="item in brandIdOptions"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="层次一" prop="level1">
          <el-select v-model="addCPForm.level1" clearable placeholder="请选择层次一">
            <el-option
              v-for="item in level1Options"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="cpQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQueryCP">重置</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"
            :disabled="multipleCP"
            @click="addCP"
          >批量添加</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearchCP" @queryTable="cpQuery"></right-toolbar>
      </el-row>
      <el-table v-loading="loadingCP" :data="CPList" @selection-change="handleSelectionChangeCP">
        <el-table-column type="selection" width="55" align="center" />
        <!--      <el-table-column label="任务id" align="center" prop="taskId" />-->
        <el-table-column label="产品编号" align="center" prop="code" />
        <el-table-column label="产品名称" align="center" prop="name" />
        <el-table-column label="品牌" align="center">
          <template slot-scope="scope">
            <span>{{brandIdFormat(scope.row,scope.column)}}</span>
          </template>
        </el-table-column>
        <el-table-column label="层次一" align="center">
          <template slot-scope="scope">
            <span>{{level1Format(scope.row,scope.column)}}</span>
          </template>
        </el-table-column>
        <el-table-column label="规格" align="center" prop="spec" width="80" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-plus"
              @click="addCP(scope.row)"
            >添加</el-button>
<!--            <el-button-->
<!--              size="mini"-->
<!--              type="text"-->
<!--              icon="el-icon-view"-->
<!--              @click="handleUpdate(scope.row)"-->
<!--              v-hasPermi="['sfa:collectionItem:edit']"-->
<!--            >预览</el-button>-->
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="totalCP>0"
        :total="totalCP"
        :page.sync="addCPForm.pageNum"
        :limit.sync="addCPForm.pageSize"
        @pagination="getListProducts"
      />
<!--      <div slot="footer" class="dialog-footer">-->
<!--        <el-button type="primary" @click="addCPVisible = false">确 定</el-button>-->
<!--        <el-button @click="addCPVisible = false">取 消</el-button>-->
<!--      </div>-->
    </el-dialog>
    <el-dialog title="添加物料" :visible.sync="addWLVisible" width="90%" append-to-body>
      <el-form ref="addWLForm" :model="addWLForm"  :inline="true" size="mini" v-show="showSearchCP" label-width="90px">

        <el-form-item label="物料名称" prop="signName">
          <el-input v-model="addWLForm.signName" clearable placeholder="请输入物料名称" />
        </el-form-item>
        <el-form-item label="物料品类" prop="signType">
          <el-input v-model="addWLForm.signType" clearable placeholder="请输入物料品类" />
<!--          <el-select v-model="addWLForm.signType" clearable placeholder="请选择物料品类">-->
<!--            <el-option-->
<!--              v-for="item in brandIdOptions"-->
<!--              :key="item.dictValue"-->
<!--              :label="item.dictLabel"-->
<!--              :value="item.dictValue">-->
<!--            </el-option>-->
<!--          </el-select>-->
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="LWQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQueryLW">重置</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"
            :disabled="multipleCP"
            @click="addWL"
          >批量添加</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearchCP" @queryTable="LWQuery"></right-toolbar>
      </el-row>
      <el-table v-loading="loadingCP" :data="LWList" @selection-change="handleSelectionChangeWL">
        <el-table-column type="selection" width="55" align="center" />
        <!--      <el-table-column label="任务id" align="center" prop="taskId" />-->
<!--        <el-table-column label="产品编号" align="center" prop="code" />-->
        <el-table-column label="物料名称" align="center" prop="signName" />
        <el-table-column label="物料类型" align="center" prop="signType" >
<!--          <template slot-scope="scope">-->
<!--            <span>{{brandIdFormat(scope.row,scope.column)}}</span>-->
<!--          </template>-->
        </el-table-column>
<!--        <el-table-column label="规格" align="center" prop="spec" width="80" />-->
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-plus"
              @click="addWL(scope.row)"
            >添加</el-button>
            <!--            <el-button-->
            <!--              size="mini"-->
            <!--              type="text"-->
            <!--              icon="el-icon-view"-->
            <!--              @click="handleUpdate(scope.row)"-->
            <!--              v-hasPermi="['sfa:collectionItem:edit']"-->
            <!--            >预览</el-button>-->
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="totalCP>0"
        :total="totalCP"
        :page.sync="addWLForm.pageNum"
        :limit.sync="addWLForm.pageSize"
        @pagination="getListLW"
      />
      <!--      <div slot="footer" class="dialog-footer">-->
      <!--        <el-button type="primary" @click="addCPVisible = false">确 定</el-button>-->
      <!--        <el-button @click="addCPVisible = false">取 消</el-button>-->
      <!--      </div>-->
    </el-dialog>
    <!-- 预览 -->
    <el-dialog title="预览" :visible.sync="preview" width="60%" append-to-body>
      <el-form class="previewFormItem" :model="item" label-width="110px" v-for="(item,index) in previewForm" :key="index">
        <el-form-item>
          <div>
            <span class="font-red" v-if="item.isMust == 0">*</span>{{item.collectionName}}
            <icon :answerType="item.answerType"></icon>
          </div>
        </el-form-item>
        <el-form-item label="" v-show="item.answerType == 'dx'">
<!--          <radio :radioValF="item.answer" :index="index" :radioOptions="item.collectionOptionList" @radioFn="radioFn"></radio>-->
          <el-radio-group v-model="item.values">
            <el-radio :label="itemc.collectionOptionId" v-for="itemc in item.collectionOptionList" :key="itemc.collectionOptionId">{{itemc.collectionOption}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <div v-show="item.answerType == 'dx'">
          <div v-for="childItem  in item.collectionOptionList" style="padding-left: 40px">
            <div v-show="childItem.collectionOptionId == item.values">
              <div v-for="itemT  in childItem.collectionItems">
            <el-form-item>
              <div>
                <span class="font-red" v-if="itemT.isMust == 0">*</span>{{itemT.collectionName}}
                <icon :answerType="itemT.answerType"></icon>
              </div>
            </el-form-item>
            <el-form-item label="" v-show="itemT.answerType == 'dx'">
<!--              <radio :radioValF="itemT.answer" :radioOptions="itemT.collectionOptionList"></radio>-->
              <el-radio-group v-model="itemT.values">
                <el-radio :label="itemTS.collectionOptionId" v-for="itemTS in itemT.collectionOptionList" :key="itemTS.collectionOptionId">{{itemTS.collectionOption}}</el-radio>
              </el-radio-group>
            </el-form-item>
                <div v-show="itemT.answerType == 'dx'">
                  <div v-for="childItemT  in itemT.collectionOptionList" style="padding-left: 80px">
                    <div v-show="childItemT.collectionOptionId == itemT.values">
                      <div v-for="itemTT  in childItemT.collectionItems">
                        <el-form-item>
                          <div>
                            <span class="font-red" v-if="itemTT.isMust == 0">*</span>{{itemTT.collectionName}}
                            <icon :answerType="itemTT.answerType"></icon>
                          </div>
                        </el-form-item>
                        <el-form-item label="" v-show="itemTT.answerType == 'dx'">
                          <el-radio-group v-model="itemTT.values">
                            <el-radio :label="itemTTS.collectionOptionId" v-for="(itemTTS,index) in itemTT.collectionOptionList" :key="index">{{itemTTS.collectionOption}}</el-radio>
                          </el-radio-group>
                        </el-form-item>
                        <div v-show="itemTT.answerType == 'dx'">
                          <div v-for="childItemT4  in itemTT.collectionOptionList" style="padding-left: 80px">
                            <div v-show="childItemT4.collectionOptionId == itemTT.values">
                              <div v-for="itemTT4  in childItemT4.collectionItems">
                                <el-form-item>
                                  <div>
                                    <span class="font-red" v-if="itemTT4.isMust == 0">*</span>{{itemTT4.collectionName}}
                                    <icon :answerType="itemTT4.answerType"></icon>
                                  </div>
                                </el-form-item>
                                <el-form-item label="" v-show="itemTT4.answerType == 'dx'">
                                  <el-radio-group v-model="itemTT4.values">
                                    <el-radio :label="itemTT4S.collectionOptionId" v-for="(itemTT4S,indet4) in itemTT4.collectionOptionList" :key="indet4">{{itemTT4S.collectionOption}}</el-radio>
                                  </el-radio-group>
                                </el-form-item>
                                <div v-show="itemTT4.answerType == 'dx'">
                                  <div v-for="childItemT5  in itemTT4.collectionOptionList" style="padding-left: 80px">
                                    <div v-show="childItemT5.collectionOptionId == itemTT4.values">
                                      <div v-for="itemTT5  in childItemT5.collectionItems">
                                        <el-form-item>
                                          <div>
                                            <span class="font-red" v-if="itemTT5.isMust == 0">*</span>{{itemTT5.collectionName}}
                                            <icon :answerType="itemTT5.answerType"></icon>
                                          </div>
                                        </el-form-item>
                                        <el-form-item label="" v-show="itemTT5.answerType == 'dx'">
                                          <radio :radioValF="itemTT5.answer" :radioOptions="itemTT5.collectionOptionList"></radio>
                                        </el-form-item>
                                        <el-form-item v-show="itemTT5.answerType == 'duox'">
                                          <checkbox :checkboxValF="itemTT5.answer" :checkboxOptions="itemTT5.collectionOptionList"></checkbox>
                                        </el-form-item>
                                        <el-form-item class="mobile-input" v-if="itemTT5.answerType == 'wb' || itemTT5.answerType == 'sz'||itemTT5.answerType == 'tel'||itemTT5.answerType == 'date'||itemTT5.answerType == 'sm'">
                                          <div v-if="itemTT5.collectionOptionList.length>0">
                                            <el-input size="mini" disabled v-model="itemTT5.collectionOptionList[0].collectionOption" type="textarea" :rows="10"  resize="none"/>
                                          </div>
                                        </el-form-item>
                                      </div>
                                    </div>
                                  </div>
                                </div>
                                <el-form-item v-show="itemTT4.answerType == 'duox'">
                                  <checkbox :checkboxValF="itemTT4.answer" :checkboxOptions="itemTT4.collectionOptionList"></checkbox>
                                </el-form-item>
                                <el-form-item class="mobile-input" v-if="itemTT4.answerType == 'wb' || itemTT4.answerType == 'sz'||itemTT4.answerType == 'tel'||itemTT4.answerType == 'date'||itemTT4.answerType == 'sm'">
                                  <div v-if="itemTT4.collectionOptionList.length>0">
                                    <el-input size="mini" disabled v-model="itemTT4.collectionOptionList[0].collectionOption" type="textarea" :rows="10"  resize="none"/>
                                  </div>
                                </el-form-item>
                              </div>
                            </div>
                          </div>
                        </div>
                        <el-form-item v-show="itemTT.answerType == 'duox'">
                          <checkbox :checkboxValF="itemTT.answer" :checkboxOptions="itemTT.collectionOptionList"></checkbox>
                        </el-form-item>
                        <el-form-item class="mobile-input" v-if="itemTT.answerType == 'wb' || itemTT.answerType == 'sz'||itemTT.answerType == 'tel'||itemTT.answerType == 'date'||itemTT.answerType == 'sm'">
                          <div v-if="itemTT.collectionOptionList.length>0">
                            <el-input size="mini" disabled v-model="itemTT.collectionOptionList[0].collectionOption" type="textarea" :rows="10"  resize="none"/>
                          </div>
                        </el-form-item>
                      </div>
                    </div>
                  </div>
                </div>
            <el-form-item v-show="itemT.answerType == 'duox'">
              <checkbox :checkboxValF="itemT.answer" :checkboxOptions="itemT.collectionOptionList"></checkbox>
            </el-form-item>
            <el-form-item class="mobile-input" v-if="itemT.answerType == 'wb' || itemT.answerType == 'sz'||itemT.answerType == 'tel'||itemT.answerType == 'date'">
              <div v-if="itemT.collectionOptionList.length>0">
                <el-input size="mini" disabled v-model="itemT.collectionOptionList[0].collectionOption"
                          type="textarea" :rows="10"  resize="none"/>
              </div>
            </el-form-item>
            </div>
            </div>
          </div>
        </div>
        <el-form-item v-show="item.answerType == 'duox'">
          <checkbox :checkboxValF="item.answer" :checkboxOptions="item.collectionOptionList"></checkbox>
        </el-form-item>
        <el-form-item class="mobile-input" v-if="item.answerType == 'wb' || item.answerType == 'sz'||item.answerType == 'tel'||item.answerType == 'date'">
          <div v-if="item.collectionOptionList.length>0">
            <el-input size="mini" disabled v-model="item.collectionOptionList[0].collectionOption"
                      type="textarea" :rows="10"  resize="none"/>
          </div>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
    import { listTask, getTask, delTask, addTask, updateTask,softRemove,removeTaskCollectionItem,updateTaskCollectionItemSort } from "@/api/sfa/task";
    import { listCollectionItem,getCollectionItem } from "@/api/sfa/collectionItem";
    import { listProducts} from "@/api/sfa/products";
    import radio from "@/views/components/sfa/radio";
    import checkbox from "@/views/components/sfa/checkbox";
    import icon from "@/views/components/sfa/icon";
    import {listModeler} from "@/api/activiti/modeler";
    import {signLists} from "@/api/sfa/material";
    export default {
        name: "Task",
        components: { radio,checkbox,icon },
        data() {
            return {
                // 遮罩层
                loading: true,
                loadingCJX: true,
                loadingCP: true,
                // 选中数组
                ids: [],
                collectionIds: [],
                collections: [],
                chanpin:[],
              chanpinWL:[],
                chanpinCodes:[],
              chanpinCodesWL:[],
                collectionAddList:[],
                chanpinAddList:[],
              WLAddList:[],
               LWList:[],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                multipleCJX: true,
                multipleCP: true,
                // 显示搜索条件
                showSearch: true,
                showSearchCJX: true,
                showSearchCP: true,
                // 总条数
                total: 0,
                totalEdit: 0,
                totalCJX: 0,
                totalCP: 0,
                // 任务表格数据
                taskList: [],
                // 添加采集项弹窗中采集项列表
                cjxList:[],
                CPList:[],
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                editVisible: false,
                addCJXVisible: false,
                addCPVisible: false,
                addWLVisible:false,
                preview: false,
              sfataskOptions:[],
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    taskCode: null,
                    taskName: null,
                    isMust: null,
                    isValid: null,
                    displayCycle: null,
                    processKey:null
                },
                // 表单参数
                editForm: {
                    // 新增任务弹窗中任务列表
                    taskType:'1',
                    isMust:'1',
                    unManage:"1",
                    collectionItemList: [],
                    signDictypeList:[],
                    photoIdentifyType:"",
                },
                addCJXForm:{
                    pageNum: 1,
                    pageSize: 10,
                },
                addCPForm:{
                    pageNum: 1,
                    pageSize: 10,
                },
              addWLForm:{
                pageNum: 1,
                pageSize: 10,
              },
                // addForm:{},
                // 表单校验
                editFormRules: {
                    taskName: [ { required: true, message: '请输入任务名称', trigger: 'blur' }],
                    isMust: [ { required: true, message: '请选择是否必填', trigger: 'change' }],
                    isValid: [ { required: true, message: '请选择是否有效', trigger: 'change' }],
                    displayCycle: [ { required: true, message: '请选择显示周期', trigger: 'change' }],
                    taskType: [ { required: true, message: '请选择任务类型', trigger: 'change' }],
                    // photoType: [ { required: true, message: '请选择照片类型', trigger: 'change' }],
                },
                sortVal:'',
                displayCycleOptions:[],
                isNotOptions:[],
                collectionTypeOptions:[],
                taskTypeOptions:[
                    {
                        dictLabel: "常规类型",
                        dictValue: "1"
                    },
                    {
                        dictLabel: "产品类型",
                        dictValue: "2"
                    },
                  {
                    dictLabel: "物料类型",
                    dictValue: "3"
                  },
                ],
                photoTypeOptions:[],
                photoIdentifyTypeOptions:[],
                previewForm:[],
                brandIdOptions:[],
                level1Options:[],
                taskTypeDisabled:false,
                listModeler:[]
            };
        },
        created() {
            // 显示周期
            this.getDicts("sfa_task_display_cycle").then(response => {
                this.displayCycleOptions = response.data;
            });
            // 是否
            this.getDicts("is_not").then(response => {
                this.isNotOptions = response.data;
            });
            // 采集项类型
            this.getDicts("sfa_collection_type").then(response => {
                this.collectionTypeOptions = response.data;
            });
            // 回答类型
            this.getDicts("sfa_collection_answer_type").then(response => {
                this.answerTypeOptions = response.data;
            });
            // 照片类型
            this.getDicts("sfa_task_photo_type").then(response => {
                this.photoTypeOptions = response.data;
            });
            // 图像识别类型
            this.getDicts("photo_identify_type").then(response => {
                this.photoIdentifyTypeOptions = response.data;
            });
            // 层次一
            this.getDicts("sfa_level1").then(response => {
                this.level1Options = response.data;
            });
            // 品牌
            this.getDicts("inspection_type").then(response => {
                this.sfataskOptions = response.data;
            });
          this.getDicts("sfa_product_brand").then(response => {
            this.brandIdOptions = response.data;
          });
            this.getList();
            this.getListModeler()
        },
        methods: {
          radioFn(val){
            console.log(val)
          },
          getListModeler(){
            listModeler().then(response=>{
              this.listModeler=response.rows
            })
          },
            onInput(){
                this.$forceUpdate();
            },
            /** 查询任务列表 */
            getList() {
                this.loading = true;
                listTask(this.queryParams).then(response => {
                    this.taskList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            // 任务类型转换
            taskTypeFormat(row, column){
                return this.selectDictLabel(this.taskTypeOptions, row.taskType);
            },
            // 是否必填中文转换
            isMustFormat(row, column){
              if(row.isMust==1){
                return "否"
              }else{
                return  "是"
              }
            },
            // 是否支持图片中文转换
            isPictureFormat(row, column){
                return this.selectDictLabel(this.isNotOptions, row.isPicture);
            },
            // 是否有效中文转换
            isValidFormat(row, column){
                return this.selectDictLabel(this.isNotOptions, row.isValid);
            },
            // 任务周期
            displayCycleFormat(row, column){
                return this.selectDictLabel(this.displayCycleOptions, row.displayCycle);
            },
            // 采集项类型中文转换
            collectionTypeFormat(row, column){
                return this.selectDictLabel(this.collectionTypeOptions, row.collectionType);
            },
            // 回答类型中文转换
            answerTypeFormat(row, column){
                return this.selectDictLabel(this.answerTypeOptions, row.answerType);
            },
            // 层次一中文转换
            level1Format(row, column){
                return this.selectDictLabel(this.level1Options, row.level1);
            },
            // 品牌中文转换
            brandIdFormat(row, column){
                return this.selectDictLabel(this.brandIdOptions, row.brandCode);
            },
            editCancel() {
                this.editVisible = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.resetForm("editForm");
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.resetForm("queryForm");
                this.handleQuery();
            },
            /** 采集项重置按钮操作 */
            resetQueryCJX() {
                this.resetForm("addCJXForm");
                this.cjxQuery();
            },
            /** 产品重置按钮操作 */
            resetQueryCP() {
                this.resetForm("addCPForm");
                this.cpQuery();
            },
          resetQueryLW() {
            this.resetForm("addLWForm");
            this.cpQuery();
          },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.taskId)
                this.single = selection.length!==1
                this.multiple = !selection.length
            },
            handleSelectionChangeCJX(selection) {
                this.collectionIds = selection.map(item => item.collectionCode);
                this.collections = selection;
                this.multipleCJX = !selection.length
            },
            handleSelectionChangeCP(selection) {
                this.chanpinCodes = selection.map(item => item.code);
                this.chanpin = selection;
                this.multipleCP = !selection.length
            },
          handleSelectionChangeWL(selection) {
            this.chanpinCodesWL = selection.map(item => item.id);
            this.chanpinWL = selection;
            console.log(this.chanpinCodesWL)
            console.log(this.chanpinWL)
            this.multipleCP = !selection.length
          },
            /** 新增按钮操作 */
            handleAdd() {
                this.resetForm("editForm");
                 this.editForm.taskId=null
                this.editForm.collectionItemList = [];
                this.editForm.signDictypeList=[]
                this.editForm.isMust = "1"
                this.editForm.taskType = '1';
                this.editForm.unManage = '1';
                this.editForm.processKey = null;
                this.editVisible = true;
                this.taskTypeDisabled = false;
                this.$forceUpdate();
                this.title = '新增任务';
                this.collectionAddList = [];
                this.chanpinAddList = [];
                this.WLAddList=[]
            },
            /** 修改任务按钮操作 */
            handleUpdate(row) {
                this.resetForm("editForm");
                this.editForm.taskType = '1';
                this.editForm.unManage = '1';
                this.title = '任务编辑';
                const taskId = row.taskId || this.ids
                this.editVisible = true;
                this.taskTypeDisabled = true;
                this.$forceUpdate();
                this.collectionAddList = [];
                this.chanpinAddList = [];
                this.WLAddList=[]
                this.getTaskData(taskId);
            },
            taskTypeChange(){
                this.$forceUpdate();
                this.editForm.collectionItemList = [];
                this.editForm.productsList = [];
                if(this.editForm.taskId){
                    this.getTaskData(this.editForm.taskId);
                }
            },
            getTaskData(taskId){
                getTask(taskId).then(response => {
                    this.editForm = response.data;
                    if(this.editForm.productsList == null){
                        this.editForm.productsList = []
                    }
                    if(this.editForm.collectionItemList == null){
                        this.editForm.collectionItemList = []
                    }
                    this.editVisible = true;
                });
            },
            getListCollectionItem(){
                this.addCJXForm.itemList = this.collectionAddList;
                this.loadingCJX = true;
                listCollectionItem(this.addCJXForm).then(response => {
                    this.cjxList = response.rows;
                    this.totalCJX = response.total;
                    this.loadingCJX = false;
                });
            },
            // 获取产品列表
            getListProducts(){
                this.addCPForm.productList = this.chanpinAddList;
                this.loadingCP = true;
                listProducts(this.addCPForm).then(response => {
                    this.CPList = response.rows;
                    this.totalCP = response.total;
                    this.loadingCP = false;
                });
            },
          getListLW(){
            this.addWLForm.signIdList = this.WLAddList;
            this.loadingCP = true;
            signLists(this.addWLForm).then(response => {
              this.LWList = response.rows;
              this.totalCP = response.total;
              this.loadingCP = false;
            });
          },
            // 采集项搜索
            cjxQuery(){
                this.addCJXForm.pageNum = 1;
                this.getListCollectionItem();
            },
            // 产品搜索
            cpQuery(){
                this.addCPForm.pageNum = 1;
                this.getListProducts();
            },
              LWQuery(){
                this.addLWForm.pageNum = 1;
                this.getListLW();
              },
            addCJX(row){
                let that = this;
                let collection = [];
                row.collectionId ? collection.push(row) : collection = this.collections;
                const collectionIds = row.collectionCode || this.collectionIds;
                let collectionItemList = that.editForm.collectionItemList;
                // this.$modal.confirm('是否确认添加采集项编号为"' + collectionIds + '"的数据项？').then(function() {
                this.$modal.confirm('是否确认添加选中信息？').then(function() {
                    // that.editForm.collectionItemList = collectionItemList.concat(collection);
                    let arr = [];

                    collection.forEach((item,index)=>{
                        // that.cjxList.forEach((cjx,i)=>{
                        //     if(item.collectionId == cjx.collectionId){
                        //         that.cjxList.splice(i,1);
                        //     }
                        // })
                        that.collectionAddList.push(item.collectionId);
                        that.editForm.collectionItemList.forEach((collectionItem,ind)=>{
                            collectionItem.collectionId != item.collectionId ? arr.push(false): arr.push(true);
                            //
                        })
                        arr.indexOf(true) == -1 ? that.editForm.collectionItemList.push(item) : that.editForm.collectionItemList;
                    })
                }).then(() => {
                    this.getListCollectionItem();
                    that.$modal.msgSuccess("添加成功");
                }).catch(() => {});
            },
            addCP(row){
              console.log(row)
              let that = this;
              let chanpin = [];
              row.code ? chanpin.push(row) : chanpin = this.chanpin;
              const chanpinCodes = row.code || this.chanpinCodes;
              let chanpinmList = that.editForm.productsList;
              this.$modal.confirm('是否添加选中信息？').then(function() {
                // that.editForm.collectionItemList = collectionItemList.concat(collection);
                let arr = [];
                chanpin.forEach((item,index)=>{
                  // that.CPList.forEach((cp,i)=>{
                  //     if(item.code == cp.code){
                  //         that.CPList.splice(i,1);
                  //     }
                  // })
                  that.chanpinAddList.push(item.productId);
                  that.editForm.productsList.forEach((product,ind)=>{
                    product.code != item.code ? arr.push(false): arr.push(true);
                    //
                  })
                  arr.indexOf(true) == -1 ? that.editForm.productsList.push(item) : that.editForm.productsList;
                })
              }).then(() => {
                this.getListProducts();
                that.$modal.msgSuccess("添加成功");
              }).catch(() => {});
            },
          addWL(row){
            let that = this;
            let chanpin = [];
            row.id ? chanpin.push(row) : chanpin = this.chanpinWL;
            const chanpinCodes = row.id || this.chanpinCodesWL;
            let chanpinmList = that.editForm.signDictypeList;
            this.$modal.confirm('是否添加选中信息？').then(function() {
              let arr = [];
              chanpin.forEach((item,index)=>{
                that.WLAddList.push(item.id);
                that.editForm.signDictypeList.forEach((product,ind)=>{
                  product.id != item.id ? arr.push(false): arr.push(true);
                })
                arr.indexOf(true) == -1 ? that.editForm.signDictypeList.push(item) : that.editForm.signDictypeList;
              })
            }).then(() => {
              this.getListLW();
              that.$modal.msgSuccess("添加成功");
            }).catch(() => {});
          },
            /** 提交按钮 */
            editSubmitForm(isAdd){
                let isAddBtn = isAdd || false;
                this.$refs["editForm"].validate(valid => {
                    if (valid) {
                        if (this.editForm.taskId != null) {
                            updateTask(this.editForm).then(response => {
                                this.$modal.msgSuccess('修改成功');
                                this.editVisible = false;
                                this.getList();
                            });
                        } else {
                            addTask(this.editForm).then(response => {
                                console.log(response)
                                this.$modal.msgSuccess('新增成功');
                                this.editVisible = false;
                                this.getList();
                            });
                        }
                    }
                });
            },
            addCJXVisiableFn(){
                if(this.editForm.taskType == '1'){
                    this.resetForm("addCJXForm");
                    this.addCJXVisible = true;
                    this.addCJXForm.taskId = this.editForm.taskId;
                    this.addCJXForm.pageNum = 1;
                    this.getListCollectionItem();
                }else if(this.editForm.taskType == '2'){
                    this.resetForm("addCPForm");
                    this.addCPVisible = true;
                    this.addCPForm.taskId = this.editForm.taskId;
                    this.addCPForm.pageNum = 1;
                    this.getListProducts();
                }else if(this.editForm.taskType == '3'){
                  this.resetForm("addWLForm");
                  this.addWLVisible = true;
                  this.addWLForm.taskId = this.editForm.taskId;
                  this.addWLForm.pageNum = 1;
                  this.getListLW();
                }else{
                    this.$modal.msgWarning("请选择任务类型");
                }
            },
            addSubmitForm(){
                addTask(this.editForm).then(response => {
                    // this.taskList = response.rows;
                    this.editVisible = false;
                    this.getList();
                });
            },
            addCJXSubmitForm(){
                this.addCJXVisible = false;
            },
            /** 删除按钮操作 */
            handleDelete(row) {
                const taskIds = row.taskId || this.ids.join(',');
                let that = this;
                // this.$modal.confirm('是否确认删除任务编号为"' + taskIds + '"的数据项？').then(function() {
                this.$modal.confirm('是否确认删除选中信息？').then(function() {
                    return softRemove({taskIds:taskIds}).then(response => {
                        that.$modal.msgSuccess("删除成功");
                        that.getList();
                    });
                })
            },
            // 删除任务中的采集项
            collectionItemDelete(row){
                console.log(row)
                // if(row.taskCollectionId != null){
                //     let obj = {
                //         taskCollectionId:row.taskCollectionId
                //     }
                //     removeTaskCollectionItem(obj).then(response => {
                //         this.$modal.msgSuccess("删除成功");
                //         this.getTaskData(this.editForm.taskId);
                //     });
                // }else{
                    this.editForm.collectionItemList.forEach((item,index)=>{
                        if(item.collectionId == row.collectionId){
                            this.editForm.collectionItemList.splice(index,1);
                            // this.$modal.msgSuccess("删除成功");
                        }
                    })
                this.collectionAddList.forEach((item,index)=>{
                  if(item == row.collectionId){
                      this.collectionAddList.splice(index,1);
                  }
                })
                // }
            },
            productsDelete(row){
                this.editForm.productsList.forEach((item,index)=>{
                    if(item.code == row.code){
                        this.editForm.productsList.splice(index,1);
                    }
                })
                this.chanpinAddList.forEach((item,index)=>{
                    if(item == row.productId){
                        this.chanpinAddList.splice(index,1);
                    }
                })
            },
          WLDelete(row){
            this.editForm.signDictypeList.forEach((item,index)=>{
              if(item.id == row.id){
                this.editForm.signDictypeList.splice(index,1);
              }
            })
            this.WLAddList.forEach((item,index)=>{
              if(item == row.id){
                this.WLAddList.splice(index,1);
              }
            })
          },
            updateTaskCollectionItemSortFn(row,index,isUPD){
                let obj = {
                    taskCollectionId:row.taskCollectionId,
                    upDown:isUPD
                };
                let msg = '';
                if(isUPD == 'u'){
                    let upData = this.editForm.collectionItemList[index - 1];
                    this.editForm.collectionItemList.splice(index - 1, 1);
                    this.editForm.collectionItemList.splice(index, 0, upData);
                    msg =  '上移成功';
                }else{
                    let downData = this.editForm.collectionItemList[index + 1];
                    this.editForm.collectionItemList.splice(index + 1, 1);
                    this.editForm.collectionItemList.splice(index, 0, downData);
                    msg =  '下移成功';
                }
                this.$modal.msgSuccess(msg);
                // updateTaskCollectionItemSort(obj).then(response => {
                //     this.$modal.msgSuccess(msg);
                //     this.getTaskData(this.editForm.taskId);
                // });
            },
            updateTaskProductsSortFn(row,index,isUPD){
                let msg = '';
                if(isUPD == 'u'){
                    let upData = this.editForm.productsList[index - 1];
                    this.editForm.productsList.splice(index - 1, 1);
                    this.editForm.productsList.splice(index, 0, upData);
                    msg =  '上移成功';
                }else{
                    let downData = this.editForm.productsList[index + 1];
                    this.editForm.productsList.splice(index + 1, 1);
                    this.editForm.productsList.splice(index, 0, downData);
                    msg =  '下移成功';
                }
                this.$modal.msgSuccess(msg);
            },
          updateWLProductsSortFn(row,index,isUPD){
            let msg = '';
            if(isUPD == 'u'){
              let upData = this.editForm.signDictypeList[index - 1];
              this.editForm.signDictypeList.splice(index - 1, 1);
              this.editForm.signDictypeList.splice(index, 0, upData);
              msg =  '上移成功';
            }else{
              let downData = this.editForm.signDictypeList[index + 1];
              this.editForm.signDictypeList.splice(index + 1, 1);
              this.editForm.signDictypeList.splice(index, 0, downData);
              msg =  '下移成功';
            }
            this.$modal.msgSuccess(msg);
          },
            /** 导出按钮操作 */
            handleExport() {
                this.download('sfa/task/export', {
                    ...this.queryParams
                }, `task_${new Date().getTime()}.xlsx`)
            },
            previewFn(row){
                this.previewForm = [];
                getTask(row.taskId).then(response => {
                    console.log(response)
                    this.previewForm = response.data.collectionItemList;
                    this.preview = true;
                });
            },
            previewFnC(row){
                this.previewForm = [];
                getCollectionItem(row.collectionId).then(response => {
                    console.log(response.data.collectionOptionList)
                    this.previewForm.push(response.data);
                    this.preview = true;
                });
            },
        }
    };
</script>
<style lang="scss" scoped>
  .font-red{
    color: #ff4949;
    position: absolute;
    left: -8px;
    top: 2px;
  }
</style>
