audio.js 3.92 KB
/*
 * @Description:
 * @Author: huyue
 * @Date: 2024-04-07 18:15:11
 * @LastEditors: 前端 qianduan01@didihu.com.cn
 * @LastEditTime: 2024-04-11 21:22:55
 */
// import { setToken, getToken, removeToken } from '@/utils/token';;
import utils from "@/utils/utils";
// const recorderManager = uni.getRecorderManager();
import upload from "@/utils/ossUploadFile/uploadFile.js";
import store from "../index";
export default {
  namespaced: true,
  state() {
    return {
      booksList: [],
      audioList: [],
      receptionStatus: 1,
      endReasonType: 0,
      audioInfo: {
        audioStatus: "",
        endReasonType: 0,
        receptionStartTime: "",
        receptionEndTime: "",
      },
    };
  },
  mutations: {
    setAudioInfo(state, data) {
      if (data.audioStatus == "start") {
        data.receptionStartTime = utils.convertDateTimeFormat(new Date(), "/");
      }
      if (data.audioStatus == "end") {
        data.receptionEndTime = utils.convertDateTimeFormat(new Date(), "/");
      }
      state.audioInfo = Object.assign(state.audioInfo, data);
    },
    setReceptionStatus(state, data) {
      state.receptionStatus = data;
    },
    setAudioList(state, data) {
      state.audioList = data;
    },
    setBooks(state, data) {
      state.booksList = data;
    },
  },
  actions: {
    // startAudio({ commit, state, dispatch }) {
    //   if (state.isStart) return;
    //   commit("setAudioStart", true);
    //   commit("setAudioList", []);
    //   commit("setAudioEnd", false);
    //   recorderManager.start({
    //     duration: 20000,
    //   });
    //   recorderManager.onStop(async (res) => {
    //     console.log("结束录音");
    //     console.log(state.isEnd, "this.isEnd");
    //     if (!state.isEnd) {
    //       uni.getRecorderManager().start({
    //         duration: 20000,
    //       });
    //     }
    //     const result = await upload(res.tempFilePath);
    //     const storageFile = [...state.audioList, result];
    //     uni.$storage.set("storageFile", storageFile);
    //     commit("setAudioList", storageFile);
    //     if (state.isEnd) {
    //       console.log("上传语音");
    //       dispatch("uploadVoice", storageFile);
    //     }
    //     return true;
    //   });
    // },
    // stopAudio({ commit, state }) {
    //   commit("setAudioStart", false);
    //   commit("setAudioEnd", true);
    //   recorderManager.stop();
    // },
    // async uploadVoice({ commit, state }, tempFilePath) {
    //   const { shopMerchantId, phone } = uni.$storage.get("userInfo"),
    //     { customerName, phoneNumber, salesUuid, carModel } =
    //       store.state.user.customerInfo,
    //     receptionCustomerPaySourceList = state.booksList.map((item) => {
    //       return {
    //         id: item.id,
    //         sourceType: item.id,
    //         sourceUrl: item.imgUrl,
    //       };
    //     }),
    //     params = {
    //       carModel,
    //       endReasonType: state.endReasonType, //原因 1.异常 0.正常
    //       customerName,
    //       phoneNumber,
    //       loginPhone: phone,
    //       salesUuid,
    //       receptionStatus: state.receptionStatus, //接待结果 1.成交 0.战败
    //       recordUrlList: tempFilePath,
    //       receptionStartTime: state.receptionStartTime,
    //       receptionEndTime: state.receptionEndTime,
    //       receptionCustomerPaySourceList, //1.付款凭证文件路径 2.客户购车发票文件路径 3.客户延保合同文件路径
    //       merchantId: shopMerchantId,
    //     };
    //   commit("setBooks", []);
    //   console.log(params);
    //   if (customerName && phoneNumber && salesUuid && carModel)
    //     uni.$api.commonApi.saveRecCustomer(params).then((res) => {
    //       console.log(res);
    //     });
    //   store.dispatch("clearCustomerInfo");
    //   commit("setReceptionStatus", 1);
    //   commit("setReceptionStatus", 0);
    //   uni.$storage.set("storageFile", "");
    // },
  },
};