<template> 
    <div class="page-body">

      <vxe-form :data="formOptions.data" ref="xForm" :title-width="formOptions.titleWidth"
                :title-align="formOptions.titleAlign" :rules="formOptions.rules" :items="formOptions.items" titleColon>
      <!--  =========================== 自定义区域 Start  ======================= -->

      <!--  =========================== 自定义区域 End  ======================= -->
      </vxe-form>

      <div class="mk-toolbar" v-if="isEdit">

      </div>

      <div class="footerbar">
        <a-button type="primary" @click="ok">确定</a-button>
        <a-button @click="cancel">取消</a-button>
      </div>

    </div>  
</template>

<script>
import BASE_URL from '@/services/Middle/bathroom/BathroomScheme/api.js'; 


export default {

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

  },

  data() {

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

      uploadDefaultImg: null,
      detailDataFieldName: "bathroom_scheme",

      actions: {
        // =============================== 接口地址 自动生成 Start ===============================
					BathroomSchemeList: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/list`, // 设计方案列表
					BathroomSchemeDetail: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/detail`, // 设计方案详情
					BathroomSchemeCreate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/create`, // 创建设计方案
					BathroomSchemeUpdate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/update`, // 更新设计方案
					BathroomSchemeDelete: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/detele`, // 删除设计方案
					BathroomSchemeBatchDelete: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/batchDelete`, // 批量删除设计方案
					BathroomSchemeBatchUpdate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/batchUpdate`, // 批量更新设计方案
					BathroomSchemeBatchCreate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/batchCreate`, // 批量创建设计方案
					BathroomSchemeExportExcel: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/export/excel`, // 导出设计方案数据到EXCEL
					BathroomSchemeImportExcel: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/import/excel`, // 批量导入EXCEL设计方案数据
					BathroomSchemeFittingsList: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/fittings/list`, // 报价单部件列表
					BathroomSchemeFittingsDetail: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/fittings/detail`, // 报价单部件详情
					BathroomSchemeFittingsCreate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/fittings/create`, // 创建报价单部件
					BathroomSchemeFittingsUpdate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/fittings/update`, // 更新报价单部件
					BathroomSchemeFittingsDelete: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/fittings/detele`, // 删除报价单部件
					BathroomSchemeFittingsBatchDelete: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/fittings/batchDelete`, // 批量删除报价单部件
					BathroomSchemeFittingsBatchUpdate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/fittings/batchUpdate`, // 批量更新报价单部件
					BathroomSchemeFittingsBatchCreate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/fittings/batchCreate`, // 批量创建报价单部件
					BathroomSchemeFittingsExportExcel: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/fittings/export/excel`, // 导出报价单部件数据到EXCEL
					BathroomSchemeFittingsImportExcel: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/fittings/import/excel`, // 批量导入EXCEL报价单部件数据
					BathroomSchemePartsList: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/parts/list`, // 报价单配件列表
					BathroomSchemePartsDetail: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/parts/detail`, // 报价单配件详情
					BathroomSchemePartsCreate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/parts/create`, // 创建报价单配件
					BathroomSchemePartsUpdate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/parts/update`, // 更新报价单配件
					BathroomSchemePartsDelete: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/parts/detele`, // 删除报价单配件
					BathroomSchemePartsBatchDelete: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/parts/batchDelete`, // 批量删除报价单配件
					BathroomSchemePartsBatchUpdate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/parts/batchUpdate`, // 批量更新报价单配件
					BathroomSchemePartsBatchCreate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/parts/batchCreate`, // 批量创建报价单配件
					BathroomSchemePartsExportExcel: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/parts/export/excel`, // 导出报价单配件数据到EXCEL
					BathroomSchemePartsImportExcel: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/parts/import/excel`, // 批量导入EXCEL报价单配件数据
					BathroomSchemeMaterialList: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/material/list`, // 报价单材料列表
					BathroomSchemeMaterialDetail: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/material/detail`, // 报价单材料详情
					BathroomSchemeMaterialCreate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/material/create`, // 创建报价单材料
					BathroomSchemeMaterialUpdate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/material/update`, // 更新报价单材料
					BathroomSchemeMaterialDelete: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/material/detele`, // 删除报价单材料
					BathroomSchemeMaterialBatchDelete: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/material/batchDelete`, // 批量删除报价单材料
					BathroomSchemeMaterialBatchUpdate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/material/batchUpdate`, // 批量更新报价单材料
					BathroomSchemeMaterialBatchCreate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/material/batchCreate`, // 批量创建报价单材料
					BathroomSchemeMaterialExportExcel: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/material/export/excel`, // 导出报价单材料数据到EXCEL
					BathroomSchemeMaterialImportExcel: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/material/import/excel`, // 批量导入EXCEL报价单材料数据
					BathroomSchemeLaborList: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/labor/list`, // 报价单人工费用列表
					BathroomSchemeLaborDetail: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/labor/detail`, // 报价单人工费用详情
					BathroomSchemeLaborCreate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/labor/create`, // 创建报价单人工费用
					BathroomSchemeLaborUpdate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/labor/update`, // 更新报价单人工费用
					BathroomSchemeLaborDelete: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/labor/detele`, // 删除报价单人工费用
					BathroomSchemeLaborBatchDelete: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/labor/batchDelete`, // 批量删除报价单人工费用
					BathroomSchemeLaborBatchUpdate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/labor/batchUpdate`, // 批量更新报价单人工费用
					BathroomSchemeLaborBatchCreate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/labor/batchCreate`, // 批量创建报价单人工费用
					BathroomSchemeLaborExportExcel: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/labor/export/excel`, // 导出报价单人工费用数据到EXCEL
					BathroomSchemeLaborImportExcel: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/labor/import/excel`, // 批量导入EXCEL报价单人工费用数据
					BathroomSchemeProcessList: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/process/list`, // 报价单工序列表
					BathroomSchemeProcessDetail: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/process/detail`, // 报价单工序详情
					BathroomSchemeProcessCreate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/process/create`, // 创建报价单工序
					BathroomSchemeProcessUpdate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/process/update`, // 更新报价单工序
					BathroomSchemeProcessDelete: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/process/detele`, // 删除报价单工序
					BathroomSchemeProcessBatchDelete: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/process/batchDelete`, // 批量删除报价单工序
					BathroomSchemeProcessBatchUpdate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/process/batchUpdate`, // 批量更新报价单工序
					BathroomSchemeProcessBatchCreate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/process/batchCreate`, // 批量创建报价单工序
					BathroomSchemeProcessExportExcel: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/process/export/excel`, // 导出报价单工序数据到EXCEL
					BathroomSchemeProcessImportExcel: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/process/import/excel`, // 批量导入EXCEL报价单工序数据
					BathroomSchemePackagingList: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/packaging/list`, // 包装材料列表
					BathroomSchemePackagingDetail: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/packaging/detail`, // 包装材料详情
					BathroomSchemePackagingCreate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/packaging/create`, // 创建包装材料
					BathroomSchemePackagingUpdate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/packaging/update`, // 更新包装材料
					BathroomSchemePackagingDelete: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/packaging/detele`, // 删除包装材料
					BathroomSchemePackagingBatchDelete: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/packaging/batchDelete`, // 批量删除包装材料
					BathroomSchemePackagingBatchUpdate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/packaging/batchUpdate`, // 批量更新包装材料
					BathroomSchemePackagingBatchCreate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/packaging/batchCreate`, // 批量创建包装材料
					BathroomSchemePackagingExportExcel: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/packaging/export/excel`, // 导出包装材料数据到EXCEL
					BathroomSchemePackagingImportExcel: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/packaging/import/excel`, // 批量导入EXCEL包装材料数据
					BathroomSchemeOutsourcingList: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/outsourcing/list`, // 外购产品列表
					BathroomSchemeOutsourcingDetail: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/outsourcing/detail`, // 外购产品详情
					BathroomSchemeOutsourcingCreate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/outsourcing/create`, // 创建外购产品
					BathroomSchemeOutsourcingUpdate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/outsourcing/update`, // 更新外购产品
					BathroomSchemeOutsourcingDelete: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/outsourcing/detele`, // 删除外购产品
					BathroomSchemeOutsourcingBatchDelete: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/outsourcing/batchDelete`, // 批量删除外购产品
					BathroomSchemeOutsourcingBatchUpdate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/outsourcing/batchUpdate`, // 批量更新外购产品
					BathroomSchemeOutsourcingBatchCreate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/outsourcing/batchCreate`, // 批量创建外购产品
					BathroomSchemeOutsourcingExportExcel: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/outsourcing/export/excel`, // 导出外购产品数据到EXCEL
					BathroomSchemeOutsourcingImportExcel: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/outsourcing/import/excel`, // 批量导入EXCEL外购产品数据
					BathroomSchemePaintList: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/paint/list`, // 油漆列表
					BathroomSchemePaintDetail: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/paint/detail`, // 油漆详情
					BathroomSchemePaintCreate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/paint/create`, // 创建油漆
					BathroomSchemePaintUpdate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/paint/update`, // 更新油漆
					BathroomSchemePaintDelete: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/paint/detele`, // 删除油漆
					BathroomSchemePaintBatchDelete: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/paint/batchDelete`, // 批量删除油漆
					BathroomSchemePaintBatchUpdate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/paint/batchUpdate`, // 批量更新油漆
					BathroomSchemePaintBatchCreate: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/paint/batchCreate`, // 批量创建油漆
					BathroomSchemePaintExportExcel: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/paint/export/excel`, // 导出油漆数据到EXCEL
					BathroomSchemePaintImportExcel: `${BASE_URL.BASE_URL}/BathroomScheme/v1/bathroom/scheme/paint/import/excel`, // 批量导入EXCEL油漆数据

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

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

					id: 0,
					scheme_id: 0,
					formula: "",
					remark: "",
					create_uid: 0,
					update_uid: 0,
					create_time: new Date(2100, 1, 1).getTime() / 10000,
					update_time: new Date(2100, 1, 1).getTime() / 10000,
					bathroom_labor: "",

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

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

					scheme_id: [
						{ required: true, message: '请输入方案ID' }
					],
					formula: [
						{ required: true, message: '请输入计算公式' }
					],
					remark: [
						{ required: true, message: '请输入备注' }
					],
					bathroom_labor: [
						{ required: true, message: '请输入人工费用方案' }
					],

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

					{ field: 'scheme_id', title: '方案ID', span: 12, itemRender: { name: '$input' } },
					{ field: 'formula', title: '计算公式', span: 12, itemRender: { name: '$input' } },
					{ field: 'remark', title: '备注', span: 12, itemRender: { name: '$input' } },
					{ field: 'bathroom_labor', title: '人工费用方案', span: 12, itemRender: { name: '$input' } },

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

      ],


    };

    pageData.actions.get = pageData.actions.BathroomSchemeDetail;
    pageData.actions.create = pageData.actions.BathroomSchemeCreate;
    pageData.actions.update = pageData.actions.BathroomSchemeUpdate;

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

    return pageData;
  },

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


  created() {


    // 获取路由的id参数
    let dataId = this.getDataId();

    // 如果有id参数，说明是编辑模式
    if (dataId) {
      const json = `{"id":${dataId}}`;
      this.$mk.post({
        url: this.actions.get,
        loading: "加载中...",
        data: json,
        config: {
          headers: {
            'Content-Type': 'application/json'
          }
        }
      }).then(a => {
        // =============================== 时间字段判断 自动生成 Start ===============================

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

        // =============================== 时间字段判断 自动生成 End ===============================
        this.formOptions.data = a.data[this.detailDataFieldName];
      }).catch((a) => {
        this.$mk.error(a.data.msg);
      });

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

    }

  },
  // 函数
  methods: {


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



    // 返回
    back() {
      // 如果是新增模式，关闭当前页面
      if (!this.isEdit) {
        this.$closePage({
          closeRoute: "/BathroomScheme/BathroomSchemeLaborAdd"
        });
      } else {
        // 如果是编辑模式，关闭当前页面
        this.$closePage({
          closeRoute: "/BathroomScheme/BathroomSchemeLaborUpdate"
        });
      }
      // 打开列表页面
      this.$openPage('/BathroomScheme/BathroomSchemeLaborList')
    },

    // 保存
    ok() {

      let save = () => {


        // 如果是新增模式，提交新增接口 如果是编辑模式，提交编辑接口
        let action = !this.isEdit ? this.actions.create : this.actions.update;
        // 如果是新增模式，提交的数据中加入id 如果是编辑模式，提交的数据中不加入id
        let postdata = Object.assign({}, this.formOptions.data);
        // 如果是编辑模式
        if (this.isEdit) {
          // postdata = { BathroomSchemeLabor: postdata }
        }
        // 格式化提交的数据
        this.$mk.formatFormData({ data: postdata, rules: this.formOptions.items });


        // 提交数据
        this.$mk.post({
          url: action,
          loading: "保存中...",
          data: postdata,
          useBigInt: true,
        }).then(() => { // 成功回调
          this.$mk.success("保存成功");
          if (!this.isEdit) { // 如果是新增模式，关闭当前页面
            this.back();
          }
        }).catch((a) => { // 失败回调
          this.$mk.error(a.data.msg); // 显示错误信息
        });


      };


      // 验证表单
      this.$mk.validateForm({ form: this.$refs.xForm }).then(() => { // 验证表单
        save(); // 提交保存
      }).catch(count => { // 验证失败
        this.$mk.error(`存在${count}项错误，请检查`);
      });


    },


    // 取消 返回
    cancel() {
      this.back();
    }
  },
  // 监听属性
  watch: {

  }
};

</script>


<style scoped lang="less">
.page-body {
  padding: 30px;
  background: @base-bg-color;
}

.formtabs .ant-tabs-tabpane {
  /* background: white; */
  padding: 12px;
}

.gridPanel {
  height: calc(100vh - 600px);
}

.footerbar {
  padding-left: 10px;
}

.imagePanel {
  cursor: pointer;
  padding: 10px;
  width: 100px;
  img {
    width: 80px;
    height: 80px;
  }
}
</style>
