<template>
  <!-- 新增申报要素-->
  <div id="addDeclareDrawer">
    <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="addDeclareDrawer">
            <a-row :gutter="24">
              <a-col :md="6" :sm="8">
                <a-form-model-item label="商品税号" prop="proTaxNum">
                  <a-input placeholder="请输入商品税号" v-model="addDeclareDrawer.proTaxNum"></a-input>
                </a-form-model-item>
              </a-col>

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

              <a-col :md="6" :sm="8">
                <a-form-model-item label="订单号" prop="orderNum">
                  <a-input placeholder="请输入订单号" v-model="addDeclareDrawer.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="addDeclareColumns"
              :data-source="addDeclareData"
              :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: 'AddDeclareDrawer', // 新增申报要素
  mixins: [JeecgListMixin],
  components: { SelectBookModal, JEllipsis }, // 选择托书
  data() {
    // let ellipsis = (v, l = 20) => <j-ellipsis value={v} length={l} />

    return {
      // 表头
      addDeclareColumns: [
        {
          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'
        }
      ],

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

      this.addDeclareData.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>
