<!-- @desc:首页工作台  @auth:洪旭东  @time:2022-05-02 10:28 -->
<template>
  <div class="main-div">
<!--    &lt;!&ndash;    待办&ndash;&gt;-->
<!--    <Card class="card card-upcoming" @contextmenu.native.prevent>-->
<!--      <p slot="title">-->
<!--        今日产量-->
<!--      </p>-->
<!--      <Tooltip style="cursor: pointer" slot="extra" :content="$t('refresh')" theme="light"-->
<!--               v-if="flgWarning">-->
<!--        <Button icon="md-refresh" shape="circle" class="circle-button" @click="refreshWaitCenter"></Button>-->
<!--      </Tooltip>-->
<!--      &lt;!&ndash;      预警设置按钮&ndash;&gt;-->
<!--      &lt;!&ndash;      <Tooltip style="cursor: pointer" slot="extra" :content="$t('earlyWarningSetting')" theme="light">&ndash;&gt;-->
<!--      &lt;!&ndash;        <Button icon="md-settings" shape="circle" class="circle-button" @click="setHomeWarning"></Button>&ndash;&gt;-->
<!--      &lt;!&ndash;      </Tooltip>&ndash;&gt;-->
<!--      <Button icon="md-settings" slot="extra" shape="circle" class="circle-button" @click="setHomeWarning"></Button>-->
<!--      <div style="display: flex;align-items: center;">-->
<!--        <div class="upcoming" :style="{padding: (flgWarning?'':0)}">-->
<!--          &lt;!&ndash;成型产量&ndash;&gt;-->
<!--          <div class="upcoming-card" v-for="(item,index) in homeWarningData_quan" :key="'quan'+index"-->
<!--               @click="openDrawer(item)">-->
<!--            <div class="upcoming-card-right">-->
<!--              <div class="upcoming-card-last">昨日{{ item.lastCount }}-->
<!--                <Icon v-if="item.currentCount<item.lastCount" type="iconfont iconfont icon-down"-->
<!--                      style="color: #191A23"/>-->
<!--                <Icon v-else-if="item.currentCount>item.lastCount" type="iconfont iconfont icon-up"-->
<!--                      style="color: #EE6666"/>-->
<!--              </div>-->
<!--              <div class="upcoming-card-number">{{ item.currentCount }}</div>-->
<!--              <div class="upcoming-card-text">{{ item.warningName }}</div>-->
<!--            </div>-->
<!--          </div>-->
<!--          &lt;!&ndash;质量&ndash;&gt;-->
<!--          <div class="upcoming-card" v-for="(item,index) in homeWarningData_qa" :key="'qa'+index"-->
<!--               @click="openDrawer(item)"-->
<!--               style="background-color: #70AD47 !important;">-->
<!--            <div class="upcoming-card-right">-->
<!--              <div class="upcoming-card-last">昨日{{ item.lastCount }}%-->
<!--                <Icon v-if="item.currentCount<item.lastCount" type="iconfont iconfont icon-down"-->
<!--                      style="color: #191A23"/>-->
<!--                <Icon v-else-if="item.currentCount>item.lastCount" type="iconfont iconfont icon-up"-->
<!--                      style="color: #EE6666"/>-->
<!--              </div>-->
<!--              <div class="upcoming-card-number">{{ item.currentCount }}%</div>-->
<!--              <div class="upcoming-card-text">{{ item.warningName }}</div>-->
<!--            </div>-->
<!--          </div>-->
<!--        </div>-->
<!--      </div>-->
<!--    </Card>-->

<!--    &lt;!&ndash;产量分析&ndash;&gt;-->
<!--    <Card class="card card-upcoming" @contextmenu.native.prevent>-->
<!--      <p slot="title">-->
<!--        产量分析-->
<!--      </p>-->
<!--      <div slot="extra">-->
<!--        <DateWeek @time="getWeekOutPutTime" ref="weekOutPutTime" init/>-->
<!--      </div>-->
<!--      <Echarts type="bar" :table-columns="tableWeekOutPutColumns" ref="chart_quantity" title="一周产量分析"-->
<!--               :style="'height: 300px;width: 100%'" :row-field-keys="tableQualityRowFields"-->
<!--               :table-data="tableWeekOutputData"/>-->
<!--    </Card>-->

<!--    &lt;!&ndash;质量分析&ndash;&gt;-->
<!--    <Card class="card card-upcoming" @contextmenu.native.prevent>-->
<!--      <p slot="title">-->
<!--        质量分析-->
<!--      </p>-->
<!--      <div slot="extra">-->
<!--        <DateWeek @time="getWeekQualityTime" ref="weekQualityTime" init/>-->
<!--      </div>-->
<!--      <Echarts type="line" :table-columns="tableWeekQualityColumns" ref="chart_quality" title="一周质量分析"-->
<!--               :style="'height: 300px;width: 100%'" :row-field-keys="tableQualityRowFields"-->
<!--               :table-data="tableWeekQualityData"/>-->
<!--    </Card>-->

