index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. <template>
  2. <div class="create-pages">
  3. <div class="create-bos">
  4. <div class="create-title flex-row-start">
  5. <el-icon color="#101828" size="16"><Document /></el-icon>
  6. <div style="margin-left: 6px">确认订单信息</div>
  7. </div>
  8. <div class="create-head flex-row-start">
  9. <span>{{ userStore.userInfo && userStore.userInfo.user ? userStore.userInfo.user.nickName : '' }}</span>
  10. <span class="border"></span>
  11. <span>{{ userStore.userInfo && userStore.userInfo.user ? userStore.userInfo.customerName : '' }}</span>
  12. </div>
  13. <div class="address-title">
  14. <div>收货地址</div>
  15. <el-button type="danger" link @click="handleAdd">
  16. <el-icon><Plus /></el-icon>新增收货地址
  17. </el-button>
  18. </div>
  19. <div class="address-bos">
  20. <div
  21. @click="onAddress(item)"
  22. v-for="(item, index) in addressList"
  23. :key="index"
  24. class="address-list flex-column-between"
  25. :class="item.id == form.shippingAddressId ? 'hig' : ''"
  26. >
  27. <div class="address1">{{ item.provincialCityCountry }}{{ item.address }}</div>
  28. <div class="address2">{{ item.consignee }}</div>
  29. <div class="address3">{{ item.phone }}</div>
  30. </div>
  31. </div>
  32. <div class="address-more flex-row-start">
  33. <!-- <div>展开全部地址</div>
  34. <el-icon style="margin-left: 6px" color="#6A7282" size="14"><ArrowDown /></el-icon> -->
  35. </div>
  36. <div class="form-bos" style="align-items: center">
  37. <div class="form-title flex-row-start">
  38. <div class="asterisk">*</div>
  39. <div>配送时间</div>
  40. </div>
  41. <el-date-picker
  42. format="YYYY-MM-DD"
  43. value-format="YYYY-MM-DD"
  44. style="width: 340px"
  45. v-model="form.deliveryDate"
  46. type="date"
  47. placeholder="选择日期"
  48. :disabled-date="disabledDate"
  49. />
  50. </div>
  51. <div class="form-bos" style="align-items: center">
  52. <div class="form-title flex-row-start">
  53. <div class="asterisk">*</div>
  54. <div>费用类型</div>
  55. </div>
  56. <el-select v-model="form.expenseType" placeholder="请选择费用类型" style="width: 340px">
  57. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
  58. </el-select>
  59. </div>
  60. <div class="form-bos">
  61. <div class="form-title flex-row-start">
  62. <div class="asterisk">*</div>
  63. <div>采购事由</div>
  64. </div>
  65. <el-input
  66. :maxlength="50"
  67. v-model="form.purchaseReason"
  68. style="width: 600px"
  69. :autosize="{ minRows: 4, maxRows: 8 }"
  70. type="textarea"
  71. show-word-limit
  72. placeholder="请输入采购事由"
  73. />
  74. </div>
  75. <div class="form-bos">
  76. <div class="form-title flex-row-start">
  77. <div class="asterisk"></div>
  78. <div>订单备注</div>
  79. </div>
  80. <el-input
  81. :maxlength="50"
  82. v-model="form.remark"
  83. style="width: 600px"
  84. :autosize="{ minRows: 4, maxRows: 8 }"
  85. type="textarea"
  86. show-word-limit
  87. placeholder="请输入订单备注"
  88. />
  89. </div>
  90. <el-table
  91. :data="tableData"
  92. style="width: 100%"
  93. :header-cell-style="{
  94. color: '#1D2129',
  95. backgroundColor: '#F2F3F5',
  96. fontWeight: 'normal'
  97. }"
  98. >
  99. <el-table-column label="商品信息" minWidth="650">
  100. <template #default="scope">
  101. <div class="cart-info">
  102. <img class="cart-img" :src="scope.row.productImage" alt="" />
  103. <div class="cart-text">
  104. <div class="text1">{{ scope.row.itemName }}</div>
  105. <div class="text2">
  106. <span>单位:{{ scope.row.unitName }}</span>
  107. </div>
  108. </div>
  109. </div>
  110. </template>
  111. </el-table-column>
  112. <el-table-column label="单价" minWidth="150">
  113. <template #default="scope"> ¥{{ scope.row.memberPrice }} </template>
  114. </el-table-column>
  115. <el-table-column label="数量" minWidth="150">
  116. <template #default="scope"> {{ scope.row.productNum }} </template>
  117. </el-table-column>
  118. <el-table-column label="小计" minWidth="150">
  119. <template #default="scope"> ¥{{ (scope.row.memberPrice * scope.row.productNum).toFixed(2) }} </template>
  120. </el-table-column>
  121. </el-table>
  122. </div>
  123. <div class="create-foot">
  124. <div class="foot-bos flex-row-between">
  125. <div></div>
  126. <div class="foot-box flex-column-between">
  127. <div class="flex-row-between" style="width: 100%">
  128. <div>商品件数</div>
  129. <div>{{ allNum }}</div>
  130. </div>
  131. <div class="flex-row-between" style="width: 100%">
  132. <div>商品总额</div>
  133. <div>¥{{ allMoney }}</div>
  134. </div>
  135. <div class="foot-yun flex-row-between">
  136. <div>运费</div>
  137. <div>¥0.00</div>
  138. </div>
  139. <div class="flex-row-between" style="width: 100%">
  140. <div>共计</div>
  141. <div class="zhu">¥{{ allMoney }}</div>
  142. </div>
  143. <div class="flex-row-between" style="width: 100%">
  144. <div></div>
  145. <div class="bnt-bos">
  146. <el-button @click="onPath('/cart')" class="bnt1">返回购物车修改</el-button>
  147. <el-button @click="onSubmit" class="bnt2" type="primary">提交订单</el-button>
  148. </div>
  149. </div>
  150. </div>
  151. </div>
  152. </div>
  153. <!-- 新增/编辑弹窗 -->
  154. <el-dialog v-model="dialogVisible" title="新增收货地址" width="550px">
  155. <el-form ref="formRef" :model="formAddress" :rules="rules" label-width="100px">
  156. <el-form-item label="收货人" prop="name">
  157. <el-input v-model="formAddress.name" placeholder="请输入收货人姓名" />
  158. </el-form-item>
  159. <el-form-item label="联系电话" prop="phone">
  160. <el-input v-model="formAddress.phone" placeholder="请输入联系电话" />
  161. </el-form-item>
  162. <el-form-item label="所在地区" prop="region">
  163. <el-cascader
  164. v-model="formAddress.regionCodes"
  165. :options="regionData as any"
  166. placeholder="请选择省/市/区"
  167. style="width: 100%"
  168. @change="handleRegionChange"
  169. />
  170. </el-form-item>
  171. <el-form-item label="详细地址" prop="address">
  172. <el-input v-model="formAddress.address" type="textarea" :rows="2" placeholder="请输入详细地址" />
  173. </el-form-item>
  174. <el-form-item label="设为默认"><el-switch v-model="formAddress.isDefault" /></el-form-item>
  175. </el-form>
  176. <template #footer>
  177. <el-button @click="dialogVisible = false">取消</el-button>
  178. <el-button type="danger" @click="handleSave">确定</el-button>
  179. </template>
  180. </el-dialog>
  181. </div>
  182. </template>
  183. <script setup lang="ts">
  184. import { getAddressList, addAddress } from '@/api/pc/enterprise';
  185. import { shoppingCartList, pcOrdersubmit } from '@/api/goods/index';
  186. import { onPath } from '@/utils/siteConfig';
  187. import { regionData } from 'element-china-area-data';
  188. import { useUserStore } from '@/store/modules/user';
  189. const userStore = useUserStore();
  190. const route = useRoute();
  191. const ids = ref<any>('');
  192. const tableData = ref<any>([]);
  193. const addressList = ref([]);
  194. const allNum = ref(0);
  195. const allMoney = ref<any>(0);
  196. const form = ref<any>({
  197. shippingAddressId: '',
  198. deliveryDate: '',
  199. expenseType: '0',
  200. purchaseReason: '',
  201. remark: '',
  202. shippingFee: 0,
  203. // 下单方式 1为购物车下单 2为直接下单
  204. placeOrderType: 1,
  205. productShoppingCartId: []
  206. });
  207. const options = [
  208. {
  209. value: '0',
  210. label: '日常物资采购'
  211. }
  212. ];
  213. //收货地址
  214. const dialogVisible = ref(false);
  215. const formRef = ref();
  216. const formAddress = reactive({ name: '', phone: '', regionCodes: [], region: '', address: '', isDefault: false });
  217. const rules = {
  218. name: [{ required: true, message: '请输入收货人姓名', trigger: 'blur' }],
  219. phone: [
  220. { required: true, message: '请输入联系电话', trigger: 'blur' },
  221. { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' }
  222. ],
  223. address: [{ required: true, message: '请输入详细地址', trigger: 'blur' }]
  224. };
  225. onMounted(() => {
  226. ids.value = route.query.ids;
  227. form.value.productShoppingCartId = ids.value.split(',');
  228. loadAddressList();
  229. getCartList();
  230. });
  231. // 加载地址列表
  232. const loadAddressList = async () => {
  233. try {
  234. const res = await getAddressList();
  235. if (res.code === 200) {
  236. addressList.value = res.rows || [];
  237. if (res.rows.length > 0) {
  238. form.value.shippingAddressId = res.rows[0].id;
  239. addressList.value.forEach((item: any) => {
  240. if (item.defaultAddress == 0) {
  241. form.value.shippingAddressId = item.id;
  242. }
  243. });
  244. }
  245. }
  246. } catch (error) {
  247. console.error('加载地址列表失败:', error);
  248. ElMessage.error('加载地址列表失败');
  249. }
  250. };
  251. //选择地址
  252. const onAddress = (res: any) => {
  253. form.value.shippingAddressId = res.id;
  254. };
  255. //购物车
  256. const getCartList = () => {
  257. const datas = { id: ids.value };
  258. shoppingCartList(datas).then((res) => {
  259. if (res.code == 200) {
  260. tableData.value = res.rows;
  261. res.rows.forEach((item: any) => {
  262. allNum.value = allNum.value + Number(item.productNum);
  263. allMoney.value = allMoney.value + Number(item.memberPrice * item.productNum);
  264. });
  265. allMoney.value = allMoney.value.toFixed(2);
  266. }
  267. });
  268. };
  269. const onSubmit = () => {
  270. if (!form.value.deliveryDate) {
  271. ElMessage.error('请选择配送时间');
  272. return;
  273. }
  274. if (!form.value.purchaseReason) {
  275. ElMessage.error('请输入采购事由');
  276. return;
  277. }
  278. pcOrdersubmit(form.value).then((res) => {
  279. if (res.code == 200) {
  280. onPath('/payc?id=' + res.data);
  281. }
  282. });
  283. console.log(form.value);
  284. };
  285. const handleAdd = () => {
  286. resetForm();
  287. dialogVisible.value = true;
  288. };
  289. const resetForm = () => {
  290. formAddress.name = '';
  291. formAddress.phone = '';
  292. formAddress.regionCodes = [];
  293. formAddress.region = '';
  294. formAddress.address = '';
  295. formAddress.isDefault = false;
  296. };
  297. // 处理地区选择变化
  298. const handleRegionChange = (value: string[]) => {
  299. if (value && value.length === 3) {
  300. // 根据选中的代码查找对应的名称
  301. // 根据编码获取名称
  302. const names: string[] = [];
  303. if (value[0]) {
  304. const province = regionData.find((item: any) => item.value === value[0]);
  305. if (province) {
  306. names.push(province.label);
  307. if (value[1] && province.children) {
  308. const city = province.children.find((item: any) => item.value === value[1]);
  309. if (city) {
  310. names.push(city.label);
  311. if (value[2] && city.children) {
  312. const county = city.children.find((item: any) => item.value === value[2]);
  313. if (county) {
  314. names.push(county.label);
  315. }
  316. }
  317. }
  318. }
  319. }
  320. }
  321. // 将省市区名称用斜杠连接
  322. formAddress.region = names.join('/');
  323. }
  324. };
  325. const handleSave = async () => {
  326. const valid = await formRef.value?.validate();
  327. if (!valid) return;
  328. try {
  329. const data: any = {
  330. consignee: formAddress.name,
  331. phone: formAddress.phone,
  332. address: formAddress.address,
  333. defaultAddress: formAddress.isDefault ? '0' : '1'
  334. };
  335. // 如果选择了省市区,发送代码
  336. if (formAddress.regionCodes && formAddress.regionCodes.length === 3) {
  337. data.provincialNo = formAddress.regionCodes[0];
  338. data.cityNo = formAddress.regionCodes[1];
  339. data.countryNo = formAddress.regionCodes[2];
  340. data.provincialCityCountry = formAddress.region;
  341. }
  342. await addAddress(data);
  343. ElMessage.success('新增成功');
  344. dialogVisible.value = false;
  345. loadAddressList();
  346. } catch (error) {
  347. ElMessage.error('操作失败');
  348. }
  349. };
  350. const disabledDate = (date: Date) => {
  351. // 获取今天的零点时间戳
  352. const today = new Date();
  353. today.setHours(0, 0, 0, 0);
  354. // 如果传入的日期 < 今天,则禁用 (返回 true)
  355. // 这样今天及以后的日期都会返回 false (可选)
  356. return date.getTime() < today.getTime();
  357. };
  358. </script>
  359. <style lang="scss" scoped>
  360. .create-pages {
  361. width: 100%;
  362. background-color: #ffffff;
  363. .create-bos {
  364. width: 100%;
  365. min-width: 1200px;
  366. max-width: 1500px;
  367. margin: 0 auto;
  368. .create-title {
  369. font-size: 16px;
  370. color: #101828;
  371. padding-top: 16px;
  372. }
  373. .create-head {
  374. width: 100%;
  375. min-width: 1200px;
  376. max-width: 1500px;
  377. height: 40px;
  378. background: #f9fafb;
  379. margin-top: 10px;
  380. font-weight: 600;
  381. font-size: 14px;
  382. color: #101828;
  383. padding-left: 10px;
  384. .border {
  385. display: inline-block;
  386. width: 1px;
  387. height: 12px;
  388. background-color: #e5e7eb;
  389. margin: 0 10px;
  390. }
  391. }
  392. .address-title {
  393. font-weight: 600;
  394. font-size: 14px;
  395. color: #101828;
  396. margin: 30px 0 10px 0;
  397. display: flex;
  398. justify-content: space-between;
  399. align-items: center;
  400. }
  401. .address-bos {
  402. display: flex;
  403. gap: 10px 12px;
  404. flex-wrap: wrap;
  405. .address-list {
  406. width: 291px;
  407. height: 92px;
  408. background: #ffffff;
  409. border-radius: 10px 10px 10px 10px;
  410. border: 1px solid #e5e7eb;
  411. padding: 12px;
  412. cursor: pointer;
  413. &.hig {
  414. border: 1px solid #e7000b;
  415. }
  416. .address1 {
  417. font-size: 14px;
  418. color: #364153;
  419. }
  420. .address2 {
  421. font-size: 14px;
  422. color: #101828;
  423. }
  424. .address3 {
  425. font-size: 14px;
  426. color: #364153;
  427. }
  428. }
  429. }
  430. .address-more {
  431. font-size: 14px;
  432. color: #6a7282;
  433. margin: 10px 0 30px 0;
  434. }
  435. .form-bos {
  436. margin-bottom: 20px;
  437. display: flex;
  438. align-items: start;
  439. .form-title {
  440. font-size: 14px;
  441. color: #1d2129;
  442. width: 80px;
  443. .asterisk {
  444. color: #f53f3f;
  445. width: 10px;
  446. }
  447. }
  448. :deep(.el-select__wrapper) {
  449. border: none;
  450. /* 可选:去除聚焦时的高亮 */
  451. box-shadow: none;
  452. outline: none;
  453. background: #f4f6f8;
  454. }
  455. :deep(.el-input__wrapper) {
  456. border: none;
  457. /* 可选:去除聚焦时的高亮 */
  458. box-shadow: none;
  459. outline: none;
  460. background: #f4f6f8;
  461. }
  462. :deep(.el-textarea__inner) {
  463. border: none;
  464. /* 可选:去除聚焦时的高亮 */
  465. box-shadow: none;
  466. outline: none;
  467. background: #f4f6f8;
  468. }
  469. }
  470. .cart-info {
  471. // width: 490px;
  472. height: 94px;
  473. display: flex;
  474. .cart-img {
  475. width: 94px;
  476. height: 94px;
  477. border-radius: 6px;
  478. }
  479. .cart-text {
  480. flex: 1;
  481. width: 0;
  482. padding-left: 10px;
  483. .text1 {
  484. font-size: 14px;
  485. color: #000000;
  486. height: 50px;
  487. }
  488. .text2 {
  489. font-size: 14px;
  490. color: #364153;
  491. span {
  492. margin-right: 10px;
  493. }
  494. }
  495. .text3 {
  496. font-size: 14px;
  497. color: #e7000b;
  498. }
  499. }
  500. }
  501. }
  502. .create-foot {
  503. width: 100%;
  504. height: 245px;
  505. background: #ffffff;
  506. box-shadow: 0px -2px 13px 0px rgba(0, 0, 0, 0.05);
  507. margin-top: 30px;
  508. .foot-bos {
  509. width: 1200px;
  510. margin: 0 auto;
  511. .foot-box {
  512. width: 458px;
  513. font-weight: 600;
  514. font-size: 14px;
  515. color: #101828;
  516. padding: 18px 0 20px 0;
  517. height: 245px;
  518. .foot-yun {
  519. width: 100%;
  520. height: 40px;
  521. background: #f7f8fc;
  522. border-radius: 10px;
  523. padding: 0 10px;
  524. font-weight: 400;
  525. font-size: 14px;
  526. color: #000000;
  527. }
  528. .zhu {
  529. color: #e7000b;
  530. }
  531. .bnt1 {
  532. width: 198px;
  533. height: 50px;
  534. background: #f7f8fa;
  535. }
  536. .bnt2 {
  537. width: 156px;
  538. height: 50px;
  539. }
  540. }
  541. }
  542. }
  543. }
  544. </style>