index.vue 11 KB

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