<!--    <div style="display: flex">-->
<!--      &lt;!&ndash;半检缺陷TOP5&ndash;&gt;-->
<!--      <Card class="card card-upcoming" style="width: 50%" @contextmenu.native.prevent>-->
<!--        <p slot="title">-->
<!--          半检缺陷TOP5-->
<!--        </p>-->
<!--        <div slot="extra">-->
<!--          <DateWeek @time="getHalfCheckTime"/>-->
<!--        </div>-->
<!--        <Echarts type="bar" :table-columns="tableHalfCheckColumns" ref="halfCheckTopDefect" title="半检缺陷TOP5"-->
<!--                 :style="'height: 300px;width: 100%'" :table-data="tableHalfCheckData" x-value/>-->
<!--      </Card>-->
<!--      &lt;!&ndash;成检缺陷TOP5&ndash;&gt;-->
<!--      <Card class="card card-upcoming" style="width: 49.5%;margin-left: 0.5%" @contextmenu.native.prevent>-->
<!--        <p slot="title">-->
<!--          成检缺陷TOP5-->
<!--        </p>-->
<!--        <div slot="extra">-->
<!--          <DateWeek @time="getCheckTime"/>-->
<!--        </div>-->
<!--        <Echarts type="bar" :table-columns="tableCheckColumns" ref="checkTopDefect" title="成检缺陷TOP5"-->
<!--                 :style="'height: 300px;width: 100%'" :table-data="tableCheckData" x-value/>-->
<!--      </Card>-->
<!--    </div>-->

<!--    &lt;!&ndash;月订单达成率&ndash;&gt;-->
<!--    <Card class="card card-upcoming" @contextmenu.native.prevent>-->
<!--      <p slot="title">-->
<!--        月订单达成率-->
<!--      </p>-->
<!--      <div slot="extra">-->
<!--        <DateWeek @time="getTime"/>-->
<!--      </div>-->
<!--      <Echarts type="bar" :table-columns="tableOrderColumns" ref="chart_quantity" title="月订单达成率"-->
<!--               subTitle="2023-08-01~2023-08-07"-->
<!--               :style="'height: 300px;width: 100%'" :row-field-keys="tableOrderRowFields" :table-data="tableOrderData"-->
<!--               :data-type="['bar', 'line']"/>-->
<!--    </Card>-->


<!--    <Drawer :closable="false" placement="bottom" v-model="drawerShow" :height="drawerHeight" style="overflow-y:hidden">-->
<!--      &lt;!&ndash;预警中心&ndash;&gt;-->
<!--      <Card :bordered="false">-->
<!--        <p slot="title">{{ drawTitle }}-->
<!--          <Tooltip :content="!drawerMax?$t('max'):$t('close')" theme="light"-->
<!--                   style="float: right;margin-right: 10px;cursor: pointer">-->
<!--            <Icon v-if="!drawerMax" type="ios-expand" size="18" @click="maxDrawer"/>-->
<!--            <Icon v-else type="md-close" size="18" @click="drawerShow = false;"/>-->
<!--          </Tooltip>-->
<!--        <div style="clear: both;"></div>-->
<!--        </p>-->
<!--        <DkTable :id="'table-'+$options.name" ref="table-select" :data="homeWarningItemData"-->
<!--                 :pageFlag="false"-->
<!--                 :choose-flag="false"-->
<!--                 :show-setting-flag="false"-->
<!--                 :auto-width-flag="false"-->
<!--                 :height="drawerHeight - 94">-->
<!--          <DkTableColumn field="nodeName"></DkTableColumn>-->
<!--          <DkTableColumn field="modelCodeName" :title="$t('pdtModel')"></DkTableColumn>-->
<!--          <DkTableColumn field="logoCodeName" :title="$t('productLogo')"></DkTableColumn>-->
<!--          <DkTableColumn field="colourCodeName" :title="$t('productColour')"></DkTableColumn>-->
<!--          <DkTableColumn field="gradeName"></DkTableColumn>-->
<!--          <DkTableColumn field="prodUserCodeName" :title="$t('prodUserCode')"></DkTableColumn>-->
<!--          <DkTableColumn field="opnTime" :dataType="$config.dataType.dateTime"></DkTableColumn>-->
<!--          <DkTableColumn field="pdtProdQty" :dataType="$config.dataType.number"></DkTableColumn>-->
<!--        </DkTable>-->
<!--      </Card>-->
<!--    </Drawer>-->
<!--    &lt;!&ndash;预警设置modal&ndash;&gt;-->
<!--    <DkModal-->
<!--      :loading="settingModalLoading"-->
<!--      v-model="settingModal"-->
<!--      ref="modal_setting"-->
<!--      :title="$t('earlyWarningSetting')"-->
<!--      :save-flag="true"-->
<!--      @on-visible-change="onVisibleChange"-->
<!--      @modalOk="saveData()"-->
<!--      width="900px"-->
<!--    >-->
<!--      <DkTabs v-model="currentWarningType" :options="tabsOptions"></DkTabs>-->
<!--      &lt;!&ndash;     预警     &ndash;&gt;-->
<!--      <div :style="'height: ' + (tableHeight )+ 'px'" class="split-div-class"-->
<!--           v-show="currentWarningType == 0">-->
<!--        <DkSplit v-model="split">-->
<!--          <EditTable slot="left" ref="warnTable_quantity"-->
<!--                     :data="warningSettingFormData"-->
<!--                     :height="tableHeight"-->
<!--                     :choose-flag="false"-->
<!--                     :auto-focus="false"-->
<!--                     :enabledRepeat=true-->
<!--                     majorField="setId"-->
<!--                     :columns="warningSettingTableColumn"-->
<!--                     :show-setting-flag="false"-->
<!--                     @delRow="warnDelRow"-->
<!--                     @current-change="currentFlow"-->
<!--          ></EditTable>-->
<!--          &lt;!&ndash; 工序行切换&ndash;&gt;-->
<!--          <EditTable slot="right" ref="flowNode"-->
<!--                     :data="warningSettingFormData[currentRowIndex]?.flowList"-->
<!--                     :height="tableHeight"-->
<!--                     control-id="nodeId"-->
<!--                     :choose-flag="false"-->
<!--                     :columns="flowNodeColumn"-->
<!--                     :show-setting-flag="false"-->
<!--                     :enabled-repeat="false"-->
<!--                     enabled-repeat-id="nodeId"-->
<!--                     @delRow="flowDelRow"-->
<!--                     @chooseData="chooseFlowValue"-->

