<template>
  <!-- 编辑 回显且可编辑-->
  <div id="editDeclareDrawer">
    <a-drawer
      title="编辑"
      width="89%"
      placement="right"
      :closable="true"
      :visible="visible"
      @close="handleCancel">
      <!-- 主表信息  回显可编辑信息 -->
      <a-card :bordered="false">
        <div class="table-page-search-wrapper">
          <a-form-model layout="inline" ref="form" :model="editDeclareDrawer">
            <a-row :gutter="24">
              <a-col :md="6" :sm="8">
                <a-form-model-item label="商品税号" prop="proTaxNum">
                  <a-input v-model="editDeclareDrawer.proTaxNum"></a-input>
                </a-form-model-item>
              </a-col>

              <a-col :md="6" :sm="8">
                <a-form-model-item label="商品名称" prop="proName">
                  <a-input v-model="editDeclareDrawer.proName"></a-input>
                </a-form-model-item>
              </a-col>

              <a-col :md="6" :sm="8">
                <a-form-model-item label="订单号" prop="orderNum">
                  <a-input v-model="editDeclareDrawer.orderNum"></a-input>
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-form-model>
        </div>
      </a-card>

      <!--操作按钮区域 选择托书 増行-->
      <a-card :bordered="false" style="margin:10px 0 60px 0;">
        <div class="table-operator">
          <a-button type="primary" @click="selectBook" icon="ordered-list">选择托书</a-button>
          <a-button type="primary" @click="handleAddColumn" icon="plus" style="margin-left: 20px">増行</a-button>
        </div>

        <!-- 子表-->
        <a-spin :spinning="confirmLoading">
          <a-form-model ref="formRef">
            <a-table
              bordered
              rowKey="id"
              :columns="editDeclareColumns"
              :data-source="editDeclareData"
              :loading="loading"
              :pagination="false"
              @change="handleTableChange"
            >
              <!-- 操作 -->
              <span slot="operationSlot" slot-scope="text, record">
                <a-popconfirm title="确定删除吗?" ok-text="是" cancel-text="否" @confirm="handleDelete(record.id)">
                  <a href="javascript:void(0);" style="color:red;">删除</a>
                </a-popconfirm>
              </span>
            </a-table>
          </a-form-model>
        </a-spin>
      </a-card>
      <!-- 页面底部提交取消 -->
      <div
        :style="{
          position: 'absolute',
          right: 0,
          bottom: 0,
          width: '100%',
          borderTop: '1px solid #e9e9e9',
          padding: '10px 16px',
          background: '#fff',
          textAlign: 'right',
          zIndex: 1
        }"
      >
        <a-popconfirm title="确定放弃编辑？" @confirm="handleCancel" okText="确定" cancelText="取消">
          <a-button :style="{ marginRight: '8px' }">取消</a-button>
        </a-popconfirm>
        <a-button type="primary" @click="submitAdd">
          提交
        </a-button>
      </div>
    </a-drawer>

    <!-- 选择托书 弹框 -->
    <selectBook-modal ref="selectBookModal" :father="aa" @ok="modalFormOk"></selectBook-modal>
  </div>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JEllipsis from '@/components/jeecg/JEllipsis'
import SelectBookModal from '@views/declare-elements/selectBookModal.vue'

export default {
  name: 'EditDeclareDrawer', // 编辑 申报要素
  mixins: [JeecgListMixin],
  components: { SelectBookModal, JEllipsis }, // 选择托书
  data() {
    // let ellipsis = (v, l = 20) => <j-ellipsis value={v} length={l} />

    return {
      // 表头
      editDeclareColumns: [
        {
          title: '序号',
          width: 90,
          dataIndex: 'index',
          customRender: (text, record, index) => `${index + 1}`,
          className: 'replacecolor'
        },
        {
          title: '申报要素内容',
          dataIndex: 'decEleContent',
          width: 90,
          className: 'replacecolor'
        },
        {
          title: '描述',
          dataIndex: 'desc',
          width: 160,
          className: 'replacecolor'
        },

        {
          title: '操作',
          dataIndex: 'operation',
          scopedSlots: { customRender: 'operationSlot' },
          width: 120,
          className: 'replacecolor'
        }
      ],

      editDeclareData: [
        { decEleContent: '品名', desc: '化纤制针织毛圈布' },
        { decEleContent: '织造方法', desc: '针织/钩编' },
        {}
      ],
      loading: false, // 表格加载
      visible: false,
      editDeclareDrawer: {},
      confirmLoading: false
    }
  },
  created() {},
  methods: {
    // 选择托书
    selectBook() {
      console.log('打开选择托书 弹框')
      this.$refs.selectBookModal.selectBookModVis = true
    },
    // 増行
    handleAddColumn() {
      console.log('増行')
      const addrow = {
        index: '',
        decEleContent: '',
        desc: '',
        operation: ''
      }

      this.editDeclareData.push(addrow)
    },
    // ----------------------------------------
    //  操作按钮 删除
    handleDelete(record) {},

    // 抽屉 取消
    handleCancel() {
      console.log('点击抽屉取消')
      this.close()
    },
    // 抽屉 提交
    submitAdd() {
      console.log('保存编辑、刷新申报列表')
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
        }
      })
      this.close()
      // this.getShipmentList() // 刷新 申报列表
    },
    // -------------------------------------
    close() {
      this.$emit('close')
      this.visible = false
      this.$refs.form.resetFields()
    },
    aa() {},
    modalFormOk() {}
  },
  computed: {},
  mounted() {}
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';
/deep/ .ant-table-thead > tr > th {
  text-align: center;
  // font-weight: 700;
}
/deep/ .ant-table-tbody {
  text-align: center;
}
// /deep/ th.replacecolor {
//   background-color: #ccc;
// }
// 抽屉里的card样式
/deep/ .ant-drawer-content {
  background-color: #f0f2f5;
}
/deep/ .ant-drawer-body {
  padding: 10px;
}
</style>
