<template>
  <div>
    <SearchBox ref="SearchBoxRef" formName="selectTop" :formData="query" @showPop="showPop" @reset="reset"></SearchBox>
    <ButtonBox @search="handleSearch" @add="insertDialog" ></ButtonBox>

    <TableBox ref="TableBoxRef" :tableData="tableData" @edit="handleEdit" @remove="handleRemove" :page="pageType"
              :paramType="paramType" :url="url" :param="query"></TableBox>

    <el-dialog class="diaClass" :close-on-click-modal="false" draggable title="新增" v-model="insertDialogShow"
               width="80%"
               top="5vh">
      <el-card class="box-card">
<!--        <el-tag>基本信息</el-tag>-->
        <el-form :model="insertForm" ref="myform" :rules="rules" label-width="130" label-position="right" :inline="true">
          <el-row>
            <el-col :span="6">
              <el-form-item label="订单号" prop="salOrdNo">
                <el-input v-model="insertForm.salOrdNo" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="客户名称" prop="supplierNm">
                <el-col :span="24">
                  <el-input v-model="insertForm.supplierNm" readonly>
                    <template #append>
                      <el-button :icon="Search" @click="insertCon"/>
                    </template>
                  </el-input>
                </el-col>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="合同编号" prop="contrNo">
                <el-input v-model="insertForm.contrNo" readonly>
                  <template #append>
                    <el-button :icon="Search" @click="insertCon"/>
                  </template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="对方合同编号" prop="khContrNo">
                <el-input v-model="insertForm.contrNo" readonly>
                  <template #append>
                    <el-button :icon="Search" @click="insertCon"/>
                  </template>
                </el-input>
              </el-form-item>
            </el-col>

          </el-row>

          <el-row>
            <el-col :span="6">
              <el-form-item label="交货日期">
                <el-date-picker
                    style="width: 100%"
                    v-model="insertForm.delvDt"
                    type="date"
                    value-format="YYYY-MM-DD"
                    placeholder="请选择日期"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="订单类型" prop="ordTy">
                <SelectorComponent :optionList="dictList.SAL_ORD_TY" :value="insertForm.ordTy" dicType="SAL_ORD_TY"
                                   @change="ordTyDict"/>
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="销售类型" prop="salTy">
                <SelectorComponent :optionList="dictList.SAL_SAL_TY" :value="insertForm.salTy" dicType="SAL_SAL_TY"
                                   @change="salTyDict"/>

              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="收款方式" prop="payMth">
                <SelectorComponent :optionList="dictList.COM_PAY_MTH" :value="insertForm.payMth" dicType="COM_PAY_MTH"
                                   @change="payMthDict"/>

              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="6">
              <el-form-item label="销售方式" prop="salMth">
                <SelectorComponent :optionList="dictList.SAL_SAL_MTH" :value="insertForm.salMth" dicType="SAL_SAL_MTH"
                                   @change="salMthDict"/>

              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="结算方式" prop="invMth">
                <SelectorComponent :optionList="dictList.SAL_INV_MTH" :value="insertForm.invMth" dicType="SAL_INV_MTH"
                                   @change="invMthDict"/>

              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="收货方">
                <el-input v-model="insertForm.delvPlace">
                  <template #append>
                    <el-button :icon="Search"/>
                  </template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="发货控制">
                <el-select v-model="insertForm.delvCtrlYn" clearable style="width: 100%">
                  <el-option value="0" label="否"></el-option>
                  <el-option value="1" label="是"></el-option>
                </el-select>

              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="订单备注">
                <el-input
                    v-model="insertForm.remark"
                    :autosize="{ minRows: 2, maxRows: 4 }"
                    type="textarea"
                    placeholder="备注"
                />
              </el-form-item>
            </el-col>
          </el-row>

        </el-form>
      </el-card>
