<template>
  <a-modal
    centered
    class="productInfoOffline-modal"
    :footer="null"
    :maskClosable="false"
    title="提示"
    v-model="isShow"
    @cancle="isShow=false"
    :width="800">
    <p v-if="loadData.length==1" style="font-weight: bold;margin-left: 20px;">确认要下线吗？</p>
    <p v-else style="font-weight: bold;margin-left: 20px;">已选有效数据{{ loadData.length }}条，确认要批量下线吗？</p>
    <a-form-model
      id="productInfoEdit-form"
      ref="ruleForm"
      :model="form"
      :rules="rules"
      :label-col="formItemLayout.labelCol"
      :wrapper-col="formItemLayout.wrapperCol">
      <a-form-model-item label="下线选项" prop="unit">
        <v-select
          code="OFFLINE_REASON_TYPE"
          id="productInfoOffline-unit"
          v-model="form.unit"
          allowClear
          placeholder="请选择下线选项"
        ></v-select>
      </a-form-model-item>
      <a-form-model-item label="通用编码" prop="unit">
        <!-- 列表 -->
        <a-table
          class="sTable"
          ref="table"
          size="small"
          :rowKey="(record) => record.id"
          :columns="columns"
          :dataSource="loadData"
          :pagination="false"
          bordered>
          <!-- 通用编码 -->
          <template slot="universalCoding" slot-scope="text, record" >
            <div>
              <a-input
                id="productInfoOffline-universalCoding"
                :maxLength="60"
                v-model="form.lowerLimit"
                placeholder="请输入通用编码(最多60个字符)"
                allowClear />
            </div>
          </template>
        </a-table>
      </a-form-model-item>
      <a-form-model-item label="下线备注" prop="otherCode">
        <a-textarea
          id="productInfoOffline-otherCode"
          :maxLength="60"
          v-model="form.otherCode"
          placeholder="请输入下线备注(最多60个字符)"
          allowClear />
      </a-form-model-item>
    </a-form-model>
    <div class="btn-cont">
      <a-button type="primary" id="productInfoOffline-submit" @click="handleSubmit">确定</a-button>
      <a-button id="productInfoOffline-cancel" @click="isShow = false" style="margin-left: 100px;">取消</a-button>
    </div>
  </a-modal>
</template>

<script>
import { VSelect } from '@/components'
import { productSnDetail } from '@/api/product'
export default {
  name: 'ProductInfoDetailModal',
  components: { VSelect },
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    },
    nowData: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  data () {
    return {
      isShow: this.openModal, //  是否打开弹框
      formItemLayout: {
        labelCol: { span: 3 },
        wrapperCol: { span: 21 }
      },
      form: {
        storageQuantity: undefined
      },
      rules: {
        supplierName: [
          { required: true, message: '请输入供应商名称', trigger: 'blur' }
        ]
      },
      columns: [
        { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
        { title: '产品编码', dataIndex: 'code', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
        { title: '通用编码', scopedSlots: { customRender: 'universalCoding' }, align: 'center' }
      ],
      loadData: []
    }
  },
  methods: {
    //  确定
    handleSubmit () {
      // productSnDetail({ sn: this.itemSn }).then(res => {
      //   if (res.status == 200) {
      //     this.detailsData = res.data
      //   } else {
      //     this.detailsData = null
      //   }
      // })
    }
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (newValue, oldValue) {
      if (!newValue) {
        this.$emit('close')
      }
    },
    nowData: {
      handler (newValue, oldValue) {
        if (this.isShow && newValue) {
          // this.getDetail()
        }
      },
      deep: true
    }
  }
}
</script>

<style lang="less">
  .productInfoOffline-modal{
    .ant-modal-body {
      padding: 40px 40px 24px;
    }
    .btn-cont {
      text-align: center;
      margin: 35px 0 10px;
    }
  }
</style>
