index.vue 6.5 KB

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