<template>
  <div v-loading="detailedLoding" class="layout-no-flex">
    <el-toolbar v-if="fromArticleEditor">
      <el-button v-if="tmpVote.ID !== null" @click="result" priv="VoteManage">
        <i class="fa fa-search"></i>查看结果</el-button>
    </el-toolbar>
    <el-toolbar v-else>
      <el-button @click="backListPage" type="primary" size="medium" round class="shadow-primary">
        <i class="fa fa-chevron-left"></i> 返回上页</el-button>
      <span class="button-separator"></span>
      <el-button @click="save" :priv="isEdit ? `VoteManage.Edit.${voteID}` : 'VoteManage'">
        <i class="fa fa-save"></i>保存</el-button>
      <span v-show="isEdit">
        <el-button @click="previewClickHandler" priv="VoteManage">
          <i class="fa fa-eye"></i>预览</el-button>
        <el-button @click="result" priv="VoteManage">
          <i class="fa fa-search"></i>查看结果</el-button>
        <el-button v-if="tmpVote.status!='auditing' && tmpVote.status!='passed' && tmpVote.isNeedAudit && tmpVote.status!='published'"
          @click="commitAuditHandler" :priv="'VoteManage.CommitAudit.'+voteID">
          <i class="fa fa-cloud-upload"></i>提交审核</el-button>
        <el-button v-if="tmpVote.status=='auditing' && tmpVote.isNeedAudit" @click="ClickHandler('passed')" :priv="'VoteManage.Audit.'+voteID">
          <i class="fa fa-check-circle-o"></i>审核通过</el-button>
        <el-button v-if="tmpVote.status=='auditing' && tmpVote.isNeedAudit" @click="AuditNotPass" :priv="'VoteManage.Audit.'+voteID">
          <i class="fa fa-exclamation-triangle text-danger"></i>审核不通过</el-button>
        <el-button v-if="(tmpVote.status=='passed' || tmpVote.status=='published')&&isEdit&&tmpVote.isNeedAudit&&tmpVote.status!='stoped'"
          @click="ClickHandler('editagain')" :priv="'VoteManage.Audit.'+voteID">
          <i class="fa fa-repeat"></i>重新编辑</el-button>
        <el-button v-if="(tmpVote.status=='passed' || tmpVote.status=='published')&&isEdit&&tmpVote.isNeedAudit&&tmpVote.status!='stoped'"
          @click="VoteStop" :priv="'VoteManage.Publish.'+voteID">
          <i class="fa fa-unlink"></i>手工终止</el-button>
        <el-button v-if="(tmpVote.status=='passed' || tmpVote.status=='published')&&isEdit&&tmpVote.isNeedAudit&&tmpVote.status!='stoped'"
          @click="VotePublish" :priv="'VoteManage.Publish.'+voteID">
          <i class="fa fa-refresh"></i>发布</el-button>
        <el-button @click="folding">
          <i :class="isflod ? 'fa fa-folder-open-o' : 'fa fa-folder-o'"></i>{{isflod ? '展开' : '折叠'}}</el-button>
      </span>
    </el-toolbar>

    <!-- 调查详情 -->
    <div>
      <div class="detail-panel vote-panel block-line-panel">
        <el-form :model="tmpVote" :rules="rules" ref="voteForm" label-width="168px" label-suffix="：">
          <el-form-item label="调查主题" prop="title" >
            <el-input v-model="tmpVote.title" @blur="getVoteAlias" class="vote-item"></el-input>
          </el-form-item>
          <el-form-item label="调查别名" prop="code" >
            <el-input v-model="tmpVote.code" :disabled="isEdit" class="vote-item"></el-input>
          </el-form-item>
          <el-form-item label="关联栏目" prop="catalogID">
            <tree-select :value.sync="tmpVote.catalogID" width="30%" :dim-info="{'enable':true}" :disabled="isEdit" placeholder="请选择">
            </tree-select>
          </el-form-item>
          <el-form-item label="是否限制IP" prop="IPLimit">
            <el-switch v-model="tmpVote.IPLimit" active-value="Y" inactive-value="N"></el-switch>
          </el-form-item>
          <el-form-item label="限制IP方式" prop="IPLimitType" v-if="tmpVote.IPLimit === 'Y'">
            <!-- 选中限制IP -->
            <el-select placeholder="" v-model="tmpVote.IPLimitType" style="width:30%;">
              <el-option v-for="item in iPLimitTypeCode" :key="item.key" :label="item.value" :value="item.key">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="是否允许查看" prop="viewType">
            <el-radio-group v-model="tmpVote.viewType">
              <el-radio class="radio" v-for="types in voteViewType" :key="types.key" :label="types.key">{{types.value}}</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="是否需要验证码" prop="verifyFlag">
            <el-switch v-model="tmpVote.verifyFlag" active-value="Y" inactive-value="N"></el-switch>
          </el-form-item>
          <el-form-item label="开始时间" prop="startTime">
            <el-date-picker id="vi-date-picker1" v-model="tmpVote.startTime" value-format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" class="vote-item">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="终止时间" prop="endTime">
            <el-date-picker id="vi-date-picker2" v-model="tmpVote.endTime" value-format="yyyy-MM-dd HH:mm:ss" type="datetime" :picker-options="pickerOptions"
              placeholder="选择日期时间" class="vote-item">
            </el-date-picker>
          </el-form-item>
        </el-form>
      </div>

      <div v-show="isEdit">
        <!-- 调查项折叠板 -->
        <el-list-view :data="tmpVote.voteSubject" :pageSize="0">
          <template slot-scope="row">
            <div class="panel-card">
              <div class="panel-header" @click.stop="foldSubject(row.$index)">
                <el-row>
                  <el-col :span="12">
                    <el-button type="text" @click.stop="foldSubject(row.$index)">
                      <i :class="activeNames.includes(row.$index) ? 'fa fa-angle-double-up' : 'fa fa-angle-double-down'" aria-hidden="true"></i>
                    </el-button>
                    <b>{{activeNames.includes(row.$index) ? '' : ((row.$index+1)+'. '+row.subject)}}</b>
                  </el-col>
                  <el-col :span="12" class="right">
                    <el-button size="small" @click.stop="orderSubject(row.ID,'up',row.$index)" v-if="row.$index > 0 && row.ID" :priv="`VoteManage.Edit.${ID}`">
                      <i class="fa fa-arrow-up" aria-hidden="true"></i>上移</el-button>
                    <el-button size="small" @click.stop="orderSubject(row.ID,'down',row.$index)" v-if="row.ID && (row.$index < tmpVote.voteSubject.length-2 || (row.$index === tmpVote.voteSubject.length-2 && tmpVote.voteSubject[tmpVote.voteSubject.length-1].ID))"
                      :priv="`VoteManage.Edit.${ID}`">
                      <i class="fa fa-arrow-down" aria-hidden="true"></i>下移</el-button>
                    <el-button size="small" @click.stop="deleteSubject(row.$index)" :priv="`VoteManage.Edit.${ID}`">
                      <i class="fa fa-times"></i>删除</el-button>
                    <el-button size="small" @click.stop="saveSubject(row.type,row.$index, true)" :priv="`VoteManage.Edit.${ID}`">
                      <i class="fa fa-save"></i>保存</el-button>
                  </el-col>
                </el-row>
              </div>
              <div style="margin-top:20px;" v-show="activeNames.includes(row.$index)">
                <div class="panel-title">
                  <!-- 显示对应的调查项类型 -->
                  <el-row :gutter="15">
                    <el-col :span="1" class="right list-card-title" style="margin:0;">
                      {{ row.$index+1 }}.
                    </el-col>
                    <el-col :span="10">
                      <el-input v-model="row.subject" @change="changeSubject(row.$index)"></el-input>
                    </el-col>
                    <el-col :span="10" :offset="2" class="type-selection">
                      <el-radio-group v-model="row.type" @change="groupHandler(row.type,row.$index);changeSubject(row.$index)">
                        <el-radio v-for="type in voteSubjectType" :key="type.key" :label="type.key">
                          {{type.value}}
                        </el-radio>
                      </el-radio-group>
                    </el-col>
                  </el-row>

                </div>
                <!-- 选中调查项类型：单选or多选 -->
                <div v-if="row.type =='S' || row.type =='D' ">
                  <div class="vote-sort-panel">
                    <div v-for="(item1,index1) in row.voteItem" :key="index1" class="panel-content-item" :vote-index="row.$index" :item-index="index1">
                      <el-row :gutter="15">
                        <el-col :span="11">
                          <div class="panel-content-item__seq">
                            <i v-if="index1>0" class="fa fa-arrow-circle-up sortable-drag" title="上移" @click="sortItem('up',row.$index,index1)">&nbsp;</i>
                            <i v-if="index1+1<row.voteItem.length" class="fa fa-arrow-circle-down sortable-drag" title="下移" @click="sortItem('down',row.$index,index1)">&nbsp;</i>
                            <em>{{String.fromCharCode((65+index1))}}</em>
                          </div>
                          <el-input v-model="item1.item" style="width: 80%;"  @change="changeSubject(row.$index)"></el-input>
                        </el-col>
                        <el-col :span="3" :offset="1">
                          <el-button @click.stop="add(row.type,row.$index,index1)" size="small" class="dashed">
                            <em>
                              <i class="fa fa-plus"></i>
                            </em>
                          </el-button>
                          <el-button @click.stop="remove(row.type,row.$index,index1)" size="small" class="dashed">
                            <em>
                              <i class="fa fa-minus"></i>
                            </em>
                          </el-button>
                        </el-col>
                        <el-col :span="4">
                          <el-input placeholder="请输入内容" v-model="item1.score"  @change="changeSubject(row.$index)">
                            <template slot="prepend">票数
                              <span class="button-separator"></span>
                            </template>
                          </el-input>
                        </el-col>
                        <el-col :span="4" class="right">
                          <el-button type="primary" plain @click.stop="handleEdit(row.$index,index1)" class="item-detail-button">投票详情</el-button>
                        </el-col>
                      </el-row>
                    </div>
                  </div>
                </div>
                <!-- 选中调查项类型：录入 -->
                <div v-if="row.type =='W'">
                  <div v-for="(item1,index1) in row.voteItem" :key="index1" class="panel-content-item">
                    <el-row :gutter="15">
                      <el-col :span="11">
                        <el-radio-group v-model="item1.itemType"  @change="changeSubject(row.$index)">
                          <el-radio v-for="type in itemType" :key="type.value" :label="type.key" style="padding-left:48px;">{{type.value}}</el-radio>
                        </el-radio-group>
                      </el-col>
                      <el-col :span="4" :offset="4">
                        <el-input placeholder="请输入内容" v-model="item1.score"  @change="changeSubject(row.$index)">
                          <template slot="prepend">票数
                            <span class="button-separator"></span>
                          </template>
                        </el-input>
                      </el-col>
                      <el-col :span="4" class="right">
                        <el-button type="primary" plain @click.stop="handleEdit(row.$index,index1)" class="item-detail-button">投票详情</el-button>
                      </el-col>
                    </el-row>
                  </div>
                </div>
                <!-- 选中调查项类型：图片 -->
                <div v-if="row.type =='I'">
                  <div v-for="(item1,index1) in row.voteItem" :key="index1" class="panel-content-item">
                    <el-row :gutter="15">
                      <el-col :span="11">
                        <el-row>
                          <el-col :span="8">
                            <div style="line-height:150px;padding-left:35px;">
                              <img v-if="item1.imagePath" @click.stop="uploadImage(row.$index,index1)" onerror="this.src='assets/images/picture404-'+((row.ID||row.$index) % 4)+'.png';"
                                :src="item1.imagePath" class="panel-content-item__img">
                              <img v-else @click.stop="uploadImage(row.$index,index1)" src="assets/images/addpicture.png" class="panel-content-item__img">
                              <el-button @click.stop="uploadImage(row.$index,index1)" style="float:left;margin:5px;padding:10px 18px;">选择图片</el-button>
                            </div>
                          </el-col>
                          <el-col :span="16" class="article-content">
                            <el-input type="textarea" :rows="3" v-model="item1.imageInfo" placeholder="请输入文字描述"  @change="changeSubject(row.$index)"></el-input>
                            <el-input disabled v-model="item1.cName" style="margin:3px 0;"  @change="changeSubject(row.$index)"></el-input>
                            <el-button type="primary" @click.stop="linkToContent(row.$index,index1)">链接到内容</el-button>
                            <el-button type="primary" @click.stop="linkToCatalog(row.$index,index1)">链接到栏目</el-button>
                            <el-button type="primary" @click.stop="linkToHttpAddress(row.$index,index1)">外部地址</el-button>
                          </el-col>
                        </el-row>
                      </el-col>
                      <el-col :span="3" :offset="1" style="margin-top:82px;">
                        <el-button @click.stop="add(row.type,row.$index,index1)" size="small" class="dashed">
                          <em>
                            <i class="fa fa-plus"></i>
                          </em>
                        </el-button>
                        <el-button @click.stop="remove(row.type,row.$index,index1)" size="small" class="dashed">
                          <em>
                            <i class="fa fa-minus"></i>
                          </em>
                        </el-button>
                      </el-col>
                      <el-col :span="4">
                        <el-input placeholder="请输入内容" v-model="item1.score" style="margin-top:82px;"  @change="changeSubject(row.$index)">
                          <template slot="prepend">票数</template>
                        </el-input>
                      </el-col>
                      <el-col :span="4" style="margin-top:82px;" class="right">
                        <el-button type="primary" plain @click.stop="handleEdit(row.$index,index1)" class="item-detail-button">投票详情</el-button>
                      </el-col>
                    </el-row>
                  </div>
                </div>
                <!-- 选中调查项类型：文章 -->
                <div v-if="row.type =='A'">
                  <el-button type="primary" @click.stop="manualSelection(row.$index)" style="margin: 10px 10px 10px 40px;">手工选择</el-button>
                  <el-button type="primary" @click.stop="conditionSelection(row.$index)" :loading="articleConditionsLoading">条件筛选</el-button>
                  <div class="vote-sort-panel">
                    <div v-for="(item1,index1) in row.voteItem" :key="index1" class="panel-content-item" :vote-index="row.$index" :item-index="index1">
                      <el-row :gutter="15" type="flex">
                        <el-col :span="11">
                          <div class="panel-content-item__seq">
                            <!-- <i class="fa fa-arrows sortable-drag"></i>&nbsp;选项： -->
                            <i v-if="index1>0" class="fa fa-arrow-circle-up sortable-drag" title="上移" @click="sortItem('up',row.$index,index1)">&nbsp;</i>
                            <i v-if="index1+1<row.voteItem.length" class="fa fa-arrow-circle-down sortable-drag" title="下移" @click="sortItem('down',row.$index,index1)">&nbsp;</i>
                            <em>{{String.fromCharCode((65+index1))}}</em>
                          </div>

                          <el-popover placement="bottom-start" :disabled="!item1.item" trigger="hover" @show="loadArticleData(item1)">
                            <div v-loading="popoverLoading">
                              <div class="content-tip">
                                <span>ID: </span>{{chooseContentData.ID}}
                              </div>
                              <div class="content-tip">
                                <span>文章标题: </span>{{chooseContentData.title}}
                              </div>
                              <div class="content-tip">
                                <span>内容类型: </span>{{chooseContentData.contentTypeName}}
                              </div>
                              <div class="content-tip">
                                <span>所属栏目: </span>{{chooseContentData.catalogName}}
                              </div>
                            </div>
                            <el-input slot="reference" v-model="item1.item" disabled style="width: 60%;"  @change="changeSubject(row.$index)"></el-input>
                          </el-popover>
                          <el-button-group>
                            <el-button @click.stop="editArticle(item1)" type="primary" icon="edit" title="编辑文章"></el-button>
                            <el-button @click.stop="edit(row.$index,index1)">选择</el-button>
                          </el-button-group>
                          <!-- <el-input v-model="item1.item" disabled style="width: 68%;"  @change="changeSubject(row.$index)"></el-input> -->
                          <!-- <el-button type="primary" @click.stop="edit(row.$index,index1)">选择</el-button> -->
                        </el-col>
                        <el-col :span="3" :offset="1">
                          <el-button @click.stop="add(row.type,row.$index,index1)" size="small" class="dashed">
                            <em>
                              <i class="fa fa-plus"></i>
                            </em>
                          </el-button>
                          <el-button @click.stop="remove(row.type,row.$index,index1)" size="small" class="dashed">
                            <em>
                              <i class="fa fa-minus"></i>
                            </em>
                          </el-button>
                        </el-col>
                        <el-col :span="4">
                          <el-input placeholder="请输入票数" v-model="item1.score"  @change="changeSubject(row.$index)">
                            <template slot="prepend">票数
                              <span class="button-separator"></span>
                            </template>
                          </el-input>
                        </el-col>
                        <el-col :span="4" class="right">
                          <el-button type="primary" plain @click.stop="handleEdit(row.$index,index1)" class="item-detail-button">投票详情</el-button>
                        </el-col>
                      </el-row>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </template>
        </el-list-view>

        <div class="add-item-div">
          <el-button @click="addItemHandler" type="text" class="item-detail-button" :priv="`VoteManage.Edit.${ID}`" :loading="addSubjectBtnLoading">
            <em>
              <i class="fa fa-plus"></i> 新增调查项</em>
          </el-button>
        </div>
      </div>
    </div>

    <!-- 投票详情框 -->
    <el-dialog title="投票详情" :visible.sync="openAddUserListModal" @open="dialogOpen" class="vote-detail-dialog">
      <el-table :data="tmpvotelog" ref="dataTable" :data-read-url="getData" :page-size="10" :auto-get-data="false" tooltip-effect="dark">
        <el-table-column type="index" align="center" width="60" label="序号"></el-table-column>
        <el-table-column prop="addUser" label="投票人" align="center" show-overflow-tooltip></el-table-column>
        <el-table-column prop="IP" label="IP" align="center" show-overflow-tooltip></el-table-column>
        <el-table-column label="投票时间" align="center" show-overflow-tooltip>
          <template slot-scope="scope"> <span>{{ scope.row.addTime | format }}</span> </template>
        </el-table-column>
        <el-table-column prop="result" label="投票详情" align="center" show-overflow-tooltip></el-table-column>
      </el-table>
      <div slot="footer">
        <el-button type="primary" @click="openAddUserListModal = false">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 批示 -->
    <el-dialog title="批示" :visible.sync="postilModal">
      <el-form :model="postil" :rules="postilRules" ref="postilForm" label-width="128px">
        <el-form-item label="批示内容" prop="content">
          <el-input type="textarea" :rows="4" placeholder="请输入批示内容" v-model="postil.content"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button type="primary" @click="ClickHandler('notpass')">确 定</el-button>
      </div>
    </el-dialog>

    <voteResult-dialog :show.sync="voteResultDialogShow" :voteSubjectType="voteSubjectType" :tmpVote="tmpVote" @callback="closeResuleDialog">
    </voteResult-dialog>

    <!-- 链接到内容弹框 -->
    <content-selector title="选择内容记录" :show.sync="selectContentModal" content-type="Article" select-type="selection" @callback="contentSelectorCallback"></content-selector>
    <content-selector title="选择内容记录" :show.sync="selectContentModal1" content-type="Article" @callback="contentSelectorCallback"></content-selector>

    <!-- 资源选择弹框 -->
    <resource-dialog :show.sync="resourceDialogModal" :resource-dialog-props="resourceDialogProps" title="图片上传" @callback="resourceDialogCallback"></resource-dialog>

    <!-- 链接到栏目弹框 -->
    <catalog-selector-dialog :show.sync="linkToCatalogModal" input-type="radio" title="选择栏目" @callback="confirmLinkToCatalogClickHandler"></catalog-selector-dialog>

    <!-- 链接到外部地址弹框 -->
    <el-dialog title="外部地址" :visible.sync="linkToHttpAddressModal" class="outer-address-dialog">
      <el-form label-width="80px">
        <el-form-item label="地址：" id="address-item">
          <el-input v-model="address.value"></el-input>
        </el-form-item>
      </el-form>
      <!-- 底部确认按钮 -->
      <div slot="footer">
        <el-button type="primary" @click="confirmLinkToHttpAddressClickHandler">确 定</el-button>
      </div>
    </el-dialog>

    <!-- 添加调查项-筛选条件弹框 -->
    <el-dialog title="条件筛选" :visible.sync="articleConditionsModal" class="condition-item-dialog">
      <el-form :model="tmpArticleConditions" label-width="128px">
        <el-form-item label="添加人：">
          <el-select style="width:220px;" placeholder="" v-model="tmpArticleConditions.userName">
            <el-option v-for="userlist in listUserName" :key="userlist.name" :laber="userlist.realName" :value="userlist.name">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="栏目名称：">
          <tree-select style="width:220px;" :value.sync="tmpArticleConditions.catalogID" :items="catalogTree" :itemsOptions="treeItemsOptions">
          </tree-select>
        </el-form-item>
        <el-form-item label="是否联级：">
          <el-radio-group v-model="tmpArticleConditions.casCade">
            <el-radio class="radio" label="Y">是</el-radio>
            <el-radio class="radio" label="N">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="Tag词：">
          <el-input style="width:220px;" v-model="tmpArticleConditions.tagWord"></el-input>
        </el-form-item>
        <el-form-item label="内容属性：">
          <el-checkbox-group v-model="tmpArticleConditions.attribute">
            <el-checkbox v-for=" type in listAttribute" :key="type.key" :label="type.key">{{type.value}}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="显示条数：">
          <el-input style="width:220px;" v-model="tmpArticleConditions.count"></el-input>
        </el-form-item>
        <el-form-item label="发布时间（始）：">
          <el-date-picker v-model="tmpArticleConditions.startDate" id="vode-item-dlg-start-date" format="yyyy-MM-dd HH:mm:ss" type="datetime"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="发布时间（终）：">
          <el-date-picker v-model="tmpArticleConditions.endDate" id="vode-item-dlg-end-date" format="yyyy-MM-dd HH:mm:ss" type="datetime"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <!-- 底部确认按钮 -->
      <div slot="footer">
        <el-button type="primary" :loading="saveArticleConditionsLoading" @click="saveArticleConditionsClickHandler">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import voteResultDialog from './voteResultDialog.vue'
