<template>
  <div>
    <basicDetails
      ref="details"
      :titleText="`单号:${mainData.sonum}`"
      :editData="mainData"
      :mainAreaData="mainAreaData"
      turnPageId="20230114105002"
      idname="sa_orderid"
      ownertable="sa_order"
      delApiId="20230116100002"
      :statusCheck="[{key:'status',value:'审核'},{key:'status',value:'交期待确认'},{key:'status',value:'提交'},{key:'status',value:'交期确认'}]"
      :tabs="['借用单明细']"
      @pageChange="pageChange"
      @onEditSuccess="queryMainData($route.query.id)">
      <div slot="customOperation" class="inline-16">
        <Edit class="inline-16" v-if="tool.checkAuth($route.name,'update') && mainData.status == '新建'" :data="mainData" @onSuccess="queryMainData();$refs.tool.listData()"/>
        <el-button v-if="tool.checkAuth($route.name,'confirmDate')" :disabled="mainData.status !== '交期待确认'" type="primary" size="mini" @click="confirmdate">确认交期</el-button>
        <el-button v-if="tool.checkAuth($route.name,'submit')" :disabled="mainData.status !== '新建'"  type="primary" size="mini" @click="onSubmit('提交')">提 交</el-button>
      </div>
      <div slot="slot0" >
        <toolList ref="tool"></toolList>
      </div>
      <div slot="slot1" >
      </div>
    </basicDetails>
  </div>
</template>

<script>
import toolList from './tabs/toolList.vue'
import confirmDate from '../modules/confirmDate.vue'
import Edit from '../modules/edit'

export default {
  name: "detail",
  data() {
    return {
      mainData:{},
      mainAreaData:{},
      options:[],
      value:''
    }
  },
  components:{
    Edit,
    toolList,
    confirmDate
  },
  methods:{
    async orderreviewtype () {
      const res = await this.$store.dispatch('optiontypeselect','orderreviewtype')
      this.options = res.data
      this.value = res.data[0].value
    },
    async queryMainData(id) {
      const res = await this.$api.requested({
        "id":20230114140402,
        "content": {
          "sa_orderid": this.$route.query.id
        }
      })
      this.mainData = res.data
      console.log(this.mainData);
      
      this.changeDataStructure()
      this.orderreviewtype()
    },
    changeDataStructure() {
      let that = this
      this.mainAreaData = [
        {
          label:'单据日期',
          value:this.mainData.billdate
        },
        {
          label:'经销商',
          value:this.mainData.enterprisename
        },
        {
          label:'状态',
          value:this.mainData.status,
          style:function () {
            let style = {}
            switch (that.mainData.status) {
              case '新建':
                style = {color:"#000000"}
                break;
              case '提交':
                style = {color:"#d90a0a"}
                break;
              case '交期待确认':
                style = {color:"#e09a1a"}
                break;
              case '交期确认':
                style = {color:"#3874f6"}
                break;
              case '审核':
                style = {color:"#52C41A"}
                break;
              case '关闭':
                style = {color:"#b2c0ea"}
                break;
              default:
                break;
            }
            return style
          }
        },
        {
          label:'合同',
          value:this.mainData.contract_title?this.mainData.contract_title:'无合同'
        },
        {
          label:'合计数量',
          value:this.mainData.qty * this.mainData.toolcount
        },
        {
          label:'金额',
          value:this.mainData.amount
        },
        {
          label:'收货人',
          value:this.mainData.name
        },
        {
          label:'收货地址',
          value:this.mainData.province + this.mainData.city + this.mainData.county + this.mainData.address
        },
        {
          label:'审核日期',
          value:this.mainData.checkdate
        },
        {
          label:'备注',
          value:this.mainData.remarks
        }
      ]
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex,tabIndex) {
      this.$refs['details'].param.content.isManage = 0
      tabIndex = this.$route.query.tabIndex
      this.$router.replace({path:'/toolBorrowingDetail',query:{id:id,rowindex:rowindex,tabIndex:tabIndex}})
      this.queryMainData(id)
    },
    // 提交订单
    onSubmit (type) {
      this.$confirm(`是否${type}该订单`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const res = await this.$api.requested({
          "id": type === '审核'?20230114161402:20230114160002,
          "content": {
            "sa_orderid": this.mainData.sa_orderid,
            "sys_enterpriseid": this.mainData.sys_enterpriseid,
            "sa_accountclassid": this.mainData.accountclass.sa_accountclassid,
            "reviewtype":type === '审核'?this.value:''
          },
        })
        this.tool.showMessage(res,async ()=>{
          this.visible = false
          this.queryMainData()
        })
      }).catch((err) => {
        this.$message({
          type: 'info',
          message: '取消'
        });          
      });
    },
    async confirmdate () {
      const res = await this.$api.requested({
        "id": 20230129154102,
        "content": {
          "sa_orderid": this.$route.query.id
        }
      })
      this.tool.showMessage(res,()=>{
        this.queryMainData()
      })
    },
  },
  mounted () {
    this.queryMainData(this.$route.query.id)
  },
  created() {
  }
}
</script>

<style scoped>

</style>