addProduct.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <template>
  2. <div v-loading="loading">
  3. <div class="form-box">
  4. <el-form
  5. label-position="top"
  6. :model="form"
  7. :rules="formRules"
  8. ref="form"
  9. label-width="100px"
  10. >
  11. <el-form-item label="产品分类" prop="classifyId">
  12. <el-cascader
  13. :options="selectList"
  14. v-model="form.classifyId"
  15. :emitPath="false"
  16. :props="{ label: 'name', value: 'id' }"
  17. style="width: 100%"
  18. ></el-cascader>
  19. </el-form-item>
  20. <el-form-item label="产品类型" prop="type">
  21. <el-radio-group v-model="form.type">
  22. <el-radio-button
  23. v-for="item in productTypeList"
  24. :key="item.id"
  25. :label="item.dictKey"
  26. >
  27. {{ item.dictValue }}</el-radio-button
  28. >
  29. </el-radio-group>
  30. </el-form-item>
  31. <el-row :gutter="10">
  32. <el-col :span="6">
  33. <el-form-item label="产品编码" prop="code">
  34. <el-input v-model="form.code" placeholder="请输入"></el-input>
  35. </el-form-item>
  36. </el-col>
  37. <el-col :span="18">
  38. <el-form-item label=".">
  39. <span>不输入则自动生成,自动编码规则示例:P00001</span>
  40. </el-form-item>
  41. </el-col>
  42. </el-row>
  43. <el-form-item label="产品名称" prop="name">
  44. <el-input v-model="form.name" placeholder="请输入"></el-input>
  45. </el-form-item>
  46. <el-form-item label="规格" prop="specs">
  47. <el-input v-model="form.specs" placeholder="请输入"></el-input>
  48. </el-form-item>
  49. <el-row>
  50. <el-col :span="6">
  51. <el-form-item label="产品单位" prop="unit">
  52. <el-select
  53. v-model="form.unit"
  54. placeholder="请选择"
  55. style="width: 100%"
  56. >
  57. <el-option
  58. v-for="item in productUnitList"
  59. :key="item.id"
  60. :label="item.dictValue"
  61. :value="item.dictKey"
  62. >
  63. </el-option>
  64. </el-select>
  65. </el-form-item>
  66. </el-col>
  67. </el-row>
  68. <el-row :gutter="10">
  69. <el-col :span="6">
  70. <el-form-item label="京东供价" prop="jdPurchasePrice">
  71. <el-input
  72. v-model="form.jdPurchasePrice"
  73. placeholder="请输入"
  74. ></el-input>
  75. </el-form-item>
  76. </el-col>
  77. <el-col :span="6">
  78. <el-form-item label="标准售价" prop="sellingPrice">
  79. <el-input
  80. v-model="form.sellingPrice"
  81. placeholder="请输入"
  82. ></el-input>
  83. </el-form-item>
  84. </el-col>
  85. </el-row>
  86. <el-row :gutter="10">
  87. <el-col :span="6">
  88. <el-form-item label="标准采购价" prop="purchasePrice">
  89. <el-input
  90. v-model="form.purchasePrice"
  91. placeholder="请输入"
  92. ></el-input>
  93. </el-form-item>
  94. </el-col>
  95. </el-row>
  96. <el-row :gutter="10">
  97. <el-col :span="6">
  98. <el-form-item label="库存清空期限" prop="clearancePeriod">
  99. <el-date-picker
  100. v-model="form.clearancePeriod"
  101. type="datetime"
  102. placeholder="请选择"
  103. value-format="yyyy-MM-dd HH:mm:ss"
  104. >
  105. </el-date-picker>
  106. </el-form-item>
  107. </el-col>
  108. </el-row>
  109. <el-form-item label="产品照片">
  110. <el-upload
  111. class="upload-demo"
  112. action="/api/service-file/uploadFile"
  113. :headers="uploadHeader"
  114. list-type="picture-card"
  115. :file-list="fileList"
  116. :on-preview="handlePreview"
  117. :on-success="handleSuccess"
  118. :on-remove="handleRemove"
  119. >
  120. <i class="el-icon-plus"></i>
  121. </el-upload>
  122. </el-form-item>
  123. <el-form-item label="是否组合" prop="combination">
  124. <el-radio-group v-model="form.combination">
  125. <el-radio-button label="1"> 是</el-radio-button>
  126. <el-radio-button label="0"> 否</el-radio-button>
  127. </el-radio-group>
  128. </el-form-item>
  129. <div style="margin-top: 20px" v-if="form.combination === '1'">
  130. <labelTitle content="组合明细"></labelTitle>
  131. </div>
  132. <el-form-item label-width="0px" v-if="form.combination === '1'">
  133. <el-button size="small" @click="selectDialog = true"> 选择</el-button>
  134. </el-form-item>
  135. <el-form-item v-if="form.combination === '1'">
  136. <el-table :data="form.productCombinationList">
  137. <el-table-column label="产品编码" prop="code"> </el-table-column>
  138. <el-table-column label="产品名称" prop="name"> </el-table-column>
  139. <el-table-column label="本次入库" prop="linkQuantity">
  140. <template slot-scope="scope">
  141. <el-form-item
  142. :prop="
  143. 'productCombinationList.' + scope.$index + '.linkQuantity'
  144. "
  145. :rules="formRules.linkQuantity"
  146. :inline-message="true"
  147. label-width="0"
  148. >
  149. <el-input
  150. v-model="scope.row.linkQuantity"
  151. placeholder="请输入"
  152. size="mini"
  153. >
  154. </el-input>
  155. </el-form-item>
  156. </template>
  157. </el-table-column>
  158. <el-table-column label="操作" width="100" align="center">
  159. <template slot-scope="scope">
  160. <el-button type="text" @click="deleteRow(scope.$index)"
  161. >删除</el-button
  162. >
  163. </template>
  164. </el-table-column>
  165. </el-table>
  166. </el-form-item>
  167. <div style="margin-top: 20px">
  168. <labelTitle content="生命周期规则"></labelTitle>
  169. </div>
  170. <el-row :gutter="10">
  171. <el-form-item label="新品期" prop="newProductsExpectedSales">
  172. <el-col :span="2" style="text-align: center">
  173. 0 &nbsp;&nbsp;~
  174. </el-col>
  175. <el-col :span="3">
  176. <el-input
  177. v-model="form.newProductsDay"
  178. placeholder="请输入"
  179. ></el-input>
  180. </el-col>
  181. <el-col :span="1" style="text-align: center"> : </el-col>
  182. <el-col :span="6">
  183. <el-input
  184. v-model="form.newProductsExpectedSales"
  185. placeholder="预期销量"
  186. ></el-input>
  187. </el-col>
  188. </el-form-item>
  189. </el-row>
  190. <el-row :gutter="10">
  191. <el-form-item label="成长期" prop="growUpExpectedSales">
  192. <el-col :span="2" style="text-align: center">
  193. 61 &nbsp;&nbsp;~
  194. </el-col>
  195. <el-col :span="3">
  196. <el-input
  197. v-model="form.growUpDay"
  198. placeholder="请输入"
  199. ></el-input>
  200. </el-col>
  201. <el-col :span="1" style="text-align: center"> : </el-col>
  202. <el-col :span="6">
  203. <el-input
  204. v-model="form.growUpExpectedSales"
  205. placeholder="预期销量"
  206. ></el-input>
  207. </el-col>
  208. </el-form-item>
  209. </el-row>
  210. <el-row>
  211. <el-form-item label="成熟期" prop="matureExpectedSales">
  212. <el-col :span="3"> 大于120天 : </el-col>
  213. <el-col :span="6">
  214. <el-input
  215. v-model="form.matureExpectedSales"
  216. placeholder="预期销量"
  217. ></el-input>
  218. </el-col>
  219. </el-form-item>
  220. </el-row>
  221. </el-form>
  222. </div>
  223. <div style="text-align: center; margin-top: 15px">
  224. <el-button size="small" @click="handleCancel">取消 </el-button>
  225. <el-button type="primary" size="small" @click="handleSubmit">
  226. 确定</el-button
  227. >
  228. </div>
  229. <el-dialog
  230. title="产品选择"
  231. v-if="selectDialog"
  232. :visible.sync="selectDialog"
  233. width="80%"
  234. top="60px"
  235. >
  236. <selectProduct @select="handleSelect"></selectProduct>
  237. </el-dialog>
  238. </div>
  239. </template>
  240. <script>
  241. import labelTitle from "@/components/label-title/index.vue";
  242. import selectProduct from "@/components/select-product/index.vue";
  243. import { getToken } from "@/util/auth";
  244. import * as API from "@/api/product-material/product/index.js";
  245. export default {
  246. name: "addProduct",
  247. components: {
  248. labelTitle,
  249. selectProduct,
  250. },
  251. props: {
  252. form: {
  253. type: Object,
  254. default: () => {},
  255. },
  256. },
  257. data() {
  258. return {
  259. uploadHeader: {
  260. Authorization: "Basic c2FiZXI6c2FiZXJfc2VjcmV0",
  261. "Blade-Auth": "bearer " + getToken(),
  262. },
  263. loading: false,
  264. selectList: [],
  265. productTypeList: [],
  266. productUnitList: [],
  267. formRules: {
  268. classifyId: [
  269. {
  270. required: true,
  271. message: "请选择产品分类",
  272. trigger: "change",
  273. },
  274. ],
  275. type: [
  276. {
  277. required: true,
  278. message: "请选择产品类型",
  279. trigger: "change",
  280. },
  281. ],
  282. unit: [
  283. {
  284. required: true,
  285. message: "请选择产品单位",
  286. trigger: "change",
  287. },
  288. ],
  289. name: [
  290. {
  291. required: true,
  292. message: "请输入产品名称",
  293. trigger: "blur",
  294. },
  295. ],
  296. specs: [
  297. {
  298. required: true,
  299. message: "请输入规格",
  300. trigger: "blur",
  301. },
  302. ],
  303. combination: [
  304. {
  305. required: true,
  306. message: "请选择是否组合",
  307. trigger: "change",
  308. },
  309. ],
  310. linkQuantity: [
  311. {
  312. required: true,
  313. message: "请输入数量",
  314. trigger: "blur",
  315. },
  316. ],
  317. },
  318. selectDialog: false,
  319. };
  320. },
  321. created() {
  322. const businessDictData = JSON.parse(
  323. window.localStorage.getItem("businessDict")
  324. );
  325. this.productTypeList = businessDictData.find(
  326. (item) => item.code === "productType"
  327. ).children;
  328. this.productUnitList = businessDictData.find(
  329. (item) => item.code === "productUnit"
  330. ).children;
  331. this.loading = true;
  332. API.productTree({
  333. type: "1",
  334. name: "",
  335. }).then(
  336. (res) => {
  337. this.selectList = res.data.data;
  338. this.loading = false;
  339. },
  340. (err) => {
  341. console.log("productTree: " + err);
  342. this.loading = false;
  343. }
  344. );
  345. },
  346. methods: {
  347. handleSubmit() {
  348. this.$refs.form.validate((valid) => {
  349. if (valid) {
  350. this.loading = true;
  351. this.form.classifyId =
  352. this.form.classifyId[this.form.classifyId.length - 1];
  353. this.$emit("submit");
  354. }
  355. });
  356. },
  357. handleCancel() {
  358. this.$emit("cancel");
  359. },
  360. handleSelect(row) {
  361. this.form.productCombinationList.push({
  362. linkProductId: row.id,
  363. linkQuantity: "",
  364. code: row.code,
  365. name: row.name,
  366. });
  367. this.msgSuccess("添加成功");
  368. },
  369. deleteRow(index) {
  370. this.form.productCombinationList.splice(index, 1);
  371. this.msgSuccess("删除成功");
  372. },
  373. },
  374. };
  375. </script>
  376. <style lang="scss" scoped>
  377. .form-box {
  378. height: calc(100vh - 280px);
  379. overflow: auto;
  380. box-sizing: border-box;
  381. padding: 10px;
  382. }
  383. ::v-deep {
  384. .el-form-item {
  385. margin-bottom: 3px;
  386. }
  387. .el-form--label-top .el-form-item__label {
  388. padding: 8px 0 0 0;
  389. }
  390. }
  391. </style>