/**
  // author：jiana
  // time:2025-04-23
  // desc:运单管理
*/
<template>
  <div class="auditPlaceShip">
    <Card>
      <!-- 筛选 -->
      <Row :gutter="8">
        <Col span="10">
          供应商名称 <Input v-model="filtInfoData.shopName" placeholder="请输入运单号" style="width:80%"/>
        </Col>
        <Col span="2">
          <Button type="primary" @click="getData">查询</Button>
        </Col>
        <Col span="2">
          <Button @click="resetData">重置</Button>
        </Col>
      </Row>
    </Card>
    <Card style="margin-top:20px;">
      <Row>
        <Col span="12">
          待审列表
        </Col>
      </Row>
      <!-- 表格部分 -->
      <el-table v-loading="loading" :data="TabData.data" border style="width: 100%;margin-top:20px;">
        <el-table-column label="供应商名称" prop="supplierName" width="160" align="center"></el-table-column>
        <el-table-column label="仓库名称" width="150" prop="name" align="center"/>
        <el-table-column label="仓库地址" width="150" prop="address" align="center"/>
        <el-table-column label="经度" width="120" prop="longitude" align="center"></el-table-column>
        <el-table-column label="纬度" prop="latitude" width="120"  align="center"></el-table-column>
        <el-table-column label="所属分类" width="220" align="center">
          <template #default="scope">
           <span v-if="scope.row.classifyList">
            <el-tag v-for="classify in scope.row.classifyList.split(',')">{{classify}}</el-tag>
           </span>
          </template>
        </el-table-column>

        <el-table-column label="添加时间" width="160" align="center">
          <template #default="scope">
            {{ moment(scope.row.addTime).format('yyyy-MM-DD hh:mm:ss') || '暂无'}}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="250"  fixed="right" align="center">
          <template  #default="scope">
            <Button class="opt_btn" size="small" type="primary" ghost @click="lookInfo(scope.row)">查看地址</Button>
            <Button class="opt_btn" size="small" type="primary" @click="auditSuccess(scope.row.id)">审核通过</Button>
            <Button class="opt_btn" size="small" type="warning" @click="auditFail(scope.row.id)">审核拒绝</Button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="page_style">
        <Page :total="TabData.total" :model-value="currentPage" show-elevator show-total @on-change="changePage" />
      </div>
    </Card>
    <!-- 查看地址 -->
    <Modal v-model="showInfo" width="60%" title="查看地址">
     <mapMark v-if="showInfo" :markInfo="markInfo"></mapMark>
    </Modal>
  </div>
</template>

<script>
import { defineComponent, ref ,reactive, onMounted} from 'vue'
import { tms } from '@/request/api'
import { Message,Modal,Spin,Input } from 'view-ui-plus'
import moment from 'moment'
import {useRoute} from 'vue-router'
import mapMark from "./mapMark.vue"
export default defineComponent({
  components:{
    mapMark
  },
  setup() {
    const route = useRoute()
    let filtInfoData = reactive({ // 搜索
      limit:10,offset:0,status:0,shopName:''
    })

    let TabData = ref([])  // 列表数据

    let loading = ref(false)
    //获取列表内容
    async function getData(){
      loading.value = true
      await tms.warehouseList(filtInfoData).then(res =>{
        if (res.code == 0) {
          TabData.value = res
        }
      })
      loading.value = false
    }
    //重置
    function resetData(){
      filtInfoData.offset = 0
      filtInfoData.limit = 10
      filtInfoData.shopName = ''
      filtInfoData.status = 0
      getData()
    }

    let currentPage = ref(1)
    //更改页码
    function changePage (page) {
      if(TabData.value.limit){
        filtInfoData.offset = (page -1) *  TabData.value.limit  //更新偏移量
        currentPage = page  //切换当前页码
        getData() 
      }
    }

    //审核通过
    function auditSuccess(id){
      this.$Modal.confirm({
        title: '提示',
        content: '<p>确定审核通过该信息吗？</p>',
        onOk: async() => {
          await tms.warehouseApprove({id:id}).then(res=>{
            if(res.code === 101){
              Message.success('审核成功！');
              getData()
            }
          })
        },
        onCancel: () => {
          this.$Message.info('已取消');
        }
      })
    }
    let refuseValue = ref('')
    //查看异常
    function auditFail(id){
      this.$Modal.confirm({
        title: '审核拒绝',
        render: (h) => {
          return h( Input, {
            size: "large",
            modelValue: refuseValue.value,
            autofocus: true,
            placeholder: '请输入拒绝原因',
            'onInput': async (event) => {
              refuseValue.value = event.target.value;
            },
          })
        },
        onOk: async () => {
          const params={
            id:id,
            remark:refuseValue.value
          }
          await tms.warehouseReject(params).then(res=>{
            if(res.code === 101){
              Message.success('拒绝成功！');
              getData()
            }
          })
        },
      })
    }
    
    const showInfo = ref(false)
    let markInfo =  reactive({
      longitude:'',latitude:''
    })
    //查看地址
    function lookInfo(data){
      markInfo.longitude = data.longitude
      markInfo.latitude = data.latitude
      showInfo.value = true
    }
    onMounted(()=>{
      getData() 
    })

    return {
      getData,changePage,moment,TabData,filtInfoData,
      loading,resetData,showInfo,auditFail,auditSuccess,refuseValue,lookInfo,markInfo
    }
  },
})
</script>

<style lang="scss" scoped>
.auditPlaceShip{
  padding: 1em;
  .opt_btn{margin-bottom:3px; margin-right: 3px;}
  .page_style{
    text-align: right; margin-top: 1em;
    // background-color: var(--system-container-background);
  }
}
</style>