<!--      <el-card class="box-card" style="margin-top: 20px" v-show="true">-->
<!--&lt;!&ndash;        <el-tag>销售订单行</el-tag>&ndash;&gt;-->
<!--        <el-button type="success" style="float: right" size="small" plain @click="onAddItemWl">新增</el-button>-->
<!--        &lt;!&ndash;        <el-button type="primary" plain>新增</el-button>&ndash;&gt;-->
<!--        <el-table :data="tableDataTwo" border highlight-current-row>-->
<!--          <el-table-column v-if="true" prop="salOrdLine" label="订单行号" width="120" header-align="center"-->
<!--                           align="center" show-overflow-tooltip>-->
<!--            <template #default="scope">-->
<!--              <span>{{ scope.$index + (currentPage - 1) * pageSize + 1 }}</span>-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column v-if="true" prop="salSts" label="行状态" header-align="center" align="center" width="160"-->
<!--                           show-overflow-tooltip>-->
<!--            <template #default="scope">-->
<!--            <span v-show="!scope.row.isEdit">-->
<!--              {{ scope.row.salSts }}-->
<!--            </span>-->
<!--              <el-input-->
<!--                  v-show="scope.row.isEdit"-->
<!--                  v-model="scope.row.salSts"-->
<!--              />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column v-if="true" prop="itemNm" label="物料名称" header-align="center" align="right" width="180"-->
<!--                           show-overflow-tooltip>-->
<!--            <template #default="scope">-->
<!--            <span v-show="!scope.row.isEdit">-->
<!--              {{ scope.row.itemNm }}-->
<!--            </span>-->
<!--              <el-input-->
<!--                  v-show="scope.row.isEdit"-->
<!--                  v-model="scope.row.itemNm"-->
<!--              >-->
<!--                <template #append>-->
<!--                  <el-button :icon="Search" @click="insertCon"/>-->
<!--                </template>-->
<!--              </el-input>-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column v-if="true" prop="itemCd" label="物料编码" header-align="center" align="center" width="180"-->
<!--                           show-overflow-tooltip>-->
<!--            <template #default="scope">-->
<!--            <span v-show="!scope.row.isEdit">-->
<!--              {{ scope.row.itemCd }}-->
<!--            </span>-->
<!--              <el-input-->
<!--                  readonly-->
<!--                  v-show="scope.row.isEdit"-->
<!--                  v-model="scope.row.itemCd"-->
<!--              >-->
<!--              </el-input>-->

<!--            </template>-->
<!--          </el-table-column>-->

<!--          <el-table-column v-if="true" prop="itemId" label="物料ID" header-align="center" align="right" width="180"-->
<!--                           show-overflow-tooltip>-->
<!--            <template #default="scope">-->
<!--            <span v-show="!scope.row.isEdit">-->
<!--              {{ scope.row.itemId }}-->
<!--            </span>-->
<!--              <el-input-->
<!--                  readonly-->
<!--                  v-show="scope.row.isEdit"-->
<!--                  v-model="scope.row.itemId"-->
<!--              >-->
<!--              </el-input>-->
<!--            </template>-->
<!--          </el-table-column>-->

