<template>
  <div class="customer-css">
    <el-dialog :title="titleCon" v-drag v-bind="$attrs" v-on="$listeners"
               width="300px" style="height: 680px;" class="customer-dialog">
      <el-form :inline="true" label-position="top" style="height: 60px;"
               label-width="80px">
        <!-- 时间 -->
        <el-row style="margin-top: -10px;">
          <el-col :span="10" >
            <el-form-item :label=labels.currentTime>
              <el-date-picker style="width: 100px;"
                              v-model="pageData.reportDate"
                              format="yyyy-MM-dd"
                              value-format="yyyy-MM-dd"
                              placeholder="">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="10" style="margin-top: 26px;">
            <el-form-item :label="''">
              <el-form-item :label="''">
                <el-time-picker style="width: 100px;"
                                v-model="pageData.reportTime"
                                format="HH:mm:ss"
                                value-format="HH:mm:ss"
                                placeholder="">
                </el-time-picker>
              </el-form-item>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="startProduceFun">{{ buttons.saveButton }}</el-button>
        <el-button type="primary" @click="closeDialog">{{ buttons.closeButton }}</el-button>
        <el-button v-if="showDefault" @click="saveMultiLanguage()" type="primary">多语言设置</el-button>
      </span>
    </el-dialog>

    <!--  卷调机-卷材料耗用  -->
    <comEndTuning ref="comEndTuning" :close-on-click-modal="false"
                           :visible.sync="endTuningFlag" @closeDialog="closeDialog">
    </comEndTuning>
  </div>
</template>

<script>
import {
  checkStartProduce,
  startProduce,
  getSystemTimeData,
}from '@/api/yieldReport//com_start_produce.js';
/*引入组件*/
import comEndTuning from './com_end_tuning';

import {
  searchSysLanguagePackList,
  searchSysLanguageParam,
  searchFunctionButtonList,
  saveButtonList,
  searchSysLanguage,
  searchLanguageListByLanguageCode,
  saveSysLanguageOne,
  searchPageLanguageData,
  removerLanguage,
  saveSysLanguageList
} from "@/api/sysLanguage.js";

