<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="30">
          <a-col :md="20" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
            </span>
          </a-col>
          <a-col :md="4" style="margin-top:-65px; z-index: 12;">
            <span style="float: right;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
            </span>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
              <a-form-item label="选择任务">
                  <a-select show-search placeholder="选择任务" option-filter-prop="children" v-model="queryParam.taskId" @change="gettable">
                      <a-select-option v-for="item in dataTypeList" :value="item.id">
                          {{ item.name }}
                      </a-select-option>
                  </a-select>
              </a-form-item>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- table区域-begin -->
    <div style="height:calc(100vh - 300px);overflow:hidden; background: #e6e9f1 !important;">
      <div class="linese"></div>
      <a-table
        ref="table"
        size="middle"
        style="height:calc(100vh - 344px);"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys,onChange: onSelectChange}"
        @change="handleTableChange">
<!--        :locale="myLocale"-->

        <!-- 字符串超长截取省略号显示-->
        <template slot="status" slot-scope="text">
            <span style="color:black;" v-if="text === 0" >未确认</span>
            <span style="color:darkorange;" v-if="text === 1">未上报</span>
            <span style="color:#87d068;" v-if="text === 2">已上报</span>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical"/>
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </a-table>
      <div class="linese"></div>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <materialSupportModal ref="modalForm" @ok="gettable"></materialSupportModal>
  </a-card>
</template>

<script>
  import materialSupportModal from './modules/materialSupportModal'
  import { taskPageList,idcMaterialSupport071delete } from '@/api/materialSupport'
  import {getAction} from '@/api/manage'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import JEllipsis from "@/components/jeecg/JEllipsis";
  import guaz from '@assets/guaz.png'

  export default {
    name: "materialSupport",
    mixins:[JeecgListMixin],
    components: {
      materialSupportModal,
      JEllipsis,
      VNodes: {
        functional: true,
        render: (h, ctx) => ctx.props.vnodes,
      },
    },
    data () {
      return {
        description: '物资保障',
        dataSources: [],
        guaz,
        queryParam: {
          taskId:'',
          pageNum :1,
          pageSize:20
        },
        taskqueryParam: {
          pageNum :1,
          pageSize:9999999
        },
        dataTypeList:[],
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'燃油重量(吨)',
            align:"center",
            dataIndex: 'fuel'
          },
          {
            title:'淡水重量(吨)',
            align:"center",
            dataIndex: 'water'
          },
          {
            title:'HQ-10 导弹数量',
            align:"center",
            dataIndex: 'hq10'
          },
          {
            title:'右中857余弹量',
            align:"center",
            dataIndex: 'rm857'
          },
          {
            title:'右后857余弹量',
            align:"center",
            dataIndex: 'rr857'
          },
          {
            title:'左中857余弹量',
            align:"center",
            dataIndex: 'lm857'
          },
          {
            title:'左后857余弹量',
            align:"center",
            dataIndex: 'lr857'
          },
          {
            title:'单76炮余弹量',
            align:"center",
            dataIndex: 'a76'
          },
          {
            title:'厘米箔条弹',
            align:"center",
            dataIndex: 'chaffCm'
          },
          {
            title:'毫米箔条弹',
            align:"center",
            dataIndex: 'chaffMm'
          },
          {
            title:'红外弹',
            align:"center",
            dataIndex: 'ir'
          },
          {
            title:'烟幕弹',
            align:"center",
            dataIndex: 'smoke'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
      }
    },
    computed: {
    },
    created () {
      this.loadData();
    },
    methods: {
      //筛选需要重写handleTableChange
      handleTableChange(pagination, filters, sorter) {
        //分页、排序、筛选变化时触发
        //TODO 筛选
        if (Object.keys(sorter).length > 0) {
          this.isorter.column = sorter.field;
          this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
        }
        this.ipagination = pagination;
        this.gettable();
      },
      gettable(){
        getAction("/idcMaterialSupport071/list", this.queryParam).then((res) => {
            if (res.success) {
                this.dataSource = res.result.records;
                if(res.result.total)
                {
                  this.ipagination.total = res.result.total;
                }
            } else {
                this.$message.warning(res.message);
            }
        });
      },
      loadData() {
        taskPageList(this.taskqueryParam).then((res) => {
            if (res.success) {
                this.dataTypeList = res.result.rows||res.result;
            } else {
                this.$message.warning(res.message);
            }
        });
      },
      handleDelete: function (id) {
        var that = this;
        idcMaterialSupport071delete({id: id}).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            that.gettable();
          } else {
            that.$message.warning(res.message);
          }
        });
      },
      handleEdit: function (record) {
        this.$refs.modalForm.edit(record);
        this.$refs.modalForm.title = "编辑";
        this.$refs.modalForm.taskId = this.queryParam.taskId
      },
      handleAdd() {
        if( this.queryParam.taskId == ''){
          this.$message.warning("请选择任务");
          return;
        }
        this.$refs.modalForm.add();
        this.$refs.modalForm.title = "新增";
        this.$refs.modalForm.taskId = this.queryParam.taskId
      },
    }
  }
</script>