<!--          ></EditTable>-->
<!--        </DkSplit>-->
<!--      </div>-->

<!--      &lt;!&ndash;     预警 2    &ndash;&gt;-->
<!--      <EditTable ref="warnTable_quality" v-show="currentWarningType == 1"-->
<!--                 :data="warningSettingFormData_qa"-->
<!--                 :height="tableHeight"-->
<!--                 :choose-flag="false"-->
<!--                 :auto-focus="false"-->
<!--                 :columns="warningSettingTableColumn_qa"-->
<!--                 :enabled-repeat="false"-->
<!--                 enabled-repeat-id="kindCode"-->
<!--                 majorField="setId"-->
<!--                 control-id="qualityType"-->
<!--                 :show-setting-flag="false"-->
<!--                 @chooseData="chooseQualityType"-->
<!--                 @delRow="warnDelRow"></EditTable>-->
<!--    </DkModal>-->
<!--    &lt;!&ndash;    底部留白&ndash;&gt;-->
<!--    <div style="width: 100%; height: 20px"></div>-->
  </div>
</template>

<script>
import funcIcon from '../../../assets/images/func-icon.png'
import Echarts from '@/components/sub/echarts/echarts'
import DateWeek from '_c/base/date-week/index'

export default {
  name: 'home',
  components: {Echarts, DateWeek},
  data() {
    let self = this
    return {
      split: 0.8,
      settingModalLoading: false,
      warningSettingFormData: [],  // 产量数据
      warningSettingFormData_qa: [],// 质量数据
      tableHeight: 438,
      //预警列表
      warningSettingTableColumn: [
        {
          field: 'warningName',
          type: 'text'
        },
        {field: 'remarks', type: 'text', width: 'auto'},
        {field: 'displayNo', type: 'number', width: 80},
      ],
      warningSettingTableColumn_qa: [
        {
          field: 'qualityType',
          type: 'select',
          controlId: 'qualityType',
          title: this.$t('qualityType'),
          labelKey: 'kindName',
          valueKey: 'kindCode',
          options: () => this.qualityTypeData,
        },
        {field: 'remarks', type: 'text', width: 'auto'},
        {field: 'displayNo', type: 'number', width: 'auto'},
      ],
      flowNodeColumn: [
        {
          field: 'nodeName',
          width: 'auto',
          controlId: 'nodeId',
          type: 'tableSelect',
          dataType: self.$config.tableSelectType.processNode,
          fieldUpdate: self.$updateColumns.outKilnStrategyStatsNodes,
        }
      ],
      currentWarningType: '0',// 默认在产量
      settingModal: false,//是否显示预警界面
      drawType: self.$config.homeDrawType.waitAudit, // 首页抽屉类型
      drawerHeight: 350,   // 抽屉的高度
      funcIcon,
      funcModal: false,
      funcModalLoading: false,
      flgWarning: false,// 是否有预警数据
      homeWarningData_quan: [],// 预警数据-数量
      homeWarningData_qa: [],// 预警数据-质量
      homeWarningItemData: [],// 预警明细数据
      drawTitle: null,
      funcList: [],
      rightFuncList: [],
      homeCommonUseList: [],
      earlySettingList: [],//预警表单数据
      qualityTypeData: [],//质量类型可选项
      tabsOptions: [
        {label: self.$t('产量'), name: '0'},
        {label: self.$t('质量'), name: '1'},
      ],
      currentRowIndex: 0,// 当前行号
      tableQualityData: [
        {date: '2023-08-01', 注浆: 10, 精坯: 18, 釉坯: 15, 烧成: 18, 成检: 19, 包装: 18},
        {date: '2023-08-02', 注浆: 15, 精坯: 17, 釉坯: 18, 烧成: 17, 成检: 16, 包装: 22},
        {date: '2023-08-03', 注浆: 18, 精坯: 18, 釉坯: 15, 烧成: 19, 成检: 19, 包装: 21},
        {date: '2023-08-04', 注浆: 12, 精坯: 20, 釉坯: 14, 烧成: 20, 成检: 28, 包装: 18},
        {date: '2023-08-05', 注浆: 22, 精坯: 28, 釉坯: 27, 烧成: 27, 成检: 29, 包装: 23},
        {date: '2023-08-06', 注浆: 20, 精坯: 22, 釉坯: 22, 烧成: 22, 成检: 22, 包装: 22},
        {date: '2023-08-07', 注浆: 18, 精坯: 17, 釉坯: 18, 烧成: 11, 成检: 17, 包装: 11},
      ],

      tableQualityRowFields: [
        'date'
      ],

      tableQualityColumns: [
        {field: 'date', title: '日期'},
        {field: '注浆', title: '注浆'},
        {field: '精坯', title: '精坯'},
        {field: '釉坯', title: '釉坯'},
        {field: '烧成', title: '烧成'},
        {field: '成检', title: '成检'},
        {field: '包装', title: '包装'},
      ],

      tableCheckColumns: [],
      tableHalfCheckColumns: [],
      tableWeekOutPutColumns: [],
      tableWeekQualityColumns: [],


      tableCheckData: [],
      tableHalfCheckData: [],
      tableWeekOutputData: [],
      tableWeekQualityData: [],

      halfCheckTimeStart: null,
      halfCheckTimeEnd: null,
      checkTimeStart: null,
      checkTimeEnd: null,

      weekQualityTimeStart: null,
      weekQualityTimeEnd: null,

      weekOutputTimeStart: null,
      weekOutputTimeEnd: null,

      tableOrderColumns: [
        {field: 'date', title: '日期'},
        {field: '实际产量', title: '实际产量'},
        {field: '计划产量', title: '计划产量'},
      ],

      tableOrderData: [
        {date: '2023-08-01', 实际产量: 10, 计划产量: 18},
        {date: '2023-08-02', 实际产量: 17, 计划产量: 22},
        {date: '2023-08-03', 实际产量: 22, 计划产量: 21},
        {date: '2023-08-04', 实际产量: 18, 计划产量: 24},
        {date: '2023-08-05', 实际产量: 21, 计划产量: 23},
        {date: '2023-08-06', 实际产量: 13, 计划产量: 18},
        {date: '2023-08-07', 实际产量: 14, 计划产量: 17},
      ],

      tableOrderRowFields: [
        'date'
      ],
      // 抽屉
      drawerShow: false,
      // 抽屉最大化
      drawerMax: false,
    }
  },
  watch: {
    drawerShow(n, o) {
      // 抽屉关闭后，进行初始化操作
      if (!n) {
        this.drawerHeight = 300;
        this.drawerMax = false;
      }
    }
  },
  mounted() {
    // 监听页面，如果大小变化，抽屉关闭
    let self = this
    window.addEventListener('resize', function (e) {
      self.drawerShow = false;
    })
  },
  methods: {
    /**
     * @desc   : 最大化drawer组件
     * @author : 周兴
     * @date   : 2023/9/5 9:39
     */
    maxDrawer() {
      this.drawerMax = true;
      this.drawerHeight = document.documentElement.clientHeight;
    },
    toPage(menu) {
      this.$router.push({path: menu.menuTag.path})
    },
    getMonthDays(date) {
      date = date || new Date()
      const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0)
      const days = temp.getDate()
      return days
    },
    /**
     * @desc   : 打开抽屉
     * @author : 洪旭东
     * @date   : 2022-05-02 17:27
     */
    openDrawer(item) {
      let drawer = document.getElementsByClassName('ivu-drawer-bottom')
      let leftSider = document.getElementsByClassName('left-sider')
      if (drawer && leftSider && drawer[0] && leftSider[0]) {
        drawer[0].style.width = (document.body.clientWidth - leftSider[0].getBoundingClientRect().width) + 'px'
      }
      // 获取明细数据
      if (item) {
        this.drawTitle = item.warningName
        this.getHomeWarningItem(item);
      }
      this.drawerShow = true
    },
    /**
     * @desc   : 待办滚动
     * @author : 洪旭东
     * @date   : 2022-05-03 17:21
     */
    scrollUpcomingCard(e) {
      for (let i = 0; i < 701; i++) {
        setTimeout(function () {
          if (e == 'left') {
            document.getElementsByClassName('upcoming')[0].scrollLeft--
          } else {
            document.getElementsByClassName('upcoming')[0].scrollLeft++
          }
        }, 100 + i)
      }
    },
    /**
     * @desc   : 刷新预警中心数据
     * @author : 周兴
     * @date   : 2022/8/20 17:22
     */
    refreshWaitCenter() {
      this.getHomeWarning();  // 查询预警数据
    },

    getTime(e) {
      console.log(e.start, e.end)
    },
    /**
     * @desc   : 半检时间选择
     * @author : 洪旭东
     * @date   : 2023-09-08 15:20
     */
    getHalfCheckTime ({start, end}) {
      this.halfCheckTimeStart = start
      this.halfCheckTimeEnd = end
      this.getTopFiveHalfCheckDefect()
    },
    /**
     * @desc   : 成检时间选择
     * @author : 洪旭东
     * @date   : 2023-09-08 15:20
     */
    getCheckTime ({start, end}) {
      this.checkTimeStart = start
      this.checkTimeEnd = end
      this.getTopFiveCheckDefect()
    },
    /**
     * @desc   : 一周产量分析时间选择
     * @author : 洪旭东
     * @date   : 2023-09-12 16:37
     */
    getWeekOutPutTime ({start, end}) {
      this.weekOutputTimeStart = start
      this.weekOutputTimeEnd = end
      this.getWeekOutPut()
    },
    /**
     * @desc   : 一周质量分析时间选择
     * @author : 洪旭东
     * @date   : 2023-09-13 11:38
     */
    getWeekQualityTime ({start, end}) {
      this.weekQualityTimeStart = start
      this.weekQualityTimeEnd = end
      this.getWeekQuality()
    },
    // region 预警信息
    /**
     * @desc   : 获取预警信息
     * @author : 周兴
     * @date   : 2023/9/1 11:35
     */
    getHomeWarning() {
      let params = {
        ftyId: this.$store.state.user.ftyId,
        date: new Date()
      }
      this.excute(this.$service.homeReportService, this.$service.homeReportService.getHomeWarning, params).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          if (res.data && res.data.length > 0) {
            // 数量
            this.homeWarningData_quan = res.data.filter(it => it.warningType === 0)
            // 质量
            this.homeWarningData_qa = res.data.filter(it => it.warningType === 1)
            this.flgWarning = true;
          } else {
            this.homeWarningData_quan = []
            this.homeWarningData_qa = []
            this.flgWarning = false;
          }
        }
      })
    },
    /**
     * @desc   : 获取明细数据
     * @author : 周兴
     * @date   : 2023/9/1 13:50
     */
    getHomeWarningItem(item) {
      let params = {
        ftyId: this.$store.state.user.ftyId,
        warningSetId: item.warningSetId,
        date: item.date
      }
      this.excute(this.$service.homeReportService, this.$service.homeReportService.getHomeWarningItem, params).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          this.homeWarningItemData = res.data
        }
      })
    },
    /**
     * @desc   : 查询成检缺陷TOP5
     * @author : 洪旭东
     * @date   : 2023-09-08 14:45
     */
    getTopFiveCheckDefect() {
      let params = {
        ftyId: this.$store.state.user.ftyId,
        nodeKind: this.$config.nodeKind.finishCheck,
        timeStart: this.checkTimeStart,
        timeEnd: this.checkTimeEnd
      }
      this.excute(this.$service.homeReportService, this.$service.homeReportService.getTopFiveDefect, params).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          this.tableCheckColumns = res.data.map(m => {return {
            field: m.defectName, title: m.defectName
          }})
          let data = {}
          for (let it of res.data) {
            data = Object.assign(data, it.res)
          }
          this.tableCheckData = [data]
        }
      })
    },
    /**
     * @desc   : 查询半检缺陷TOP5
     * @author : 洪旭东
     * @date   : 2023-09-08 15:19
     */
    getTopFiveHalfCheckDefect() {
      let params = {
        ftyId: this.$store.state.user.ftyId,
        nodeKind: this.$config.nodeKind.halfCheck,
        timeStart: this.halfCheckTimeStart,
        timeEnd: this.halfCheckTimeEnd
      }
      this.excute(this.$service.homeReportService, this.$service.homeReportService.getTopFiveDefect, params).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          this.tableHalfCheckColumns = res.data.map(m => {return {
            field: m.defectName, title: m.defectName
          }})
          let data = {}
          for (let it of res.data) {
            data = Object.assign(data, it.res)
          }
          this.tableHalfCheckData = [data]
        }
      })
    },
    /**
     * @desc   : 一周产量分析
     * @author : 洪旭东
     * @date   : 2023-09-12 15:58
     */
    getWeekOutPut() {
      let params = {
        ftyId: this.$store.state.user.ftyId,
        timeStart: this.weekOutputTimeStart,
        timeEnd: this.weekOutputTimeEnd
      }
      this.excute(this.$service.homeReportService, this.$service.homeReportService.getWeekOutPut, params).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          let col = []
          let list = []
          let data = {}
          for (let it of res.data) {
            data.date = it.opDate
            for (let item of it.res) {
              data = Object.assign(data, item)
            }
            list.push(data)
            col = col.concat(Object.keys(data))
            data = {}
          }
          this.tableWeekOutputData = list
          this.tableWeekOutPutColumns = col.unique().map(m => {return {
            field: m, title: m === 'date' ? '日期':m
          }})
        }
      })
    },
    /**
     * @desc   : 一周质量分析
     * @author : 洪旭东
     * @date   : 2023-09-12 16:02
     */
    getWeekQuality () {
      let params = {
        ftyId: this.$store.state.user.ftyId,
        timeStart: this.weekQualityTimeStart,
        timeEnd: this.weekQualityTimeEnd
      }
      this.excute(this.$service.homeReportService, this.$service.homeReportService.getWeekQuality, params).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          let col = []
          let list = []
          let data = {}
          for (let it of res.data) {
            data.date = it.opDate
            for (let item of it.res) {
              data = Object.assign(data, item)
            }
            list.push(data)
            col = col.concat(Object.keys(data))
            data = {}
          }
          this.tableWeekQualityData = list
          this.tableWeekQualityColumns = col.unique().map(m => {return {
            field: m, title: m === 'date' ? '日期':m
          }})
        }
      })
    },
    /**
     * @desc   : 设置预警信息
     * @author : 王曦平
     * @date   : 2023/8/30 9:27
     */
    setHomeWarning() {
      this.settingModal = true
    },
    /**
     * @desc   : 加载预警设置信息
     * @author : 王曦平
     * @date   : 2023/8/30 13:35
     */
    getHomeWarningSet() {
      let param = {
        ftyId: this.$store.state.user.ftyId
      }
      this.settingModalLoading = true;
      this.excute(this.$service.homeWarningSetService, this.$service.homeWarningSetService.selectByCond, param).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          if (res.data && res.data.list) {
            // 产量数据源
            this.warningSettingFormData = res.data.list.filter(it => it.warningType === 0);
            // 质量数据
            this.warningSettingFormData_qa = res.data.list.filter(it => it.warningType === 1);
            // 质量需要设置名称
            this.warningSettingFormData_qa.forEach(it => {
              this.$set(it, 'qualityType_Name', it.qualityKindName)
            })
            this.currentRowIndex = 0;
          } else {
            this.warningSettingFormData = []
            this.warningSettingFormData_qa = []
          }
        }
        this.settingModalLoading = false;
      })
    },
    /**
     * @desc   : 获取质量
     * @author : 周兴
     * @date   : 2023/9/6 17:04
     */
    getQualityTypeData() {
      // 读取系统字典
      let dataKindList =this.$store.state.user.dataKindList
      let data = dataKindList.filter(it=>it.kindType == this.$config.kindType.qualityType)
      this.qualityTypeData = data;
    },
    /**
     * @desc   : 行切换
     * @author : 王曦平
     * @date   : 2023/9/1 16:41
     */
    warnCurrentChange({row}) {
      if (row != null) {
        this.currentWarningType = row.warningType;
        this.currentRowIndex = 0;
        // 结束编辑状态
        if (row.warningType === 0) {
          this.$refs['warnTable_quality'].$refs['xTable'].clearActived();
          this.$refs['warnTable_quality'].$refs['xTable'].clearCurrentRow();
        } else {
          this.$refs['warnTable_quantity'].$refs['xTable'].clearActived();
          this.$refs['warnTable_quantity'].$refs['xTable'].clearCurrentRow();
        }
      }
    },
    /**
     * @desc   : 校验数据
     * @author : 周兴
     * @date   : 2023/9/6 15:57
     */
    validData() {
      // 产量类型的预警，预警名称必须填写，工序必须选择
      return new Promise(resolve => {
        let table = this.$refs['warnTable_quantity'].getTableDataFilter();
        let filters = table.filter(it => !it.warningName);
        // 名称有为空
        if (filters && filters.length > 0) {
          this.$Message.warning(this.$t('W_042', {'param': this.$t('warningName')}))
          resolve(false)
          return;
        }
        // 工序为空
        filters = table.filter(it => !it.flowList || it.flowList.length === 0);
        if (filters && filters.length > 0) {
          this.$Message.warning(this.$t('W_069', {'param': this.$t('flowNodeName')}))
          resolve(false)
          return;
        }
        resolve(true)
      })
    },
    /**
     * @desc   : 给参数赋值
     * @author : 周兴
     * @date   : 2023/9/6 16:24
     */
    setParams() {
      let table_quantity = this.$refs['warnTable_quantity'].getTableDataFilter();//0
      let table_quality = this.$refs['warnTable_quality'].getTableDataFilter();//1
      if (table_quantity && table_quantity.length > 0) {
        table_quantity.forEach(it => {
          it.warningType = 0;
          it.ftyId = this.$store.state.user.ftyId;
        })
      }
      if (table_quality && table_quality.length > 0) {
        table_quality.forEach(it => {
          // 质量的工序为空
          it.flowList = []
          it.warningType = 1;
          it.ftyId = this.$store.state.user.ftyId;
        })
      }
      let columns = ['setId', 'warningType', 'warningName', 'qualityType', 'flowNodeId', 'remarks', 'displayNo', 'ftyId']
      let table = table_quantity.union(table_quality)?.filterColumns(columns);//新建编辑
      let del0 = this.$refs['warnTable_quantity'].getDeleteData()
      let del1 = this.$refs['warnTable_quality'].getDeleteData()
      let delTable = del0.union(del1)?.filterColumns(['setId'])
      let params = {}
      params.updateList = table;
      params.delList = delTable;
      return params;
    },
    /**
     * @desc   : 保存
     * @author : 王曦平
     * @date   : 2023/9/1 16:41
     */
    saveData() {
      this.validData().then(res => {
        if (!res) {
          return;
        }
        this.settingModalLoading = true;
        let params = this.setParams();
        this.excute(this.$service.homeWarningSetService, this.$service.homeWarningSetService.insertOrUpdate, params).then(res => {
          if (res.code === this.$config.SUCCESS_CODE) {
            this.$Message.success(this.$t('I_002'))
            // 重新调取查询方法
            this.getHomeWarningSet();
            // 查询预警数据
            this.getHomeWarning();
          } else {
            this.$Message.warning(res.message)
          }
          this.settingModalLoading = false;
        })
      })
    },
    /**
     * @desc   : 打开modal
     * @author : 周兴
     * @date   : 2023/9/6 14:40
     */
    onVisibleChange(e) {
      if (e) {
        // 获取预警设置信息
        this.getHomeWarningSet();
        // 获取质量类型
        this.getQualityTypeData();
      }
    }
    ,
    /**
     * @desc   : 工序行切换
     * @author : 王曦平
     * @date   : 2023/9/4 15:46
     */
    currentFlow(e) {
      this.currentRowIndex = e.rowIndex;
    }
    ,
    /**
     * @desc   : 工序改变值
     * @author : 王曦平
     * @date   : 2023/9/5 9:01
     */
    chooseFlowValue() {
      this.$nextTick(() => {
        let table = this.$refs.flowNode.getTableDataFilter();
        let filters = table.map(it => it.nodeId);
        this.$set(this.warningSettingFormData[this.currentRowIndex], 'flowList', table);
        this.$set(this.warningSettingFormData[this.currentRowIndex], 'flowNodeId', filters);
      })
    }
    ,
    /**
     * @desc   : 选择质量类型
     * @author : 周兴
     * @date   : 2023/9/7 15:50
     */
    chooseQualityType(row, rowIndex) {
      this.$set(this.warningSettingFormData_qa[rowIndex], 'warningName', row['qualityType_Name'])
    },
    /**
     * @desc   : 删除工序事件
     * @author : 王曦平
     * @date   : 2023/9/5 13:27
     */
    flowDelRow(row, rowIndex) {
      this.chooseFlowValue();     // 重新给产量工序赋值
    }
    ,
    /**
     * @desc   : 删除预警行
     * @author : 周兴
     * @date   : 2023/9/7 15:18
     */
    warnDelRow(row, rowIndex) {
      this.warningSettingFormData = this.warningSettingFormData.filter((it, index) => index != rowIndex);
      let table = this.$refs['warnTable_quantity'].getTableData();
      if (table && this.currentRowIndex >= table.length) {
        this.currentRowIndex = this.currentRowIndex - 1;
      }
    },
    // endregion
  },
  created() {
    // this.getHomeWarning();// 获取预警数据
    // //查询半检、成检缺陷TOP5
    // this.getTopFiveHalfCheckDefect()
    // this.getTopFiveCheckDefect()
    this.routeObjName = 'home'  // 设置路由名称
    this.primaryKey = 'setId'  // 设置主键Id
  },
}
</script>
<style lang="less" scoped>
@cell_height: 30px;
.func-item-title {
  font-size: 12px;
  margin-top: 5px;
}