import TreeSelect from '@src/components/TreeSelect.vue'
import util from '@src/common/util.js'

import ContentSelector from '@src/components/contentComponent/ContentSelector.vue'
import catalogSelector from '../contentcore/components/CatalogSelector.vue'
import resourceDialog from '../contentcore/resourceDialog.vue'
export default {
  components: {
    'voteResult-dialog': voteResultDialog,
    'tree-select': TreeSelect,

    'resource-dialog': resourceDialog,
    'content-selector': ContentSelector,
    'catalog-selector-dialog': catalogSelector
  },
  data() {
    return {
      popoverLoading: false,
      chooseContentData: {},
      pickerOptions: {
        disabledDate(time) {
          return Date.now() >= time.getTime()
        }
      }, // 时间选择器限制
      voteViewType: [], // 调查查看类型
      iPLimitTypeCode: [], // IP限制方式
      voteSubjectType: [], // 调查项类型
      detailedLoding: false, // 详细页loading
      voteResultDialogShow: false, // 查看结果弹出框
      tmpvotelog: [], // 投票详情
      openAddUserListModal: false, // 投票详情框
      postilModal: false, // 批示内容弹出框
      postil: { content: '' }, // 批示内容
      postilRules: {
        content: [{ max: 150, message: '批示内容不能超过150个字符', trigger: 'blur' }]
      },
      tmpVote: {
        code: '',
        title: '',
        catalogID: '',
        catalogName: '',
        IPLimit: 'N',
        IPLimitType: '',
        viewType: 'Yes',
        verifyFlag: 'N',
        startTime: '',
        endTime: '',
        voteSubject: []
      },
      myCatalogName: '',

      catalogTree: [], // 关联栏目树数据
      treeItemsOptions: {
        children: 'children',
        label: 'name',
        key: 'ID'
      }, // 关联栏目树属性
      isEdit: false, // 弹框时，判断当时是否为修改
      detialItemID: '',
      detialSubjectID: '',
      detialVoteID: '',
      activeNames: [], // 折叠控制参数
      activeMiddleNames: [], // 折叠控制参数中间值
      isflod: false,
      index: {
        subject: 0,
        item: 0
      },

      selectContentModal1: false,
      resourceDialogProps: {
        resourceType: 'image',
        imageWidth: 120,
        imageHeight: 120
      },
      resourceDialogModal: false,
      linkToHttpAddressModal: false,
      address: { value: '' }, // 链接到外部地址的地址值
      selectContentModal: false, // 选择内容弹框控制
      linkToCatalogModal: false, // 链接到栏目弹框控制
      articleConditionsLoading: false, // 添加调查项-筛选条件弹框按钮加载
      articleConditionsModal: false, // 添加调查项-筛选条件弹框控制
      saveArticleConditionsLoading: false, // 添加调查项-筛选条件弹框确定按钮加载
      // 添加调查项-筛选条件
      tmpArticleConditions: {},
      // 添加调查项-筛选条件联系人集合
      listUserName: [],
      // 添加调查项-筛选条件内容属性集合
      listAttribute: [],
      itemType: [{ key: '2', value: '多行文本' }, { key: '1', value: '单行文本' }],
      // 调查项类型为录入的集合
      // 调查项类型为文章的集合
      // 调查项类型为单选or多选的集合
      listArticle: [],
      voteID: null,
      addSubjectBtnLoading: false,
      rules: {
        title: [
          {
            required: true,
            validator: (rule, value, back) => {
              if (!value) {
                back(new Error('不能为空'))
              }
              if (util.getLengthEx(value, true) > 500) {
                back(new Error('必须小于等于166个汉字或者500个字母'))
              } else {
                back()
              }
            },
            trigger: 'blur'
          }
        ],
        // 在validator方法中写正则表达式
        code: [
          {
            required: true,
            validator: (rule, value, back) => {
              if (!value) {
                back(new Error('不能为空'))
              }
              if (value.length >= 100) {
                back(new Error('必须小于100个字母'))
              } else if (/^[0-9a-zA-Z]*$/.test(value) === false) {
                back(new Error('只能是数字和字母组成'))
              } else {
                back()
              }
            },
            trigger: 'blur'
          }
        ]
      }
    }
  },
  props: {
    ID: {
      type: [Number, String]
    },
    fromArticleEditor: {
      type: Boolean
    }
  },
  created() {
    this.voteID = this.ID
    this.isEdit = this.voteID !== 'new'
    this.initVoteProp()
    this.loadingData()
  },
  methods: {
    async loadArticleData(item) {
      this.popoverLoading = true
      let params = {
        ID: item.voteDocID,
        contentType: item.linkType
      }
      let res = await axios.get('/ui/article/datas', { params })
      res = res.data
      if (res.status === 1) {
        Object.assign(this.chooseContentData, res.data)
        this.popoverLoading = false
      }
    },
    async editArticle(data) {
      await this.loadArticleData(data)

      let path = ''
      if (this.chooseContentData.contentTypeID === 'Special') {
        path = `/special/${this.chooseContentData.catalogID}/${this.chooseContentData.ID}`
        this.$router.push(path)
      } else {
        path = `/contentEditor/${this.chooseContentData.ID}?type=${this.chooseContentData.contentTypeID}&cid=${
          this.chooseContentData.catalogID
        }`
        window.open('contentEditor.html#' + path)
      }
    },
    changeSubject(index) {
      this.tmpVote.voteSubject[index].isNeedSubmit = true
    },
    // 预览
    previewClickHandler() {
      if (!this.voteID || this.voteID === null) {
        this.$alert('数据异常,请重新选择', '提示', {
          type: 'warning'
        })
        return
      }
      window.open(`preview.html?ID=${this.voteID}&type=Vote`)
    },
    sortItem(way, voteIndex, subIndex) {
      let voteItem = this.tmpVote.voteSubject[voteIndex].voteItem
      let index = way === 'up' ? subIndex - 1 : subIndex + 1
      let sortedItem = voteItem.splice(subIndex, 1)[0]
      voteItem.splice(index, 0, sortedItem)
      this.changeSubject(voteIndex)
    },
    backListPage() {
      this.$router.back()
    },
    getVoteAlias() {
      if (this.tmpVote.title && this.voteID === 'new') {
        this.tmpVote.code = window.util.getSpell(this.tmpVote.title, true)
      }
    },
    dialogOpen() {
      this.$nextTick(() => {
        this.getVoteDetail()
      })
    },
    result() {
      this.voteResultDialogShow = true
    },
    closeResuleDialog() {
      this.voteResultDialogShow = false
    },
    async loadingData() {
      this.detailedLoding = true
      if (!this.isEdit) {
        this.detailedLoding = false
        return
      }
      try {
        // 获取对象
        let getVotedataById = await axios.get(`/ui/votes/${this.voteID}`)
        this.tmpVote = getVotedataById.data.data
        this.tmpVote.IPLimitType += ''
        this.tmpVote.voteSubject.forEach((row, index) => {
          this.activeMiddleNames.push(index)
        })
        this.activeNames = this.activeMiddleNames
      } catch (e) {}
      this.detailedLoding = false
    },
    folding() {
      this.activeNames = this.isflod ? this.activeMiddleNames : []
      this.isflod = !this.isflod
    },
    foldSubject(index) {
      if (this.activeNames.includes(index)) {
        this.activeNames = this.activeNames.filter(val => val !== index)
      } else {
        this.activeNames.push(index)
      }
    },
    AuditNotPass() {
      this.postilModal = true
    },
    //  审核通过、审核不通过和重新编辑
    async ClickHandler(status) {
      let strIDs = this.tmpVote.ID
      if (status === 'notpass' || status === 'pass') {
        if (this.tmpVote.status !== 'auditing') {
          util.showError('没有提交审核的记录不能直接进行审核')
          return
        }
      }

      if (status === 'notpass') {
        try {
          await util.validateForm(this.$refs['postilForm'])
        } catch (e) {
          util.showErrorMessageBox(e)
          return
        }
        this.postilModal = false
        let postilContent = this.postil.content
        let voteAuditResult = await axios.put('/ui/votes/voteaudit', {
          strIDs,
          status,
          postilContent
        })
        util.showResponseMessage(voteAuditResult.data)
        if (voteAuditResult.data.status === 1) {
          let getVotedataById = await axios.get(`/ui/votes/${this.voteID}`)
          this.tmpVote = getVotedataById.data.data
          this.tmpVote.isNeedAudit = true
          this.$emit('callback')
        }
      } else {
        let voteAuditResult = await axios.put('/ui/votes/voteaudit', {
          strIDs,
          status
        })
        util.showResponseMessage(voteAuditResult.data)
        if (voteAuditResult.data.status === 1) {
          let getVotedataById = await axios.get(`/ui/votes/${this.voteID}`)
          this.tmpVote = getVotedataById.data.data
          this.tmpVote.isNeedAudit = true
          this.$emit('callback')
        }
      }
    },
    //  调查审核
    async commitAuditHandler() {
      try {
        await this.$confirm('确定要提交审核吗？', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        let rowIds = []
        rowIds.push(this.tmpVote.ID)
        if (!rowIds) {
          return
        }
        let strIDs = rowIds.join(',')
        let commitAuditResult = await axios.put('/ui/votes/commitaudit', {
          strIDs
        })
        util.showResponseMessage(commitAuditResult.data)
        if (commitAuditResult.data.status === 1) {
          let getVotedataById = await axios.get(`/ui/votes/${this.voteID}`)
          this.tmpVote = getVotedataById.data.data
          this.tmpVote.isNeedAudit = true
          this.$emit('callback')
        }
      } catch (e) {

      }
    },

    //  手工终止
    async VoteStop() {
      try {
        await this.$confirm('确定要终止调查吗？', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        let rowIds = []
        rowIds.push(this.tmpVote.ID)
        if (!rowIds) {
          return
        }
        let strIDs = rowIds.join(',')
        let stopResult = await axios.put('/ui/votes/stop', { strIDs })
        util.showResponseMessage(stopResult.data)
        if (stopResult.data.status === 1) {
          let getVotedataById = await axios.get(`/ui/votes/${this.voteID}`)
          this.tmpVote = getVotedataById.data.data
          this.tmpVote.isNeedAudit = true
          this.$emit('callback')
        }
      } catch (e) {

      }
    },

    //  发布
    async VotePublish() {
      if (this.tmpVote.status === 'passed' || this.tmpVote.status === 'published') {
        try {
          await this.$confirm('确定要发布调查吗？', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          })
          let rowIds = []
          rowIds.push(this.tmpVote.ID)
          if (!rowIds) {
            return
          }
          let strIDs = rowIds.join(',')
          let publishResult = await axios.put(`/ui/votes/${strIDs}/publish`)
          util.showResponseMessage(publishResult.data)
          if (publishResult.data.status === 1) {
            let getVotedataById = await axios.get(`/ui/votes/${this.voteID}`)
            this.tmpVote = getVotedataById.data.data
            this.tmpVote.isneedaudit = true
            this.$emit('callback')
          }
        } catch (e) {

        }
      } else {
        util.showError('不是审核通过的调查不能进行发布')
      }
    },

    //  删除调查项
    async deleteSubject(index) {
      try {
        let subjectId = this.tmpVote.voteSubject[index].ID
        if (subjectId) {
          await this.$confirm('确定删除吗？删除后无法恢复。是否继续删除？', '删除确认', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          })
          let delVoteSubject = await axios.delete(`/ui/votes/${this.voteID}/items/${subjectId}`)
          if (delVoteSubject.data.status === 1) {
            this.tmpVote.voteSubject.splice(index, 1)
          }
          util.showResponseMessage(delVoteSubject.data)
        } else {
          this.tmpVote.voteSubject.splice(index, 1)
        }
      } catch (e) {

      }
    },

    //  点击新增调查项
    async addItemHandler() {
      // 新增前保存最后一个调查项
      this.addSubjectBtnLoading = true
      if (this.tmpVote.voteSubject.length) {
        let lastVoteSubject = this.tmpVote.voteSubject[this.tmpVote.voteSubject.length - 1]
        let saveFlag = await this.saveSubject(lastVoteSubject.type, lastVoteSubject.$index, false)
        if (!saveFlag) {
          this.addSubjectBtnLoading = false
          return
        }
      }
      let index = this.tmpVote.voteSubject.length
      let obj = {
        $index: index,
        subject: '',
        type: 'S',
        voteID: this.voteID,
        voteItem: [
          {
            item: '',
            score: 0,
            configProps: '',
            log: [],
            itemType: '0'
          }
        ]
      }
      this.activeNames.push(index)
      this.tmpVote.voteSubject.push(obj)
      this.addSubjectBtnLoading = false
    },

    // 获取对应的投票详情(投票项索引，调查项索引)
    handleEdit(subjectIndex, itemIndex) {
      // 投票项itemId
      this.detialItemID = this.tmpVote.voteSubject[subjectIndex].voteItem[itemIndex].ID
      // 调查项subjectId
      this.detialSubjectID = this.tmpVote.voteSubject[subjectIndex].voteItem[itemIndex].subjectID
      // 投票调查voteId
      this.detialVoteID = this.tmpVote.voteSubject[subjectIndex].voteItem[itemIndex].voteID
      this.openAddUserListModal = true
    },
    async orderSubject(ID, orderType, index) {
      let orderItem = await axios.put(`/ui/votes/${this.voteID}/items/${ID}/order`, {orderType})
      if (orderItem.data.status === 1) {
        let curSubject = this.tmpVote.voteSubject[index]
        let exchangeSubjectIdx
        if (orderType === 'up') {
          exchangeSubjectIdx = index - 1
        } else {
          exchangeSubjectIdx = index + 1
        }
        let exchangeSubject = this.tmpVote.voteSubject[exchangeSubjectIdx];
        [exchangeSubject.orderFlag, curSubject.orderFlag] = [curSubject.orderFlag, exchangeSubject.orderFlag];
        [exchangeSubject, curSubject] = [curSubject, exchangeSubject]
        Vue.set(this.tmpVote.voteSubject, index, curSubject)
        Vue.set(this.tmpVote.voteSubject, exchangeSubjectIdx, exchangeSubject)
      } else {
        util.showResponseMessage(orderItem.data)
      }
    },

    async getVoteDetail() {
      await this.$refs.dataTable.getData()
    },
    getData() {
      return [
        '/ui/votes/binditemadduser',
        {
          params: {
            itemID: this.detialItemID,
            subjectID: this.detialSubjectID,
            voteID: this.detialVoteID
          }
        }
      ]
    },
    async initVoteProp() {
      let getinitVoteProp = await axios.get('/ui/votes/initVoteProp')
      this.iPLimitTypeCode = getinitVoteProp.data.data.IPLimitTypeCode
      this.voteViewType = getinitVoteProp.data.data.voteViewType
      this.voteSubjectType = getinitVoteProp.data.data.voteSubjectType
      let getCatalogTree = await axios.get('/ui/catalog', {params: {contentType: 'Article'}})
      this.catalogTree = getCatalogTree.data.data
    },
    async save() {
      if (this.tmpVote.startTime !== '' && this.tmpVote.endTime !== '' && this.tmpVote.startTime >= this.tmpVote.endTime) {
        this.$alert('调查终止时间不能在开始时间之前', '提示', {
          type: 'warning'
        })
        return
      }
      try {
        await util.validateForm(this.$refs['voteForm'])
        this.saveLoading = true
        let res = !this.isEdit
          ? await axios.post('/ui/votes', this.tmpVote)
          : await axios.put(`/ui/votes/${this.tmpVote.ID}`, this.tmpVote)
        this.saveLoading = false
        util.showResponseMessage(res.data)
        if (res.data.status !== 1 || this.isEdit) {
          return
        }
        await this.$nextTick()
        await util.updatePriv()
        this.voteID = res.data.ID
        this.isEdit = true
        this.loadingData()
        this.$router.replace(this.$route.path.replace('vote/new', `vote/${this.voteID}`))
      } catch (e) {
        util.showErrorMessageBox(e)
      }
    },
    async saveSubject(type, index, manualSave) {
      let validate = () => {
        return new Promise((resolve, reject) => {
          if (type === 'A') {
            if (this.tmpVote.voteSubject[index].voteItem.length === 0) {
              return reject(new Error('至少选择一篇文章'))
            }
          }
          this.tmpVote.voteSubject[index].voteItem.forEach(row => {
            let type = this.tmpVote.voteSubject[index]['type']
            if (!row.item && type !== 'W') {
              return reject(new Error('选项不能为空'))
            }
            if (!/^[0-9]\d*$/.test(row.score)) {
              return reject(new Error('票数只能输入数字且只能为0或正整数'))
            }
          })
          return resolve(true)
        })
      }

      // let compare = property => {
      //   return (a, b) => {
      //     var value1 = a[property]
      //     var value2 = b[property]
      //     return value1 - value2
      //   }
      // }

      try {
        await validate()
        let id = this.tmpVote.voteSubject[index].ID

        let data = _.cloneDeep(this.tmpVote.voteSubject[index])
        // let voteItem = _.cloneDeep(this.tmpVote.voteSubject[index]['voteItem'])
        // voteItem.sort(compare('_newIndex'))
        // data['voteItem']=voteItem

        let res
        if (id) {
          res = await axios.put(`/ui/votes/${this.voteID}/items/${this.tmpVote.voteSubject[index].ID}`, data)
        } else {
          res = await axios.post(`/ui/votes/${this.voteID}/items`, data)
        }
        let savedSubject = res.data.subject
        if (res.data.status === 1 && savedSubject) {
          savedSubject.$index = index
          this.tmpVote.voteSubject[index] = savedSubject
          // this.tmpVote.voteSubject = _.cloneDeep(this.tmpVote.voteSubject)
          Vue.set(this.tmpVote.voteSubject, index, savedSubject)
          if (manualSave) {
            this.$message('调查项保存成功')
          }
          return true
        }
        util.showResponseMessage(res.data)
        return false
      } catch (e) {
        util.showErrorMessageBox(e)
        return false
      }
    },
    // 图片类型调查项资源选择回调方法
    resourceDialogCallback(val1, val2) {
      this.tmpVote.voteSubject[this.index.subject].voteItem[this.index.item].imagePath = val1
      this.tmpVote.voteSubject[this.index.subject].voteItem[this.index.item].item = val2
      this.changeSubject(this.index.subject)
    },
    // 链接到内容回调方法
    contentSelectorCallback(data) {
      if (this.tmpVote.voteSubject[this.index.subject].type === 'I') {
        this.tmpVote.voteSubject[this.index.subject].voteItem[this.index.item].cName = data.contentTypeID + '：' + data.title
        this.tmpVote.voteSubject[this.index.subject].voteItem[this.index.item].linkURL = data.link
        this.tmpVote.voteSubject[this.index.subject].voteItem[this.index.item].linkType = 'Article'
        this.changeSubject(this.index.subject)
        return
      }

      if (this.index.item >= 0 && typeof data === 'object') {
        this.tmpVote.voteSubject[this.index.subject].voteItem[this.index.item].item = data.title
        this.tmpVote.voteSubject[this.index.subject].voteItem[this.index.item].voteDocID = data.ID
        if (this.tmpVote.voteSubject[this.index.subject].type === 'A') {
          this.tmpVote.voteSubject[this.index.subject].voteItem[this.index.item].linkURL = data.link
        }
        this.changeSubject(this.index.subject)
        return
      }
      if (this.tmpVote.voteSubject[this.index.subject].voteItem.length === 0) {
        data.forEach(row => {
          this.tmpVote.voteSubject[this.index.subject].voteItem.push({
            item: row.title,
            score: 0,
            configProps: '',
            log: [],
            itemType: '4',
            linkType: 'Article',
            voteDocID: row.ID
          })
        })
        this.changeSubject(this.index.subject)
      } else {
        let repeatList = []
        let listArticle = this.tmpVote.voteSubject[this.index.subject].voteItem
        data.forEach(function(row, index) {
          listArticle.forEach(rows => {
            if (rows.voteDocID === row.ID) {
              repeatList.push(index)
            }
          })
        })
        // 将查出的结果的重复项去除
        for (let i = repeatList.length - 1; i >= 0; i--) {
          data.splice(repeatList[i], 1)
        }
        data.forEach(row => {
          this.tmpVote.voteSubject[this.index.subject].voteItem.push({
            item: row.title,
            score: 0,
            configProps: '',
            log: [],
            itemType: '4',
            linkType: 'Article',
            voteDocID: row.ID
          })
        })
        this.changeSubject(this.index.subject)
      }
    },
    // 增加调查项选项
    add(type, subjectIndex, itemIndex) {
      let obj
      if (type === 'I') {
        obj = {
          item: '',
          score: 0,
          configProps: '',
          log: [],
          itemType: '3',
          imageInfo: '',
          imagePath: '',
          linkURL: '',
          cName: ''
        }
      } else if (type === 'S' || type === 'D') {
        obj = {
          item: '',
          score: 0,
          configProps: '',
          log: [],
          itemType: '0'
        }
      } else if (type === 'A') {
        obj = {
          item: '',
          score: 0,
          configProps: '',
          log: [],
          itemType: '4'
        }
      }
      this.tmpVote.voteSubject[subjectIndex].voteItem.splice(itemIndex + 1, 0, obj)
      this.changeSubject(subjectIndex)
    },
    // 删除调查项选项
    remove(type, subjectIndex, itemIndex) {
      if (this.tmpVote.voteSubject[subjectIndex].voteItem.length === 1) {
        this.$message.error('不能删除最后一行')
        return
      }
      this.tmpVote.voteSubject[subjectIndex].voteItem.splice(itemIndex, 1)
      this.changeSubject(subjectIndex)
    },
    // 调查项类型改变事件
    groupHandler(type, index) {
      if (type === 'D' || type === 'S') {
        if (this.tmpVote.voteSubject[index].voteItem[0] && String(this.tmpVote.voteSubject[index].voteItem[0].itemType) === '0') {
          return
        }
        this.tmpVote.voteSubject[index].voteItem = [
          {
            item: '',
            score: 0,
            configProps: '',
            log: [],
            itemType: '0'
          }
        ]
      }
      if (type === 'W') {
        this.tmpVote.voteSubject[index].voteItem = [
          {
            item: '',
            score: 0,
            configProps: '',
            log: [],
            itemType: '1'
          }
        ]
      }

      if (type === 'I') {
        this.tmpVote.voteSubject[index].voteItem = [
          {
            item: '',
            score: 0,
            configProps: '',
            log: [],
            itemType: '3',
            imageInfo: '',
            imagePath: '',
            linkURL: '',
            cName: ''
          }
        ]
      }
      if (type === 'A') {
        this.tmpVote.voteSubject[index].voteItem = []
      }
    },
    // 图片上传
    uploadImage(subjectIndex, itemIndex) {
      this.index = {
        subject: subjectIndex,
        item: itemIndex
      }
      this.resourceDialogModal = true
    },
    //  链接到内容按钮点击事件
    linkToContent(subjectIndex, itemIndex) {
      this.index = {
        subject: subjectIndex,
        item: itemIndex
      }
      this.selectContentModal1 = true
    },
    //  链接到栏目按钮点击事件
    linkToCatalog(subjectIndex, itemIndex) {
      this.index = {
        subject: subjectIndex,
        item: itemIndex
      }
      this.linkToCatalogModal = true
    },
    //  链接到外部地址按钮点击事件
    linkToHttpAddress(subjectIndex, itemIndex) {
      this.index = {
        subject: subjectIndex,
        item: itemIndex
      }
      this.address.value = 'http://'
      this.linkToHttpAddressModal = true
    },
    //  链接到栏目-底部确定按钮点击事件
    confirmLinkToCatalogClickHandler(row) {
      this.tmpVote.voteSubject[this.index.subject].voteItem[this.index.item].cName = '栏目：' + row.name
      this.tmpVote.voteSubject[this.index.subject].voteItem[this.index.item].linkURL = row.link
      this.tmpVote.voteSubject[this.index.subject].voteItem[this.index.item].linkType = 'Catalog'
    },
    // 链接到外部地址弹框底部确认按钮点击事件
    confirmLinkToHttpAddressClickHandler() {
      this.tmpVote.voteSubject[this.index.subject].voteItem[this.index.item].cName = this.address.value
      this.tmpVote.voteSubject[this.index.subject].voteItem[this.index.item].linkURL = this.address.value
      this.tmpVote.voteSubject[this.index.subject].voteItem[this.index.item].linkType = 'LinkURL'
      this.linkToHttpAddressModal = false
    },
    //  手工选择
    manualSelection(index) {
      // 弹框内容展示
      this.selectContentModal = true
      this.index = {
        subject: index,
        item: -1
      }
    },
    //  修改手工选择的项
    edit(subjectIndex, itemIndex) {
      this.index = {
        subject: subjectIndex,
        item: itemIndex
      }
      this.selectContentModal1 = true
    },
    //  条件筛选
    async conditionSelection(index) {
      this.index = {
        subject: index,
        item: -1
      }
      // 按钮加载
      this.articleConditionsLoading = true
      // 初始化值
      this.tmpArticleConditions = {
        userName: '', // 添加人
        catalogID: '', // 栏目名称
        casCade: 'Y', // 是否联级
        tagWord: '', // tag词
        attribute: [], // 内容属性
        count: 5, // 显示条数
        startDate: '', // 发布时间（始）
        endDate: '', // 发布时间（终）
        type: 'PUBLISHED' // 发布状态，默认是发布
      }
      let getSelectUser = await axios.get('/ui/votes/users')
      this.listUserName = getSelectUser.data.data
      let getCheckAttribute = await axios.get('/ui/votes/attribute')
      this.listAttribute = getCheckAttribute.data.data
      this.articleConditionsModal = true
      this.articleConditionsLoading = false
    },
    //  条件筛选确定按钮点击事件
    async saveArticleConditionsClickHandler() {
      this.saveArticleConditionsLoading = true
      // 获取关联项目ID
      let getArticleConditions = null
      try {
        getArticleConditions = await axios.get('/ui/voteitem/contents', {
          params: this.tmpArticleConditions
        })
      } catch (e) {
        this.saveArticleConditionsLoading = false
        return
      }
      // 如果文章集合为空 则不需要判断 直接push
      if (this.tmpVote.voteSubject[this.index.subject].voteItem.length === 0) {
        getArticleConditions.data.data.forEach(row => {
          this.tmpVote.voteSubject[this.index.subject].voteItem.push({
            item: row.title,
            score: 0,
            configProps: '',
            log: [],
            itemType: '4',
            linkType: 'Article',
            voteDocID: row.ID,
            catalogID: row.catalogID
          })
        })
      } else {
        let repeatList = []
        let listArticle = this.tmpVote.voteSubject[this.index.subject].voteItem
        getArticleConditions.data.data.forEach(function(row, index) {
          listArticle.forEach(rows => {
            if (rows.voteDocID === row.ID) {
              repeatList.push(index)
            }
          })
        })
        // 将查出的结果的重复项去除
        for (let i = repeatList.length - 1; i >= 0; i--) {
          getArticleConditions.data.data.splice(repeatList[i], 1)
        }
        getArticleConditions.data.data.forEach(row => {
          this.tmpVote.voteSubject[this.index.subject].voteItem.push({
            item: row.title,
            score: 0,
            configProps: '',
            log: [],
            itemType: '4',
            linkType: 'Article',
            voteDocID: row.ID,
            catalogID: row.catalogID
          })
        })
      }
      // 加载完弹框关闭
      this.articleConditionsModal = false
      // 加载完按钮
      this.saveArticleConditionsLoading = false
    }
  }
}
</script>
<style>
.vote-detail-dialog .el-dialog {
  width: 700px;
}

