<template>
  <div>
    <el-card class="el-card">
      <el-form :model="filterQuery" class="query-form" size="mini" label-width="100px" v-if="showSearch">
        <el-row>
          <el-col :span="8">
            <el-form-item class="query-form-item" label="患者信息:">
              <el-input v-model="filterQuery.name" placeholder="请输入患者信息"
                        style="width: 90%"
                        clearable="true"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="top-right-btn">
        <el-button-group>
          <el-button icon="el-icon-view" type="primary" @click="hideSearch">显示/隐藏搜索栏</el-button>
          <el-button
            type="primary"
            icon="el-icon-refresh"
            @click="onReset"
          >重置
          </el-button>
          <el-button type="primary" icon="el-icon-search" @click="onSubmit"
          >查询
          </el-button
          >
        </el-button-group>
      </div>
    </el-card>
    <el-divider style="margin: 15px"></el-divider>
    <el-card class="el-card">

      <el-row>
        <el-col :span="4" v-for="(bazi,key) in list" :key="key" class="text-center">
          <BaziPanel :info="bazi" @baziPanel="getValue"></BaziPanel>
        </el-col>
      </el-row>
      <pagination style="height: 20px"
                  v-show="total>0"
                  :total="total"
                  :page-sizes=[24,48,96]
                  :page.sync="filterQuery.page"
                  :limit.sync="filterQuery.limit"
                  @pagination="getList"
      />
    </el-card>
    <el-dialog
      :title=title
      :visible.sync="addOrderVisible"
      width="85%"
      append-to-body
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      v-if="addOrderVisible"
      @close="closeDialog"
    >
      <addOrder
        :closeDialog="closeDialog"
        :orderQuery="this.idQuery"
        :sickerAdNum="this.sickerAdNum"
        :viewType="2"
        :errView="0"
      ></addOrder>
    </el-dialog>
  </div>

</template>

<script>
import BaziPanel from '@/components/inout/baziPanel.vue'
import { getSkSickerList,getOrderListbyCode } from '@/api/inout/ioDepartmentOrder'
import addOrder from "@/views/inout/DialogCreateOrder";

export default {
  components: { BaziPanel,addOrder },
  name: 'IoDepartmentOrder',
  data() {
    return {
      title:"新增单据",
      resultQuery: {
        orderId: null,
        code: null,
        page: 1,
        limit: 24
      },
      total: 0,
      list: [],
      showSearch: true,
      filterQuery: {
        name: '',
        page: 1,
        limit: 24

      },
      sickerAdNum:null,
      addOrderVisible: false,
      idQuery:{
        billNo: null,
        corpOrderId: null,
        action: null,
        invCode: null,
        fromCorp: null,
        fromCorpName: null,
        fromName: null,
        fromInvCode: null,
        remark: null,
        fromType: 2,
        errMsg: null,
        checkPreInOrders: null,
        checkPreInInvCode: null,
        checkPreInSpaceCode: null,
        curSpaceCode: null,
        preSpaceCode: null,
        preCurSpaceCode: null,  //单据
        sickerAdNum: null,
      },
      orderListDate:[]
    }
  },
  methods: {
    getValue(info) {
      getOrderListbyCode(info.adNum)
        .then((response) => {
        if (response.code === 20000) {
          this.orderListDate = response.data.list || []
          if (this.orderListDate.length > 0){
            this.idQuery = this.orderListDate[0]
          }else {
            this.idQuery.fromCorp = info.adNum
            this.idQuery.sickerAdNum = info.adNum
            this.sickerAdNum = info.adNum
          }
          this.addOrderVisible = true
        } else {
          this.$message.error(response.message)
        }
      }).catch((error) => {
          this.$message.error(error.message)
          this.list = []
          this.total = 0
        })
      console.log(this.idQuery)
    },
    closeDialog() {
      this.addOrderVisible = false;
      this.getList();
    },
    getList() {
      getSkSickerList(this.filterQuery)
        .then((response) => {
          if (response.code === 20000) {
            this.list = response.data.list || []
            this.total = response.data.total || 0
          } else {
            this.$message.error(response.message)
          }
        })
        .catch((error) => {
          this.$message.error(error.message)
          this.list = []
          this.total = 0
        })
    },
    onSubmit() {
      this.getList()
    },
    onReset() {
      this.filterQuery = {
        name: '',
        page: 1,
        limit: 24
      }
      this.getList()
    },
    hideSearch() {
      this.showSearch = !this.showSearch
    }
  },
  mounted() {

  },
  created() {
    this.getList()
  }
}
</script>

<style scoped>

</style>
