import React, { Component } from "react";
import Taro from "@tarojs/taro";
import { Button, Text, View, Radio, RadioGroup, Label } from "@tarojs/components";
import dayjs from "dayjs";
import "./index.less";

import ImagePicker from "../../components/common/imagePicker";

import { AtButton, AtTextarea, AtIcon, AtCalendar } from "taro-ui";
import {
  addPublicRelease,
  getWorkingHoursList,
  checkOrderNoDuration,
  getRestrictProjectUser,
} from "../../utils/servers/servers";

import {
  getHours,
  getNumHourse,
  getUserWordTimes,
  getNameList,
  isPublicity,
} from "../../utils/tools";

import "taro-ui/dist/style/components/form.scss";
import "taro-ui/dist/style/components/button.scss";
import "taro-ui/dist/style/components/loading.scss";
import "taro-ui/dist/style/components/icon.scss";
import "taro-ui/dist/style/components/icon.scss";
import "taro-ui/dist/style/components/textarea.scss";
import "taro-ui/dist/style/components/calendar.scss";

import "./publicContent.less";
import InquiryModal from "../../components/common/inquiryModal"; //提示弹窗
import UserQuery from "../../components/common/userquery"; //选择协单人弹窗
import CheckboxPicker from "../../components/common/CheckboxPicker";
import { assistTypeList, assistContentList } from "../../utils/tools/config";
import { Fragment } from "react";

class PublicContent extends Component {
  constructor(props) {
    super(props);
    this.state = {
      rangeStartVal: "",
      rangeEndVal: "",
      rangeEndMinuteVal: "",
      rangeStartMinuteVal: "",
      reason: "",
      plan: "",
      expectedEffect: "",
      imgs: [],
      validDates: [],
      totalDuration: 0,
      loading: false,
      workTypeList: [],
      workType: 0,
      isPickerRender: false,
      coorderList: [],
      cList: [],
      popup: false,
      isNewshow: false,
      alone: 1, // 0非协单 1协单一起 2技术单独协单

      assistType: '',
      assistTypeName: '',
      assistContentType: '',
      assistContentTypeName: '',
      assistContent: '',

      multiplePickerShow: false,
      multiplePickerType: '',
      multiplePickerTitle: '',
      multiplePickerOptions: [],
      multiplePickerCheckedList: [],
    };
    this.onSubmit = this.onSubmit.bind(this);
    this.selectArrder = this.selectArrder.bind(this);
    this.onChange = this.onChange.bind(this);
    this.getWorkingHoursList = this.getWorkingHoursList.bind(this);
    this.onPickerHide = this.onPickerHide.bind(this);
    this.onSetPickerTime = this.onSetPickerTime.bind(this);
    this.getNumHourse = this.getNumHourse.bind(this);
    this.handleOpenMultiplePicker = this.handleOpenMultiplePicker.bind(this)
    this.handleMultipleConfirm = this.handleMultipleConfirm.bind(this)
  }

  componentDidMount() {
    Taro.eventCenter.on("result", () => {
      this.imagePickerRef && this.imagePickerRef.clear();
      this.setState({
        rangeStartVal: "",
        rangeEndVal: "",
        rangeEndMinuteVal: "",
        rangeStartMinuteVal: "",
        reason: "",
        plan: "",
        expectedEffect: "",
        imgs: [],
        validDates: [],
        totalDuration: 0,
        loading: false,
      });
    });
    this.getWorkingHoursList();
  }

  getNumHourse(startTime, endTime) {
    this.setState({
      totalDuration: getNumHourse(
        startTime,
        endTime,
        this.state.validDates.length
      ),
    });
  }

  // 增加 省 市 区拼接，地址带区域的则把区域去掉
  getArea() {
    const { selectArrderLocation } = this.props

    if (!Object.keys(selectArrderLocation).length) {
      return ''
    }

    let address = selectArrderLocation.name;
    let defaultProvince = selectArrderLocation.province || "";
    let defaultCity = selectArrderLocation.city || "";
    let defaultDistrict = selectArrderLocation.district || "";

    // 假设省市区的关键字有 "省", "市", "区"
    const provinceKeyword = '省';
    const cityKeyword = '市';
    const districtKeyword = '区';

    // 判断是否包含省市区关键字，如果不包含则进行补全
    if (address.indexOf(provinceKeyword) === -1) {
      address = `${defaultProvince}${address}`;
    }
    if (address.indexOf(cityKeyword) === -1) {
      address = address.replace(provinceKeyword, `${provinceKeyword}${defaultCity}`);
    }
    if (address.indexOf(districtKeyword) !== -1 && address.indexOf("小区") !== -1) {
      address = address.replace(cityKeyword, `${cityKeyword}${defaultDistrict}`);
    } else if (address.indexOf(districtKeyword) === -1) {
      address = address.replace(cityKeyword, `${cityKeyword}${defaultDistrict}`);
    }
    return address;
  }

