<!-- 工种管理 -->
<template>
  <div class="work-type">
    <template v-if="!assignVisible && !noticeChangeVisible && !submitVisible">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="queryData()">
        <el-form-item label="任务号">
          <el-input v-model="dataForm.orderCode" placeholder="" clearable/>
        </el-form-item>
        <el-form-item>
          <el-button @click="queryData()">查询</el-button>
          <el-button @click="noticeSettingHandle(null, false)">通知设置</el-button>
        </el-form-item>
      </el-form>
      <el-table
        :data="dataList"
        border
        v-loading="dataListLoading"
        style="width: 100%;">
        <el-table-column
          label="序号"
          type="index"
          width="100"
          align="center">
        </el-table-column>
         <el-table-column
          prop="projectName"
          header-align="center"
          align="center"
          min-width="140"
          :show-tooltip-when-overflow="true"
          label="项目名称">
        </el-table-column>
        <el-table-column
          prop="orderCode"
          header-align="center"
          align="center"
          min-width="160"
          :show-tooltip-when-overflow="true"
          label="任务号">
        </el-table-column>
        <el-table-column
          prop="customerName"
          header-align="center"
          align="center"
          min-width="160"
          :show-tooltip-when-overflow="true"
          label="客户名称">
        </el-table-column>
        <el-table-column
          prop="deliveryDate"
          header-align="center"
          align="center"
          min-width="160"
          :show-tooltip-when-overflow="true"
          label="合同交期">
        </el-table-column>
        <el-table-column
          prop="createTime"
          header-align="center"
          align="center"
          min-width="160"
          :show-tooltip-when-overflow="true"
          label="创建时间">
        </el-table-column>
        <el-table-column
          prop="responsibilityPerson"
          header-align="center"
          align="center"
          min-width="160"
          :show-tooltip-when-overflow="true"
          label="责任人">
        </el-table-column>
        <el-table-column
          prop="state"
          header-align="center"
          align="center"
          min-width="160"
          :show-tooltip-when-overflow="true"
          :formatter="formatState"
          label="状态">
        </el-table-column>
        <el-table-column
          fixed="right"
          header-align="center"
          align="center"
          width="220"
          label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="submitHandle(scope.row, true)">查看</el-button>
            <el-button type="text" size="small" @click="assignHandle(scope.row)">分派</el-button>
            <el-button type="text" size="small" @click="submitHandle(scope.row, false)">处理</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
    </template>
    <!-- 弹窗 -->
    <assign v-if="assignVisible" ref="assign" @onChose="onChose"/>
    <notice-change v-if="noticeChangeVisible" ref="noticeChange" @onChose="onChose"/>
    <submit-plan v-if="submitVisible" ref="submit" @onChose="onChose"/>
  </div>
</template>

<script>
  import Assign from '@/views/modules/tech/project-tech-assign'
  import NoticeChange from '@/views/modules/tech/project-tech-notice-change-setting'
  import SubmitPlan from '@/views/modules/tech/project-tech-submit'
  export default {
    name: 'plan',
    components: {
      Assign, NoticeChange, SubmitPlan
    },
    data () {
      return {
        assignVisible: false,
        noticeChangeVisible: false,
        submitVisible: false,
        dataForm: {},
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        optionsLevel: [],
        importLoading: false,
        importData: {},
        fileList: [],
        stateOption: [
          {label: '待处理', value: '1'},
          {label: '已处理', value: '2'}
        ]
      }
    },
    created () {
      this.getDataList()
    },
    methods: {
      onChose () {
        this.detailVisible = false
        this.assignVisible = false
        this.noticeChangeVisible = false
        this.submitVisible = false
      },
      // 查询
      queryData () {
        this.pageIndex = 1
        this.getDataList()
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.addOrUpdateVisible = false

        this.$http({
          url: this.$http.adornUrl(`/biz-service/projTechnology/list`),
          method: 'get',
          params: this.$http.adornParams({
            'current': this.pageIndex,
            'size': this.pageSize,
            'orderCode': this.dataForm.orderCode
          })
        }).then(({data}) => {
          this.dataListLoading = false
          if (data && data.code === '200') {
            this.dataList = data.data.records
            this.totalPage = Number(data.data.total)
          } else {
            this.dataList = []
            this.totalPage = 0
          }
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      assignHandle (item) {
        this.assignVisible = true
        this.$nextTick(() => {
          this.$refs.assign.init(item)
        })
      },
      submitHandle (item, readonly) {
        this.submitVisible = true
        this.$nextTick(() => {
          this.$refs.submit.init(item, readonly)
        })
      },
      formatState (row) {
        if (!row.state) return ''

        return this.getStateStr(row.state)
      },
      getStateStr (state) {
        let option = this.stateOption.find(t => t.value === state)
        if (option != null) {
          return option.label
        }
        return ''
      },
      noticeSettingHandle () {
        this.noticeChangeVisible = true
        this.$nextTick(() => {
          this.$refs.noticeChange.init()
        })
      }
    }
  }
</script>

<style scoped>

</style>
