/**
* @Author think
* @Date 2019-07-16 20:00
*/

<template>
  <h-view class="form" title="From">
    <h-header>
      <div slot="left" class="h-header-btn" @click="$hlsExit()">
        <i class="ion-ios-arrow-back"/>
      </div>
      <div slot="center">From</div>
      <div slot="right" class="h-header-btn">右边</div>
    </h-header>
    <h-layout
      v-if="layoutShow"
      :layout-data="layoutData" :show-form-title="showFormTitle" :show-btn-divider="true"
      :show-tab-divider="true" :formData="data" v-model="data" :read-only="readOnly"
      :show-btn="showBtn"
      @tabClick="tabClick"
      @showSelect="showSelect" @showTime="showTime" @filedClick="filedClick"
      @btnClick="btnClick"/>
  </h-view>
</template>

<script>
import layoutData from './layout.json'

export default {
  name: 'Form',
  data () {
    return {
      showFormTitle: true,
      layoutData: [],
      layoutShow: false,
      readOnly: false,
      showBtn: true,
      data: {
        contract: {
          contract_id: 1,
          postion: '01',
          postion_n: '技术顾问',
          enable_flag: false,
          checkValue: true,
        },
      },
      postionList: [
        {code: '01', code_name: '技术顾问'},
        {code: '02', code_name: '技术经理'},
        {code: '03', code_name: '项目经理'},
      ],
    }
  },
  created () {
    let vm = this
    /* axios.get('http://leafservice.hand-china.com/r/api/get/layoutCode?layoutCode=CON_QURERY', {
      header: {'Content-Type': 'application/json',
        'Authorization': 'bearer SRHJVdrftyGUYguyhiHiuiojmgrrcgv' },
    }).then(res => {
      vm.layoutData = res.rows
      vm.layoutShow = true
    }) */

    setTimeout(() => {
      vm.layoutData = layoutData
      vm.layoutShow = true
    }, 100)
  },
  methods: {
    /**
     * tab的点击事件
     * @param index
     */
    tabClick (index) {
      this.tabIndex = index
    },
    showPostion (configCode, filedCode) {
      let vm = this
      vm.hlsPopup.selectList({
        list: vm.postionList,
        code: filedCode,
        object: vm.data[configCode],
        returnItem (index) {
          vm.data[configCode][filedCode] = vm.postionList[index].code
          vm.data[configCode][filedCode + '_n'] = vm.postionList[index].code_name
        },
      })
    },
    /**
     * 下拉框点击事件
     * @param configCode
     * @param filedCode
     */
    showSelect (configCode, filedCode) {
      let vm = this
      switch (filedCode) {
        case 'postion':
          vm.showPostion(configCode, filedCode)
          break
        default:
      }
    },
    showOrderDate (configCode, filedCode) {
      let vm = this
      vm.hlsPopup.showTime({
        callback (time) {
          vm.data[configCode][filedCode] = time
        },
      })
    },
    /**
     * 事件选择事件
     * @param configCode
     * @param filedCode
     */
    showTime (configCode, filedCode) {
      let vm = this
      switch (filedCode) {
        case 'order_date':
          vm.showOrderDate(configCode, filedCode)
          break
        default:
      }
    },
    /**
     * 其他字端的点击事件
     * @param configCode
     * @param filedCode
     */
    filedClick (configCode, filedCode) {
      debugger
    },
    /**
     * 按钮点击事件
     * @param btn
     */
    btnClick (btn) {
      console.log(JSON.stringify(this.data, '', 2))
      if (btn.btnType === 'BottomTab') {
        if (btn.btnCode === 'save') {
          alert('底部固定按钮的保存')
        }
        if (btn.btnCode === 'submit') {
          alert('底部固定按钮的提交')
        }
      } if (btn.btnType === 'Button') {
        if (btn.btnCode === 'nextBtn') {
          alert('按钮继续')
        }
      }
    },
  },
}
</script>

<style  lang="less">
  .form {
  }
</style>
