<template>
	<view>
		<cu-custom bgColor="bg-gradual-blueness" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">入职申请</block>
		</cu-custom>
    <scroll-view scroll-y="false" >
		  <view class="form">
        <!-- 入职申请 -->
        <uni-section title="入职申请" type="line" class="margin-top" padding>
          <view class="cu-form-group margin-top-xs">
            <view class="title">入职企业</view>
            <zqs-select
                :multiple="false"
                :list="dictData.APPLY_CORP.list"
                :show-search="true"
                v-model="form.CORPINFO_ID"
                label-key="CORP_NAME"
                value-key="CORPINFO_ID"
                placeholder="请选择入职企业"
                title="选择入职企业"
                clearable
                @search="searchSelect($event, 'APPLY_CORP')"
            ></zqs-select>
          </view>
        </uni-section>
        <view class="cu-form-group margin-top-xs">
          <view class="title">申请描述</view>
          <textarea v-model="form.APPLY_CONTENT" maxlength="200" placeholder="请输入描述(选填)"></textarea>
        </view>
      </view>
      <view class="cu-bar btn-group" style="margin-top: 30upx;">
        <button class="cu-btn bg-blue margin-tb-sm lg" @click="$noMultipleClicks(confirm)">提交申请</button>
<!--        <button class="cu-btn bg-green margin-tb-sm lg" @click="$noMultipleClicks(goback)">返回</button>-->
      </view>
    </scroll-view>
	</view>
</template>

<script>
import {basePath, getLevel, listCorpAll, loginUser} from "../../../common/tool";
import UniSection from "../../../components/uni-section/components/uni-section/uni-section";
import ZqsSelect from '../../../components/zqs-select/zqs-select.vue'
	export default {
    components: {
      UniSection, ZqsSelect
    },
		data() {
			return {
        noClick: true,
        form:{
          CORPINFO_ID: '',
          APPLY_CONTENT: ''
        },
        dictData:{
          // 企业列表
          APPLY_CORP: {
            index: -1,
            list:[],
            tempList:[]
          },
        }
			}
		},
    mounted() {
      this.getDictList()
    },
    methods: {
      async getDictList(){
        // 准驾车型
        this.dictData.APPLY_CORP.list = await listCorpAll({ISDELETE: '0'});
        this.dictData.APPLY_CORP.tempList = JSON.parse(JSON.stringify(this.dictData.APPLY_CORP.list));

      },
      searchSelect(e, name) {
        console.log('查询事件参数', e)
        this.dictData.APPLY_CORP.list = JSON.parse(JSON.stringify(this.dictData.APPLY_CORP.tempList));
        if (e) {
          this.dictData.APPLY_CORP.list = this.dictData[name].list.filter(item => item.CORP_NAME.indexOf(e) > -1);
        }
      },
			//跳转事件
      confirm(e) {
        var that = this
        uni.showModal({
          title: '温馨提示',
          content: '确定要提交申请吗？',
          cancelColor: "#000000",
          cancelText: '取消',
          confirmText: '确定',
          success: res => {
            if (res.confirm) {
              uni.request({
                url: basePath+'/app/user/setPractitionerEntryByUser',
                method: 'POST',
                dataType: 'json',
                header: {
                  'Content-type':'application/x-www-form-urlencoded'
                },
                data: {
                  ...that.form,
                  USER_ID: loginUser.USER_ID,
                  NAME: loginUser.NAME
                },
                success: (res) => {
                  uni.hideLoading();
                  if ("success" == res.data.result) {
                    uni.showToast({
                      icon:'none',
                      title: '申请提交成功',
                      duration: 1500
                    });
                    that.goback()
                  }else{
                    uni.hideLoading();
                    uni.showToast({
                      icon:'none',
                      title: '系统错误',
                      duration: 2000
                    });
                  }
                }
              });
            } else {
              uni.hideLoading();
            }
          }
        })
			},
      validateData() {
        if (!this.form.CORPINFO_ID) {
          uni.showToast({
            icon: 'none',
            title: '请选择入职企业',
            duration: 2000
          });
          return false;
        }
        return true;
      },
      goback(){
        var pages = getCurrentPages();	// 获取当前页面栈
        var prePage = pages[pages.length - 2];	// 上二级页面
        prePage.$vm.initflag = true;    // A 页面 init方法 为true
        uni.navigateBack({delta: 1});
        uni.hideLoading();
      },
		}
	}
</script>

<style>
	page{
		background-color: #f3f2f2;
	}
  .prevent {
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    overflow: hidden;
  }
  .cu-form-title{
    padding: 20upx 0;
  }
  .cu-form-textarea{
    background-color: #ffffff;
    padding: 1upx 30upx 20upx;
    min-height: 100upx;
  }
  .cu-form-textarea textarea {
    height: 4.6em;
    width: 100%;
    line-height: 1.2em;
    flex: 1;
    font-size: 28upx;
    padding: 0;
  }
  .selected{
    display: flex;
    align-items: center;
    height: 100upx;
  }
  .selected .radio{
    transform:scale(0.8);
    margin-right: 10upx;
  }
  .group{
    display: flex;
    align-items: center;
  }
  .cu-form-group .title{
    font-size: 28upx;
    font-weight: bold;
  }
  .cu-bar .action:first-child {
    font-size: 28upx;
  }
  .cu-form-group .picker{
    color: #808080;
  }
  .picker-tree{
    color: #808080;
  }
</style>