  onSubmit() {
    let objectType = this.props.enterpriseInfor.id.indexOf(',') > -1 ? 1 : 0
    const { selectArrderLocation } = this.props
    let addressName = ''  
    let longitude = ''
    let latitude = ''
    if (Object.keys(selectArrderLocation).length) {
      addressName = selectArrderLocation.province + selectArrderLocation.city + selectArrderLocation.district
      longitude = selectArrderLocation.longitude
      latitude = selectArrderLocation.latitude
    }
    this.setState({
      loading: true,
    });
    let datas = {
      objectType,
      uids: this.props.enterpriseInfor.id,
      releaseStarts: this.state.rangeStartMinuteVal,
      releaseEnds: this.state.rangeEndMinuteVal,
      districtName: this.getArea(),
      addressName,
      longitude,
      latitude,
      annexUrl: this.state.imgs.length === 0 ? "" : this.state.imgs.join(","),
      duration: this.state.totalDuration,
      type: this.props.enterpriseInfor.type,
      validDate: JSON.stringify(this.state.validDates),
      alone: this.state.coorderList.length === 0 ? 0 : this.state.alone,
      assist: this.state.coorderList.length === 0 ? 0 : 1,
      assistAid: this.state.coorderList.length === 0 ? "" : this.state.coorderList.join(","),
      assistAidName: this.state.coorderList.length === 0 ? "" : getNameList(this.state.coorderList, this.state.cList).join(","),
    };
    if (this.props.enterpriseInfor.type == 0) {
      if (this.props.uaiIdList.length) {
        datas.uais = this.props.uaiIdList.join(',');
      }
      if (this.state.cList.length) {
        datas.assistType = this.state.assistType
        datas.assistContentType = this.state.assistContentType
        // 协单类型内容补充
        datas.assistContent = this.state.assistContent
      }
    } else if (this.props.enterpriseInfor.type == 2) {
      datas = { ...datas, remarks: this.state.reason };
    } else if (this.props.enterpriseInfor.type == 5) {
      datas = {
        ...datas,
        assistType: this.state.assistType,
        assistContentType: this.state.assistContentType,
        // 协单类型内容补充
        assistContent: this.state.assistContent,
        remarks: this.state.reason,
        plan: this.state.plan,
        expectedEffect: this.state.expectedEffect,
        duration: 0,
      }
    } else {
      datas = {
        ...datas,
        ...{
          remarks: this.state.reason,
          plan: this.state.plan,
          expectedEffect: this.state.expectedEffect,
          orderNo: this.props.enterpriseInfor.orderNo,
        }
      };
    }

    addPublicRelease(datas)
      .then((v) => {
        this.setState({
          loading: false,
        });
        let newData = {
          ...v.data,
          ...{
            isShow: this.props.enterpriseInfor.type == 0
              ? isPublicity(this.props.enterpriseInfor.userList, 0) : this.props.enterpriseInfor.type == 1
                ? this.state.isNewshow : false,
            list: isPublicity(this.props.enterpriseInfor.userList, 1)
          }
        }
        if (v.error.length === 0) {
          Taro.eventCenter.trigger("publicContent", newData);
        } else {
          Taro.showToast({
            title: v.error[0].message,
            icon: "none",
          });
        }
      })
      .catch(() => {
        this.setState({
          loading: false,
        });
      });
  }

  selectArrder() {
    const key = "AWBBZ-GRAC2-JFYUO-CLA7I-JAHXK-YFFGT"; //使用在腾讯位置服务申请的key
    const referer = "科德打卡定位"; //调用插件的app的名称
    const category = "公司企业,房产小区";
    Taro.navigateTo({
      url:
        "plugin://chooseLocation/index?key=" +
        key +
        "&referer=" +
        referer +
        "&category=" +
        category,
    });
  }