<!--          <el-table-column v-if="true" prop="stlGrd" label="钢种" header-align="center" align="center" width="160"-->
<!--                           show-overflow-toox`ltip>-->
<!--            <template #default="scope">-->
<!--            <span v-show="!scope.row.isEdit">-->
<!--              {{ scope.row.stlGrd }}-->
<!--            </span>-->
<!--              <el-input-->
<!--                  v-show="scope.row.isEdit"-->
<!--                  v-model="scope.row.stlGrd"-->
<!--              />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column v-if="true" prop="specType" label="规格型号" header-align="center" align="center" width="160"-->
<!--                           show-overflow-tooltip>-->
<!--            <template #default="scope">-->
<!--            <span v-show="!scope.row.isEdit">-->
<!--              {{ scope.row.specType }}-->
<!--            </span>-->
<!--              <el-input-->
<!--                  v-show="scope.row.isEdit"-->
<!--                  v-model="scope.row.specType"-->
<!--              />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column v-if="true" prop="qty" label="数量" header-align="center" align="center" width="180"-->
<!--                           show-overflow-tooltip>-->
<!--            <template #default="scope">-->
<!--            <span v-show="!scope.row.isEdit">-->
<!--              {{ scope.row.qty }}-->
<!--            </span>-->
<!--              <el-input-number-->
<!--                  :min="0"-->
<!--                  :step="1"-->
<!--                  v-show="scope.row.isEdit"-->
<!--                  v-model="scope.row.qty"-->
<!--              />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column v-if="true" prop="uom" label="计量单位" header-align="center" align="center" width="160"-->
<!--                           show-overflow-tooltip>-->
<!--            <template #default="scope">-->
<!--            <span v-show="!scope.row.isEdit">-->
<!--              {{ scope.row.uom }}-->
<!--            </span>-->
<!--              <el-input-->
<!--                  v-show="scope.row.isEdit"-->
<!--                  v-model="scope.row.uom"-->
<!--              />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column v-if="true" prop="taxRate" label="税率" header-align="center" align="center" width="160"-->
<!--                           show-overflow-tooltip>-->
<!--            <template #default="scope">-->
<!--            <span v-show="!scope.row.isEdit">-->
<!--              {{ scope.row.taxRate }}-->
<!--            </span>-->
<!--              <el-input-->
<!--                  v-show="scope.row.isEdit"-->
<!--                  v-model="scope.row.taxRate"-->
<!--              />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column v-if="true" prop="priceCash" label="不含税单价" header-align="center" align="center"-->
<!--                           width="160"-->
<!--                           show-overflow-tooltip>-->
<!--            <template #default="scope">-->
<!--            <span v-show="!scope.row.isEdit">-->
<!--              {{ scope.row.priceCash }}-->
<!--            </span>-->
<!--              <el-input-number-->
<!--                  v-show="scope.row.isEdit"-->
<!--                  v-model="scope.row.priceCash"-->
<!--              />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column v-if="true" prop="taxPriceCash" label="含税单价" header-align="center" align="center"-->
<!--                           width="160"-->
<!--                           show-overflow-tooltip>-->
<!--            <template #default="scope">-->
<!--            <span v-show="!scope.row.isEdit">-->
<!--              {{ scope.row.taxPriceCash }}-->
<!--            </span>-->
<!--              <el-input-number-->
<!--                  v-show="scope.row.isEdit"-->
<!--                  v-model="scope.row.taxPriceCash"-->
<!--              />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column v-if="true" prop="amtCash" label="不含税金额" header-align="center" align="center"-->
<!--                           width="160"-->
<!--                           show-overflow-tooltip>-->
<!--            <template #default="scope">-->
<!--            <span v-show="!scope.row.isEdit">-->
<!--              {{ scope.row.amtCash }}-->
<!--            </span>-->
<!--              <el-input-number-->
<!--                  v-show="scope.row.isEdit"-->
<!--                  v-model="scope.row.amtCash"-->
<!--              />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column v-if="true" prop="taxAmtCash" label="税额" header-align="center" align="center" width="160"-->
<!--                           show-overflow-tooltip>-->
<!--            <template #default="scope">-->
<!--            <span v-show="!scope.row.isEdit">-->
<!--              {{ scope.row.taxAmtCash }}-->
<!--            </span>-->
<!--              <el-input-number-->
<!--                  v-show="scope.row.isEdit"-->
<!--                  v-model="scope.row.taxAmtCash"-->
<!--              />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column v-if="true" prop="totalAmtCash" label="含税金额" header-align="center" align="center"-->
<!--                           width="160"-->
<!--                           show-overflow-tooltip>-->
<!--            <template #default="scope">-->
<!--            <span v-show="!scope.row.isEdit">-->
<!--              {{ scope.row.totalAmtCash }}-->
<!--            </span>-->
<!--              <el-input-number-->
<!--                  v-show="scope.row.isEdit"-->
<!--                  v-model="scope.row.totalAmtCash"-->
<!--              />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column v-if="true" prop="priceBill" label="承兑不含税单价" header-align="center" align="center"-->
<!--                           width="160"-->
<!--                           show-overflow-tooltip>-->
<!--            <template #default="scope">-->
<!--            <span v-show="!scope.row.isEdit">-->
<!--              {{ scope.row.priceBill }}-->
<!--            </span>-->
<!--              <el-input-number-->
<!--                  v-show="scope.row.isEdit"-->
<!--                  v-model="scope.row.priceBill"-->
<!--              />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column v-if="true" prop="taxPriceBill" label="承兑含税单价" header-align="center" align="center"-->
<!--                           width="160"-->
<!--                           show-overflow-tooltip>-->
<!--            <template #default="scope">-->
<!--            <span v-show="!scope.row.isEdit">-->
<!--              {{ scope.row.taxPriceBill }}-->
<!--            </span>-->
<!--              <el-input-number-->
<!--                  v-show="scope.row.isEdit"-->
<!--                  v-model="scope.row.taxPriceBill"-->
<!--              />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column v-if="true" prop="amtBill" label="承兑不含税金额" header-align="center" align="center"-->
<!--                           width="160"-->
<!--                           show-overflow-tooltip>-->
<!--            <template #default="scope">-->
<!--            <span v-show="!scope.row.isEdit">-->
<!--              {{ scope.row.amtBill }}-->
<!--            </span>-->
<!--              <el-input-number-->
<!--                  v-show="scope.row.isEdit"-->
<!--                  v-model="scope.row.amtBill"-->
<!--              />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column v-if="true" prop="taxAmtbill" label="承兑金额" header-align="center" align="center"-->
<!--                           width="160"-->
<!--                           show-overflow-tooltip>-->
<!--            <template #default="scope">-->
<!--            <span v-show="!scope.row.isEdit">-->
<!--              {{ scope.row.taxAmtbill }}-->
<!--            </span>-->
<!--              <el-input-number-->
<!--                  v-show="scope.row.isEdit"-->
<!--                  v-model="scope.row.taxAmtbill"-->
<!--              />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column v-if="true" prop="totalAmtBill" label="承兑含税金额" header-align="center" align="center"-->
<!--                           width="160"-->
<!--                           show-overflow-tooltip>-->
<!--            <template #default="scope">-->
<!--            <span v-show="!scope.row.isEdit">-->
<!--              {{ scope.row.totalAmtBill }}-->
<!--            </span>-->
<!--              <el-input-number-->
<!--                  v-show="scope.row.isEdit"-->
<!--                  v-model="scope.row.totalAmtBill"-->
<!--              />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column v-if="true" prop="delvTol" label="发货允差上下限" header-align="center" align="center"-->
<!--                           width="160"-->
<!--                           show-overflow-tooltip>-->
<!--            <template #default="scope">-->
<!--            <span v-show="!scope.row.isEdit">-->
<!--              {{ scope.row.delvTol }}-->
<!--            </span>-->
<!--              <el-input-->
<!--                  v-show="scope.row.isEdit"-->
<!--                  v-model="scope.row.delvTol"-->
<!--              />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column v-if="true" prop="ordDelvDt" label="发货完成时间" header-align="center" align="center"-->
<!--                           width="300"-->
<!--                           show-overflow-tooltip>-->
<!--            <template #default="scope">-->
<!--              <span v-show="!scope.row.isEdit">-->
<!--               <el-date-picker-->
<!--                   disabled-->
<!--                   v-model="scope.row.ordDelvDt"-->
<!--                   type="datetime"-->
<!--                   placeholder=""-->
<!--               />-->
<!--             </span>-->
<!--              <el-date-picker-->
<!--                  v-if="scope.row.isEdit"-->
<!--                  v-model="scope.row.ordDelvDt"-->
<!--                  type="datetime"-->
<!--                  placeholder=""-->
<!--              />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column v-if="true" prop="remark" label="备注" header-align="center" align="center"-->
<!--                           width="300"-->
<!--                           show-overflow-tooltip>-->
<!--            <template #default="scope">-->
<!--            <span v-show="!scope.row.isEdit">-->
<!--              {{ scope.row.remark }}-->
<!--            </span>-->
<!--              <el-input-->
<!--                  v-show="scope.row.isEdit"-->
<!--                  v-model="scope.row.remark"-->
<!--              />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="操作" header-align="center" align="center" width="280px" fixed="right">-->
<!--            <template #header>-->
<!--              <div style="display: flex;justify-content: center;align-items: center; color: #67c23a !important; cursor: pointer" @click="onAddItemWl">-->
<!--&lt;!&ndash;              <el-input v-model="search" size="small" placeholder="Type to search" />&ndash;&gt;-->
<!--                <span>操作</span>-->
<!--              <el-icon><CirclePlus /></el-icon>-->
<!--              </div>-->
<!--            </template>-->
<!--            <template #default="scope">-->
<!--              <el-button plain type="warning" v-if="!scope.row.isEdit" @click="rowEdit(scope.row)">编辑</el-button>-->
<!--              <el-button plain type="success" v-else @click="rowEditSave(scope.row)">保存</el-button>-->
<!--              <el-button plain type="" @click="rowCopy(scope.row)">复制</el-button>-->
<!--              <el-button plain type="danger" @click="rowRemove(scope.row )">删除</el-button>-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--        </el-table>-->
<!--      </el-card>-->
      <template #footer>
        <div class="dialog-footer">
<!--          <el-button type="success" @click="insertDialogSave1">保存1</el-button>-->
          <el-button type="success" @click="insertDialogSave">保存</el-button>
          <el-button type="danger" @click="insertDialogShow = false">取消</el-button>
        </div>
      </template>


    </el-dialog>

    <!--    <el-dialog class="diaClass" :close-on-click-modal="false" draggable title="合同" v-model="conDialogShow"-->
    <!--               width="40%"-->
    <!--               top="5vh">-->

    <!--&lt;!&ndash;    <base-con></base-con>&ndash;&gt;-->
    <!--      -->
    <!--    </el-dialog>-->
<!--    <PopupSal ref="PopupRef" :url=conUrl :column="column" @receiveFromChild="getContract"></PopupSal>-->
    <PopupBas ref="PopupRef"  @receiveFromChild="getContract"></PopupBas>
  </div>
</template>

<script setup>
import {
  ref,
  reactive,
  onMounted,
  getCurrentInstance
} from 'vue'
import {Search} from '@element-plus/icons-vue'
import PopupSal from '@/views/sal/components/Popup_sal.vue'
import PopupBas from '@/views/bas/Popup_base_ks.vue'

const {
  proxy
} = getCurrentInstance()
import style from '@/tools/style'

const cardBodyStyle = ref(style.card)

// 合同弹框控制
const conDialogShow = ref(false)
const searchBarRef = ref(null)
const pageType = ref(true)
const url = ref("sal/salOrd/query")
const conUrl = ref("cot/Head/queryCotHead")
const SearchBoxRef = ref(null)
const PopupRef = ref(null)
const handle = () => {
  PopupRef.value.open()
}
const getContract = (val) => {
  console.log(val)
  insertForm.supplierNm = val.supplierNm
  insertForm.contrNo = val.contrNo
  insertForm.kHcontrNo = val.kHcontrNo
}
const reset = () => {
  Object.keys(query.value).map(key => {
    query.value[key] = ''
  })
}
const column = ref([
  {
    prop: 'contrNm',
    label: '合同名称',
  },
  {
    prop: 'contrNo',
    label: '合同编号',
  },
  {
    prop: 'khContrNo',
    label: '对方合同编号'
  },
  {
    prop: 'supplierNm',
    label: '客户名称',
  },
  {
    prop: 'supplierCd',
    label: '客户编码',
  },
  {
    prop: 'supplierNm',
    label: '客户名称',
  },
  {
    prop: 'totalAmt',
    label: '合同金额',
  }
])

const searchForm = (val) => {
  query.value = searchBarRef.value.form
  console.log(JSON.stringify(query.value))
}

/**
 *   查询
 */

const query = ref({
  birthDate: '',
  type: '',
  code: '',
  name: '',
  sex: '',
  contractType: '',
  contractFlag: '',
  addTime: ['', '']
})
const tableData = ref([])
const tableDataTwo = ref([])
const handleSearch = (val) => {
  // query.value = searchBarRef.value.form
  // currentPage.value = 1
  // getTableData()


  TableBoxRef.value.search()
}
const TableBoxRef = ref(null)
const getTableData = () => {
  var url = 'exp/Search/structurePage'
  var param = {
    page: currentPage.value,
    rows: pageSize.value,
    params: JSON.stringify(query.value)
  }
  proxy.$axios.get(url, param).then(response => {
    if (response.data.code == '0') {
      tableData.value = response.data.data.records
      totalRows.value = response.data.data.total
    } else {
      ElMessage.error('操作失败！' + response.data.msg)
    }
  })
}
/**
 *   查询
 */
/**
 * 分页
 */
const currentPage = ref(1)
const totalRows = ref(0)
const pageSizes = ref([5, 10, 20, 30, 40])
const pageSize = ref(5)
const handleSizeChange = (val) => {
  pageSize.value = val
  getTableData()
}

/**
 * 分页
 */

import PopupMenuTree from '@/components/PopupMenuTree.vue'
import ButtonBar from "@/components/ButtonBar.vue";
import SelectorComponent from "@/views/sal/components/Selector_component.vue";
import SearchBox from "@/components/SearchBox.vue";
import ButtonBox from "@/components/ButtonBox.vue";
import TableBox from "@/components/TableBox.vue";
import Popup from "@/views/exp/controller/Popup.vue";

const PopupMenuTreeRef = ref(null)
const showPop = () => {
  console.log('showPop')
  PopupMenuTreeRef.value.show()
}
/**
 * 新增表单form
 */
const insertForm = reactive({
  id: '',
  ddh: '',
  ordTy: '',
  supplierNm: '',
  salTy: '',
  payMth: '',
  salMth: '',
  kczz: '',
  bz: '',
  salOrdNo: '',
  contrNo: '',
  htrq: '',
  delvDt: '',
  invMth: '',
  delvPlace: '',
  jhfs: '',
  scfs: '',
  ysfs: '',
  hthl: '',
  myfs: '',
  shhl: '',
  ckgj: '',
  qsd: '',
  mdd: '',
  djysbl: '',
  dkysbl: '',
  remark: '',
  khContrNo: '',
  hzsl: '',
  shxx: '',
  jeht: '',
  hzje: '',
  zlsm: '',
})

const myform = ref()
const clearForm = ()=> {
  // Object.assign(insertForm, {})
  Object.keys(insertForm).map(key => {
    delete form[key]
  })
}

// 新增订单
const insertDialogShow = ref(false)
const insertDialog = () => {
  // clearForm()
  // insertForm = reactive({})

  // Object.assign(insertForm, {})
  // let dat = Object.keys(insertForm)
  // dat.map((k) => {
  //   insertForm[k] = undefined
  // })

  insertDialogShow.value = true




}
const handleEdit = () => {
  insertDialogShow.value = true
}
const handleDelete = (row) => {
  ElMessageBox.confirm(
      '确定删除本条记录?',
      '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
        draggable: true,
      }
  )
      .then(() => {
        ElMessage({
          type: 'success',
          message: '删除成功',
        })
      })
      .catch(() => {
        ElMessage({
          type: 'info',
          message: '已取消',
        })
      })
}

const insertDialogSave = () => {
  //
  var url = 'sal/salOrd/save'
  console.log(insertForm)
  console.log(tableDataTwo.value)
  var param = {
    head: JSON.stringify(insertForm),
    line: JSON.stringify(tableDataTwo.value),
  }
  console.log(param)

  proxy.$axios.post(url, param ,"application/x-www-form-urlencoded").then(response => {
    if (response.data.code == 0) {
      ElMessage({
        message: '保存成功',
        type: 'success',
      })
      insertDialogShow.value = false
      handleSearch()
    } else {
      ElMessage({
        type: 'error',
        message: '操作失败' + response.data.msg
      })
    }
  });
}
// 校验
const rules = reactive({
  contrNo: [
    {required: true, message: '请选择', trigger: 'blur'},
  ],
  ordTy: [
    {required: true, message: 'Please input Activity name', trigger: 'blur'},
  ],
  supplierNm: [
    {required: true, message: '请选择', trigger: 'blur'},
  ],
  salTy: [
    {required: true, message: 'Please input Activity name', trigger: 'blur'},
  ],
  payMth: [
    {required: true, message: 'Please input Activity name', trigger: 'blur'},
  ],
  salMth: [
    {required: true, message: 'Please input Activity name', trigger: 'blur'},
  ],
  kczz: [
    {required: true, message: 'Please input Activity name', trigger: 'blur'},
  ],
  bz: [
    {required: true, message: 'Please input Activity name', trigger: 'blur'},
  ],
})

const otherQuery = () => {

}
const insertCon = () => {
  // conDialogShow.value = true
  handle()
}
const dictList = ref({})
const dictData = () => {
  var url = 'framework/Common/querySelectorList'
  var param = {
    type: JSON.stringify(['SAL_ORD_TY', 'SAL_SAL_TY', 'COM_PAY_MTH', 'SAL_SAL_MTH', 'SAL_INV_MTH'])
  }
  proxy.$axios.get(url, param).then(response => {
    if (response.data.code == '0') {
      dictList.value = response.data.data
      console.log(response.data.data)

    } else {
      ElMessage.error('操作失败！' + response.data.msg)
    }
  })
}
const ordTyDict = (val) => {
  insertForm.ordTy = val
}
const salTyDict = (val) => {
  insertForm.salTy = val
}
const payMthDict = (val) => {
  insertForm.payMth = val
}
const salMthDict = (val) => {
  insertForm.salMth = val
}
const invMthDict = (val) => {
  insertForm.invMth = val
}

// 销售订单行 -add row、
const onAddItemWl = () => {
  const now = new Date()
  now.setDate(now.getDate() + 1)
  tableDataTwo.value.push({
    key:now.getTime(),
    id: '',
    isEdit: false,
    salOrdLine: "",
    salSts: "",
    itemCd: "",
    itemNm: "",
    itemId: "",
    stlGrd: "",
    specType: "",
    qty: 0,
    uom: '',
    taxRate: "",
    priceCash: 0,
    taxPriceCash: 0,
    amtCash: 0,
    taxAmtCash: 0,
    totalAmtCash: 0,
    priceBill: 0,
    taxPriceBill: 0,
    amtBill: 0,
    taxAmtbill: 0,
    totalAmtBill: 0,
    delvTol: "",
    ordDelvDt: "",
    remark: "",
  })
}

// 销售订单行 行编辑
const rowEdit = (scope) => {
  scope.isEdit = true
}

// 销售订单行 行保存
const rowEditSave = (scope) => {
  scope.isEdit = false
}

// 销售订单行 行删除
const rowRemove = (index) => {
  tableDataTwo.value.splice(index, 1)
}

// 销售订单行 行复制
const rowCopy = (row) => {
  console.log("row", row)

  const now = new Date()
  now.setDate(now.getDate() + 1)
  tableDataTwo.value.push({
    key: now.getTime(),
    id: '',
    isEdit: false,
    salOrdLine: row.salOrdLine,
    salSts: row.salSts,
    itemCd: row.itemCd,
    itemNm: row.itemNm,
    itemId: row.itemId,
    stlGrd: row.stlGrd,
    specType: row.specType,
    qty: row.qty,
    uom: row.uom,
    taxRate: row.taxRate,
    priceCash: row.priceCash,
    taxPriceCash: row.taxPriceCash,
    amtCash: row.amtCash,
    taxAmtCash: row.taxAmtCash,
    totalAmtCash: row.totalAmtCash,
    priceBill: row.priceBill,
    taxPriceBill: row.taxPriceBill,
    amtBill: row.amtBill,
    taxAmtbill: row.taxAmtbill,
    totalAmtBill: row.totalAmtBill,
    delvTol: row.delvTol,
    ordDelvDt: row.ordDelvDt,
    remark: row.remark,
  })
}

const insertDialogSave1 = () =>{
  console.log(tableDataTwo.value)
  console.log(tableDataTwo.value[1])
}

onMounted(() => {
  dictData()
  console.log(`the component is now mounted.`)
})
</script>

<style scoped>
::v-deep .diaClass .el-form-item {
  width: 100%
}

::v-deep .el-dialog__body {
  background-color: #F2F6FC;
}

.el-date-editor--date {
  width: 100%;
}
</style>
