index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. <template>
  2. <view class="oder_form_wrap">
  3. <u-navbar placeholder :autoBack="true" title="发单表单">
  4. </u-navbar>
  5. <view class="form_wrap">
  6. <u--form labelPosition="top" labelWidth="100" :model="form" :rules="rules" ref="form" class="form_wrap"
  7. :errorType="'toast'">
  8. <u-form-item label="品牌" prop="brand" class="brand_wrap">
  9. <ld-select :list="brandDict" label-key="dictLabel" value-key="dictValue" placeholder="请选择物品品牌"
  10. v-model="form.brand" :border="false" border></ld-select>
  11. <u-icon slot="right" name="arrow-right"></u-icon>
  12. </u-form-item>
  13. <u-row gutter="5" justify="space-between">
  14. <u-col span="6">
  15. <u-form-item label="型号" prop="model">
  16. <u--input v-model="form.model" placeholder="例如:CF小号" border="surround"></u--input>
  17. </u-form-item>
  18. </u-col>
  19. <u-col span="6">
  20. <u-form-item label="实价" prop="price">
  21. <u--input v-model="form.price" placeholder="0.00" border="surround"></u--input>
  22. </u-form-item>
  23. </u-col>
  24. </u-row>
  25. <u-row gutter="5" justify="space-between">
  26. <u-col span="6">
  27. <u-form-item label="客户电话" prop="phone">
  28. <u--input v-model="form.phone" placeholder="电话号" border="surround"></u--input>
  29. </u-form-item>
  30. </u-col>
  31. <u-col span="6">
  32. <u-form-item label="客户微信" prop="wechat">
  33. <u--input v-model="form.wechat" placeholder="微信号" border="surround"></u--input>
  34. </u-form-item>
  35. </u-col>
  36. </u-row>
  37. <view class="address_wrap">
  38. <view class="address_title">
  39. <u-icon name="map" color="#3b82f6" size="16"></u-icon>
  40. <view>地址信息</view>
  41. </view>
  42. <u-form-item label="详细地址" prop="address" class='form_card'>
  43. <pick-regions :defaultRegion="defaultRegion" @getRegion="handleGetRegion" clearable
  44. class="region-picker">
  45. <view>
  46. <template v-if="form.province">
  47. <u--input :value="form.province + '/' + form.city + '/' + form.area"
  48. placeholder="点击选择" readonly suffixIcon="arrow-right"
  49. suffixIconStyle="color : #c0c4cc"></u--input>
  50. </template>
  51. <template v-else>
  52. <u--input placeholder="点击选择" readonly suffixIcon="arrow-right"
  53. suffixIconStyle="color : #c0c4cc"></u--input>
  54. </template>
  55. </view>
  56. </pick-regions>
  57. </u-form-item>
  58. <u--textarea v-model="form.address" placeholder="粘贴地址自动识别(例如:浙江省杭州市...)" confirmType="done"
  59. @blur="handleAddressBlur"></u--textarea>
  60. </view>
  61. <u-form-item label="上门时间" prop="visitTime" class="visit_time_wrap">
  62. <date-time-picker v-model="form.visitTime" :value-format="'YYYY-MM-DD HH:mm:ss'" :type="'datetime'">
  63. </date-time-picker>
  64. </u-form-item>
  65. <u-form-item label="类型" prop="category" class="category_wrap">
  66. <view class="category_select_wrap">
  67. <ld-select :list="categoryDict" label-key="dictLabel" value-key="dictValue" placeholder="请选择类型"
  68. v-model="form.category" :border="false"></ld-select>
  69. <u-icon slot="right" name="arrow-right"></u-icon>
  70. </view>
  71. </u-form-item>
  72. <u-form-item label="价格范围" prop="priceRange">
  73. <u--input v-model="form.priceRange" placeholder="请输入价格范围" border="surround"></u--input>
  74. </u-form-item>
  75. <u-form-item label="战术选择" prop="tactic">
  76. <view class="tactic-buttons">
  77. <view v-for="item in tacticDict" :key="item.dictValue" class="tactic-button"
  78. :class="{ 'active': form.tactic === item.dictValue }" @click="form.tactic = item.dictValue">
  79. {{ item.dictLabel }}
  80. </view>
  81. </view>
  82. </u-form-item>
  83. <u-form-item label="备注信息" prop="remarks" class="remarks_wrap">
  84. <u--textarea v-model="form.remarks" placeholder="填写线索来源、客户特殊要求等..." count
  85. confirmType="done"></u--textarea>
  86. </u-form-item>
  87. </u--form>
  88. </view>
  89. <!-- 文件上传区域 -->
  90. <view class="upload_area" v-if="!sendFormId">
  91. <!-- 聊天记录附件 -->
  92. <order-file-upload title="聊天记录附件" orderFileType="1" fileType="image" :file-list="form.chatAttachmentList"
  93. @update:fileList="updateChatFiles" tip-text="上传聊天截图、录音等文件"></order-file-upload>
  94. <!-- 报价附件 -->
  95. <order-file-upload title="报价附件" orderFileType="2" fileType="image" :file-list="form.quoteAttachmentList"
  96. @update:fileList="updateQuoteFiles" tip-text="上传报价附件"></order-file-upload>
  97. <!-- 高清图附件 -->
  98. <order-file-upload title="高清图附件" orderFileType="3" fileType="image" :file-list="form.hdImageAttachmentList"
  99. @update:fileList="updateHdImageFiles" tip-text="上传物品高清图片"></order-file-upload>
  100. <!-- 其他附件 -->
  101. <order-file-upload title="其他附件" orderFileType="4" fileType="image" :file-list="form.otherAttachmentList"
  102. @update:fileList="updateOtherFiles" tip-text="上传其他相关文件"></order-file-upload>
  103. </view>
  104. <u-button @click="handleNavSaveClick" type="primary">提交订单</u-button>
  105. </view>
  106. </template>
  107. <script>
  108. import orderFileUpload from '@/components/order-file-upload/order-file-upload.vue'
  109. import dateTimePicker from "@/components/dateTimePicker/dateTimePicker.vue"
  110. import ldSelect from "@/components/ld-select/ld-select.vue"
  111. export default {
  112. components: {
  113. orderFileUpload,
  114. dateTimePicker,
  115. ldSelect
  116. },
  117. data() {
  118. return {
  119. defaultRegion: ['广东省', '广州市', '番禺区'],
  120. categoryDict: [],
  121. tacticDict: [],
  122. brandDict: [],
  123. sendFormId: undefined,
  124. form: {
  125. clueId: '',
  126. sendDate: '',
  127. website: '',
  128. item: '',
  129. phone: '',
  130. wechat: '',
  131. address: '',
  132. visitTime: '',
  133. remarks: '',
  134. category: '1',
  135. brand: '',
  136. model: '',
  137. price: '',
  138. priceRange: '',
  139. tactic: '',
  140. // 地区信息
  141. province: '',
  142. city: '',
  143. area: '',
  144. // 附件列表
  145. chatAttachmentList: [], // 聊天记录附件
  146. quoteAttachmentList: [], // 报价附件
  147. hdImageAttachmentList: [], // 高清图附件
  148. otherAttachmentList: [] // 其他附件
  149. },
  150. rules: {
  151. sendDate: {
  152. type: 'string',
  153. required: true,
  154. message: '请输入发单日期',
  155. trigger: ['blur', 'change']
  156. },
  157. model: {
  158. type: 'string',
  159. required: true,
  160. message: '请输入型号',
  161. trigger: ['blur', 'change']
  162. },
  163. price: {
  164. type: 'string',
  165. required: true,
  166. message: '请输入实价',
  167. trigger: ['blur', 'change']
  168. },
  169. website: {
  170. type: 'url',
  171. message: '请输入正确的网址格式',
  172. trigger: ['blur', 'change']
  173. },
  174. item: {
  175. type: 'string',
  176. required: true,
  177. message: '请输入物品描述',
  178. trigger: ['blur', 'change']
  179. },
  180. wechat: {
  181. type: 'string',
  182. required: false,
  183. message: '请输入客户微信',
  184. trigger: ['blur', 'change']
  185. },
  186. phone: {
  187. type: 'string',
  188. required: false,
  189. message: '请输入联系电话',
  190. trigger: ['blur', 'change']
  191. },
  192. address: {
  193. type: 'string',
  194. required: true,
  195. message: '请输入详细地址',
  196. trigger: ['blur', 'change']
  197. },
  198. visitTime: {
  199. type: 'string',
  200. required: true,
  201. message: '请输入上门时间',
  202. trigger: ['blur', 'change']
  203. },
  204. category: {
  205. type: 'string',
  206. required: true,
  207. message: '请选择类型',
  208. trigger: ['blur', 'change']
  209. },
  210. brand: {
  211. type: 'string',
  212. required: true,
  213. message: '请选择物品品牌',
  214. trigger: ['blur', 'change']
  215. },
  216. tactic: {
  217. type: 'string',
  218. required: true,
  219. message: '请选择战术',
  220. trigger: ['blur', 'change']
  221. }
  222. }
  223. }
  224. },
  225. methods: {
  226. // 加载表单数据
  227. async loadFormData(sendFormId) {
  228. try {
  229. const res = await uni.$u.api.getClueSendFormVoByOrderId({
  230. id: sendFormId
  231. });
  232. if (res.code === 200) {
  233. this.form = res.data;
  234. }
  235. } catch (error) {
  236. console.error('加载表单数据失败:', error);
  237. uni.$u.toast('加载表单数据失败');
  238. }
  239. },
  240. // 获取地区选择
  241. handleGetRegion(region) {
  242. const [provinceData, cityData, areaData] = region;
  243. this.form.province = provinceData.name;
  244. this.form.city = cityData.name;
  245. this.form.area = areaData.name;
  246. // 构建完整的地区信息
  247. const regionText = this.form.province + this.form.city + this.form.area;
  248. // 检查当前地址内容是否为纯地区信息(没有具体街道等)
  249. const isPureRegion = !this.form.address ||
  250. this.form.address.trim() === '' ||
  251. this.form.address.trim().includes(this.form.province) ||
  252. this.form.address.trim().includes(this.form.city) ||
  253. this.form.address.trim().includes(this.form.area);
  254. // 如果是纯地区信息或者是空地址,则更新为选择的地区
  255. if (isPureRegion) {
  256. this.form.address = regionText;
  257. } else {
  258. // 如果有具体地址信息,保留原有地址,但更新地区部分
  259. // 这里可以保持原有地址不变,让用户自己选择是否更新
  260. // 或者可以选择性地更新地区信息
  261. }
  262. },
  263. // 地址失焦时自动解析地址信息
  264. handleAddressBlur() {
  265. },
  266. // 更新各类附件
  267. updateChatFiles(fileList) {
  268. this.form.chatAttachmentList = fileList;
  269. },
  270. updateQuoteFiles(fileList) {
  271. this.form.quoteAttachmentList = fileList;
  272. },
  273. updateHdImageFiles(fileList) {
  274. this.form.hdImageAttachmentList = fileList;
  275. },
  276. updateOtherFiles(fileList) {
  277. this.form.otherAttachmentList = fileList;
  278. },
  279. // 文件变化处理
  280. handleFileChange(data) {
  281. console.log('文件上传变化:', data);
  282. },
  283. // 获取字典数据
  284. async getDicts() {
  285. try {
  286. const [categoryRes, tacticRes, brandRes] = await Promise.all([
  287. this.$getDicts('crm_form_category'),
  288. this.$getDicts('crm_form_tactic'),
  289. this.$getDicts('crm_form_brand')
  290. ]);
  291. this.categoryDict = categoryRes;
  292. this.tacticDict = tacticRes;
  293. this.brandDict = brandRes;
  294. } catch (error) {
  295. console.error('获取字典数据失败:', error);
  296. }
  297. },
  298. // 处理保存
  299. async handleNavSaveClick() {
  300. try {
  301. // 表单验证
  302. await this.$refs.form.validate();
  303. if (this.form.id) {
  304. const updatedForm = {
  305. clueId: this.form.clueId,
  306. model: this.form.model,
  307. price: this.form.price,
  308. wechat: this.form.wechat,
  309. id: this.form.id,
  310. item: this.form.item,
  311. phone: this.form.phone,
  312. authenticateUserId: this.form.authenticateUserId,
  313. category: this.form.category,
  314. brand: this.form.brand,
  315. idCard: this.form.idCard,
  316. customName: this.form.customName,
  317. bankCardNumber: this.form.bankCardNumber,
  318. bankName: this.form.bankName,
  319. paymentMethod: this.form.paymentMethod,
  320. visitTime: this.form.visitTime,
  321. remarks: this.form.remarks,
  322. priceRange: this.form.priceRange,
  323. tactic: this.form.tactic
  324. }
  325. await uni.$u.api.updateClueOrderForm(updatedForm);
  326. uni.$emit('updateSendFormSuccess');
  327. uni.$u.toast('发单记录更新成功');
  328. } else {
  329. // 合并所有附件
  330. const allAttachments = [
  331. ...this.form.chatAttachmentList,
  332. ...this.form.quoteAttachmentList,
  333. ...this.form.hdImageAttachmentList,
  334. ...this.form.otherAttachmentList
  335. ];
  336. // 准备提交数据
  337. const submitData = {
  338. ...this.form,
  339. uploadList: allAttachments
  340. };
  341. await uni.$u.api.saveClueOrderForm(submitData);
  342. uni.$u.toast('发单记录添加成功');
  343. }
  344. // 延迟返回
  345. setTimeout(() => {
  346. uni.navigateBack();
  347. }, 1500);
  348. } catch (error) {
  349. console.error('保存失败:', error);
  350. if (error.message) {
  351. uni.$u.toast(error.message);
  352. }
  353. }
  354. }
  355. },
  356. onLoad(option) {
  357. console.log('option', option);
  358. const clueId = option.clueId;
  359. this.sendFormId = option.sendFormId;
  360. this.form.clueId = clueId;
  361. this.getDicts();
  362. if (option.sendFormId) {
  363. this.loadFormData(option.sendFormId);
  364. }
  365. }
  366. }
  367. </script>
  368. <style lang="scss" scoped>
  369. .oder_form_wrap {
  370. background-color: #f8f9fa;
  371. min-height: 100vh;
  372. padding-bottom: 10rpx;
  373. padding-top: 10px;
  374. padding-left: 20rpx;
  375. padding-right: 20rpx;
  376. }
  377. .upload_area {
  378. padding: 0 10rpx;
  379. }
  380. .bottom_btn {
  381. position: fixed;
  382. bottom: 0;
  383. left: 0;
  384. right: 0;
  385. padding: 20rpx;
  386. background: #fff;
  387. box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
  388. }
  389. ::v-deep .u-form-item {
  390. /* 移除底部边框 */
  391. border-bottom: none;
  392. /* 添加卡片样式 */
  393. // background-color: #fff;
  394. border-radius: 16rpx;
  395. /* 添加内边距 */
  396. padding: 10rpx;
  397. /* 确保内容不会溢出 */
  398. overflow: hidden;
  399. .u-input--square {
  400. border-radius: 20rpx;
  401. }
  402. .u-input--square:focus-within,
  403. .u-input--square.u-input--focus {
  404. border: 2rpx solid #2563eb !important;
  405. background-color: #fff !important;
  406. }
  407. }
  408. .brand_wrap {
  409. ::v-deep .u-form-item__body__right__content {
  410. border: 1px solid #dadbde;
  411. padding: 10rpx;
  412. border-radius: 20rpx;
  413. .inputWrap {
  414. border: none;
  415. }
  416. }
  417. }
  418. .address_wrap {
  419. border-radius: 20rpx;
  420. padding: 24rpx;
  421. display: flex;
  422. flex-direction: column;
  423. background-color: #fff;
  424. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
  425. margin: 0 10rpx;
  426. .address_title {
  427. display: flex;
  428. align-items: center;
  429. background-color: #fff;
  430. padding-bottom: 12rpx;
  431. gap: 16rpx;
  432. font-size: 26rpx;
  433. color: #6b7280;
  434. font-weight: 600;
  435. }
  436. ::v-deep .u-form-item {
  437. margin-bottom: 0 !important;
  438. padding: 0;
  439. .u-input--square {
  440. background-color: #f9fafb;
  441. }
  442. }
  443. ::v-deep .u-textarea--radius {
  444. border-radius: 20rpx;
  445. }
  446. .region-picker {
  447. width: 100%;
  448. }
  449. ::v-deep .u-textarea {
  450. background-color: #f9fafb;
  451. }
  452. }
  453. .visit_time_wrap {
  454. ::v-deep .uni-date-x {
  455. border-radius: 10px;
  456. padding: 8rpx 10rpx;
  457. border: 1px solid #dadbde;
  458. background-color: #f8f9fa;
  459. }
  460. }
  461. .category_wrap {
  462. .category_select_wrap {
  463. border-radius: 20rpx;
  464. border: 1px solid #dadbde;
  465. padding: 6rpx;
  466. width: 100%;
  467. ::v-deep .ldSelectInput {
  468. font-size: 28rpx !important;
  469. }
  470. }
  471. .category_select_wrap:focus-within,
  472. .category_select_wrap:focus {
  473. border: 2rpx solid #2563eb !important;
  474. background-color: #fff !important;
  475. }
  476. }
  477. .remarks_wrap {
  478. .u-textarea {
  479. background-color: #fff;
  480. }
  481. ::v-deep .u-textarea--radius {
  482. border-radius: 20rpx;
  483. }
  484. }
  485. ::v-deep .u-form-item__body {
  486. padding: 10rpx 0rpx;
  487. }
  488. ::v-deep .u-form-item__body__left__content__label {
  489. color: rgb(107 114 128 / 1) !important;
  490. font-size: 28rpx;
  491. font-weight: 700;
  492. }
  493. .u-button {
  494. border-radius: 40rpx;
  495. background-color: #2563eb;
  496. border: none;
  497. color: #fff;
  498. font-weight: 700;
  499. font-size: 40rpx;
  500. height: 100rpx;
  501. }
  502. .tactic-buttons {
  503. display: flex;
  504. justify-content: space-between;
  505. margin-top: 10rpx;
  506. width: 100%;
  507. }
  508. .tactic-button {
  509. position: relative;
  510. border-width: 3rpx;
  511. border-style: solid;
  512. border-color: #e5e7eb;
  513. width: 30%;
  514. height: 80rpx;
  515. line-height: 80rpx;
  516. text-align: center;
  517. border-radius: 30rpx;
  518. background-color: #f9fafb;
  519. color: rgb(107 114 128 / 1);
  520. font-size: 28rpx;
  521. transition: all 0.3s ease;
  522. font-weight: 700;
  523. }
  524. .tactic-button.active {
  525. border-color: #3b82f6;
  526. color: #3b82f6;
  527. background-color: #eff6ff;
  528. }
  529. .tactic-button::after {
  530. content: '';
  531. position: absolute;
  532. border-width: 5rpx;
  533. border-style: solid;
  534. border-color: #ffffff;
  535. top: 4%;
  536. right: -12%;
  537. transform: translate(-50%, -50%);
  538. width: 25rpx;
  539. height: 25rpx;
  540. border-radius: 50%;
  541. background-color: #3b82f6;
  542. opacity: 0;
  543. transition: all 0.3s ease;
  544. }
  545. .tactic-button.active::after {
  546. opacity: 1;
  547. }
  548. .u-textarea {
  549. background-color: #f5f5f5;
  550. }
  551. </style>