<template>
  <basic-page-edit :desc="desc" :dataId="getDataId()" :options="pageOptions"></basic-page-edit>
</template>

<script>
import BASE_URL from '@/services/mes/api.js';


export default {

  i18n: require('./i18n'),
  components: {},
  props: {
    pageMode: {
      type: String,
      default: "edit"
    },
    dataId: {
    }
  },

  data() {
 
    return {
      pageOptions: {}
    };
  },

  computed: {
    desc() {
      return this.$t('editPageDesc')
    }
  },


  created() {

    this.optionsInit();
    this.dataInit(); 

  },
  // 函数
  methods: {



    optionsInit() {
      // 页面数据变量
      var pageData = {
        // 当前项目名称
        currentConfigName: "",
        // 当前项目ID
        currentBeid: 0,

        addPageUrl: "/MesCeramicsMaterialClassification/MesCeramicsMaterialClassificationAdd",
        editPageUrl: "/MesCeramicsMaterialClassification/MesCeramicsMaterialClassificationUpdate/",
        listPageUrl: "/MesCeramicsMaterialClassification/MesCeramicsMaterialClassificationList",


        uploadDefaultImg: null,

      detailDataFieldName: "mes_ceramics_material_classification",

      actions: {
        // =============================== 接口地址 自动生成 Start ===============================
					MesCeramicsMaterialClassificationList: `${BASE_URL.BASE_URL}/MesCeramicsMaterialClassification/v1/mes/ceramics/material/classification/list`, // 陶瓷类物料分类列表
					MesCeramicsMaterialClassificationDetail: `${BASE_URL.BASE_URL}/MesCeramicsMaterialClassification/v1/mes/ceramics/material/classification/detail`, // 陶瓷类物料分类详情
					MesCeramicsMaterialClassificationCreate: `${BASE_URL.BASE_URL}/MesCeramicsMaterialClassification/v1/mes/ceramics/material/classification/create`, // 创建陶瓷类物料分类
					MesCeramicsMaterialClassificationUpdate: `${BASE_URL.BASE_URL}/MesCeramicsMaterialClassification/v1/mes/ceramics/material/classification/update`, // 更新陶瓷类物料分类
					MesCeramicsMaterialClassificationDelete: `${BASE_URL.BASE_URL}/MesCeramicsMaterialClassification/v1/mes/ceramics/material/classification/detele`, // 删除陶瓷类物料分类
					MesCeramicsMaterialClassificationBatchDelete: `${BASE_URL.BASE_URL}/MesCeramicsMaterialClassification/v1/mes/ceramics/material/classification/batchDelete`, // 批量删除陶瓷类物料分类
					MesCeramicsMaterialClassificationBatchUpdate: `${BASE_URL.BASE_URL}/MesCeramicsMaterialClassification/v1/mes/ceramics/material/classification/batchUpdate`, // 批量更新陶瓷类物料分类
					MesCeramicsMaterialClassificationBatchCreate: `${BASE_URL.BASE_URL}/MesCeramicsMaterialClassification/v1/mes/ceramics/material/classification/batchCreate`, // 批量创建陶瓷类物料分类
					MesCeramicsMaterialClassificationExportExcel: `${BASE_URL.BASE_URL}/MesCeramicsMaterialClassification/v1/mes/ceramics/material/classification/export/excel`, // 导出陶瓷类物料分类数据到EXCEL
					MesCeramicsMaterialClassificationImportExcel: `${BASE_URL.BASE_URL}/MesCeramicsMaterialClassification/v1/mes/ceramics/material/classification/import/excel`, // 批量导入EXCEL陶瓷类物料分类数据
					CeramicMaterialClassificationProcessSegmentList: `${BASE_URL.BASE_URL}/MesCeramicsMaterialClassification/v1/ceramic/material/classification/process/segment/list`, // 关联工序段物料分类列表
					CeramicMaterialClassificationProcessSegmentDetail: `${BASE_URL.BASE_URL}/MesCeramicsMaterialClassification/v1/ceramic/material/classification/process/segment/detail`, // 关联工序段物料分类详情
					CeramicMaterialClassificationProcessSegmentCreate: `${BASE_URL.BASE_URL}/MesCeramicsMaterialClassification/v1/ceramic/material/classification/process/segment/create`, // 创建关联工序段物料分类
					CeramicMaterialClassificationProcessSegmentUpdate: `${BASE_URL.BASE_URL}/MesCeramicsMaterialClassification/v1/ceramic/material/classification/process/segment/update`, // 更新关联工序段物料分类
					CeramicMaterialClassificationProcessSegmentDelete: `${BASE_URL.BASE_URL}/MesCeramicsMaterialClassification/v1/ceramic/material/classification/process/segment/detele`, // 删除关联工序段物料分类
					CeramicMaterialClassificationProcessSegmentBatchDelete: `${BASE_URL.BASE_URL}/MesCeramicsMaterialClassification/v1/ceramic/material/classification/process/segment/batchDelete`, // 批量删除关联工序段物料分类
					CeramicMaterialClassificationProcessSegmentBatchUpdate: `${BASE_URL.BASE_URL}/MesCeramicsMaterialClassification/v1/ceramic/material/classification/process/segment/batchUpdate`, // 批量更新关联工序段物料分类
					CeramicMaterialClassificationProcessSegmentBatchCreate: `${BASE_URL.BASE_URL}/MesCeramicsMaterialClassification/v1/ceramic/material/classification/process/segment/batchCreate`, // 批量创建关联工序段物料分类
					CeramicMaterialClassificationProcessSegmentExportExcel: `${BASE_URL.BASE_URL}/MesCeramicsMaterialClassification/v1/ceramic/material/classification/process/segment/export/excel`, // 导出关联工序段物料分类数据到EXCEL
					CeramicMaterialClassificationProcessSegmentImportExcel: `${BASE_URL.BASE_URL}/MesCeramicsMaterialClassification/v1/ceramic/material/classification/process/segment/import/excel`, // 批量导入EXCEL关联工序段物料分类数据

        // =============================== 接口地址 自动生成 End ===============================
      },

        keyName: 'id',
        // 是否编辑模式
        isEdit: false,
        // 表单数据
        formOptions: {
          data: {
            // =============================== 表单数据 自动生成 Start ===============================

					id: 0,
					code: "",
					name: "",
					english_name: "",
					create_uid: 0,
					update_uid: 0,
					create_time: new Date(2100, 1, 1).getTime() / 10000,
					update_time: new Date(2100, 1, 1).getTime() / 10000,

            // =============================== 表单数据 自动生成 End ===============================
          },
          // 标题宽度
          titleWidth: 200,
          // 标题对齐方式
          titleAlign: 'right',

          // 表单校验规则
          rules: {
            // =============================== 表单校验 自动生成 Start ===============================

         
            name: [
              { required: true, message: '请输入分类名称' }
            ],

            // =============================== 表单校验 自动生成 End ===============================
          },
          // 表单项
          items: [
            // =============================== 表单项 自动生成 Start ===============================

					{ field: 'name', title: '分类名称', span: 24, itemRender: { name: '$input' } },
					{ field: 'code', title: '编码', span: 24, itemRender: { name: '$input' } },
					{ field: 'english_name', title: '分类英文名称', span: 24, itemRender: { name: '$input' } },

          // =============================== 表单项 自动生成 End ===============================
        ]
        },
        // 新增模式表单项
        addModeItems: [

        ],


      };

    pageData.actions.get = pageData.actions.MesCeramicsMaterialClassificationDetail;
    pageData.actions.create = pageData.actions.MesCeramicsMaterialClassificationCreate;
    pageData.actions.update = pageData.actions.MesCeramicsMaterialClassificationUpdate;

    // 合并表单数据及配置
      pageData.formOptions = Object.assign({}, this.$mk.config.defaults.formOptions, pageData.formOptions);

      this.pageOptions = pageData;
    },

    dataInit() {
      // 获取路由的id参数
      let dataId = this.getDataId();
      // 如果有id参数，说明是编辑模式
      if (dataId) {
        const json = `{"id":${dataId}}`;
        this.$mk.post({
          url: this.pageOptions.actions.get,
          loading: "加载中...",
          data: json,
          config: {
            headers: {
              'Content-Type': 'application/json'
            }
          }
        }).then(a => {

          let detailDataFieldName = this.pageOptions.detailDataFieldName;

          if (a.data[detailDataFieldName].create_time) {
            a.data[detailDataFieldName].create_time = new Date(a.data[detailDataFieldName].create_time * 1000);
          }
          if (a.data[detailDataFieldName].update_time) {
            a.data[detailDataFieldName].update_time = new Date(a.data[detailDataFieldName].update_time * 1000);
          }

          this.pageOptions.formOptions.data = a.data[detailDataFieldName];
          
          this.$forceUpdate()
        }).catch((a) => {
          this.$mk.error(a.data.msg);
        });
 
        this.pageOptions.isEdit = true;

        this.$forceUpdate()
      } else {
        // 如果没有id参数，说明是新增模式
        this.addModeItems.forEach(item => {
          this.pageOptions.formOptions.items.push(item);
        })

      }
    },

    // 获取路由的id参数
    getDataId() {
      let dataId = this.dataId;
      if (this.$route.params.id) {
        dataId = this.$route.params.id;
      }
      if (!dataId) {
        dataId = 0;
      }
      return dataId;
    } 
  },
  // 监听属性
  watch: {

  }
};

</script>
 