index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <view class="follow_wrap">
  3. <u-navbar placeholder :autoBack="true" title="上传录音" @rightClick="handleNavSaveClick">
  4. <view class="u-nav-slot" slot="right">
  5. 保存
  6. </view>
  7. </u-navbar>
  8. <view class="form_wrap">
  9. <u--form labelPosition="left" labelWidth="80" :model="form" :rules="rules" ref="form" class="form_wrap">
  10. <u-form-item label="线索id">
  11. {{ clueDetail && clueDetail.id ? clueDetail.id : "-" }}
  12. </u-form-item>
  13. <u-form-item label="线索名称">
  14. {{ clueDetail && clueDetail.name ? clueDetail.name : "-" }}
  15. </u-form-item>
  16. <u-form-item label="操作人">
  17. {{ userInfo.nickName }}
  18. </u-form-item>
  19. <u-form-item label="主叫号码" prop="caller">
  20. <u--input clearable v-model="form.caller" placeholder="请输入主叫号码"></u--input>
  21. </u-form-item>
  22. <u-form-item label="被叫号码" prop="callee">
  23. <u--input clearable v-model="form.callee" placeholder="请输入被叫号码"></u--input>
  24. </u-form-item>
  25. <u-form-item label="录音" prop="fileUrl">
  26. <ld-select :list="filelist" label-key="fileName" value-key="filePath" placeholder="请选择"
  27. v-model="form.fileUrl" :border="false" @change="handleFileChange"></ld-select>
  28. <u-icon slot="right" name="arrow-right"></u-icon>
  29. </u-form-item>
  30. <u-form-item label="备注" prop="remark">
  31. <u--textarea v-model="form.remark" placeholder="请输入内容" count confirmType="done" maxlength="500">
  32. </u--textarea>
  33. </u-form-item>
  34. </u--form>
  35. </view>
  36. <!-- 录音确认对话框 -->
  37. <u-popup :show="showConfirmDialog" mode="center" :closeable="false" :closeOnClickOverlay="false">
  38. <view class="confirm-dialog">
  39. <view class="dialog-title">确认录音</view>
  40. <view class="dialog-content">
  41. <view class="file-info">
  42. <view class="file-name">{{ selectedFile.fileName }}</view>
  43. </view>
  44. <view class="play-section">
  45. <audio :src="selectedFile.filePath" controls class="audio-player"></audio>
  46. </view>
  47. </view>
  48. <view class="dialog-buttons">
  49. <u-button text="取消" @click="cancelConfirm" :plain="true"></u-button>
  50. <u-button text="确认" @click="confirmUpload" type="primary"></u-button>
  51. </view>
  52. </view>
  53. </u-popup>
  54. <!-- <drag-button :isDock="true" /> -->
  55. </view>
  56. </template>
  57. <script>
  58. export default {
  59. computed: {
  60. userInfo() {
  61. return this.$store.state.user.userInfo;
  62. },
  63. filelist() {
  64. return this.$store.state.call.filelist;
  65. },
  66. storeForm() {
  67. return this.$store.state.call.form;
  68. },
  69. },
  70. data() {
  71. return {
  72. rules: {
  73. 'caller': {
  74. type: 'string',
  75. required: true,
  76. message: '请输入内容',
  77. trigger: ['blur', 'change']
  78. },
  79. 'callee': {
  80. type: 'string',
  81. required: true,
  82. message: '请输入内容',
  83. trigger: ['blur', 'change']
  84. },
  85. 'fileUrl': {
  86. type: 'string',
  87. required: true,
  88. message: '请输入内容',
  89. trigger: ['blur', 'change']
  90. },
  91. },
  92. form: {
  93. clueId: undefined,
  94. remark: '',
  95. fileUrl: undefined,
  96. fileName: undefined,
  97. type: '3',
  98. list: [],
  99. caller: '',
  100. callee: ''
  101. },
  102. clueDetail: {},
  103. // 对话框相关状态
  104. showConfirmDialog: false,
  105. selectedFile: {
  106. filePath: '',
  107. fileName: ''
  108. },
  109. }
  110. },
  111. methods: {
  112. initFormFromStore() {
  113. const storeFormData = this.storeForm;
  114. this.form = {
  115. ...this.form,
  116. caller: storeFormData.caller || '',
  117. callee: storeFormData.callee || '',
  118. fileUrl: storeFormData.fileUrl,
  119. fileName: storeFormData.fileName,
  120. remark: storeFormData.remark,
  121. type: storeFormData.type,
  122. list: storeFormData.list
  123. };
  124. uni.$u.api.getClueMainInfoById({ id: this.form.clueId }).then(({ data }) => {
  125. this.clueDetail = data;
  126. })
  127. if (!this.form.callee) {
  128. // 没有准备被叫号码 直接去查线索的telephone
  129. this.form.callee = this.clueDetail.telephone;
  130. };
  131. if (!this.form.caller) {
  132. // 没有准备主叫号码 直接去尝试获取
  133. this.$store.dispatch("call/getUserPhoneNumber").then(phone => {
  134. this.form.caller = phone;
  135. })
  136. }
  137. if (storeFormData.fileUrl) {
  138. // 初始化带了fileUrl 说明是从监听那边跳转的
  139. this.handleFileChange({ filePath: storeFormData.fileUrl, fileName: storeFormData.fileName });
  140. }
  141. this.$store.dispatch("call/resetForm");
  142. },
  143. handleFileChange(file) {
  144. // {
  145. // "filePath": "/storage/emulated/0/Recordings/Record/Call/15099989786 2025-11-11 09-41-57.m4a",
  146. // "fileName": "15099989786 2025-11-11 09-41-57.m4a"
  147. // }
  148. const { filePath, fileName } = file;
  149. // 显示确认对话框
  150. this.selectedFile = { filePath, fileName };
  151. this.showConfirmDialog = true;
  152. },
  153. // 取消确认
  154. cancelConfirm() {
  155. this.showConfirmDialog = false;
  156. this.selectedFile = { filePath: '', fileName: '' };
  157. this.form.fileUrl = undefined;
  158. this.form.fileName = undefined;
  159. },
  160. // 确认上传
  161. async confirmUpload() {
  162. try {
  163. // 调用上传接口
  164. const result = await uni.$u.api.uploadFile(this.selectedFile.filePath);
  165. if (result && result.data) {
  166. result.data.remark = this.form.remark;
  167. result.data.fileName = result.data.name;
  168. result.data.fileUrl = result.data.url;
  169. this.form.list = [result.data];
  170. }
  171. // 设置表单值
  172. this.form.fileUrl = this.selectedFile.filePath;
  173. this.form.fileName = this.selectedFile.fileName;
  174. // 关闭对话框
  175. this.showConfirmDialog = false;
  176. } catch (error) {
  177. uni.hideLoading();
  178. console.error('上传失败:', error);
  179. uni.$u.toast('上传失败,请重试');
  180. }
  181. },
  182. handleNavSaveClick() {
  183. if (!this.form.clueId) {
  184. uni.$u.toast("相关线索id为空");
  185. }
  186. this.$refs.form.validate().then(async () => {
  187. await uni.$u.api.saveClueFile(this.form);
  188. uni.$u.toast("保存成功");
  189. this.timer = setTimeout(() => {
  190. uni.$emit('uploadRecordSuccess');
  191. uni.navigateBack();
  192. clearTimeout(this.timer);
  193. }, 1000)
  194. })
  195. },
  196. },
  197. onLoad(option) {
  198. this.$store.dispatch("call/getFileList");
  199. this.form.clueId = option.clueId;
  200. this.initFormFromStore();
  201. },
  202. }
  203. </script>
  204. <style lang="scss" scoped>
  205. .form_wrap {
  206. background-color: #fff;
  207. margin: 20rpx 0;
  208. .form_wrap {
  209. ::v-deep .u-form-item__body {
  210. padding: 20rpx 40rpx;
  211. }
  212. }
  213. }
  214. /* 录音确认对话框样式 */
  215. .confirm-dialog {
  216. padding: 40rpx;
  217. min-width: 500rpx;
  218. background: #fff;
  219. border-radius: 20rpx;
  220. .dialog-title {
  221. text-align: center;
  222. font-size: 32rpx;
  223. font-weight: bold;
  224. color: #333;
  225. margin-bottom: 40rpx;
  226. }
  227. .dialog-content {
  228. margin-bottom: 40rpx;
  229. .file-info {
  230. margin-bottom: 30rpx;
  231. .file-name {
  232. background: #f5f5f5;
  233. padding: 20rpx;
  234. border-radius: 10rpx;
  235. font-size: 28rpx;
  236. color: #333;
  237. word-break: break-all;
  238. text-align: center;
  239. }
  240. }
  241. .play-section {
  242. .audio-player {
  243. width: 100%;
  244. }
  245. }
  246. }
  247. .dialog-buttons {
  248. display: flex;
  249. gap: 30rpx;
  250. ::v-deep .u-button {
  251. flex: 1;
  252. }
  253. }
  254. }
  255. </style>