index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. <template>
  2. <view class="order-container">
  3. <erp-nav-bar title="添加型号" />
  4. <scroll-view :scroll-y="!showTypePicker && !showSurfacePicker && !showPackagePicker" class="order-scroll"
  5. :show-scrollbar="false" :enhanced="true">
  6. <view class="form-content">
  7. <!-- 模块 1:型材 -->
  8. <view class="section-card">
  9. <view class="section-header">
  10. <view class="blue-bar"></view>
  11. <text class="section-title">型材</text>
  12. </view>
  13. <view class="form-item">
  14. <text class="label required">型号</text>
  15. <view class="picker-box" @click="openTypePicker">
  16. <view class="picker-inner">
  17. <view class="picker-val" :class="{ placeholder: !formData.type }">
  18. {{ formData.type || '请选择型号' }}
  19. </view>
  20. <view class="line-arrow-down"></view>
  21. </view>
  22. </view>
  23. </view>
  24. <view class="row-flex">
  25. <view class="half-item">
  26. <text class="label">名称</text>
  27. <input class="input-box readonly small-font" v-model="formData.name" disabled
  28. placeholder="型号名称" />
  29. </view>
  30. <view class="half-item">
  31. <text class="label">材质</text>
  32. <input class="input-box readonly small-font" v-model="formData.material" disabled
  33. placeholder="材质" />
  34. </view>
  35. </view>
  36. </view>
  37. <!-- 模块 2:表面处理 -->
  38. <view class="section-card">
  39. <view class="section-header">
  40. <view class="blue-bar"></view>
  41. <text class="section-title">表面处理</text>
  42. </view>
  43. <view class="form-item">
  44. <text class="label required">表面名称</text>
  45. <view class="picker-box" @click="openSurfacePicker">
  46. <view class="picker-inner">
  47. <view class="picker-val" :class="{ placeholder: !formData.surfaceName }">
  48. {{ formData.surfaceName || '请选择表面名称' }}
  49. </view>
  50. <view class="line-arrow-down"></view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. <!-- 模块 3:包装 -->
  56. <view class="section-card">
  57. <view class="section-header">
  58. <view class="blue-bar"></view>
  59. <text class="section-title">包装</text>
  60. </view>
  61. <view class="form-item">
  62. <text class="label required">包装方式</text>
  63. <view class="picker-box" @click="openPackagePicker">
  64. <view class="picker-inner">
  65. <view class="picker-val" :class="{ placeholder: !formData.packageMethod }">
  66. {{ formData.packageMethod || '请选择包装方式' }}
  67. </view>
  68. <view class="line-arrow-down"></view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. <!-- 模块 4:壁厚 -->
  74. <view class="section-card">
  75. <view class="section-header">
  76. <view class="blue-bar"></view>
  77. <text class="section-title">壁厚</text>
  78. </view>
  79. <view class="row-flex">
  80. <view class="half-item">
  81. <text class="label required">长度</text>
  82. <view class="input-wrap">
  83. <input class="input-box" type="digit" v-model="formData.length" placeholder="请输入" />
  84. <text class="unit">mm</text>
  85. </view>
  86. </view>
  87. <view class="half-item">
  88. <text class="label required">壁厚</text>
  89. <view class="input-wrap">
  90. <input class="input-box" type="digit" v-model="formData.wallThickness"
  91. placeholder="请输入" />
  92. <text class="unit">mm</text>
  93. </view>
  94. </view>
  95. </view>
  96. </view>
  97. <!-- 模块 5:数量 -->
  98. <view class="section-card">
  99. <view class="section-header">
  100. <view class="blue-bar"></view>
  101. <text class="section-title">数量</text>
  102. </view>
  103. <view class="form-item no-margin-bottom">
  104. <text class="label required">支数</text>
  105. <input class="input-box full-width" type="number" v-model="formData.count"
  106. placeholder="请输入支数" />
  107. </view>
  108. </view>
  109. <view class="bottom-placeholder"></view>
  110. </view>
  111. </scroll-view>
  112. <view class="fixed-submit-bar">
  113. <button class="submit-btn" @click="confirmAddModel">确认并添加</button>
  114. </view>
  115. <!-- 型号选择 -->
  116. <view class="custom-picker-mask" v-if="showTypePicker" @click="closeTypePicker" @touchmove.stop.prevent>
  117. <view class="picker-popup" @click.stop>
  118. <view class="popup-header">
  119. <text class="cancel-text" @click="closeTypePicker">取消</text>
  120. <text class="popup-title">选择产品型号</text>
  121. <text class="confirm-text" @click="confirmTypeSelect">确定</text>
  122. </view>
  123. <scroll-view scroll-y class="item-list">
  124. <view class="option-item" v-for="(item, index) in typeList" :key="index"
  125. :class="{ active: tempSelectedIndex === index }" @click="selectTypeItem(index)">
  126. <text>{{ item.fnum }} - {{ item.fname }}</text>
  127. <icon type="success_no_circle" size="16" color="#C1001C" v-if="tempSelectedIndex === index">
  128. </icon>
  129. </view>
  130. </scroll-view>
  131. </view>
  132. </view>
  133. <!-- 表面处理选择 -->
  134. <view class="custom-picker-mask" v-if="showSurfacePicker" @click="closeSurfacePicker" @touchmove.stop.prevent>
  135. <view class="picker-popup" @click.stop>
  136. <view class="popup-header">
  137. <text class="cancel-text" @click="closeSurfacePicker">取消</text>
  138. <text class="popup-title">选择表面处理</text>
  139. <text class="confirm-text" @click="confirmSurfaceSelect">确定</text>
  140. </view>
  141. <scroll-view scroll-y class="item-list">
  142. <view class="option-item" v-for="(item, index) in surfaceList" :key="index"
  143. :class="{ active: tempSurfaceIndex === index }" @click="selectSurfaceItem(index)">
  144. <text>{{ item.fnum }} - {{ item.fname }}</text>
  145. <icon type="success_no_circle" size="16" color="#C1001C" v-if="tempSurfaceIndex === index">
  146. </icon>
  147. </view>
  148. </scroll-view>
  149. </view>
  150. </view>
  151. <!-- 包装方式选择 -->
  152. <view class="custom-picker-mask" v-if="showPackagePicker" @click="closePackagePicker" @touchmove.stop.prevent>
  153. <view class="picker-popup" @click.stop>
  154. <view class="popup-header">
  155. <text class="cancel-text" @click="closePackagePicker">取消</text>
  156. <text class="popup-title">选择包装方式</text>
  157. <text class="confirm-text" @click="confirmPackageSelect">确定</text>
  158. </view>
  159. <scroll-view scroll-y class="item-list">
  160. <view class="option-item" v-for="(item, index) in packageList" :key="index"
  161. :class="{ active: tempPackageIndex === index }" @click="selectPackageItem(index)">
  162. <text>{{ item.fnum }} - {{ item.fname }}</text>
  163. <icon type="success_no_circle" size="16" color="#C1001C" v-if="tempPackageIndex === index">
  164. </icon>
  165. </view>
  166. </scroll-view>
  167. </view>
  168. </view>
  169. </view>
  170. </template>
  171. <script>
  172. import ErpNavBar from '@/components/erp-nav-bar.vue';
  173. import { listAllColorKind } from '@/api/erp/colorKind.js';
  174. import { listAllPack } from '@/api/erp/pack.js';
  175. import { listAllModel } from '@/api/erp/model.js';
  176. import { addOrderDetail } from '@/api/erp/orderDetail.js';
  177. export default {
  178. components: { ErpNavBar },
  179. data() {
  180. return {
  181. showTypePicker: false, showSurfacePicker: false, showPackagePicker: false,
  182. tempSelectedIndex: -1, tempSurfaceIndex: -1, tempPackageIndex: -1,
  183. typeList: [],
  184. surfaceList: [],
  185. packageList: [],
  186. formData: {
  187. type: '', modelId: '', name: '', material: '',
  188. surfaceName: '', surfaceId: '', packageMethod: '', packageId: '', length: '',
  189. wallThickness: '', count: ''
  190. }
  191. }
  192. },
  193. async onLoad() {
  194. await Promise.all([
  195. this.loadModels(),
  196. this.loadSurfaceKinds(),
  197. this.loadPackageMethods()
  198. ]);
  199. },
  200. methods: {
  201. async loadModels() {
  202. try {
  203. const res = await listAllModel();
  204. this.typeList = res.data || [];
  205. } catch (e) {
  206. uni.showToast({ title: '加载型号失败', icon: 'none' });
  207. }
  208. },
  209. async loadPackageMethods() {
  210. try {
  211. const res = await listAllPack();
  212. this.packageList = res.data || [];
  213. } catch (e) {
  214. uni.showToast({ title: '加载包装方式失败', icon: 'none' });
  215. }
  216. },
  217. async loadSurfaceKinds() {
  218. try {
  219. const res = await listAllColorKind();
  220. this.surfaceList = (res.data || []).filter(item => item.fname !== '所有类别');
  221. } catch (e) {
  222. uni.showToast({ title: '加载表面处理失败', icon: 'none' });
  223. }
  224. },
  225. openTypePicker() { if (this.formData.type) this.tempSelectedIndex = this.typeList.findIndex(item => item.fnum === this.formData.type); this.showTypePicker = true; },
  226. closeTypePicker() { this.showTypePicker = false; },
  227. selectTypeItem(index) { this.tempSelectedIndex = index; },
  228. confirmTypeSelect() {
  229. if (this.tempSelectedIndex === -1) return;
  230. const item = this.typeList[this.tempSelectedIndex];
  231. this.formData.type = item.fnum;
  232. this.formData.modelId = item.frowId;
  233. this.formData.name = item.fname;
  234. this.formData.wallThickness = item.thick ? Number(item.thick).toFixed(4) : '';
  235. // 材质目前默认为 6063-T5,后续如有材质表可对接
  236. this.formData.material = '6063-T5';
  237. this.closeTypePicker();
  238. },
  239. openSurfacePicker() { if (this.formData.surfaceName) this.tempSurfaceIndex = this.surfaceList.findIndex(item => item.fname === this.formData.surfaceName); this.showSurfacePicker = true; },
  240. closeSurfacePicker() { this.showSurfacePicker = false; },
  241. selectSurfaceItem(index) { this.tempSurfaceIndex = index; },
  242. confirmSurfaceSelect() {
  243. if (this.tempSurfaceIndex === -1) return;
  244. const item = this.surfaceList[this.tempSurfaceIndex];
  245. this.formData.surfaceName = item.fname;
  246. this.formData.surfaceId = item.frowId;
  247. this.closeSurfacePicker();
  248. },
  249. openPackagePicker() { if (this.formData.packageMethod) this.tempPackageIndex = this.packageList.findIndex(item => item.fname === this.formData.packageMethod); this.showPackagePicker = true; },
  250. closePackagePicker() { this.showPackagePicker = false; },
  251. selectPackageItem(index) { this.tempPackageIndex = index; },
  252. confirmPackageSelect() {
  253. if (this.tempPackageIndex === -1) return;
  254. const item = this.packageList[this.tempPackageIndex];
  255. this.formData.packageMethod = item.fname;
  256. this.formData.packageId = item.frowId;
  257. this.closePackagePicker();
  258. },
  259. async confirmAddModel() {
  260. const fields = [
  261. { key: 'type', label: '型号' },
  262. { key: 'surfaceName', label: '表面名称' },
  263. { key: 'packageMethod', label: '包装方式' },
  264. { key: 'length', label: '长度' },
  265. { key: 'wallThickness', label: '壁厚' },
  266. { key: 'count', label: '支数' }
  267. ];
  268. for (let item of fields) {
  269. if (!this.formData[item.key]) {
  270. uni.showToast({ title: `请完善项目:${item.label}`, icon: 'none' });
  271. return;
  272. }
  273. }
  274. // 数据处理:保留四位小数
  275. const finalData = {
  276. fOrderId: null,
  277. modelId: this.formData.modelId,
  278. modelNum: this.formData.type,
  279. modelName: this.formData.name,
  280. material: this.formData.material,
  281. surfaceId: this.formData.surfaceId,
  282. surfaceName: this.formData.surfaceName,
  283. packId: this.formData.packageId,
  284. packName: this.formData.packageMethod,
  285. length: parseFloat(this.formData.length || 0).toFixed(4),
  286. wallThickness: parseFloat(this.formData.wallThickness || 0).toFixed(4),
  287. count: parseInt(this.formData.count || 0)
  288. };
  289. uni.showLoading({ title: '正在保存...' });
  290. try {
  291. await addOrderDetail(finalData);
  292. uni.hideLoading();
  293. uni.showToast({ title: '添加成功', icon: 'success' });
  294. uni.$emit('add_order_item', finalData);
  295. setTimeout(() => {
  296. uni.navigateBack();
  297. }, 1000);
  298. } catch (e) {
  299. uni.hideLoading();
  300. // 错误已由 request.js 拦截提示,若未拦截可在此处处理提示
  301. }
  302. }
  303. }
  304. }
  305. </script>
  306. <style scoped>
  307. /deep/ ::-webkit-scrollbar {
  308. display: none !important;
  309. width: 0 !important;
  310. height: 0 !important;
  311. }
  312. .order-container {
  313. width: 100%;
  314. height: 100vh;
  315. background: #f7f8fa;
  316. display: flex;
  317. flex-direction: column;
  318. overflow: hidden;
  319. }
  320. .order-scroll {
  321. flex: 1;
  322. height: 0;
  323. }
  324. .form-content {
  325. padding: 30rpx;
  326. padding-bottom: calc(180rpx + env(safe-area-inset-bottom));
  327. }
  328. .section-card {
  329. background: #fff;
  330. border-radius: 24rpx;
  331. padding: 30rpx;
  332. margin-bottom: 30rpx;
  333. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.02);
  334. }
  335. .section-header {
  336. display: flex;
  337. align-items: center;
  338. margin-bottom: 40rpx;
  339. }
  340. .blue-bar {
  341. width: 8rpx;
  342. height: 32rpx;
  343. background: #C1001C;
  344. border-radius: 4rpx;
  345. margin-right: 16rpx;
  346. }
  347. .section-title {
  348. font-size: 32rpx;
  349. font-weight: bold;
  350. color: #333;
  351. }
  352. .form-item {
  353. margin-bottom: 40rpx;
  354. }
  355. .no-margin-bottom {
  356. margin-bottom: 0;
  357. }
  358. .row-flex {
  359. display: flex;
  360. justify-content: space-between;
  361. }
  362. .half-item {
  363. width: 48%;
  364. }
  365. .label {
  366. font-size: 28rpx;
  367. color: #333;
  368. margin-bottom: 20rpx;
  369. display: block;
  370. font-weight: 500;
  371. }
  372. .label.required::after {
  373. content: ' *';
  374. color: #ff4d4f;
  375. font-weight: bold;
  376. margin-left: 4rpx;
  377. }
  378. .picker-box {
  379. background: #f9fafc;
  380. border-radius: 12rpx;
  381. height: 100rpx;
  382. border: 1rpx solid #eee;
  383. display: flex;
  384. align-items: center;
  385. }
  386. .picker-inner {
  387. width: 100%;
  388. height: 100%;
  389. display: flex;
  390. align-items: center;
  391. justify-content: space-between;
  392. padding: 0 30rpx;
  393. box-sizing: border-box;
  394. }
  395. .picker-val {
  396. font-size: 30rpx;
  397. color: #333;
  398. }
  399. .picker-val.placeholder {
  400. color: #ccc;
  401. font-size: 28rpx;
  402. }
  403. .line-arrow-down {
  404. width: 14rpx;
  405. height: 14rpx;
  406. border-right: 3rpx solid #bbb;
  407. border-bottom: 3rpx solid #bbb;
  408. transform: rotate(45deg);
  409. margin-top: -8rpx;
  410. margin-right: 4rpx;
  411. }
  412. .input-wrap {
  413. position: relative;
  414. width: 100%;
  415. }
  416. .input-box {
  417. font-size: 30rpx;
  418. color: #333;
  419. width: 100%;
  420. height: 100rpx;
  421. background: #f9fafc;
  422. border-radius: 12rpx;
  423. padding: 0 80rpx 0 30rpx;
  424. box-sizing: border-box;
  425. border: 1rpx solid #eee;
  426. }
  427. .input-box.readonly {
  428. background: #f8f9fa;
  429. color: #666;
  430. border-color: #f0f0f0;
  431. }
  432. .input-box.full-width {
  433. padding: 0 30rpx;
  434. }
  435. .unit {
  436. position: absolute;
  437. right: 24rpx;
  438. top: 50%;
  439. transform: translateY(-50%);
  440. font-size: 26rpx;
  441. color: #999;
  442. font-weight: 500;
  443. }
  444. .small-font {
  445. font-size: 26rpx !important;
  446. }
  447. .fixed-submit-bar {
  448. position: fixed;
  449. bottom: 0;
  450. left: 0;
  451. width: 100%;
  452. background: #fff;
  453. padding: 20rpx 30rpx calc(env(safe-area-inset-bottom) + 20rpx);
  454. box-sizing: border-box;
  455. box-shadow: 0 -10rpx 30rpx rgba(0, 0, 0, 0.05);
  456. z-index: 100;
  457. }
  458. .submit-btn {
  459. background: #C1001C;
  460. color: #fff;
  461. height: 100rpx;
  462. border-radius: 50rpx;
  463. display: flex;
  464. align-items: center;
  465. justify-content: center;
  466. font-size: 34rpx;
  467. font-weight: bold;
  468. border: none;
  469. }
  470. .submit-btn:active {
  471. opacity: 0.9;
  472. transform: scale(0.98);
  473. }
  474. .custom-picker-mask {
  475. position: fixed;
  476. top: 0;
  477. left: 0;
  478. right: 0;
  479. bottom: 0;
  480. background: rgba(0, 0, 0, 0.4);
  481. z-index: 1000;
  482. display: flex;
  483. align-items: flex-end;
  484. }
  485. .picker-popup {
  486. width: 100%;
  487. background: #fff;
  488. border-radius: 32rpx 32rpx 0 0;
  489. padding-bottom: calc(env(safe-area-inset-bottom) + 20rpx);
  490. animation: slideUp 0.15s ease-out;
  491. }
  492. @keyframes slideUp {
  493. from {
  494. transform: translateY(100%);
  495. }
  496. to {
  497. transform: translateY(0);
  498. }
  499. }
  500. .popup-header {
  501. display: flex;
  502. justify-content: space-between;
  503. align-items: center;
  504. padding: 30rpx 40rpx;
  505. border-bottom: 1rpx solid #f0f0f0;
  506. }
  507. .popup-title {
  508. font-size: 32rpx;
  509. font-weight: bold;
  510. color: #333;
  511. }
  512. .cancel-text,
  513. .confirm-text {
  514. font-size: 30rpx;
  515. padding: 10rpx;
  516. }
  517. .confirm-text {
  518. color: #C1001C;
  519. font-weight: bold;
  520. }
  521. .item-list {
  522. max-height: 50vh;
  523. padding: 0 40rpx;
  524. }
  525. .option-item {
  526. height: 110rpx;
  527. display: flex;
  528. align-items: center;
  529. justify-content: space-between;
  530. border-bottom: 1rpx solid #f8f8f8;
  531. font-size: 32rpx;
  532. color: #333;
  533. }
  534. .option-item.active {
  535. color: #C1001C;
  536. font-weight: bold;
  537. }
  538. .bottom-placeholder {
  539. height: 60rpx;
  540. }
  541. </style>