<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="工序名称">
              <a-input placeholder="请输入工序名称" v-model="queryParam.processName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="设备名称">
              <a-input placeholder="请输入设备名称" v-model="queryParam.machineNames"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
                      <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                        <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                        <a-button type="primary" @click="searchReset" icon="reload"
                                  style="margin-left: 8px">重置</a-button>
                      </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- 高级查询区域 -->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="gw" slot-scope="text, record">
          <a @click="gw(record.stationId)">{{text}}</a>
        </template>
        <template slot="gd" slot-scope="text, record">
          <a @click="gd(record.productNo)">{{text}}</a>
        </template>
        <template slot="cp" slot-scope="text, record">
          <a @click="cp(record.productCode)">{{text}}</a>
        </template>
        <template slot="gx" slot-scope="text, record">
          <a @click="gx(record.processId)">{{text}}</a>
        </template>
        <template slot="sb" slot-scope="text, record">
          <a @click="sb(record.machineIds)">{{text}}</a>
        </template>
        <template slot="nodata" slot-scope="text, record">
          <span v-if="!text" style="font-size: 14px;font-style: italic;">无</span>
          <span v-else style="font-size: 14px;font-style: italic;">{{record.proProcessName}}</span>
        </template>
        <template slot="nodata1" slot-scope="text, record">
          <span v-if="!text" style="font-size: 14px;font-style: italic;">无</span>
          <span v-else style="font-size: 14px;font-style: italic;">{{record.postProcessName}}</span>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <zy-plan-process-modal ref="modalForm" @ok="modalFormOk"></zy-plan-process-modal>
    <station-modal1 ref="modalFormgw"></station-modal1>
    <work-order-modal ref="modalFormgd"></work-order-modal>
    <zy-product-modal ref="modalFormcp"></zy-product-modal>
    <ZyProcessDetail ref="zyProcessDetail"></ZyProcessDetail>
    <ZyDeviceDetail ref="ZyDeviceDetail"></ZyDeviceDetail>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ZyPlanProcessModal from './modules/ZyPlanProcessModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import StationModal1 from "../team/modules/StationModal1";
  import WorkOrderModal from "../workorder/modules/WorkOrderModal";
  import {deleteAction, getAction} from "@api/manage";
  import ZyProductModal from "../zyWorkProduct/modules/ZyProductModal";
  import ZyProcessDetail from "../process/modules/ZyProcessDetail";
  import ZyDeviceDetail from "../device/modules/ZyDeviceDetail";

  export default {
    name: 'ZyPlanProcessList1',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      ZyPlanProcessModal,
      StationModal1,
      WorkOrderModal,
      ZyProductModal,
      ZyProcessDetail,
      ZyDeviceDetail
    },
    data () {
      return {
        description: '生产计划工序管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'工单编号',
            align:"center",
            dataIndex: 'productNo',
            scopedSlots: {customRender: 'gd'}
          },
          {
            title:'产品名称',
            align:"center",
            dataIndex: 'productCode_dictText',
            scopedSlots: {customRender: 'cp'}
          },
          {
            title:'工序名称',
            align:"center",
            dataIndex: 'processName',
            scopedSlots: {customRender: 'gx'}
          },
          {
            title:'工位名称',
            align:"center",
            dataIndex: 'stationName',
            scopedSlots: {customRender: 'gw'}
          },
          {
            title:'工位序号',
            align:"center",
            dataIndex: 'stationNum'
          },
          {
            title:'设备名称',
            align:"center",
            dataIndex: 'machineNames',
            scopedSlots: {customRender: 'sb'}
          },
/*          {
            title:'工具名称',
            align:"center",
            dataIndex: 'toolsNames'
          },*/
          {
            title:'前导工序',
            align:"center",
            dataIndex: 'proProcessName',
            scopedSlots: {customRender: 'nodata'}
          },
          {
            title:'后导工序',
            align:"center",
            dataIndex: 'postProcessName',
            scopedSlots: {customRender: 'nodata1'}
          },
/*          {
            title:'输入产品',
            align:"center",
            dataIndex: 'inputProduct'
          },
          {
            title:'成品/半成品',
            align:"center",
            dataIndex: 'semiProduct'
          },
          {
            title:'工人名称',
            align:"center",
            dataIndex: 'userNames'
          },*/
          {
            title:'机器时长',
            align:"center",
            dataIndex: 'totalMachine'
          },
          {
            title:'人工时长',
            align:"center",
            dataIndex: 'totalMaunal'
          },
/*          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }*/
        ],
        url: {
          list: "/org.jeecg.modules.productplan/zyPlanProcess/pagelist1",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    //this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      gw(stationId){
        getAction("/team/station/queryById", {id: stationId}).then((res) => {
          if (res.success) {
            this.$refs.modalFormgw.edit(res.result);
            this.$refs.modalFormgw.title="详情";
          } else {
          }
        })
      },
      gd(orderCode){
        getAction("/workOrder/workOrder/queryByOrderCode", {orderCode: orderCode}).then((res) => {
          if (res.success) {
            this.$refs.modalFormgd.edit(res.result);
            this.$refs.modalFormgd.title="详情";
            this.$refs.modalFormgd.disableSubmit = true;
          } else {
          }
        })
      },
      cp(productCode){
        getAction("/zyproduct/zyProduct/queryByProductCode", {productCode: productCode}).then((res) => {
          if (res.success) {
            this.$refs.modalFormcp.edit(res.result);
            this.$refs.modalFormcp.title="详情";
            this.$refs.modalFormcp.disableSubmit = true;
          } else {
          }
        })
      },
      gx(processId){
        this.$refs.zyProcessDetail.showModal(processId);
      },
      sb(machineIds){
        this.$refs.ZyDeviceDetail.showModal(machineIds.split(",")[0]);
      },
      initDictConfig(){
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>