index.vue 15 KB

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