<template>
  <div class="goreport">
    <div class="form gaisideshurukuang">
      <uni-forms
        ref="baseForm"
        style="font-size: 26rpx"
        :modelValue="form"
        label-width="170rpx"
      >
        <uni-forms-item
          label="走访公司"
          class="mt42rpx pd42rpx border_bottom_ccc"
        >
          <div
            @click="chosseAboutCompany()"
            style="height: 73rpx; line-height: 73rpx"
          >
            <picker
              style="float: left; width: 440rpx; height: 40rpx; color: #777"
              @change="getCompany"
              range-key="label"
              :range="companyAllList"
            >
              {{
                !form.companyId
                  ? "请选择走访公司"
                  : companyAllList[form.companyIndex].label
              }}
            </picker>
          </div>
        </uni-forms-item>
        <uni-forms-item
          label="走访时间："
          class="mt42rpx pd42rpx border_bottom_ccc"
        >
          <div style="height: 73rpx; line-height: 73rpx">
            <picker
              style="float: left; width: 100%; height: 40rpx; color: #777"
              mode="date"
              :value="form.interviewTime"
              @change="getInterviewTime"
            >
              {{ !form.interviewTime ? "请选择走访时间" : form.interviewTime }}
            </picker>
          </div>
        </uni-forms-item>

        <uni-forms-item
          label="走访类型："
          class="mt42rpx pd42rpx border_bottom_ccc"
        >
          <div style="height: 73rpx; line-height: 73rpx">
            <picker
              style="float: left; width: 100%; height: 40rpx; color: #777"
              :range="dic_SelectList.interviewType"
              :value="0"
              @change="bindPickerChange"
              range-key="label"
            >
              {{
                !form.interviewType
                  ? "请选择"
                  : dic_SelectList.interviewType[form.interviewTypeIndex].label
              }}
            </picker>
          </div>
        </uni-forms-item>
        <uni-forms-item
          label="是否需要处理"
          class="mt42rpx pd42rpx border_bottom_ccc"
        >
          <div style="height: 73rpx; line-height: 73rpx; width: 100%">
            <span style="color: #777" v-if="form.isStatus == 2">是</span>
            <span style="color: #777" v-if="form.isStatus == 1">否</span>
          </div>
        </uni-forms-item>
      </uni-forms>
    </div>

    <div class="form zoufangjilu" style="margin-bottom: 146rpx">
      <van-row>
        <van-col :span="24"> 走访记录 </van-col>
        <van-col :span="24">
          <div class="margint16rpx">
            <uni-easyinput
              type="textarea"
              inputBorder
              class="textarea_info"
              style="margin-top: 16rpx"
              v-model="form.interviewRecord"
              placeholder="请输入"
            />
          </div>
        </van-col>
      </van-row>
      <uni-forms
        v-if="form.isStatus != 1"
        ref="baseForm"
        style="font-size: 26rpx"
        :modelValue="form"
        label-width="170rpx"
      >
        <uni-forms-item
          label="处理人"
          class="mt42rpx mb42rpx border_bottom_ccc"
        >
          <div style="height: 73rpx; line-height: 73rpx; width: 100%">
            <input
              v-model="form.handleUserName"
              style="
                height: 73rpx;
                line-height: 73rpx;
                width: 100%;
                color: #777;
              "
            />
            <!-- <span style="color: #777">{{ form.handleUserName }}</span> -->
          </div>
        </uni-forms-item>
        <div style="margin-top: 16rpx">
          <van-row>
            <van-col :span="24" style="margin-top: 15rpx"> 处理结果 </van-col>
            <van-col :span="24">
              <div class="margint16rpx">
                <uni-easyinput
                  type="textarea"
                  inputBorder
                  class="textarea_info"
                  style="margin-top: 16rpx"
                  v-model="form.handleResult"
                  placeholder="请输入"
                />
              </div>
            </van-col>
          </van-row>
        </div>

        <uni-forms-item
          label="处理时间"
          class="mt42rpx pd42rpx border_bottom_ccc"
        >
          <div style="height: 73rpx; line-height: 73rpx; width: 100%">
            <span style="color: #777">{{ form.handleTime }}</span>
          </div>
        </uni-forms-item>
      </uni-forms>
    </div>
    <!-- <multiple-select
        v-model="show"
        model="false"
        :all-show="false"
        :data="companyAllList"
        :default-selected="defaultSelected"
        @confirm="confirm"
      ></multiple-select> -->
    <view class="btn-view">
      <button
        class="btn"
        @click="dialogInputConfirm()"
        style="margin-left: 10rpx"
      >
        编辑完成
      </button>
    </view>
  </div>
</template>
    
    <script>
import multipleSelect from "../../../subPackages/components/momo-multipleSelect/momo-multipleSelect";

import {
  getByCodes,
  addInterview,
  getBySaveStatus,
  editInterview,
  getCompanyAll,
  getInterviewDetails,
} from "@/js_sdk/http.js";
import vanRow from "../../../wxcomponents/weapp/dist/row";
import vanCol from "../../../wxcomponents/weapp/dist/col";