/deep/ .ttt > .ivu-checkbox {
  position: absolute !important;
  z-index: 1;
  right: 24%;
  top: -8%;
}

.draggable-div[draggable=true] {
  //opacity: 0 !important;
}

.modal-left-div::-webkit-scrollbar {
  width: 5px;
}

.modal-left-div::-webkit-scrollbar-track {
  width: 5px !important;
  background: #dcdcdc;
  border-radius: 10px;
}

.modal-left-div::-webkit-scrollbar-thumb {
  width: 5px;
  background: #b6b6b6;
  border-radius: 10px;
}

//Card标签
.card {
  margin-top: 8px;
  overflow-x: auto;
}

//圆形按钮
.circle-button {
  font-size: 20px !important;
  margin-left: 5px;
  margin-right: 5px;
}

//待办
.upcoming {
  width: 100%;
  display: flex;
  overflow-x: auto;
  transition: scrollLeft 2s;
  padding: 10px;

  .upcoming-card {
    height: 100px;
    min-width: 140px;
    //background-color: #f4f8ff;
    background-color: #2D8CF0;
    color: #fff;
    padding: 15px 0 10px 0;
    margin-right: 20px;
    cursor: pointer;
    border-radius: 15px;
    display: flex;
    box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.5);
    //margin-bottom: 10px;

    .upcoming-card-icon {
      padding: 16px 0;
      width: 50px;
    }

    .upcoming-card-right {
      width: 100%;
    }

    .upcoming-card-number {
      font-size: 26px;
      font-weight: bolder;
      display: flex !important;
      justify-content: center;
    }

    .upcoming-card-text {
      font-size: 13px;
      font-weight: 500;
      display: flex !important;
      justify-content: center;
    }
  }
}

