<!--变更/分配-->
<template>
  <div>
    <dialog-edit :visible.sync="dialogVisible"
                 :autoSave="false"
                 :autoClose="false"
                 :editModel="editModel"
                 :form="{}"
                 center
                 :title="assignType==='1'?$t('coordManageMain.editAssignTitle1'):$t('coordManageMain.editAssignTitle2')">
      <data-table :sourceData.sync="sourceData"
                  :api="taskAssignTraceApi"
                  :queryParas="queryParas"
                  :loadCount.sync="loadCount"
                  loadPage="getList"
                  :pageAll="true"
                  :row-style="rowStyle"
                  :showPage="true"
                  :columns="columns"
                  @handleFilter="handleFilter"
                  :menuFlag="false"
                  ref="dataTable">
              <template slot="traceUserName" slot-scope="scope">
                  <a @click="showSituation(scope.data.row)" :style="scope.data.row.busyLevel==='3'?'color:#f56c6c':'color:#4c84ff'">{{scope.data.row.traceUserName}}</a>
              </template>
              <template slot="dealingProduct" slot-scope="scope">
                  <a @click="showTask(scope.data.row)" :style="scope.data.row.busyLevel==='3'?'color:#f56c6c':'color:#4c84ff'">{{$t('coordManageMain.viewTask')}}</a>
              </template>
              <template slot="busyMemo" slot-scope="scope">
                <span-plus :index="scope.data.$index" :text="scope.data.row.busyMemo"></span-plus>
              </template>
              <el-table-column :label="$t('coordManageMain.operate')" align="center" width="80px" fixed="right">
                  <template slot-scope="scope">
                    <auth-button :title="$t('coordManageMain.choose')" class="iconCircle margin-left" icon="iconfont iconxuanze" @click="choose(scope.row)"></auth-button>
                  </template>
          </el-table-column>
      </data-table>
    </dialog-edit>
    <trace-user-deal-info-pop :editModel="newEditModel" :form="hgForm" v-if="traceUserInfoVisible" :visible.sync="traceUserInfoVisible"></trace-user-deal-info-pop>
    <trace-user-task-pop :editModel="newEditModel" :form="hgForm" v-if="traceUserTaskVisible" :visible.sync="traceUserTaskVisible"></trace-user-task-pop>
  </div>