  onChange(value, type) {
    let arr = this.state.imgs.concat([]);
    if (type === "add") {
      arr.push(value);
    } else if (type === "remove") {
      arr.splice(value, 1);
    }
    this.setState({
      imgs: arr,
    });
  }

  getWorkingHoursList() {
    getWorkingHoursList({})
      .then((v) => {
        if (v.error.length === 0) {
          let obj = Taro.getStorageSync("userInfor");
          let index = v.data.findIndex(
            (value) => value.type === obj.workTimeInfor.type
          );
          this.setState({
            workType: index !== -1 ? index : 0,
          });
          this.setState({
            workTypeList: v.data,
          });
        } else {
          Taro.showToast({
            title: v.error[0].message,
            icon: "none",
          });
        }
      })
      .catch((err) => {
        //console.log(err);
      });
  }

  onPickerHide() {
    this.setState({
      isPickerRender: false,
    });
  }

  onSetPickerTime(val) {
    let data = val.detail;
    
    if(this.props.enterpriseInfor.type == 5) {
      data.selectStartTime = dayjs(data.selectStartTime).format('YYYY-MM-DD 08:30:00')
      data.selectEndTime = dayjs(data.selectEndTime).format('YYYY-MM-DD 17:30:00')
      data.startTime = dayjs(data.startTime).format('YYYY-MM-DD 08:30:00')
      data.endTime = dayjs(data.endTime).format('YYYY-MM-DD 17:30:00')
    }

    let rangeStartMinuteVal = data.selectStartTime;
    let rangeEndMinuteVal = data.selectEndTime;

    if (this.props.enterpriseInfor.type == 5) {
      rangeStartMinuteVal = dayjs(data.selectStartTime).format('YYYY-MM-DD');
      rangeEndMinuteVal = dayjs(data.selectEndTime).format('YYYY-MM-DD');
    }
    this.setState({ rangeStartMinuteVal, rangeEndMinuteVal });
    let arr = [];
    if (data.startTime && data.endTime) {
      let a = dayjs(data.startTime);
      let b = dayjs(data.endTime);
      let num;
      if (a.hour() <= b.hour()) {
        num = b.diff(a, "day") + 1;
      } else {
        num = b.diff(a, "day") + 2;
      }
      let strAdd = data.startTime;
      for (let i = 0; i < num; i++) {
        let time = dayjs(strAdd).add(i, "days").format("YYYY-MM-DD");
        arr.push({ value: time });
      }
    }
    this.setState({
      rangeEndVal: dayjs(data.endTime).format("YYYY-MM-DD"),
      rangeStartVal: dayjs(data.startTime).format("YYYY-MM-DD"),
      validDates: arr,
    }, () => {
      let a1 = dayjs(dayjs(data.endTime).format("YYYY-MM-DD HH:mm:ss"));
      let b1 = dayjs(dayjs(data.startTime).format("YYYY-MM-DD  HH:mm:ss"));
      this.getNumHourse(b1, a1);
    });
  }
  // 新增技术协单
  setList(list, arr) {
    this.setState({
      cList: list,
      coorderList: arr
    })
  }
  // 弹窗开关
  popupClick() {
    this.setState({
      popup: !this.state.popup
    })
  }
  // 技术公出逻辑判断
  checkOrderNoDuration() {
    const _this = this
    if (this.state.totalDuration == 0) {
      Taro.showToast({ title: "请选择公出时间", icon: "none" });
      return
    }
    checkOrderNoDuration({
      duration: this.state.totalDuration,
      orderNo: this.props.enterpriseInfor.orderNo,
    })
      .then((v) => {
        if (v.error.length == 0) {
          if (!v.data.code) {
            let obj = v.data.data
            _this.setState({
              isNewshow: true,
              isInquiryOpened: true,
              inquiryTitle: "提醒",
              inquiryContent: <View style={{ padding: "10px 15px" }}>
                <View>您准备公出<Text style={{ color: 'red' }}>{obj.userName}（{obj.contractNo}）</Text>，</View>
                <View>总计公出：<Text style={{ color: 'red' }}>{obj.peopleCount}人，{obj.timesCount}次，{obj.durationCount}时</Text>。</View>
                <View>
                  <Text style={{ color: 'red' }}>
                    {obj.amountName}，{obj.amountType}
                  </Text>。
                </View>
                <View>如需公出，需<Text style={{ color: 'red' }}>{obj.adminName}</Text>审核。</View>
                <View>请确定，是否发起公出申请！</View>
              </View>,
              inquiryFn: () => {
                _this.onSubmit();
              },
            })
          } else {
            _this.setState({
              isNewshow: false,
              isInquiryOpened: true,
              inquiryTitle: "提醒",
              inquiryContent: "您确定要提交此申请吗?",
              inquiryFn: () => {
                _this.onSubmit();
              },
            })
          }
        } else {
          Taro.showToast({
            title: v.error[0].message,
            icon: "none",
          });
        }
      })
      .catch(() => {
        this.setState({
          loading: false,
        });
      });
  }
  // 业务公出限定项目
  getRestrictProjectUser() {
    const _this = this
    getRestrictProjectUser({
      ids: this.props.enterpriseInfor.id,
    })
      .then((v) => {
        if (v.error.length === 0) {
          let arr = []
          if (v.data && v.data.length > 0) {
            v.data.forEach(e => {
              e.type == 1 && arr.push(e["userName"])
            })
          }
          this.setState({
            isInquiryOpened: true,
            inquiryTitle: "提醒",
            inquiryContent: arr.length > 0
              ? <View style={{ color: 'red' }}>您公出的{arr.toString()}，为限定项目的企业，建议您由经理协助公出恰谈！</View>
              : "您确定要提交此申请吗?",
            inquiryFn: () => {
              _this.onSubmit();
            },
          });
        } else {
          Taro.showToast({
            title: v.error[0].message,
            icon: "none",
          });
        }
      })
      .catch((err) => {

      });
  }