.card-upcoming /deep/ .ivu-card-body {
  padding-bottom: 0 !important;

}

//图表
.echarts {
  width: 300px;
  height: 200px
}

// 销售简报radio数字
.sales-report-radio-number {
  position: relative;
  right: 50px;
}

// 销售简报radio选中的文字
.sales-report-radio-checked {
  font-weight: bolder;
}

// 销售简报右侧col
.sales-report-col {
  padding-right: 10px;
  padding-top: 10px;
}

// 销售简报card 个数 数字
.sales-report-card-number {
  color: grey;
}

// 销售简报card 钱数 数字
.sales-report-card-money {
  color: orange;
}

// 销售简报 简略模式card
.sales-report-simple-card {
  margin: 10px;
}

// 销售简报 简略模式 文字
.sales-report-simple-card-text {
  font-weight: bolder;
}

.sales-report-simple-card-text2 {
  color: grey;
}

.sales-report-simple-card-text3 {
  color: orange;
}

// 销售助手 card 外 col
.sales-helper-col {
  padding: 5px;
}

// 销售助手 card
.sales-helper-card {
  background-color: #f7f7f9;
  padding: 5px;
}

// 销售助手 card 第一行
.sales-helper-card-icon-title {
  display: flex;
  align-items: center;
}

// 销售助手 card 标题
.sales-helper-card-title {
  line-height: 34px;
  margin-left: 10px;
}

