<template>
  <div class="borderless" v-loading="pageLoading">
    <div class="customer-head">
      <div class="customer-back">
        <el-button type="danger" style="border: none;background: none;color: red" icon="el-icon-arrow-left"
          @click="backToList">返回列表
        </el-button>
      </div>
      <div class="add-customer-btn">
        <el-button type="primary" size="small" v-if="detailData.status == 1" class="el-button--small-yh "
          @click.stop="openEdit">编辑
        </el-button>
        <el-button type="primary" :disabled="disabled" @click="editCustomer" :loading="subLoading"
          v-if="detailData.status != 1" size="small">保存数据
        </el-button>
      </div>
    </div>
    <div class="customer-main">
      <trade-card title="基础信息">
        <avue-form ref="form" class="trading-form" v-model="form" :option="option">
        </avue-form>
      </trade-card>
      <trade-card title="货转明细">
        <avue-crud ref="crud" :data="data" :option="tableOption" @row-del="rowDel" @saveColumn="saveColumn"
          @resetColumn="resetColumn" :cell-style="cellStyle">
        </avue-crud>
      </trade-card>
      <collection :data="[]" />
      <payment :data="[]" />
    </div>
  </div>
</template>

<script>
import tableOption from "./config/customerContact.json";
import collection from "@/components/collection/main";
import payment from "@/components/payment/main";
export default {
  name: "detailsPageEdit",
  data() {
    return {
      show: true,
      oldExchange: null,
      treeStyle: "height:" + (window.innerHeight - 315) + "px",
      switchDialog: false,
      form: {},
      disabled: false,
      tableOption: {},
      option: {
        menuBtn: false,
        labelWidth: 100,
        column: [
          {
            label: "提单号",
            prop: "mblno",
            span: 6
          },
          {
            label: "客户名称",
            prop: "corpid",
            span: 6
          },
          {
            label: "新客户名称",
            prop: "tocorpid",
            span: 6
          },
          {
            label: "货转日期",
            prop: "bsdate",
            span: 6
          },
          {
            label: "仓储费日期",
            prop: "chargedate",
            span: 6
          },
          {
            label: "仓库",
            prop: "warehouseid",
            span: 6
          },
          {
            label: "结算方式",
            prop: "stltypeid",
            span: 6
          },

          {
            label: "计费单位",
            prop: "feetUnit",
            span: 6
          },
          {
            label: "贸易方式",
            prop: "trademodeid",
            span: 6
          },
          {
            label: "业务编号",
            prop: "billno",
            span: 6
          },
          {
            label: "原始入库单号",
            prop: "originalbillno",
            span: 6
          },
          {
            label: "原始入库日期",
            prop: "orgStorageDate",
            span: 6
          },
          {
            label: "品牌",
            prop: "marks",
            span: 6
          },
          {
            label: "品名",
            prop: "productName",
            span: 6
          },
          {
            label: "制单人",
            prop: "createBy",
            span: 6
          },
          {
            label: "打印抬头",
            prop: "company",
            span: 6
          }
        ]
      },
      data: [],
      loading: false,
      subLoading: false,
      pageLoading: false,
    };
  },
  props: {
    detailData: {
      type: Object
    }
  },
  components: {
    collection,
    payment
  },
  async created() {
    if (this.detailData.id) {
      this.getDetail(this.detailData.id);
    }
    this.tableOption = await this.getColumnData(
      this.getColumnName(168),
      tableOption
    );

  },
  methods: {
    cellStyle() {
      return "padding:0;height:40px;";
    },
    addRow() {
      this.data.push({ $cellEdit: true });
    },
    rowCell(row, index) {
      if (row.$cellEdit == true) {
        this.$set(row, "$cellEdit", false);
      } else {
        this.$set(row, "$cellEdit", true);
      }
    },
    rowSave(row) {
      this.$set(row, "$cellEdit", false);
    },
    rowDel(row) {
      this.$confirm("确定删除数据?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.$message({
          type: "success",
          message: "删除成功!"
        });
        this.data.splice(row.$index, 1);
      });
    },
    getDetail(id) {
      this.loading = true;
      this.pageLoading = true;
    },
    //修改提交触发
    editCustomer(status) {
      this.$refs["form"].validate((valid, done) => {
        done();
        if (valid) {
          this.subLoading = true;
        } else {
          return false;
        }
      });
    },
    //返回列表
    backToList() {
      this.$emit("goBack");
    },
    openEdit() {
      this.detailData.status = 2;
      this.option = this.$options.data().option;
      this.$refs.crud.refreshTable();
    },
    async saveColumn() {
      const inSave = await this.saveColumnData(
        this.getColumnName(168),
        this.tableOption
      );
      if (inSave) {
        this.$nextTick(() => {
          this.$refs.crud.doLayout();
        });
        this.$message.success("保存成功");
        //关闭窗口
        this.$refs.crud.$refs.dialogColumn.columnBox = false;
      }
    },
    async resetColumn() {
      this.tableOption = tableOption;
      const inSave = await this.delColumnData(
        this.getColumnName(168),
        tableOption
      );
      if (inSave) {
        this.$nextTick(() => {
          this.$refs.crud.doLayout();
        });
        this.$message.success("重置成功");
        //关闭窗口
        setTimeout(() => {
          this.$refs.crud.$refs.dialogColumn.columnBox = false;
        }, 1000);
      }
    }
  },
  watch: {
  }
};
</script>

<style lang="scss" scoped>
.trading-form ::v-deep .el-form-item {
  margin-bottom: 8px !important;
}

::v-deep .el-form-item__error {
  display: none !important;
}

::v-deep .select-component {
  display: flex !important;
}
</style>