  // 公出类型名称
  getBusTripTypeName() {
    let str  = ''
    switch (this.props.enterpriseInfor.type) {
      case 0:
        str = '业务公出'
        break;
      case 1:
        str = '技术公出'
        break;
      case 2:
        str = '行政公出'
        break;
      case 3:
        str = '技术协单'
        break;
      case 5:
        str = '非公出协单'
        break;
      case 6:
        str = '非公出协单'
        break;
      default:
        break;
    }
    return str
  }

  handleOpenMultiplePicker(type) {
    let multiplePickerOptions = [];
    let multiplePickerTitle = '';
    let multiplePickerCheckedList = [];
    const { assistType, assistContentType } = this.state;
    switch (type) {
      case 'assistType':
        // 协单项目类型
        multiplePickerOptions = assistTypeList;
        multiplePickerCheckedList = assistType ? assistType.toString().split(',') : []
        multiplePickerTitle = '请选择协单项目类型';
        break;
      case 'assistContentType':
        // 协单项目内容
        multiplePickerOptions = assistContentList;
        multiplePickerCheckedList = assistContentType ? assistContentType.toString().split(',') : []
        multiplePickerTitle = '请选择协单项目内容';
        break;
      default:
        break;
    }

    this.setState({
      multiplePickerShow: true,
      multiplePickerType: type,
      multiplePickerTitle,
      multiplePickerOptions,
      multiplePickerCheckedList: multiplePickerCheckedList
    })
  }

  handleMultipleConfirm(selectedIds, selectedLabels) {
    const { multiplePickerType } = this.state;
    switch (multiplePickerType) {
      case "assistType":
        // 协单项目类型
        this.setState({
          assistType: selectedIds.join(','),
          assistTypeName: selectedLabels.join(',')
        })
        break;
      case "assistContentType":
        // 协单项目内容
        this.setState({
          assistContentType: selectedIds.join(','),
          assistContentTypeName: selectedLabels.join(',')
        })
        break;
      default:
        break;
    }
  }