// 销售助手 card 内容 蓝色
.sales-helper-card-content {
  margin-top: 10px;
  color: #71a6ec;
}

// 销售助手 card 内容 灰色
.sales-helper-card-content2 {
  margin-top: 10px;
  color: grey;
}

// 底部抽屉
/deep/ .ivu-drawer-bottom {
  right: 0;
  bottom: 0;
  top: unset;
}

/deep/ .ivu-tabs-tab {
  bottom: 10px;
  font-size: 18px !important;
}

.ivu-row {
  display: flex;
}

/deep/ .ivu-list {
  height: 245px !important;
  overflow-y: auto;
}

/deep/ .ivu-list-item-meta-title {
  margin-bottom: 2px !important;
  font-size: 15px !important;
  cursor: pointer;
  text-decoration: underline;
}

/deep/ .ivu-list-item {
  padding: 10px 0 0 0 !important;
}

/deep/ .ivu-list-item-meta-content {
  width: 100%;
}

/deep/ .ivu-list-item-meta {
  margin-bottom: 6px !important;
}

/deep/ .ivu-list-item-meta-description {
  //width: 253px;
  font-size: 12px;
  line-height: 22px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/deep/ .ivu-checkbox-checked .ivu-checkbox-inner {
  background-color: #1B365D !important;
  border-color: #1B365D !important;
}

.clear-btn {
  border: #b6b6b6 1px dashed;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 88%;
  height: 30px;
  background: #00aaed;
  border-radius: 5px;
  cursor: pointer;
  transition: .3s;
}

.clear-btn:hover {
  background: #4dcbff;
}

.upcoming-card-last {
  width: calc(100% + 10px);
  margin-top: -5px;
  margin-right: -10px;
  text-align: right;
  height: 11px;
  font-size: 11px;
  transform: scale(0.75);
}

/deep/ .ivu-card-body {
  padding: 5px;
}

/deep/ .ivu-tabs-tab {
  //width:100px!important;
  height: @cell_height !important;
  line-height: @cell_height !important;
  text-align: center !important;
  margin-top: 10px !important;
  font-size: 14px !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}

/deep/ .ivu-card-extra {
  top: 8px;
}

/deep/.ivu-card-body{
  padding: 0 !important;
}

</style>
