SupplierInfoForm.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <!-- 商品发布 - 基础设置 -->
  2. <template>
  3. <ContentWrap v-loading="formLoading">
  4. <el-form
  5. ref="formRef"
  6. :disabled="isDetail"
  7. :model="formData"
  8. :rules="rules"
  9. label-width="120px"
  10. >
  11. <el-row>
  12. <el-col :span="8">
  13. <el-form-item label="客商性质" prop="customerNature">
  14. <el-select v-model="formData.customerNature" placeholder="请选择客商性质" class="w-80!">
  15. <el-option
  16. v-for="dict in getStrDictOptions(DICT_TYPE.PMS_SUPPLIER_NATURE)"
  17. :key="dict.id"
  18. :label="dict.label"
  19. :value="dict.value"
  20. />
  21. </el-select>
  22. </el-form-item>
  23. </el-col>
  24. <el-col :span="8">
  25. <el-form-item label="供应商名称" prop="name">
  26. <el-input v-model="formData.name" placeholder="请输入供应商名称" class="w-80!" />
  27. </el-form-item>
  28. </el-col>
  29. <el-col :span="8">
  30. <el-form-item label="供应商分类" prop="classification">
  31. <el-select v-model="formData.classification" placeholder="请选择分类" class="w-80!">
  32. <el-option
  33. v-for="dict in getStrDictOptions(DICT_TYPE.SUPPLIER_TYPE)"
  34. :key="dict.value"
  35. :label="dict.label"
  36. :value="dict.value"
  37. />
  38. </el-select>
  39. </el-form-item>
  40. </el-col>
  41. </el-row>
  42. <el-row>
  43. <el-col :span="8">
  44. <el-form-item label="公司类型" prop="type">
  45. <el-select v-model="formData.type" placeholder="请选择公司类型" class="w-80!">
  46. <el-option
  47. v-for="dict in getStrDictOptions(DICT_TYPE.SUPPLIER_COMPANY_TYPE)"
  48. :key="dict.value"
  49. :label="dict.label"
  50. :value="dict.value"
  51. />
  52. </el-select>
  53. </el-form-item>
  54. </el-col>
  55. <el-col :span="8">
  56. <el-form-item label="供应商性质" prop="nature">
  57. <el-select v-model="formData.nature" placeholder="请选择供应商性质" class="w-80!">
  58. <el-option
  59. v-for="dict in getStrDictOptions(DICT_TYPE.SUPPLIER_NATURE)"
  60. :key="dict.id"
  61. :label="dict.label"
  62. :value="dict.value"
  63. />
  64. </el-select>
  65. </el-form-item>
  66. </el-col>
  67. <!-- <el-col :span="8">-->
  68. <!-- <el-form-item label="状态" prop="status">-->
  69. <!-- <el-select v-model="formData.status" placeholder="请选择状态" class="w-80!">-->
  70. <!-- <el-option-->
  71. <!-- v-for="dict in getIntDictOptions(DICT_TYPE.SUPPLIER_STATUS)"-->
  72. <!-- :key="dict.value"-->
  73. <!-- :label="dict.label"-->
  74. <!-- :value="dict.value"-->
  75. <!-- />-->
  76. <!-- </el-select>-->
  77. <!-- </el-form-item>-->
  78. <!-- </el-col>-->
  79. <el-col :span="8">
  80. <el-form-item label="社会信用代码" prop="creditCode">
  81. <el-input
  82. v-model="formData.creditCode"
  83. class="w-80!"
  84. placeholder="请输入社会信用代码"
  85. />
  86. </el-form-item>
  87. </el-col>
  88. </el-row>
  89. <el-row>
  90. <el-col :span="8">
  91. <el-form-item label="公司规模" prop="size">
  92. <el-select v-model="formData.size" placeholder="请选择公司规模" class="w-80!">
  93. <el-option
  94. v-for="dict in getStrDictOptions(DICT_TYPE.SUPPLIER_SIZE)"
  95. :key="dict.value"
  96. :label="dict.label"
  97. :value="dict.value"
  98. />
  99. </el-select>
  100. </el-form-item>
  101. </el-col>
  102. <el-col :span="8">
  103. <el-form-item label="纳税人识别号" prop="tin">
  104. <el-input v-model="formData.tin" class="w-80!" placeholder="请输入纳税人识别号" />
  105. </el-form-item>
  106. </el-col>
  107. <el-col :span="8">
  108. <el-form-item label="法人" prop="corporation">
  109. <el-input v-model="formData.corporation" class="w-80!" placeholder="请输入法人" />
  110. </el-form-item>
  111. </el-col>
  112. </el-row>
  113. <el-row>
  114. <el-col :span="8">
  115. <el-form-item label="成立日期" prop="incorporationDate">
  116. <el-date-picker
  117. class="w-80!"
  118. v-model="formData.incorporationDate"
  119. type="date"
  120. value-format="x"
  121. placeholder="选择成立日期"
  122. />
  123. </el-form-item>
  124. </el-col>
  125. <el-col :span="8">
  126. <el-form-item label="公司地址" prop="address">
  127. <el-input v-model="formData.address" class="w-80!" placeholder="请输入公司地址" />
  128. </el-form-item>
  129. </el-col>
  130. <el-col :span="8">
  131. <el-form-item label="注册资金(万元)" prop="registeredCapital">
  132. <el-input
  133. type="number"
  134. v-model="formData.registeredCapital"
  135. class="w-80!"
  136. placeholder="请输入注册资金"
  137. />
  138. </el-form-item>
  139. </el-col>
  140. </el-row>
  141. <el-row>
  142. <el-col :span="8">
  143. <el-form-item label="年营业额(万元)" prop="annualTurnove">
  144. <el-input
  145. v-model="formData.annualTurnove"
  146. type="number"
  147. class="w-80!"
  148. placeholder="请输入年营业额"
  149. />
  150. </el-form-item>
  151. </el-col>
  152. <el-col :span="8">
  153. <el-form-item label="经营范围" prop="bizScope">
  154. <el-input type="textarea" v-model="formData.bizScope" placeholder="请输入经营范围" />
  155. </el-form-item>
  156. </el-col>
  157. <el-col :span="8">
  158. <el-form-item label="备注" prop="remark">
  159. <el-input type="textarea" v-model="formData.remark" placeholder="请输入备注" />
  160. </el-form-item>
  161. </el-col>
  162. </el-row>
  163. <!-- <el-form-item label="商品简介" prop="introduction">-->
  164. <!-- <el-input-->
  165. <!-- v-model="formData.introduction"-->
  166. <!-- :autosize="{ minRows: 2, maxRows: 2 }"-->
  167. <!-- :clearable="true"-->
  168. <!-- :show-word-limit="true"-->
  169. <!-- class="w-80!"-->
  170. <!-- maxlength="128"-->
  171. <!-- placeholder="请输入商品简介"-->
  172. <!-- type="textarea"-->
  173. <!-- />-->
  174. <!-- </el-form-item>-->
  175. <!-- <el-form-item label="商品封面图" prop="picUrl">-->
  176. <!-- <UploadImg v-model="formData.picUrl" :disabled="isDetail" height="80px" />-->
  177. <!-- </el-form-item>-->
  178. <!-- <el-form-item label="商品轮播图" prop="sliderPicUrls">-->
  179. <!-- <UploadImgs v-model="formData.sliderPicUrls" :disabled="isDetail" />-->
  180. <!-- </el-form-item>-->
  181. </el-form>
  182. <el-form>
  183. <el-form-item style="float: right">
  184. <el-button v-if="!isDetail" :loading="formLoading" type="warning" @click="submitForm">
  185. 保存
  186. </el-button>
  187. <el-button @click="close" type="primary">返回</el-button>
  188. </el-form-item>
  189. </el-form>
  190. </ContentWrap>
  191. </template>
  192. <script lang="ts" setup>
  193. import { PropType } from 'vue'
  194. import { copyValueToTarget } from '@/utils'
  195. import { propTypes } from '@/utils/propTypes'
  196. import {DICT_TYPE, getIntDictOptions, getStrDictOptions} from '@/utils/dict'
  197. import { Api, SupplierVO } from '@/api/supplier/base'
  198. import {useTagsViewStore} from "@/store/modules/tagsView";
  199. import type { Supplier } from '@/api/supplier/base/index'
  200. const { delView } = useTagsViewStore() // 视图操作
  201. const { push, currentRoute } = useRouter() // 路由
  202. const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  203. const { t } = useI18n() // 国际化
  204. defineOptions({ name: 'SupplierBaseInfo' })
  205. const props = defineProps({
  206. propFormData: {
  207. type: Object as PropType<Supplier>,
  208. default: () => {}
  209. },
  210. isDetail: propTypes.bool.def(false), // 是否作为详情组件
  211. supplierId: {type:String,required:true}
  212. })
  213. const supplierid = props.supplierId;
  214. const message = useMessage() // 消息弹窗
  215. const formRef = ref() // 表单 Ref
  216. const formData = reactive<Supplier>({
  217. id: '',
  218. customerNature: undefined,
  219. code: undefined,
  220. name: undefined,
  221. classification: undefined,
  222. type: undefined,
  223. nature: undefined,
  224. creditCode: undefined,
  225. tin: undefined,
  226. corporation: undefined,
  227. incorporationDate: undefined,
  228. address: undefined,
  229. bizScope: undefined,
  230. registeredCapital: undefined,
  231. annualTurnove: undefined,
  232. size: undefined,
  233. status: undefined,
  234. remark: undefined
  235. })
  236. // const rules = reactive({
  237. // name: [required],
  238. // categoryId: [required],
  239. // keyword: [required],
  240. // introduction: [required],
  241. // picUrl: [required],
  242. // sliderPicUrls: [required],
  243. // brandId: [required]
  244. // })
  245. /** 将传进来的值赋值给 formData */
  246. watch(
  247. () => props.propFormData,
  248. (data) => {
  249. if (!data) {
  250. return
  251. }
  252. copyValueToTarget(formData, data)
  253. },
  254. {
  255. immediate: true
  256. }
  257. )
  258. const rules = reactive({
  259. customerNature: [{ required: true, message: '客商性质不能为空', trigger: 'blur' }],
  260. name: [{ required: true, message: '名称不能为空', trigger: 'blur' }],
  261. classification: [{ required: true, message: '供应商分类不能为空', trigger: 'blur' }],
  262. type: [{ required: true, message: '公司类型不能为空', trigger: 'blur' }],
  263. nature: [{ required: true, message: '供应商性质不能为空', trigger: 'blur' }],
  264. status: [{ required: true, message: '状态不能为空', trigger: 'blur' }]
  265. })
  266. /** 表单校验 */
  267. const validate = async () => {
  268. if (!formRef) return
  269. try {
  270. await unref(formRef)?.validate()
  271. // 校验通过更新数据
  272. Object.assign(props.propFormData, formData)
  273. } catch (e) {
  274. message.error('【基础设置】不完善,请填写相关信息')
  275. emit('update:activeName', 'info')
  276. throw e // 目的截断之后的校验
  277. }
  278. }
  279. defineExpose({ validate })
  280. const emit = defineEmits(['success','update:activeName','sendParam']) // 定义 success 事件,用于操作成功后的回调
  281. const submitForm = async () => {
  282. // 校验表单
  283. await formRef.value.validate()
  284. // 提交请求
  285. formLoading.value = true
  286. try {
  287. const data = formData as unknown as SupplierVO
  288. if (!supplierid.id){
  289. await Api.create(data).then(res => {
  290. if (res.code ===0) {
  291. const param = {id: res.data}
  292. emit('sendParam', param);
  293. message.success(t('common.createSuccess'))
  294. } else {
  295. message.error(res.msg)
  296. }
  297. })
  298. } else {
  299. await Api.update(data)
  300. message.success(t('common.updateSuccess'))
  301. }
  302. // 发送操作成功的事件
  303. emit('success')
  304. } finally {
  305. formLoading.value = false
  306. }
  307. //try {
  308. // 校验各表单
  309. // await unref(infoRef)?.validate()
  310. // await unref(skuRef)?.validate()
  311. // await unref(deliveryRef)?.validate()
  312. // await unref(descriptionRef)?.validate()
  313. // await unref(otherRef)?.validate()
  314. // // 深拷贝一份, 这样最终 server 端不满足,不需要影响原始数据
  315. // const deepCopyFormData = cloneDeep(unref(formData.value)) as ProductSpuApi.Spu
  316. // deepCopyFormData.skus!.forEach((item) => {
  317. // // 给sku name赋值
  318. // item.name = deepCopyFormData.name
  319. // // sku相关价格元转分
  320. // item.price = convertToInteger(item.price)
  321. // item.marketPrice = convertToInteger(item.marketPrice)
  322. // item.costPrice = convertToInteger(item.costPrice)
  323. // item.firstBrokeragePrice = convertToInteger(item.firstBrokeragePrice)
  324. // item.secondBrokeragePrice = convertToInteger(item.secondBrokeragePrice)
  325. // })
  326. // // 处理轮播图列表
  327. // const newSliderPicUrls: any[] = []
  328. // deepCopyFormData.sliderPicUrls!.forEach((item: any) => {
  329. // // 如果是前端选的图
  330. // typeof item === 'object' ? newSliderPicUrls.push(item.url) : newSliderPicUrls.push(item)
  331. // })
  332. // deepCopyFormData.sliderPicUrls = newSliderPicUrls
  333. // 校验都通过后提交表单
  334. // const data = deepCopyFormData as ProductSpuApi.Spu
  335. // const id = params.id as unknown as number
  336. // if (!id) {
  337. // await ProductSpuApi.createSpu(data)
  338. // message.success(t('common.createSuccess'))
  339. // } else {
  340. // await ProductSpuApi.updateSpu(data)
  341. // message.success(t('common.updateSuccess'))
  342. // }
  343. // close()
  344. //} finally {
  345. // formLoading.value = false
  346. //}
  347. }
  348. const close = () => {
  349. delView(unref(currentRoute))
  350. push({ name: 'Suppliers',query: {
  351. date: new Date().getTime(),
  352. } })
  353. }
  354. /** 初始化 */
  355. onMounted(async () => {
  356. // 获得分类树
  357. // const data = await ProductCategoryApi.getCategoryList({})
  358. // categoryList.value = handleTree(data, 'id')
  359. // 获取商品品牌列表
  360. // brandList.value = await ProductBrandApi.getSimpleBrandList()
  361. console.log(JSON.stringify(formData.value))
  362. })
  363. </script>
  364. <style lang="scss" scoped>
  365. .el-input__inner {
  366. color: #0a0505;
  367. }
  368. </style>