taskForm.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <view class="">
  3. <u-sticky offset-top="50">
  4. <u-subsection fontSize='25' mode='subsection' :list="list" :current="curNow" @change="sectionChange"
  5. activeColor='#157A2C'></u-subsection>
  6. </u-sticky>
  7. <!-- 基本信息 -->
  8. <view v-show='curNow===0'>
  9. <u--form style="margin: 0 20px;" labelPosition="left" :model="form" ref="uForm" labelWidth='180rpx'>
  10. <u-form-item label="采购计划单名称" prop="planName" borderBottom @click="handParent">
  11. <u--input style="width: 100%;" v-model="form.planName" placeholder="点击选择"></u--input>
  12. </u-form-item>
  13. <u-form-item label="询价单名称" prop="inquiryName" borderBottom>
  14. <u--input style="width: 100%;" v-model="form.inquiryName"></u--input>
  15. </u-form-item>
  16. <u-form-item label="是否接受拆单" prop="acceptUnpack" borderBottom>
  17. <u-tag v-if='form.acceptUnpack==1' text="接受" size="large" type="success"></u-tag>
  18. <u-tag v-else-if='form.acceptUnpack==0' text="不接受" size="large" type="warning"></u-tag>
  19. <u--input v-else style="width: 100%;" disabled value="-"></u--input>
  20. </u-form-item>
  21. <u-form-item label="备注" prop="remark" borderBottom>
  22. <u--input style="width: 100%;" v-model="form.remark"></u--input>
  23. </u-form-item>
  24. <u-form-item label="附件" prop="files" borderBottom>
  25. <fileMain v-model="form.files" type="add"></fileMain>
  26. </u-form-item>
  27. </u--form>
  28. </view>
  29. <!-- 物品清单 -->
  30. <view v-show='curNow===1'>
  31. <inventoryTable :productList="productList" :acceptUnpack="form.acceptUnpack" status="edit"
  32. ref="inventoryTableRef" @supplierSelect="onItemSupplierSelect">
  33. </inventoryTable>
  34. </view>
  35. <!-- 报价清单 -->
  36. <view v-show='curNow===2'>
  37. <inquiryTable ref="inquiryTableRef" :supplierList="supplierList" status="edit"></inquiryTable>
  38. <u-empty v-if="!supplierList.length" text="暂无报价" mode="list"></u-empty>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import {
  44. getpurchaseinquiry
  45. } from '@/api/purchasingManage/inquiryManage'
  46. import { getplanDetail } from '@/api/purchasingManage/purchasePlanManage'
  47. import fileMain from "@/pages/doc/index.vue"
  48. import inquiryTable from './inquiryTable.vue'
  49. import inventoryTable from './inventoryTable.vue'
  50. import { contactQueryByCategoryIdsAPI } from '@/api/warehouseManagement/index.js'
  51. import { orderSourceType } from '@/enum/dict'
  52. export default {
  53. components: {
  54. fileMain,
  55. inquiryTable,
  56. inventoryTable
  57. },
  58. props: {
  59. businessId: {
  60. default: ''
  61. },
  62. taskDefinitionKey: {
  63. default: ''
  64. },
  65. },
  66. data() {
  67. return {
  68. form: {},
  69. supplierList: [],
  70. productList: [],
  71. rawList: [],
  72. outputList: [],
  73. loading: false,
  74. list: ['基本信息', '物品清单', '报价清单'],
  75. curNow: 0
  76. }
  77. },
  78. async mounted() {
  79. await this.getDetailData(this.businessId, 'init')
  80. // 监听采购计划选择回调
  81. uni.$on('changeInquiryManageList', (data) => {
  82. this.changeInquiryManageList(data)
  83. })
  84. // 监听供应商选择回调
  85. uni.$on('supplierManageChange', (data) => {
  86. this.supplierManageChange(data)
  87. })
  88. },
  89. beforeDestroy() {
  90. uni.$off('changeInquiryManageList')
  91. uni.$off('supplierManageChange')
  92. },
  93. methods: {
  94. sectionChange(index) {
  95. this.curNow = index
  96. },
  97. // 打开采购计划选择页
  98. handParent() {
  99. uni.navigateTo({
  100. url: '/pages/home/wt/components/pricingManage/inquiryManageList?planCode=' + (this.form.planCode || '')
  101. })
  102. },
  103. // 打开供应商选择页
  104. openSupplier() {
  105. uni.navigateTo({
  106. url: '/pages/home/wt/components/pricingManage/supplierManageList'
  107. })
  108. },
  109. // 选择采购计划后回调
  110. changeInquiryManageList(data) {
  111. console.log('changeInquiryManageList~~', data)
  112. this.getplanData(data.id, 'change')
  113. },
  114. // 选择供应商后回调
  115. supplierManageChange(list) {
  116. const existingIds = this.supplierList.map(item => item.supplierId)
  117. list.forEach(supplier => {
  118. if (!existingIds.includes(supplier.supplierId)) {
  119. this.supplierList.push(supplier)
  120. }
  121. })
  122. },
  123. // 物品清单中某产品选择供应商
  124. onItemSupplierSelect(item, index) {
  125. console.log('onItemSupplierSelect~~', item)
  126. uni.navigateTo({
  127. url: '/pages/home/wt/components/pricingManage/supplierManageList'
  128. })
  129. },
  130. // 获取计划详情
  131. async getplanData(id, type) {
  132. this.loading = true
  133. const data = await getplanDetail(id)
  134. this.rawList = data.rawDetailList || []
  135. this.outputList = data.outputDetailList || []
  136. this.loading = false
  137. if (data) {
  138. // 获取产品对应的供应商
  139. const supplierObj = await this.getSupplierObj(data.detailList, 'productId')
  140. // 处理产品列表:补充到货日期和供应商信息
  141. data.detailList.forEach((item) => {
  142. if (item.arrivalWay == 2 && item.arrivalBatch && item.arrivalBatch.length > 0) {
  143. item.expectReceiveDate = item.arrivalBatch[item.arrivalBatch.length - 1].arriveDate
  144. }
  145. item.supplierList = supplierObj[item.productId] || []
  146. if (item.supplierList.length === 1) {
  147. item.supplierIds = [item.supplierList[0].id]
  148. }
  149. })
  150. // 设置表单字段
  151. this.$set(this.form, 'acceptUnpack', data.acceptUnpack)
  152. this.form.planId = data.id
  153. this.form.planCode = data.planCode
  154. this.form.planName = data.planName
  155. // init 类型不覆盖 productList(已在 getDetailData 中设置)
  156. if (type === 'init') return
  157. // 变更时合并产品清单
  158. if (orderSourceType.includes(this.form.sourceType)) {
  159. this.productList = [...data.detailList, ...this.rawList, ...this.outputList]
  160. } else {
  161. this.productList = [...data.detailList]
  162. }
  163. }
  164. },
  165. async getSupplierObj(productList, queryName) {
  166. try {
  167. const categoryIds = productList.map((item) => item[queryName])
  168. return await contactQueryByCategoryIdsAPI({ categoryIds })
  169. } catch (e) {
  170. return Promise.resolve({})
  171. }
  172. },
  173. async getDetailData(id, type) {
  174. this.loading = true
  175. const data = await getpurchaseinquiry(id)
  176. this.loading = false
  177. if (data) {
  178. this.form = data
  179. this.supplierList = data.supplierList || []
  180. // 获取产品对应的供应商列表
  181. const supplierObj = await this.getSupplierObj(data.detailList, 'productId')
  182. data.detailList.forEach((item) => {
  183. item.supplierList = supplierObj[item.productId] || []
  184. })
  185. // 合并产品清单
  186. this.rawList = data.rawList || []
  187. this.outputList = data.outputList || []
  188. if (orderSourceType.includes(this.form.sourceType)) {
  189. this.productList = [...data.detailList, ...this.rawList, ...this.outputList]
  190. } else {
  191. this.productList = [...data.detailList]
  192. }
  193. // 是否首次加载,需要拉取计划详情
  194. if (type === 'init') {
  195. this.getplanData(data.planId, type)
  196. }
  197. }
  198. },
  199. async getTableValue() {
  200. // 1. 校验基本信息
  201. if (!this.form.inquiryName) {
  202. uni.showToast({ title: '请输入询价单名称', icon: 'none' })
  203. return false
  204. }
  205. if (!this.form.planId) {
  206. uni.showToast({ title: '请选择采购计划', icon: 'none' })
  207. return false
  208. }
  209. // 2. 校验物品清单不为空
  210. const inventoryData = this.$refs.inventoryTableRef?.getTableValue()
  211. if (!inventoryData || inventoryData.length === 0) {
  212. uni.showToast({ title: '物品清单不能为空', icon: 'none' })
  213. return false
  214. }
  215. // 3. 校验报价清单
  216. const supplierList = this.$refs.inquiryTableRef?.getTableValue() || []
  217. if (supplierList.length === 0) {
  218. uni.showToast({ title: '报价清单不能为空', icon: 'none' })
  219. return false
  220. }
  221. for (let i = 0; i < supplierList.length; i++) {
  222. const supplier = supplierList[i]
  223. // 校验供应商可填写字段
  224. if (!supplier.settlementMode) {
  225. uni.showToast({ title: `供应商${supplier.supplierName || i + 1}:请选择结算方式`, icon: 'none' })
  226. return false
  227. }
  228. if (!supplier.deliveryDate) {
  229. uni.showToast({ title: `供应商${supplier.supplierName || i + 1}:请选择交货日期`, icon: 'none' })
  230. return false
  231. }
  232. // 校验报价明细
  233. const items = supplier.resultList || []
  234. for (let j = 0; j < items.length; j++) {
  235. const item = items[j]
  236. const name = item.productName || item.productCode || (j + 1)
  237. if (item.isWinner === '' || item.isWinner === null || item.isWinner === undefined) {
  238. uni.showToast({ title: `${supplier.supplierName || ''} ${name}:请选择是否中标`, icon: 'none' })
  239. return false
  240. }
  241. if (!item.supplierProductName) {
  242. uni.showToast({ title: `${supplier.supplierName || ''} ${name}:请输入供应商产品名称`, icon: 'none' })
  243. return false
  244. }
  245. if (!item.purchaseCount || item.purchaseCount <= 0) {
  246. uni.showToast({ title: `${supplier.supplierName || ''} ${name}:请输入数量`, icon: 'none' })
  247. return false
  248. }
  249. if (!item.singlePrice || item.singlePrice <= 0) {
  250. uni.showToast({ title: `${supplier.supplierName || ''} ${name}:请输入单价`, icon: 'none' })
  251. return false
  252. }
  253. if (!item.taxRate && item.taxRate !== 0) {
  254. uni.showToast({ title: `${supplier.supplierName || ''} ${name}:请输入税率`, icon: 'none' })
  255. return false
  256. }
  257. // 校验最低订购量
  258. if (item.minimumOrderQuantity && item.purchaseCount < item.minimumOrderQuantity) {
  259. uni.showToast({ title: `${supplier.supplierName || ''} ${name}:购买数量不能小于最低订购量`, icon: 'none' })
  260. return false
  261. }
  262. }
  263. }
  264. // 4. 组装返回数据
  265. this.form.detailList = inventoryData
  266. this.form.supplierList = supplierList
  267. // 合并 rawList/outputList 到 supplierList
  268. if (orderSourceType.includes(this.form.sourceType)) {
  269. this.form.supplierList.forEach(sup => {
  270. sup.resultList = [...(sup.resultList || []), ...this.rawList, ...this.outputList]
  271. })
  272. }
  273. this.form.files = this.form.files || []
  274. return this.form
  275. },
  276. }
  277. }
  278. </script>
  279. <style lang="scss" scoped>
  280. </style>