<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <search-bar
      :formConfigs="formConfig"
      ref="searchBarForm"
      @headBtnClick="buttonClick"
    />
    <!-- 列表 -->
    <base-table
      :page="queryParams.pageNo"
      :limit="queryParams.pageSize"
      :table-props="tableProps"
      :table-data="list"
      :max-height="tableH"
    >
      <method-btn
        v-if="tableBtn.length"
        slot="handleBtn"
        :width="80"
        label="操作"
        :method-list="tableBtn"
        @clickBtn="handleClick"
      />
    </base-table>
    <pagination
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      :total="total"
      @pagination="getList"
    />
    <!-- 新增&编辑 -->
    <base-dialog
      :dialogTitle="addOrEditTitle"
      :dialogVisible="centervisible"
      @cancel="handleCancel"
      @confirm="handleConfirm"
      :before-close="handleCancel"
      width='70%'
    >
      <order-add ref="orderAdd" @successSubmit="successSubmit" />
    </base-dialog>
    <!-- 查看详情 -->
  </div>
</template>
<script>
import { parseTime } from '@/utils/ruoyi'
import { getOrderPage } from '@/api/base/orderManage'
import OrderAdd from './components/orderAdd.vue'
const tableProps = [
  {
    prop: 'createTime',
    label: '添加时间',
    filter: parseTime,
    minWidth: 150
  },
  {
    prop: 'name',
    label: '订单名称'
  },
  {
    prop: 'code',
    label: '订单编码',
    minWidth: 220
  },
  {
    prop: 'num',
    label: '客户'
  },
  {
    prop: 'leaderName',
    label: '来源'
  },
  {
    prop: 'leaderName1',
    label: '优先级'
  },
  {
    prop: 'leaderNam1e',
    label: '订单状态'
  },
  {
    prop: 'leaderName3',
    label: '计划加工量'
  },
  {
    prop: 'leaderName9',
    label: '实际加工量'
  },
  {
    prop: 'leaderN4ame',
    label: '产品'
  },
  {
    prop: 'leade2rName',
    label: '单位'
  },
  {
    prop: 'leaderN11ame',
    label: '单价(元)'
  },
  {
    prop: 'leaderName22',
    label: '工单数量'
  }
]
export default {
  name: 'OrderManage',
  data() {
    return {
      formConfig: [
        {
          type: 'input',
          label: '订单名称',
          placeholder: '订单名称',
          param: 'name'
        },
        {
          type: 'select',
          label: '状态',
          selectOptions: this.getDictDatas(this.DICT_TYPE.ORDER_STATUS),
          labelField: 'label',
          valueField: 'value',
          param: 'status'
        },
        {
          type: 'datePicker',
          label: '时间段',
          dateType: 'daterange',
          format: 'yyyy-MM-dd',
          valueFormat: "yyyy-MM-dd",
          rangeSeparator: '-',
          startPlaceholder: '开始时间',
          endPlaceholder: '结束时间',
          param: 'timeVal',
          defaultSelect: [],
          width: 250
        },
        {
          type: 'button',
          btnName: '查询',
          name: 'search',
          color: 'primary'
        },
        {
          type: 'separate'
        },
        {
          type: 'button',
          btnName: '新增',
          name: 'add',
          color: 'success',
          plain: true
        }
      ],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 20,
        name: null,
        status: null,
        lastIssuedTime: []
      },
      total: 0,
      tableProps,
      list: [],
      tableH: this.tableHeight(260),
      tableBtn: [
        this.$auth.hasPermi('base:group-team:update')
          ? {
              type: 'edit',
              btnName: '编辑'
            }
          : undefined,
        this.$auth.hasPermi('base:group-team:delete')
          ? {
              type: 'delete',
              btnName: '删除'
            }
          : undefined
      ].filter((v) => v),
      addOrEditTitle: '',
      centervisible: false
    }
  },
  components: { OrderAdd },
  created() {
    window.addEventListener('resize', () => {
      this.tableH = this.tableHeight(260)
    })
    this.getList();
  },
  methods: {
    getList() {
      getOrderPage({...this.queryParams}).then(res => {
        console.log(res)
      })
    },
    buttonClick(val) {
      console.log(val)
      if (val.btnName === 'search') {
        this.queryParams.name = val.name
        this.queryParams.status = val.status
        if (val.timeVal.length > 0) {
          this.queryParams.lastIssuedTime[0] = val.timeVal[0] + ' 00:00:00'
          this.queryParams.lastIssuedTime[1] = val.timeVal[1] + ' 23:59:59'
        } else {
          this.queryParams.lastIssuedTime = []
        }
        this.getList()
      } else {
        this.addOrEditTitle = '新增'
        this.centervisible = true
      }
    },
    handleClick(val) {
      switch (val.type) {
        case 'edit':
          this.addOrEditTitle = '编辑'
          this.$nextTick(() => {
            this.$refs.groupList.init(val.data.id)
          })
          this.centervisible = true
          break
        default:
        this.handleDelete(val.data)
      }
    },
    // 新增
    handleCancel() {
      this.$refs.orderAdd.formClear()
      this.centervisible = false
      this.addOrEditTitle = ''
    },
    handleConfirm() {
      this.$refs.orderAdd.submitForm()
    },
    successSubmit() {
      this.handleCancel()
      this.getList()
    },
  }
}
</script>