// import { findYuanQuList } from "@/js_sdk/http.js";
const form = {
  id: null,
  isStatus: null,
  interviewTime: null,
  interviewType: null,
  interviewTypeIndex: null,
  companyId: null,
  companyIndex: null,
  projectType: "",
  interviewRecord: "",
  associationCompanyString: [],
};
export default {
  components: {
    vanRow,
    vanCol,
    multipleSelect,
  },
  data() {
    return {
      id: "",
      isStatus: 2,
      range: [
        { value: 2, text: "是" },
        { value: 1, text: "否" },
      ],
      defaultSelected: [],
      dic_key: ["interviewType"],
      dic_SelectList: {},
      companyIndex: null,
      companyAllList: [],
      defaultSelected: [],
      show: false,
      active: 0,
      form: { ...form },
      index: 0,
    };
  },
  onLoad: function (option) {
    this.getCompanyAll();
    this.id = option.id; //打印出上个页面传递的参数。\
    this.getByCodes();
  },
  methods: {
    async dialogInputConfirm() {
      let data = await editInterview({ ...this.form });
      if (data.code == 200) {
        this.$showToast("修改成功");
        uni.navigateBack({});
      }
    },
    async getInterviewDetails() {
      let detail = await getInterviewDetails(this.id);
      this.form = detail;
      this.getCompanyIdByApiList({ companyId: detail.companyId });
      this.getInterviewLableByApiList({
        interviewType: this.form.interviewType,
      });
      this.form.isStatus = detail.isStatus;
    },

    getCompanyIdByApiList(params) {
      this.form.companyId = params.companyId;

      let companyIndex = this.companyAllList.findIndex(
        (e) => e.value == params.companyId
      );
      this.form.companyIndex = companyIndex;
    },
    getInterviewLableByApiList(params) {
      let interviewTypeIndex = this.dic_SelectList.interviewType.findIndex(
        (e) => e.value == params.interviewType
      );
      this.form.interviewType =
        this.dic_SelectList.interviewType[interviewTypeIndex].value;
      this.form.interviewTypeIndex = interviewTypeIndex;
    },
    getInterviewTime(e) {
      this.form.interviewTime = e.detail.value;
    },
    async takeParamsGoBack(e) {
      const token = uni.getStorageSync("laocui_user_info");
      let data;
      if (this.form.id) {
        data = await editInterview({
          ...this.form,
          status: e,
          createdBy: JSON.parse(token).user.id,
        });
      } else {
        if (this.form.companyId == null) {
          return this.$showToast("请选择走访公司");
        }
        if (this.form.interviewTime == null || this.form.interviewTime == "") {
          return this.$showToast("请选择走访时间");
        }
        if (this.form.interviewType == null) {
          return this.$showToast("请选择走访类型");
        }
        if (this.form.isStatus == null) {
          return this.$showToast("请选择是否需要处理");
        }
        data = await addInterview({
          ...this.form,
          status: e,
          createdBy: JSON.parse(token).user.id,
        });
      }

      if (data.code == 200) {
        if (e == 1) {
          this.$emit("changeActive");
          this.$showToast("提交成功");
          this.form = { ...form };
        }
        if (e == 0) {
          this.$showToast("保存成功");
        }
      }
    },
    getCompany(e) {
      this.form.companyIndex = e.detail.value;
      this.form.companyId = this.companyAllList[e.detail.value].value;
    },
    chosseAboutCompany() {
      this.show = true;
    },
    async getCompanyAll() {
      let companyAllList = await getCompanyAll();
      this.getInterviewDetails();
      this.companyAllList = companyAllList.map((e) => {
        return {
          label: e.qymc,
          value: e.id,
        };
      });
    },
    async getByCodes() {
      let data = await getByCodes(JSON.stringify(this.dic_key));
      this.dic_SelectList = this.$common.handleDicList(data);
    },
    confirm(e) {
      let associationCompanyString = [];
      let associationCompany = [];
      for (var p in e) {
        associationCompanyString.push(e[p].label);
        associationCompany.push(e[p].value);
      }
      this.form.associationCompanyString = associationCompanyString.join(",");
      this.form.associationCompany = associationCompany.join(",");
    },
    bindPickerChange(e) {
      this.form.interviewTypeIndex = e.detail.value;
      this.form.interviewType =
        this.dic_SelectList.interviewType[e.detail.value].value;
    },
  },
  // onLoad: function (){
  // 	this.$refs.findYuanQuList()
  // },
};
</script>
    
    <style lang="scss">
.gaisideshurukuang {
  .btn-view {
    width: 100%;
    height: 100rpx;
    padding: 20rpx 10%;
    background-color: #ffffff;
    position: fixed;
    bottom: 0;
    left: 0;
  }
  .btn {
    width: 80%;
    height: 90rpx;
    border-radius: 50rpx 50rpx 50rpx 50rpx;
    background: #1d18bc;
    line-height: 90rpx;
    color: white;
  }
  font-size: 26rpx !important;
  .is-input-border {
    border-top: none !important;
    border-left: none !important;
    border-right: none !important;
    border: none;
    border-radius: 0 !important;
  }
  .uni-forms-item {
    margin-bottom: 0px;
    border-bottom: 2rpx solid #cccccc !important;
  }
}
.btn-view {
  width: 100%;
  height: 100rpx;
  padding: 20rpx 10%;
  background-color: #ffffff;
  position: fixed;
  bottom: 0;
  left: 0;
}
.btn {
  width: 80%;
  height: 90rpx;
  border-radius: 50rpx 50rpx 50rpx 50rpx;
  background: #1d18bc;
  line-height: 90rpx;
  color: white;
}
.goreport {
  .uni-forms-item {
    margin-bottom: 0px;
    border-bottom: 2rpx solid #cccccc !important;
  }
  .textarea_info {
    textarea {
      background: #f9f9f9;
    }
  }
  .is-disabled {
    background: white !important;
    color: #777;
  }
  .form {
    width: calc(100% - 128rpx);
    margin: 32rpx;
    background: #ffffff;
    padding: 32rpx;

    .label {
      height: 53rpx;
      line-height: 53rpx;
    }
    .is-input-border {
    }
    .uni-forms-item {
      border-bottom: 2rpx solid #cccccc !important;
    }
  }
}
</style>
    