<template>
  <div id="deliveryAddressList">
    <div v-if="isList">
      <el-card>
        <el-form class="search_area" label-width="120px">
          <el-row :gutter="10">
            <el-col :span="1.5">
              <el-form-item label="单据编号">
                <el-input
                  v-model="queryParams.code"
                  size="mini"
                  clearable
                  style="width: 200px"
                />
              </el-form-item>
            </el-col>
            <el-col :span="1.5">
              <el-form-item label="目标名称">
                <el-input
                  v-model="queryParams.name"
                  size="mini"
                  clearable
                  style="width: 200px"
                />
              </el-form-item>
            </el-col>
            <!-- <el-col :span="1.5">
              <el-form-item label="模板">
                <el-input
                  v-model="queryParams.template"
                  size="mini"
                  clearable
                  style="width: 200px"
                />
              </el-form-item>
            </el-col>
            <el-col :span="1.5">
              <el-form-item label="年度">
                <el-input
                  v-model="queryParams.year"
                  size="mini"
                  clearable
                  style="width: 200px"
                />
              </el-form-item>
            </el-col> -->
            <el-col :span="1.5">
              <el-form-item label="" label-width="20px">
                <el-button type="primary" size="mini" icon="el-icon-search" plain @click="useSearch">搜索</el-button>
                <el-button size="mini" icon="el-icon-refresh" plain @click="useReset">重置</el-button>
              </el-form-item>
            </el-col>
          </el-row>
          <CollapseTransition>
            <div v-show="expanded">
              
            </div>
          </CollapseTransition>
        </el-form>
        <el-divider class="lines"><i style="cursor: pointer;" :class="expanded?'el-icon-arrow-up':'el-icon-arrow-down'" @click="drop"></i></el-divider>
      
        <div class="btn_grooup">
          <el-button type="primary" size="mini" @click="useAdd">新增</el-button>
          <el-button type="primary" size="mini" @click="useAdd">模板导出</el-button>
          <el-button type="primary" size="mini" @click="useAdd">导入</el-button>
        </div>

        <el-table 
          :data="tableList" 
          fit
          max-height="480"
          style="font-size: 12px;"
          @selection-change="useSelectionRow"
          @row-dblclick="useDoubleClick"
        >
          <el-table-column show-overflow-tooltip type="selection" width="55" />
          <el-table-column show-overflow-tooltip label="单据编号" align="center" width="200" prop="code"/>
          <el-table-column show-overflow-tooltip label="单据日期" align="center" width="200" prop="date"/>
          <el-table-column show-overflow-tooltip label="目标名称" align="center" width="200" prop="name"/>
          <el-table-column show-overflow-tooltip label="年度" align="center" width="200" prop="templateData.year"/>
          <el-table-column show-overflow-tooltip label="模板" align="center" width="200" prop="templateData.name"/>
          <el-table-column show-overflow-tooltip label="开始日期" align="center" width="200" prop="templateData.startTime" />
          <el-table-column show-overflow-tooltip label="结束日期" align="center" width="200" prop="templateData.deadlineTime" />
          <el-table-column show-overflow-tooltip label="周期" align="center" width="200" prop="templateData.cycle">
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.mk_periodic_unit"
                :value="scope.row.templateData.cycle"
              />
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip label="维度" align="center" min-width="200" prop="templateData.dimensionalitys">
            <template slot-scope="scope">
              <div style="display:flex;">
                <span v-for="o in scope.row.templateData.dimensionalitys">
                  <dict-tag
                    :options="dict.type.mk_dimensionality"
                    :value="o.dimensionality"
                    />
                  </span>
              </div>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip label="指标" align="center" min-width="200" prop="templateData.indexs">
            <template slot-scope="scope">
              <div style="display:flex;">
                <span v-for="o in scope.row.templateData.indexs">
                  <dict-tag
                    :options="dict.type.mk_index_type"
                    :value="o.target"
                  />
                </span>
              </div>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip label="创建人" align="center" width="200" prop="createByName" />
          <el-table-column show-overflow-tooltip label="创建时间" align="center" width="200" prop="createTime" />
          <el-table-column show-overflow-tooltip label="修改人" align="center" width="200" prop="updateByName" />
          <el-table-column show-overflow-tooltip label="修改时间" align="center" width="200" prop="updateTime" />
          <el-table-column fixed="right" label="操作" align="center" width="200">
            <template slot-scope="scope">
              <!-- <el-button type="text" size="mini" @click="useSubmit(scope.row)">提交</el-button> -->
              <el-button type="text" size="mini" @click="useEdit(scope.row)">编辑</el-button>
              <el-button type="text" size="mini" @click="useDel(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <el-pagination
          background
          @size-change="useChangePageSize"
          @current-change="useCurrentChange"
          :current-page="queryParams.pageNum"
          :page-sizes="[10, 15, 20]"
          :page-size="100"
          layout="total, sizes, prev, pager, next, jumper"
          :total=total>
        </el-pagination>
      </el-card>
    </div>
    <Add v-model="isList" v-if="!isList" :pageStu="page" :disable="disable" :row="rowDetail" @refresh="useSearch"/>
  </div>
