index.vue 11 KB

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