var functionId = 'C10000009';
/*开始生产时候报告调机的材料的使用数量*/
export default {
  data() {
    return {
      titleCon: '开始生产',
      showDefault: false,
      endTuningFlag: false,
      sfdcTimeList: [],
      pageData: {
        site: this.$store.state.user.site,
        username: this.$store.state.user.name,
        seqNo: '',
        orderNo: '',
        itemNo: 0,
        rollNo: '',
        operatorId: '',
        reportDate: '',
        reportTime: '',
      },
      operatorData: {
        site: this.$store.state.user.site,
        username: this.$store.state.user.name,
        operatorId: '',
        operatorName: '',
        status: '',
        seqNo: '',
        showFlag: false
      },
      dataListLoading: false,
      buttons: {
        saveButton: '保存',
        closeButton: '关闭',
      },
      buttonList: [
        {
          functionId: functionId,
          languageValue: '保存',
          objectId: 'saveButton',
          objectType: 'button',
          tableId: '*'
        }, {
          functionId: functionId,
          languageValue: '关闭',
          objectId: 'closeButton',
          objectType: 'button',
          tableId: '*'
        },
      ],
      queryButton: {
        functionId: functionId,
        table_id: '*',
        languageCode: this.$i18n.locale,
        objectType: 'button'
      },
      labels: {
        titleCon: '开始生产 ',
        seqNoName: '派工单号:',
        currentTime: '当前时间:',
      },
      labelsList: [
        {
          functionId: functionId,
          languageValue: '开始生产 ',
          objectId: 'titleCon',
          objectType: 'label',
          tableId: '*'
        }, {
          functionId: functionId,
          languageValue: '派工单号:',
          objectId: 'seqNoName',
          objectType: 'label',
          tableId: '*'
        }, {
          functionId: functionId,
          languageValue: '当前时间:',
          objectId: 'currentTime',
          objectType: 'label',
          tableId: '*'
        },
      ],
      queryLabel: {
        functionId: functionId,
        table_id: '*',
        languageCode: this.$i18n.locale,
        objectType: 'label'
      },
    }
  },
  components: {
    comEndTuning,/*开始生产时 调用结束调机的功能*/
  },
  methods: {

    /*页面的初始化方法*/
    init(scheduleData, operatorData) {
      //设置参数
      this.pageData.orderNo = scheduleData.orderNo;
      this.pageData.itemNo = scheduleData.itemNo;
      this.pageData.seqNo = scheduleData.seqNo;
      this.pageData.rollNo = scheduleData.rollNo;
      this.pageData.operatorId = operatorData.operatorId;
      //重置时间
      //this.pageData.reportDate = this.dayjs(new Date()).format('YYYY-MM-DD');
     // this.pageData.reportTime = this.dayjs(new Date()).format('HH:mm:ss');
       //判断是否启用多语言
      this.getMultiLanguageList();  //刷新多语言的信息
      //刷新当前的服务器时间
      this.refreshSystemTime();
      //初始化操作员对象
      this.operatorData = JSON.parse(JSON.stringify(operatorData));
      //初始化标题
      //初始化标题
      this.titleCon = this.labels.titleCon+this.labels.seqNoName+scheduleData.seqNo;
      // this.currentRollOps.seqNo = seqNo;
      // this.currentRollOps.rollNo = rollNo;
      //刷新当前派工单的信息
      //this.refreshPageData();
    },

    /*刷新服务器的时间*/
    refreshSystemTime(){
      getSystemTimeData().then(({data}) => {
        //判断是否操作成功
        if(data.code == 200){
          //重置系统的时间
          this.pageData.reportDate = data.resultMap.sysDate;
          this.pageData.reportTime = data.resultMap.sysTime;
        }
      });
    },

    /*关闭modal*/
    closeDialog(){
      //刷新报工的页面
      this.$emit('refreshPageData');
      //关闭当前的页面
      this.$emit('update:visible', false);
    },

    /*开始生产的方法*/
    startProduceFun(){
      //首先要检查是否可以开始生产
      checkStartProduce(this.pageData).then(({data}) => {
        //判断返回的结果 ---》异常
        if(data.code == 500){
          this.$message.error(data.msg);
          //需要跳转到结束调机的功能
        }else if (data.resultMap.resultCode == 201){
          //需要跳到结束停机的页面
          this.comEndTuningModal();
        }else{
          //需要报告开始生产
          this.startProduceOperation();
        }

      });
    },

    /*打开结束调机的modal*/
    comEndTuningModal(){
      //打开当前的页面
      this.$nextTick(() => {
        //打开modal
        this.endTuningFlag = true;
        this.$refs.comEndTuning.init(this.pageData, this.operatorData);
      });
    },

    /*打开结束调机的modal*/
    startProduceOperation(){
      startProduce(this.pageData).then(({data}) => {
        //判断操作是否成功
        if(data.code == 500){
          this.$message.error(data.msg);
        }else{
         //直接关闭当前的modal
          this.closeDialog();
        }
      });
    },


    // 保存 默认配置 列
    async saveMultiLanguage() {
      // 保存页面 button label title 属性
      let buttons = this.buttonList;
      let labels = this.labelsList;
      await saveButtonList(buttons)
      await saveButtonList(labels)
    },

    getMultiLanguageList() {
      //首先查询当前按钮的多语言
      searchFunctionButtonList(this.queryButton).then(({data}) => {
        if (data && data.code == 0 ) {
          this.buttons = data.data
        } else {
          // saveButtonList(this.buttonList).then(({data}) => {
          // })
        }
      });
      //其次查询当前标签的多语言
      searchFunctionButtonList(this.queryLabel).then(({data}) => {
        if (data && data.code == 0 ) {
          this.labels = data.data
        } else {
          // saveButtonList(this.buttonList).then(({data}) => {
          // })
        }
      });
    },

  },
  created() {
    // this.factoryList()
    // this.getLanguageList()
  }
}

</script>

<style scoped lang="scss">
/*调节页面button和input的上下间距*/
.customer-css .customer-button{
  margin-top: 25px;
}

/*调节fieldset下的样式*/
.customer-fieldset .customer-item{
  margin-top: -15px;
}

/*fieldset下table的样式*/
.customer-fieldset /deep/ .el-table__header th.is-leaf{
  line-height: 16px;
}

/deep/ .customer-tab .el-tabs__content{
  padding: 0px !important;
}

</style>