</template>

<script>
import Add from './add.vue'
import CollapseTransition from '@/components/MyCollapse/collapse.vue'
import { listTarget,delTarget } from "@/api/business/spd/starget/target";
export default {
  name: 'target',
  dicts: [
    "mk_periodic_unit","mk_dimensionality","mk_index_type"
  ],
  components: { Add,CollapseTransition},
  data() {
    return {
      expanded: false,
      // 页面配置
      isList: true,
      // 页面状态
      page: '',
      // 搜索框参数
      queryParams: {
        code: '',
        name: '',
        template:'',
        year:'',
        pageNum: 1,
        pageSize: 10
      },
      //总条数
      total: 0,
      //列表数据
      tableList:[],
      disable: false,
      rowDetail:{},
    }
  },
  created() {
    this.getList(this.queryParams)
  },
  methods: {
    //新增
    useAdd(){
      this.isList = false
      this.page = 'add'
      this.disable = false
    },
    //提交
    useSubmit(){
      
    },
    //修改
    useEdit(row){
      this.isList = false
      this.page = 'edit'
      this.rowDetail = row
      this.disable = false
    },
    //删除
    useDel(row){
      this.$modal.confirm('确认删除选择数据').then(() => {
        delTarget(row.id).then(res => {
          if (res.code === 200) {
            this.$modal.msgSuccess("删除成功");
            this.getList(this.queryParams)
          }
        })
      }).catch(() => {})
    },
    //查看
    useSee(){

    },
    //选择列
    useSelectionRow(){

    },
    //双击
    useDoubleClick(row){
      this.isList = false
      this.page = 'see'
      this.rowDetail = row
      this.disable = false
    },
    //改变一页显示条数
    useChangePageSize(val){
      this.queryParams.pageSize = val
      this.getList(this.queryParams)
    },
    //翻页
    useCurrentChange(val){
      this.queryParams.pageNum = val
      this.getList(this.queryParams)
    },
    //搜索
    useSearch() {
      this.getList(this.queryParams)
    },
    //重置
    useReset(){
      this.queryParams = {
        code: '',
        name: '',
        template:'',
        year:'',
        pageNum: 1,
        pageSize: 10
      }
      this.getList(this.queryParams)
    },
    //查询列表
    getList(params){
      listTarget(params).then(res => {
        if (res.code === 200) {
          this.tableList = res.rows
          this.total = res.total
        }
      })
    },
    drop() {
      this.expanded = !this.expanded
    },
  }
};
</script>

<style lang="scss" scoped>
#deliveryAddressList {
  height: calc(100vh - 84px);
  padding: 12px;
  box-sizing: border-box;
  overflow-y: scroll;
}
.btn_grooup {
  margin-bottom: 10px;
  display: flex;
  justify-content: flex-end;
}
.lines {
  margin-top: 0;
}
.el-pagination {
  margin-top: 10px;
  text-align: right;
}
</style>