</template>
<script>
import { DialogEdit, authButton, DataTable, SpanPlus } from 'newepoch-components'
import * as format from '@/filters/index'
import traceUserDealInfoPop from '@/pages/assetoutfeedback/coordManage/traceUserDealInfoPop'
import traceUserTaskPop from '@/pages/assetoutfeedback/coordManage/traceUserTaskPop'
import coordManageApi from '@/api/assetoutfeedback/coordManage/coordManageApi'
import BasePage from '@/pages/baseEditPage'
export default {
  name: 'editAssignPop',
  extends: new BasePage(),
  components: {
    DialogEdit,
    authButton,
    DataTable,
    SpanPlus,
    traceUserDealInfoPop,
    traceUserTaskPop
  },
  props: {
    editModel: {
      type: [String],
      default () {
        return 'E'
      }
    },
    assignKeyId: {
      type: [Array, String],
      default () {
        return ''
      }
    },
    assignStatus: {
      type: String,
      default () {
        return ''
      }
    },
    keyId: {
      type: [Array, String],
      default () {
        return ''
      }
    },
    form: {
      type: [Object],
      default () {
        return {}
      }
    },
    assignType: {
      type: String,
      default () {
        return ''
      }
    }
  },
  data () {
    return {
      newEditModel: 'V',
      traceUserInfoVisible: false,
      traceUserTaskVisible: false, // 查看任务
      loadCount: 0,
      queryParas: {
        pageIndex: 1,
        pageSize: 10
      },
      columns: [
        {
          // 姓名
          prop: 'traceUserName',
          slot: true,
          align: 'left',
          width: '100px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.userName
        },
        {
          // 处理中的产品
          prop: 'dealingProduct',
          slot: true,
          align: 'center',
          width: '100px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.dealingProduct
        },
        {
          // 正在解决的笔数
          prop: 'solvingAssetNum',
          align: 'center',
          width: '100px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.solvingAssetNum,
          format: row => {
            return row.solvingAssetNum ? row.solvingAssetNum : '0'
          }
        },
        {
          // 正在解决问题数
          prop: 'solvingQuestionNum',
          align: 'center',
          width: '100px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.solvingQuestionNum,
          format: row => {
            return row.solvingQuestionNum ? row.solvingQuestionNum : '0'
          }
        },
        {
          // 抽样未完成数量
          prop: 'sampleUnfinishedNum',
          align: 'center',
          width: '100px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.sampleUnfinishedNum,
          format: row => {
            return row.sampleUnfinishedNum ? row.sampleUnfinishedNum : '0'
          }
        },
        {
          // 是否定稿当天
          prop: 'whetherFinalizeDateList',
          align: 'center',
          width: '100px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.whetherFinalizeDate,
          format: (row) => {
            return this.whetherFinalizeDate(row.whetherFinalizeDateList)
          }
        },
        {
          // 是否统筹人
          prop: 'whetherChargeUser',
          align: 'center',
          width: '100px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.whetherChargeUser,
          format: (row) => {
            return row.whetherChargeUser === '2' ? this.$t('common.yes') : this.$t('common.no')
          }
        },
        {
          // 闲忙程度
          prop: 'busyLevel',
          align: 'center',
          width: '80px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.busyLevel,
          format: (row) => {
            return format.formatDict(row.busyLevel, 'AUDIT_OUT_TRACE_BUSY_STATUS')
          }
        },
        {
          // 闲忙备注
          prop: 'busyMemo',
          align: 'left',
          width: '150px',
          slot: true,
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.busyMemo
        }
      ],
      sourceData: [],
      chooseMsg: '确认分配给该跟进人？',
      hgForm: {}
    }
  },
  mounted () {
    this.getData()
  },
  methods: {
    getData () {
      Object.assign(this.queryParas, this.form)
      if (JSON.stringify(this.projectInfo) !== '{}') {
        this.$nextTick(() => {
          this.handleFilter()
        })
      }
    },
    // 是否定稿当天
    whetherFinalizeDate (data) {
      let flag = false
      data.forEach(item => {
        if (item) {
          let date1 = format.formatDateNull(new Date(), 'yyyy-MM-dd')
          let date2 = format.formatDateNull(item, 'yyyy-MM-dd')
          if (date1 === date2) {
            flag = true
          }
        }
      })
      if (flag) {
        return this.$t('common.yes')
      } else {
        return this.$t('common.no')
      }
    },
    showSituation (val) {
      this.newEditModel = 'V'
      this.hgForm = {
        traceUserId: val.traceUserId,
        traceUserName: val.traceUserName,
        whetherChargeUser: val.whetherChargeUser
      }
      Object.assign(this.hgForm, this.form)
      this.traceUserInfoVisible = true
    },
    showTask (val) {
      this.newEditModel = 'V'
      this.hgForm = {
        traceUserId: val.traceUserId,
        traceUserName: val.traceUserName
      }
      Object.assign(this.hgForm, this.form)
      this.traceUserTaskVisible = true
    },
    // 选择跟进人
    choose (data) {
      let updateTraceUserDTO = {
        assignKeyIds: this.assignKeyId,
        assetKeyIds: this.keyId,
        assignStatus: this.assignStatus,
        traceUserId: data.traceUserId
      }
      this.$confirm(this.chooseMsg, '提示', {
        type: 'warning'
      }).then(() => {
        this.assetpkgmgrFullScreenLoading()
        this.traceTaskAssignApi.defaultNewSave(updateTraceUserDTO).then(res => {
          this.assetpkgmgrFullScreenLoading().close()
          let dialogTitle = this.assignType === '1' ? this.$t('coordManageMain.editAssignTitle1') : this.$t('coordManageMain.editAssignTitle2')
          if (res.success) {
            this.success(dialogTitle + this.$t('common.successfully'))
            this.$emit('chooseBtnClick', true)
            this.dialogVisible = false
          } else {
            this.error(dialogTitle + this.$t('common.failed'))
            this.$emit('chooseBtnClick', true)
            this.dialogVisible = false
          }
        }).catch(res => this.assetpkgmgrFullScreenLoading().close())
      })
    },
    // 忙时字体颜色
    rowStyle ({ row, rowIndex }) {
      if (row.busyLevel === '3') {
        return 'color:#f56c6c'
      }
    }
  },
  computed: {
    taskAssignTraceApi () {
      return coordManageApi.taskAssignTrace
    },
    traceTaskAssignApi () {
      return coordManageApi.traceTaskAssign
    }
  }
}
</script>
