index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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. onPullDownRefresh() {
  154. // 下拉刷新时重新加载所有数据
  155. Promise.all([
  156. this.loadOrderDetail(),
  157. this.loadReceiptList()
  158. ]).finally(() => {
  159. uni.stopPullDownRefresh()
  160. uni.$u.toast('刷新成功')
  161. })
  162. },
  163. methods: {
  164. /**
  165. * 初始化参数
  166. */
  167. initParams(options) {
  168. const { item, orderId, type, clueId } = options
  169. this.item = item || ''
  170. this.orderId = orderId || ''
  171. this.type = type || ''
  172. this.clueId = clueId || ''
  173. },
  174. /**
  175. * 加载订单详情
  176. */
  177. async loadOrderDetail() {
  178. try {
  179. const res = await uni.$u.api.getClueSendFormVoByOrderId({
  180. id: this.orderId
  181. })
  182. if (res.code === 200) {
  183. this.orderDetail = res.data || {}
  184. }
  185. } catch (error) {
  186. console.error('加载订单详情失败:', error)
  187. uni.$u.toast('加载订单详情失败')
  188. }
  189. },
  190. /**
  191. * 加载收单列表
  192. */
  193. async loadReceiptList() {
  194. try {
  195. const res = await uni.$u.api.clueReceiptFormListByOrderId(this.orderId)
  196. if (res.code === 200) {
  197. this.receiptList = res.data || []
  198. // 默认选择第一个收单
  199. if (this.receiptList.length > 0) {
  200. this.handleReceiptClick(this.receiptList[0])
  201. }
  202. }
  203. } catch (error) {
  204. console.error('加载收单列表失败:', error)
  205. uni.$u.toast('加载收单列表失败')
  206. }
  207. },
  208. /**
  209. * 点击收单项
  210. */
  211. handleReceiptClick(item) {
  212. this.currentReceipt = item
  213. this.topInfo.brand = item.brand || '暂无'
  214. this.topInfo.model = item.model || '暂无'
  215. this.topInfo.price = item.sellingPrice || '暂无'
  216. },
  217. /**
  218. * 点击品牌
  219. */
  220. handleBrandClick() {
  221. this.editBrandSelectorVisible = true
  222. this.loadBrandList()
  223. },
  224. /**
  225. * 点击型号
  226. */
  227. handleModelClick() {
  228. this.modalConfig = {
  229. title: '修改型号',
  230. value: this.currentReceipt.model || '',
  231. placeholder: '请输入型号'
  232. }
  233. this.currentEditField = 'model'
  234. this.modalVisible = true
  235. },
  236. /**
  237. * 点击价格
  238. */
  239. handlePriceClick() {
  240. this.modalConfig = {
  241. title: '修改价格',
  242. value: this.currentReceipt.sellingPrice?.toString() || '',
  243. placeholder: '请输入价格'
  244. }
  245. this.currentEditField = 'price'
  246. this.modalVisible = true
  247. },
  248. /**
  249. * 点击加一单
  250. */
  251. handleAddClick() {
  252. this.addOneModalVisible = true
  253. this.loadBrandList()
  254. },
  255. /**
  256. * 加载品牌列表
  257. */
  258. async loadBrandList() {
  259. try {
  260. const res = await this.$getDicts('crm_form_brand')
  261. this.brandColumns = [res]
  262. } catch (error) {
  263. console.error('加载品牌列表失败:', error)
  264. }
  265. },
  266. /**
  267. * 确认修改模态窗
  268. */
  269. async handleModalConfirm(value) {
  270. try {
  271. if (this.currentEditField === 'model') {
  272. await uni.$u.api.updateReceiptForm({
  273. model: value,
  274. id: this.currentReceipt.id
  275. })
  276. } else if (this.currentEditField === 'price') {
  277. await uni.$u.api.updateReceiptForm({
  278. sellingPrice: value,
  279. id: this.currentReceipt.id
  280. })
  281. }
  282. uni.$u.toast('修改成功')
  283. this.loadReceiptList()
  284. } catch (error) {
  285. console.error('修改失败:', error)
  286. uni.$u.toast('修改失败')
  287. } finally {
  288. this.modalVisible = false
  289. }
  290. },
  291. /**
  292. * 取消修改模态窗
  293. */
  294. handleModalCancel() {
  295. this.modalVisible = false
  296. },
  297. /**
  298. * 确认编辑品牌
  299. */
  300. async handleEditBrandConfirm(data) {
  301. try {
  302. await uni.$u.api.updateReceiptForm({
  303. brand: data.value[0].dictValue,
  304. id: this.currentReceipt.id
  305. })
  306. uni.$u.toast('修改成功')
  307. this.loadReceiptList()
  308. } catch (error) {
  309. console.error('修改品牌失败:', error)
  310. uni.$u.toast('修改失败')
  311. } finally {
  312. this.editBrandSelectorVisible = false
  313. }
  314. },
  315. /**
  316. * 确认选择品牌(加一单)
  317. */
  318. handleBrandConfirm(data) {
  319. this.currentAddBrand = data.value[0]
  320. this.showBrandSelector = false
  321. },
  322. /**
  323. * 确认加一单
  324. */
  325. async handleAddOneConfirm() {
  326. // 验证品牌是否已选择(必选)
  327. if (!this.currentAddBrand.dictValue) {
  328. uni.$u.toast('请选择品牌')
  329. return
  330. }
  331. try {
  332. await uni.$u.api.addReceiptForm({
  333. brand: this.currentAddBrand.dictValue,
  334. model: this.currentAddModel || '',
  335. sellingPrice: this.currentAddPrice || '',
  336. sendFormId: this.orderId,
  337. clueId: this.clueId
  338. })
  339. uni.$u.toast('添加成功')
  340. this.loadReceiptList()
  341. } catch (error) {
  342. console.error('添加失败:', error)
  343. uni.$u.toast('添加失败')
  344. } finally {
  345. this.addOneModalVisible = false
  346. this.currentAddBrand = {}
  347. this.currentAddModel = ''
  348. this.currentAddPrice = ''
  349. }
  350. },
  351. /**
  352. * 取消加一单
  353. */
  354. handleAddOneCancel() {
  355. this.addOneModalVisible = false
  356. this.currentAddBrand = {}
  357. this.currentAddModel = ''
  358. this.currentAddPrice = ''
  359. }
  360. }
  361. }
  362. </script>
  363. <style scoped lang="scss">
  364. .order-detail-container {
  365. min-height: 100vh;
  366. background-color: #f9fafb;
  367. }
  368. .navbar-center {
  369. display: flex;
  370. align-items: center;
  371. background-color: #fff;
  372. border-radius: 40rpx;
  373. padding: 10rpx 20rpx;
  374. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  375. }
  376. .navbar-item {
  377. font-weight: bold;
  378. color: #333;
  379. font-size: 28rpx;
  380. &.price {
  381. color: blueviolet;
  382. }
  383. }
  384. .navbar-divider {
  385. margin: 0 15rpx;
  386. color: #ddd;
  387. font-size: 28rpx;
  388. }
  389. .navbar-right {
  390. display: flex;
  391. flex-direction: column;
  392. align-items: center;
  393. justify-content: center;
  394. font-size: 20rpx;
  395. color: blueviolet;
  396. }
  397. .add-icon {
  398. width: 30rpx;
  399. height: 30rpx;
  400. }
  401. .add-text {
  402. margin-top: 4rpx;
  403. }
  404. .receipt-tabs {
  405. background-color: #fff;
  406. }
  407. .add-one-modal-content {
  408. padding: 20rpx 0;
  409. }
  410. .add-one-form-item {
  411. margin-bottom: 30rpx;
  412. &:last-child {
  413. margin-bottom: 0;
  414. }
  415. }
  416. .form-label {
  417. display: block;
  418. font-size: 28rpx;
  419. color: #333;
  420. margin-bottom: 15rpx;
  421. font-weight: 500;
  422. }
  423. .required {
  424. color: #f56c6c;
  425. margin-left: 4rpx;
  426. }
  427. .brand-select-btn {
  428. width: 100%;
  429. }
  430. .form-input {
  431. width: 100%;
  432. border: 2rpx solid #e0e0e0;
  433. border-radius: 10rpx;
  434. padding: 20rpx;
  435. font-size: 28rpx;
  436. }
  437. </style>