index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <template>
  2. <view class="order-detail-container">
  3. <!-- 顶部导航栏 -->
  4. <u-navbar :autoBack="true" :placeholder="true" v-hideNav>
  5. <template slot="center">
  6. <view class="navbar-center">
  7. <text class="navbar-item" @click="handleBrandClick">{{ topInfo.brand }}</text>
  8. <text class="navbar-divider">|</text>
  9. <text class="navbar-item" @click="handleModelClick">{{ topInfo.model }}</text>
  10. <text class="navbar-divider">|</text>
  11. <text class="navbar-item price" @click="handlePriceClick">¥{{ topInfo.price }}</text>
  12. </view>
  13. </template>
  14. <template slot="right">
  15. <view class="navbar-right" @click="handleAddClick">
  16. <image src="/static/icons/plus.png" mode="scaleToFill" class="add-icon" />
  17. <text class="add-text">加一单</text>
  18. </view>
  19. </template>
  20. </u-navbar>
  21. <!-- 收单列表切换 -->
  22. <u-tabs
  23. keyName="brand"
  24. :list="receiptList"
  25. @click="handleReceiptClick"
  26. class="receipt-tabs"
  27. />
  28. <!-- 订单详情视图 -->
  29. <OrderDetailView
  30. :order-detail="orderDetail"
  31. :top-info="topInfo"
  32. :order-id="orderId"
  33. :current-receipt="currentReceipt"
  34. />
  35. <!-- 加一单模态窗 -->
  36. <u-modal
  37. :show="addOneModalVisible"
  38. title="加一单"
  39. showCancelButton
  40. @cancel="handleAddOneCancel"
  41. @confirm="handleAddOneConfirm"
  42. >
  43. <view class="add-one-modal-content">
  44. <view class="add-one-form-item">
  45. <text class="form-label">品牌<text class="required">*</text></text>
  46. <u-button
  47. type="primary"
  48. plain
  49. @click="showBrandSelector = true"
  50. class="brand-select-btn"
  51. >
  52. {{ currentAddBrand.dictLabel || '点击请选择品牌' }}
  53. </u-button>
  54. </view>
  55. <view class="add-one-form-item">
  56. <text class="form-label">型号</text>
  57. <u-input
  58. v-model="currentAddModel"
  59. placeholder="请输入型号"
  60. class="form-input"
  61. />
  62. </view>
  63. <view class="add-one-form-item">
  64. <text class="form-label">价格</text>
  65. <u-input
  66. v-model="currentAddPrice"
  67. placeholder="请输入价格"
  68. type="number"
  69. class="form-input"
  70. />
  71. </view>
  72. </view>
  73. </u-modal>
  74. <!-- 品牌选择器 -->
  75. <u-picker
  76. :show="showBrandSelector"
  77. :columns="brandColumns"
  78. keyName="dictLabel"
  79. @confirm="handleBrandConfirm"
  80. @cancel="showBrandSelector = false"
  81. />
  82. <!-- 编辑品牌选择器 -->
  83. <u-picker
  84. :show="editBrandSelectorVisible"
  85. :columns="brandColumns"
  86. keyName="dictLabel"
  87. @confirm="handleEditBrandConfirm"
  88. @cancel="editBrandSelectorVisible = false"
  89. />
  90. <!-- 修改型号/价格弹窗 -->
  91. <CustomModal
  92. :visible="modalVisible"
  93. :title="modalConfig.title"
  94. :value="modalConfig.value"
  95. :placeholder="modalConfig.placeholder"
  96. @cancel="handleModalCancel"
  97. @confirm="handleModalConfirm"
  98. />
  99. </view>
  100. </template>
  101. <script>
  102. import OrderDetailView from './components/OrderDetailView.vue'
  103. import CustomModal from './components/CustomModal.vue'
  104. export default {
  105. name: 'OrderDetailIndex',
  106. components: {
  107. OrderDetailView,
  108. CustomModal
  109. },
  110. data() {
  111. return {
  112. // 顶部信息
  113. topInfo: {
  114. brand: '',
  115. model: '',
  116. price: ''
  117. },
  118. // 路由参数
  119. orderId: '',
  120. clueId: '',
  121. item: '',
  122. type: '',
  123. // 订单详情
  124. orderDetail: {},
  125. // 收单列表
  126. receiptList: [],
  127. // 当前选中的收单
  128. currentReceipt: {},
  129. // 模态窗状态
  130. addOneModalVisible: false,
  131. showBrandSelector: false,
  132. editBrandSelectorVisible: false,
  133. modalVisible: false,
  134. // 品牌选择相关
  135. brandColumns: [[]],
  136. currentAddBrand: {},
  137. currentAddModel: '',
  138. currentAddPrice: '',
  139. // 模态窗配置
  140. modalConfig: {
  141. title: '',
  142. value: '',
  143. placeholder: ''
  144. },
  145. currentEditField: ''
  146. }
  147. },
  148. onLoad(options) {
  149. this.initParams(options)
  150. this.loadOrderDetail()
  151. this.loadReceiptList()
  152. },
  153. methods: {
  154. /**
  155. * 初始化参数
  156. */
  157. initParams(options) {
  158. const { item, orderId, type, clueId } = options
  159. this.item = item || ''
  160. this.orderId = orderId || ''
  161. this.type = type || ''
  162. this.clueId = clueId || ''
  163. },
  164. /**
  165. * 加载订单详情
  166. */
  167. async loadOrderDetail() {
  168. try {
  169. const res = await uni.$u.api.getClueSendFormVoByOrderId({
  170. id: this.orderId
  171. })
  172. if (res.code === 200) {
  173. this.orderDetail = res.data || {}
  174. }
  175. } catch (error) {
  176. console.error('加载订单详情失败:', error)
  177. uni.$u.toast('加载订单详情失败')
  178. }
  179. },
  180. /**
  181. * 加载收单列表
  182. */
  183. async loadReceiptList() {
  184. try {
  185. const res = await uni.$u.api.clueReceiptFormListByOrderId(this.orderId)
  186. if (res.code === 200) {
  187. this.receiptList = res.data || []
  188. // 默认选择第一个收单
  189. if (this.receiptList.length > 0) {
  190. this.handleReceiptClick(this.receiptList[0])
  191. }
  192. }
  193. } catch (error) {
  194. console.error('加载收单列表失败:', error)
  195. uni.$u.toast('加载收单列表失败')
  196. }
  197. },
  198. /**
  199. * 点击收单项
  200. */
  201. handleReceiptClick(item) {
  202. this.currentReceipt = item
  203. this.topInfo.brand = item.brand || '暂无'
  204. this.topInfo.model = item.model || '暂无'
  205. this.topInfo.price = item.sellingPrice || '暂无'
  206. },
  207. /**
  208. * 点击品牌
  209. */
  210. handleBrandClick() {
  211. this.editBrandSelectorVisible = true
  212. this.loadBrandList()
  213. },
  214. /**
  215. * 点击型号
  216. */
  217. handleModelClick() {
  218. this.modalConfig = {
  219. title: '修改型号',
  220. value: this.currentReceipt.model || '',
  221. placeholder: '请输入型号'
  222. }
  223. this.currentEditField = 'model'
  224. this.modalVisible = true
  225. },
  226. /**
  227. * 点击价格
  228. */
  229. handlePriceClick() {
  230. this.modalConfig = {
  231. title: '修改价格',
  232. value: this.currentReceipt.sellingPrice?.toString() || '',
  233. placeholder: '请输入价格'
  234. }
  235. this.currentEditField = 'price'
  236. this.modalVisible = true
  237. },
  238. /**
  239. * 点击加一单
  240. */
  241. handleAddClick() {
  242. this.addOneModalVisible = true
  243. this.loadBrandList()
  244. },
  245. /**
  246. * 加载品牌列表
  247. */
  248. async loadBrandList() {
  249. try {
  250. const res = await this.$getDicts('crm_form_brand')
  251. this.brandColumns = [res]
  252. } catch (error) {
  253. console.error('加载品牌列表失败:', error)
  254. }
  255. },
  256. /**
  257. * 确认修改模态窗
  258. */
  259. async handleModalConfirm(value) {
  260. try {
  261. if (this.currentEditField === 'model') {
  262. await uni.$u.api.updateReceiptForm({
  263. model: value,
  264. id: this.currentReceipt.id
  265. })
  266. } else if (this.currentEditField === 'price') {
  267. await uni.$u.api.updateReceiptForm({
  268. sellingPrice: value,
  269. id: this.currentReceipt.id
  270. })
  271. }
  272. uni.$u.toast('修改成功')
  273. this.loadReceiptList()
  274. } catch (error) {
  275. console.error('修改失败:', error)
  276. uni.$u.toast('修改失败')
  277. } finally {
  278. this.modalVisible = false
  279. }
  280. },
  281. /**
  282. * 取消修改模态窗
  283. */
  284. handleModalCancel() {
  285. this.modalVisible = false
  286. },
  287. /**
  288. * 确认编辑品牌
  289. */
  290. async handleEditBrandConfirm(data) {
  291. try {
  292. await uni.$u.api.updateReceiptForm({
  293. brand: data.value[0].dictValue,
  294. id: this.currentReceipt.id
  295. })
  296. uni.$u.toast('修改成功')
  297. this.loadReceiptList()
  298. } catch (error) {
  299. console.error('修改品牌失败:', error)
  300. uni.$u.toast('修改失败')
  301. } finally {
  302. this.editBrandSelectorVisible = false
  303. }
  304. },
  305. /**
  306. * 确认选择品牌(加一单)
  307. */
  308. handleBrandConfirm(data) {
  309. this.currentAddBrand = data.value[0]
  310. this.showBrandSelector = false
  311. },
  312. /**
  313. * 确认加一单
  314. */
  315. async handleAddOneConfirm() {
  316. // 验证品牌是否已选择(必选)
  317. if (!this.currentAddBrand.dictValue) {
  318. uni.$u.toast('请选择品牌')
  319. return
  320. }
  321. try {
  322. await uni.$u.api.addReceiptForm({
  323. brand: this.currentAddBrand.dictValue,
  324. model: this.currentAddModel || '',
  325. sellingPrice: this.currentAddPrice || '',
  326. sendFormId: this.orderId,
  327. clueId: this.clueId
  328. })
  329. uni.$u.toast('添加成功')
  330. this.loadReceiptList()
  331. } catch (error) {
  332. console.error('添加失败:', error)
  333. uni.$u.toast('添加失败')
  334. } finally {
  335. this.addOneModalVisible = false
  336. this.currentAddBrand = {}
  337. this.currentAddModel = ''
  338. this.currentAddPrice = ''
  339. }
  340. },
  341. /**
  342. * 取消加一单
  343. */
  344. handleAddOneCancel() {
  345. this.addOneModalVisible = false
  346. this.currentAddBrand = {}
  347. this.currentAddModel = ''
  348. this.currentAddPrice = ''
  349. }
  350. }
  351. }
  352. </script>
  353. <style scoped lang="scss">
  354. .order-detail-container {
  355. min-height: 100vh;
  356. background-color: #f9fafb;
  357. }
  358. .navbar-center {
  359. display: flex;
  360. align-items: center;
  361. background-color: #fff;
  362. border-radius: 40rpx;
  363. padding: 10rpx 20rpx;
  364. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  365. }
  366. .navbar-item {
  367. font-weight: bold;
  368. color: #333;
  369. font-size: 28rpx;
  370. &.price {
  371. color: blueviolet;
  372. }
  373. }
  374. .navbar-divider {
  375. margin: 0 15rpx;
  376. color: #ddd;
  377. font-size: 28rpx;
  378. }
  379. .navbar-right {
  380. display: flex;
  381. flex-direction: column;
  382. align-items: center;
  383. justify-content: center;
  384. font-size: 20rpx;
  385. color: blueviolet;
  386. }
  387. .add-icon {
  388. width: 30rpx;
  389. height: 30rpx;
  390. }
  391. .add-text {
  392. margin-top: 4rpx;
  393. }
  394. .receipt-tabs {
  395. background-color: #fff;
  396. }
  397. .add-one-modal-content {
  398. padding: 20rpx 0;
  399. }
  400. .add-one-form-item {
  401. margin-bottom: 30rpx;
  402. &:last-child {
  403. margin-bottom: 0;
  404. }
  405. }
  406. .form-label {
  407. display: block;
  408. font-size: 28rpx;
  409. color: #333;
  410. margin-bottom: 15rpx;
  411. font-weight: 500;
  412. }
  413. .required {
  414. color: #f56c6c;
  415. margin-left: 4rpx;
  416. }
  417. .brand-select-btn {
  418. width: 100%;
  419. }
  420. .form-input {
  421. width: 100%;
  422. border: 2rpx solid #e0e0e0;
  423. border-radius: 10rpx;
  424. padding: 20rpx;
  425. font-size: 28rpx;
  426. }
  427. </style>