@media (max-width: 480px) {
  .vote-detail-dialog .el-dialog {
    width: 96%;
  }
}

.outer-address-dialog .el-dialog {
  width: 450px;
}

@media (max-width: 480px) {
  .outer-address-dialog .el-dialog {
    width: 96%;
  }
}

.add-item-div .el-button {
  font-size: 14px;
}
</style>
<style scoped>
.sortable-drag {
  cursor: pointer;
  color: #f6ad3a;
}

.item-detail-button {
  width: 110px;
}

.type-selection {
  text-align: right;
  padding: 0 !important;
}

.add-item-div {
  text-align: right;
  padding-right: 61px;
}

.panel-card .el-radio + .el-radio {
  margin: 5px 5px 5px 12px;
}

.vote-panel .el-radio + .el-radio {
  margin: 15px;
}

.vote-panel {
  font-size: 15px;
}

.vote-item {
  width: 90%;
}

.item-title {
  padding: 2px 10px 5px;
  font-size: 18px;
  display: inline-block;
  vertical-align: middle;
}

.info-form .prop {
  text-align: right;
}

.info {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pageBar {
  text-align: right;
  padding: 5px 2px 0 0;
  background-color: #f5f5f5;
}

.panel-card .el-input__inner {
  border: none !important;
  background: #333 !important;
  border-radius: 0 !important;
}

.panel-card .panel-header {
  border-bottom: 1px solid #f5f5f5;
  padding: 10px 20px;
  margin: -15px -20px 0;
  background-color: #f9f9f9;
  border-radius: 4px 4px 0 0;
}

.panel-card .panel-title {
}

.panel-card .panel-content-item {
  padding: 10px 0;
}

.panel-card .panel-content-item__seq {
  float: left;
  width: 18%;
  text-align: right;
  padding-right: 10px;
  font-size: 15px;
  font-weight: bold;
}

.panel-card .panel-content-item__img {
  float: left;
  max-width: 100px;
  max-height: 110px;
}

.article-content .el-button + .el-button {
  margin-left: 8px;
}
</style>
