index.vue 11 KB

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