  render() {
    const { cList, coorderList, popup } = this.state
    const info = Taro.getStorageSync("userInfor");
    return (
      <View className="publicContent">
        <View className="formItem">
          <View className="formName">公出企业:</View>
          <View className="formValue" style={{ flexDirection: "column", alignItems: "flex-end" }}>
            {
              !!this.props.enterpriseInfor.name && this.props.enterpriseInfor.name.indexOf(',') > -1
                ? this.props.enterpriseInfor.name.split(',')?.map((item, index) => <View key={index}>{item}</View>)
                : this.props.enterpriseInfor.name
            }
          </View>
        </View>
        {
          (this.props.enterpriseInfor.type == 0 && isPublicity(this.props.enterpriseInfor.userList, 0)) &&
          <View className="othersTips">您正在申请公出他人企业：需跟单员“
            {isPublicity(this.props.enterpriseInfor.userList, 1).toString()}
            ”审核同意，您才可公出!</View>
        }
        <View className="formItem">
          <View className="formName">公出类型:</View>
          <View className="formValue">{this.getBusTripTypeName()}</View>
        </View>
        {this.props.enterpriseInfor.contractNo ? (
          <View className="formItem">
            <View className="formName">合同编号:</View>
            <View className="formValue">
              {this.props.enterpriseInfor.contractNo}
            </View>
          </View>
        ) : (
          ""
        )}
        <View className="formItem">
          <View className="formName">作息时间类型:</View>
          <View className="formValue">
            {this.state.workTypeList[this.state.workType]
              ? this.state.workTypeList[this.state.workType].name
              : ""}
          </View>
        </View>
        <View className="formItem">
          <View className="formName">公出时间:</View>
          <View className="formValue">
            <View
              className="time"
              onClick={() => {
                this.setState({
                  isPickerRender: true,
                });
              }}
            >
              {this.state.rangeStartMinuteVal &&
                this.state.rangeEndMinuteVal ? (
                <View className="timeContent">
                  <View>开始时间:{this.state.rangeStartMinuteVal}</View>
                  <View>结束时间:{this.state.rangeEndMinuteVal}</View>
                </View>
              ) : (
                "请选择公出时间"
              )}
            </View>
            { this.state.isPickerRender && (
              <timePicker
                config={{
                  endDate: true,
                  column: this.props.enterpriseInfor.type == 5 ? "day" : 'minute',
                  dateLimit: false,
                  initStartTime: this.state.rangeStartMinuteVal, //默认开始时间
                  initEndTime: this.state.rangeEndMinuteVal,   //默认结束时间
                  limitStartTime: dayjs()
                    .subtract(3, "year")
                    .format("YYYY-MM-DD HH:mm:ss"),
                  limitEndTime: dayjs()
                    .add(3, "year")
                    .format("YYYY-MM-DD HH:mm:ss"),
                }}
                isPartition
                pickerShow={this.state.isPickerRender}
                onconditionaljudgment={(v) => {
                  const { enterpriseInfor } = this.props
                  let formatTemp = enterpriseInfor.type == 5 ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm:ss"
                  let selTimeStr = dayjs(v.detail.startTime).second(0).format(formatTemp)
                  let selEndTimeStr = dayjs(v.detail.endTime).second(0).format(formatTemp)
                  
                  let startTimeD = dayjs(enterpriseInfor.type == 5 ? `${selTimeStr} 00:00:00` : selTimeStr);
                  let endTimeD = dayjs(enterpriseInfor.type == 5 ? `${selEndTimeStr} 23:59:59` : selEndTimeStr);

                  let now = dayjs()
                  let currTime = enterpriseInfor.type == 5 ? now.subtract(1, 'day').set('hour', 23).set('minute', 59).set('second', 59) : dayjs().second(0)

                  let currTimeD = dayjs(currTime.format("YYYY-MM-DD HH:mm:ss"));
                  if (!startTimeD.isAfter(currTimeD)) {
                    Taro.showToast({
                      title: "开始时间不能小于当前时间",
                      icon: "none",
                    });
                    v.detail.setLv(false);
                  } else if (!endTimeD.isAfter(startTimeD)) {
                    Taro.showToast({
                      title: "结束时间不能小于开始时间",
                      icon: "none",
                    });
                    v.detail.setLv(false);
                  }
                }}
                onhidepicker={() => {
                  this.onPickerHide();
                }}
                onsetpickertime={(v) => {
                  this.onSetPickerTime(v);
                }}
              />
            ) }
          </View>
        </View>
        { this.props.enterpriseInfor.type != 5 ? (
          <View className="formItem">
            <View className="formName">总时长:</View>
            <View className="formValue">{this.state.totalDuration}小时</View>
          </View>
        ) : null }
        {this.state.validDates.length !== 0 ? (
          <View
            className="formItem"
            style={{ display: "block", paddingTop: "15px" }}
          >
            <View className="formName">
              <View>去除放假时间:</View>
            </View>
            <View className="tips">
              绿色方块为公出时间,长按即可去除放假时间
            </View>
            <AtCalendar
              currentDate={this.state.rangeStartVal}
              minDate={this.state.rangeStartVal}
              maxDate={this.state.rangeEndVal}
              isSwiper={false}
              validDates={this.state.validDates}
              onDayLongClick={(item) => {
                if (
                  !(
                    dayjs(item.value).isSame(this.state.rangeStartVal) ||
                    dayjs(item.value).isSame(this.state.rangeEndVal)
                  )
                ) {
                  if (
                    !(
                      dayjs(item.value).isAfter(this.state.rangeStartVal) &&
                      dayjs(item.value).isBefore(this.state.rangeEndVal)
                    )
                  ) {
                    return;
                  }
                } else {
                  Taro.showToast({
                    title: "开始结束时间不能取消",
                    icon: "none",
                  });
                  return;
                }
                let index = this.state.validDates.findIndex((v) => {
                  let lv = dayjs(v.value).isSame(item.value);
                  return lv;
                });
                const { start, end } = getUserWordTimes();
                let totalDuration = getHours(
                  dayjs().format("YYYY-MM-DD") + start,
                  dayjs(dayjs().format("YYYY-MM-DD") + end)
                ); //一天工作时长
                if (index < 0) {
                  let arr = item.value.split("-");
                  this.state.validDates.push({ value: arr.join("-") });
                  this.setState({
                    validDates: this.state.validDates,
                    totalDuration: this.state.totalDuration + totalDuration,
                  });
                } else {
                  this.state.validDates.splice(index, 1);
                  this.setState({
                    validDates: this.state.validDates,
                    totalDuration: this.state.totalDuration - totalDuration,
                  });
                }
              }}
            />
          </View>
        ) : null}
        <View className="formItem" style={{ paddingBottom: 0 }}>
          <View className="formName">公出地点:</View>
          <View className="formValue" onClick={this.selectArrder}>
            <Text className="formValueText">
              {this.props.selectArrderLocation.name}
            </Text>
            <AtIcon value="chevron-right" size="30" color="#bbbbbb" />
          </View>
        </View>
        <View className="tips">
          以地图为中心100米范围为可打卡区域,移动红标只需要拖动地图即可
        </View>
        {
          [0, 5].indexOf(this.props.enterpriseInfor.type) > -1 &&
          <View className="formItems" style={{ alignItems: "center", paddingBottom: 0, marginTop: 10 }}>
            <View className="formNames">技术协单: </View>
            <View className="formValues" style={{ alignItems: "center" }}>
              {
                cList.length == 0
                  ? <Text>无</Text>
                  : cList.map((item, index) =>
                    <View className="fitems" key={index}>
                      {item.name}
                      <View className="fclose"
                        onClick={() => {
                          coorderList.includes(item.id) &&
                            (
                              cList.splice(coorderList.indexOf(item.id), 1),
                              coorderList.splice(coorderList.indexOf(item.id), 1)
                            )
                          this.setState({
                            cList,
                            coorderList,
                          })
                        }}
                      ><AtIcon value="close-circle" size="15" color="#bbbbbb" /></View>
                    </View>
                  )
              }
              {cList.length < 5 && <Button className="addbuttom" type='primary' onClick={this.popupClick.bind(this)}>新增技术协单</Button>}
            </View>
          </View>
        }
        {
          [0, 5].indexOf(this.props.enterpriseInfor.type) > -1 &&
          <View className="tips">
            请与技术协商后，再发起协单，协单将统计公出成本等
          </View>
        }
        {
          cList.length >= 1 &&
          <View
            className="formItem"
            style={{ paddingBottom: 0, marginTop: 10 }}
          >
            <View className="formName">
              <Text>本人公出:</Text>
            </View>
            <View>
              <RadioGroup
                onChange={e => {
                  this.setState({
                    alone: e.detail.value
                  })
                }}
              >
                {[{ text: "是，一同公出", value: 1 },
                { text: "否，本人不公出", value: 2 }].map((item, i) => {
                  return (
                    <Radio
                      style={{ marginLeft: 10 }}
                      key={i}
                      value={item.value}
                      checked={item.value == this.state.alone}>
                      {item.text}
                    </Radio>
                  )
                })}
              </RadioGroup>
            </View>
          </View>
        }

        { this.props.enterpriseInfor.type == 5 || (this.props.enterpriseInfor.type == 0 && this.state.cList.length >= 1 ) ? (
          <Fragment>
            <View className="formItem">
              <View className="formName"><Text style={{ color: "red" }}>*</Text>协单类型:</View>
              <View className="formValue" onClick={() => this.handleOpenMultiplePicker('assistType')}>
                <Text className="formValueText">
                  { this.state.assistTypeName }
                </Text>
                <AtIcon value="chevron-right" size="30" color="#bbbbbb" />
              </View>
            </View>
            <View className="formItem">
              <View className="formName"><Text style={{ color: "red" }}>*</Text>协单内容:</View>
              <View className="formValue" onClick={() => this.handleOpenMultiplePicker('assistContentType')}>
                <Text className="formValueText">
                  { this.state.assistContentTypeName }
                </Text>
                <AtIcon value="chevron-right" size="30" color="#bbbbbb" />
              </View>
            </View>
            { this.state.assistContentType.indexOf('0') > -1 ? (
              <View className="formItem">
                <View className="formName"><Text style={{ color: "red" }}>*</Text>内容说明:</View>
                <View
                className="formValue"
                style={{ paddingTop: "10px", textAlign: "left" }}
                >
                <AtTextarea
                    height={46}
                    value={this.state.assistContent}
                    onChange={(v) => {
                    this.setState({
                      assistContent: v,
                    });
                    }}
                    count={false}
                    maxLength={1000}
                    placeholder="请输入协单内容说明"
                />
                </View>
              </View>
            ) : null }
          </Fragment>
        ) : null }
        
        <View
          className="formItem"
          style={{ display: "block", paddingTop: "10px" }}
        >
          {/* 公出目标 */}
          {[1, 2, 5].indexOf(this.props.enterpriseInfor.type) > -1 && (
            <View className="formName">
                <Text><Text style={{ color: "red" }}>*</Text>公出目标:</Text>
                <View
                className="formValue"
                style={{ paddingTop: "10px", textAlign: "left" }}
                >
                <AtTextarea
                    height={46}
                    value={this.state.reason}
                    onChange={(v) => {
                    this.setState({
                        reason: v,
                    });
                    }}
                    count={false}
                    maxLength={1000}
                    placeholder={
                    this.props.enterpriseInfor.type == 2
                        ? "详细说明本次公出的内容，预计完成的内容"
                        : "本次公出目标，谈的思路与步骤？"
                    }
                />
                </View>
            </View>
          )}
          
          {/* 公出计划 */}
          {[1, 5].indexOf(this.props.enterpriseInfor.type) > -1 && (
            <View className="formName">
              <Text><Text style={{ color: "red" }}>*</Text>公出计划:</Text>
              <View
                className="formValue"
                style={{ paddingTop: "10px", textAlign: "left" }}
              >
                <AtTextarea
                  height={46}
                  value={this.state.plan}
                  onChange={(v) => {
                    this.setState({
                      plan: v,
                    });
                  }}
                  count={false}
                  maxLength={1000}
                  placeholder="本次公出准备工作"
                />
              </View>
            </View>
          )}
          {/* 预计效果 */}
          {[1, 5].indexOf(this.props.enterpriseInfor.type) > -1 && (
            <View className="formName">
              <Text><Text style={{ color: "red" }}>*</Text>预计效果:</Text>
              <View
                className="formValue"
                style={{ paddingTop: "10px", textAlign: "left" }}
              >
                <AtTextarea
                  height={46}
                  value={this.state.expectedEffect}
                  onChange={(v) => {
                    this.setState({
                      expectedEffect: v,
                    });
                  }}
                  maxLength={200}
                  placeholder="预计本次公出效果"
                />
              </View>
            </View>
          )}
        </View>
        {/*  */}
        <View className="formItem" style={{ display: "block", paddingBottom: 0 }}>
          <View className="formName">
            {this.state.totalDuration > info.workTimeInfor.minHours && ![5, 6].includes(this.props.enterpriseInfor.type) && <Text style={{ color: "red" }}>*</Text>}
            附件:
          </View>
          {this.state.totalDuration > info.workTimeInfor.minHours &&
            <View className="tips">
              请上传公出事由的凭证截图，如您与企业的对话截图等
            </View>}
          <View
            className="formValue"
            style={{ paddingTop: "10px", textAlign: "left" }}
          >
            <ImagePicker
              showAddBtn
              ref={(ref) => (this.imagePickerRef = ref)}
              url="/api/admin/release/upload"
              onChange={this.onChange}
            />
          </View>
        </View>
        <View className="operation">
          <AtButton
            disabled={this.state.loading}
            type="secondary"
            circle
            onClick={() => {
              Taro.eventCenter.trigger("enterpriseBack");
            }}
          >
            上一步
          </AtButton>
          <AtButton
            type="primary"
            loading={this.state.loading}
            circle
            onClick={() => {
              if (this.state.loading) {
                return;
              }
              const { type } = this.props.enterpriseInfor
              if (!this.state.rangeStartMinuteVal) {
                Taro.showToast({ title: "请选择公出时间", icon: "none" });
                return;
              }
              if (!this.state.rangeEndMinuteVal) {
                Taro.showToast({ title: "请选择公出时间", icon: "none" });
                return;
              }
              if (
                type != 5 && !(
                  this.props.selectArrderLocation.longitude &&
                  this.props.selectArrderLocation.latitude
                )
              ) {
                Taro.showToast({ title: "请选择公出地点", icon: "none" });
                return;
              }

              if (type == 5 && !this.state.cList.length) {
                Taro.showToast({ title: "请选择协单人", icon: "none" });
                return;
              }

              if(type == 5 || (type == 0 && this.state.cList.length)) {
                if (!this.state.assistType) {
                  Taro.showToast({ title: "请选择协单类型", icon: "none" });
                  return
                }
                if (!this.state.assistContentType) {
                  Taro.showToast({ title: "请选择协单内容", icon: "none" });
                  return
                }
                if (this.state.assistContentType.indexOf('0') > -1 && !this.state.assistContent) {
                  Taro.showToast({ title: "请输入协单内容说明", icon: "none" });
                  return
                }
              }

              if (type !=0 && !this.state.reason) {
                Taro.showToast({ title: "请输入公出目标", icon: "none" });
                return;
              }
              if ((type == 1 || type == 5) && !this.state.plan) {
                Taro.showToast({ title: "请输入公出计划", icon: "none" });
                return;
              }
              if ((type == 1 || type == 5) && !this.state.expectedEffect) {
                Taro.showToast({ title: "请输入预计效果", icon: "none" });
                return;
              }
              if (this.state.totalDuration === 0) {
                Taro.showToast({
                  title: "请选择公出时间，目前设置公出时间不足0.5小时",
                  icon: "none",
                });
                return;
              }
              let info = Taro.getStorageSync("userInfor");
              if (type != 5 && this.state.totalDuration > info.workTimeInfor.minHours && this.state.imgs.length == 0) {
                Taro.showToast({ title: "请上传附件", icon: "none" });
                return
              }

              type == 1 ? this.checkOrderNoDuration() : type == 0
                ? this.getRestrictProjectUser()
                : this.setState({
                  isInquiryOpened: true,
                  inquiryTitle: "提醒",
                  inquiryContent: "您确定要提交此申请吗?",
                  inquiryFn: () => {
                    this.onSubmit();
                  },
                });
            }}
          >
            提交申请
          </AtButton>
        </View>
        <InquiryModal
          isOpened={this.state.isInquiryOpened}
          title={this.state.inquiryTitle}
          content={this.state.inquiryContent}
          onClose={() => {
            this.setState({
              isInquiryOpened: false,
              inquiryTitle: "",
              inquiryContent: "",
            });
          }}
          onDetermine={() => {
            this.state.inquiryFn();
            this.setState({
              isInquiryOpened: false,
              inquiryTitle: "",
              inquiryContent: "",
              inquiryFn: () => { },
            });
          }}
        />
        {
          popup &&
          <UserQuery
            isOpened={popup}
            onDesc={this.popupClick.bind(this)}
            cList={cList}
            selList={[]}
            coorderList={coorderList}
            setList={this.setList.bind(this)}
          />
        }

        {/* 多选框 */}
        <CheckboxPicker
          isOpened={this.state.multiplePickerShow}
          title={this.state.multiplePickerTitle}
          options={this.state.multiplePickerOptions}
          checkedList={this.state.multiplePickerCheckedList}
          onClose={() => { this.setState({ multiplePickerShow: false, multiplePickerCheckedList: [] }) }}
          onConfirm={this.handleMultipleConfirm}
        ></CheckboxPicker>
      </View >
    );
  }
}

export default PublicContent;
