addForm.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. <template>
  2. <el-row>
  3. <el-col :span="24">
  4. <el-form
  5. ref="ruleForm"
  6. :model="ruleForm"
  7. status-icon
  8. :size="'mini'"
  9. :rules="rulesThis"
  10. label-width="112px"
  11. >
  12. <el-row>
  13. <el-col :span="12">
  14. <el-form-item label="项目名称" prop="name">
  15. <el-input
  16. v-model="ruleForm.name"
  17. placeholder="项目名称"
  18. :disabled="type === 'view'"
  19. maxlength="100"
  20. />
  21. </el-form-item>
  22. </el-col>
  23. <el-col :span="12">
  24. <el-form-item label="所属平台" prop="platform">
  25. <search-terrace
  26. :value="ruleForm.platform"
  27. :disabled="type === 'view'"
  28. :size="'mini'"
  29. :isDetail="type === 'view'"
  30. :names="platform_name"
  31. :placeholder="'所属平台'"
  32. @searchChange="platform_codesearchChange"
  33. />
  34. </el-form-item>
  35. </el-col>
  36. <el-col :span="12">
  37. <el-form-item label="销售方" prop="companyNo">
  38. <search-work-company
  39. :value="ruleForm.companyNo"
  40. :placeholder="'销售方公司'"
  41. :disabled="type === 'view'"
  42. :size="'mini'"
  43. :isDetail="type === 'view'"
  44. @searchChange="company_idsearchChange"
  45. />
  46. </el-form-item>
  47. </el-col>
  48. <el-col :span="12">
  49. <el-form-item label="购买方" prop="khNo">
  50. <search-customer
  51. :value="ruleForm.khNo"
  52. :names="ruleForm.customer_name"
  53. :placeholder="'购买方公司'"
  54. :size="'mini'"
  55. @searchChange="customerChange"
  56. :disabled="type === 'view'"
  57. :is-detail="type === 'view'"
  58. />
  59. </el-form-item>
  60. </el-col>
  61. <el-col :span="8">
  62. <el-form-item label="项目总预算" prop="budget_total">
  63. <digital-input
  64. :values="ruleForm.budget_total"
  65. :placeholder="'项目总预算'"
  66. :min="0"
  67. :max="100000000000"
  68. :position="'right'"
  69. :precision="2"
  70. :size="'mini'"
  71. :disabled="type === 'view'"
  72. :controls="false"
  73. :append="'元'"
  74. @reschange="budget_total_change"
  75. />
  76. </el-form-item>
  77. </el-col>
  78. <el-col :span="8">
  79. <el-form-item label="要求到货时间" prop="arrtime">
  80. <el-date-picker
  81. v-model="ruleForm.arrtime"
  82. type="date"
  83. style="width: 100%"
  84. :disabled="type === 'view'"
  85. @change="time_change($event, 1)"
  86. value-format="yyyy-MM-dd"
  87. :picker-options="pickerOptions"
  88. placeholder="要求到货时间"
  89. >
  90. </el-date-picker>
  91. </el-form-item>
  92. </el-col>
  93. <el-col :span="8">
  94. <el-form-item label="咨询截止时间" prop="endtime">
  95. <el-date-picker
  96. v-model="ruleForm.endtime"
  97. type="datetime"
  98. style="width: 100%"
  99. :disabled="type === 'view'"
  100. @change="time_change($event, 2)"
  101. value-format="yyyy-MM-dd HH:mm:ss"
  102. :picker-options="pickerOptions"
  103. placeholder="要求到货时间"
  104. >
  105. </el-date-picker>
  106. </el-form-item>
  107. </el-col>
  108. <el-col :span="24">
  109. <el-form-item label="项目用途" prop="use_desc">
  110. <el-input
  111. type="textarea"
  112. :rows="2"
  113. placeholder="项目用途"
  114. :disabled="type === 'view'"
  115. v-model="ruleForm.use_desc"
  116. show-word-limit
  117. />
  118. </el-form-item>
  119. </el-col>
  120. <el-col :span="24">
  121. <el-form-item label="商品要求" prop="ladder">
  122. <el-table
  123. :data="ruleForm.ladder"
  124. :size="'mini'"
  125. border
  126. stripe
  127. style="width: 100%"
  128. >
  129. <el-table-column label="商品阶梯" width="70px">
  130. <template slot-scope="scope">
  131. {{ scope.$index + 1 }}</template
  132. >
  133. </el-table-column>
  134. <el-table-column prop="good_type" label="商品类型" width="80px">
  135. <template slot-scope="scope">
  136. <el-tag
  137. :size="'mini'"
  138. v-text="
  139. (
  140. statusOptions.find(
  141. (item) => item.value == scope.row.good_type
  142. ) || {}
  143. ).label || '--'
  144. "
  145. ></el-tag
  146. ></template>
  147. </el-table-column>
  148. <el-table-column
  149. prop="budget_price"
  150. label="预算单价"
  151. width="110"
  152. />
  153. <el-table-column prop="num" label="购买数量" width="110" />
  154. <el-table-column prop="cat_name" label="商品分类" />
  155. <el-table-column prop="good_img" label="图片" width="50">
  156. <template slot-scope="scope">
  157. <div
  158. v-if="scope.row.good_img"
  159. style="width: 20px; height: 20px"
  160. class="hover"
  161. v-viewer
  162. >
  163. <img
  164. :src="scope.row.good_img"
  165. style="display: inline-block; width: 100%; height: 100%"
  166. alt=""
  167. />
  168. </div>
  169. </template>
  170. </el-table-column>
  171. <el-table-column prop="good_name" label="商品名称" />
  172. <el-table-column
  173. fixed="right"
  174. width="110"
  175. v-if="type === 'add'"
  176. >
  177. <template slot="header" slot-scope="scope">
  178. <span>操作</span>
  179. <el-tooltip
  180. effect="dark"
  181. content="添加阶梯"
  182. placement="top"
  183. >
  184. <i
  185. class="el-icon-circle-plus-outline tb-icon fr"
  186. @click="openCostEdit(-1, {})"
  187. ></i>
  188. </el-tooltip>
  189. </template>
  190. <template slot-scope="scope">
  191. <el-tooltip effect="dark" content="修改" placement="top">
  192. <i
  193. class="el-icon-edit tb-icon"
  194. @click="openCostEdit(scope.$index, scope.row)"
  195. ></i>
  196. </el-tooltip>
  197. <el-tooltip effect="dark" content="删除" placement="top">
  198. <i
  199. class="el-icon-delete tb-icon"
  200. @click="openCostEditDelete(scope.$index)"
  201. ></i>
  202. </el-tooltip>
  203. </template>
  204. </el-table-column>
  205. </el-table>
  206. </el-form-item>
  207. <!-- 弹窗 新增/修改 -->
  208. <cost-form-add-edit
  209. :index="costmodelIndex"
  210. :show-model="costshowModel"
  211. :sitem="costsitem"
  212. @refresh="costrefreshEdit"
  213. @cancel="costshowModel = false"
  214. />
  215. </el-col>
  216. </el-row>
  217. </el-form>
  218. </el-col>
  219. <el-col :span="24" style="text-align: right" v-if="type === 'add'">
  220. <el-button type="primary" :size="'mini'" @click="submitForm"
  221. >保 存
  222. </el-button>
  223. </el-col>
  224. </el-row>
  225. </template>
  226. <script>
  227. import asyncRequest from "@/apis/service/sellOut/project";
  228. import resToken from "@/mixins/resToken";
  229. import costFormAddEdit from "./costFormAddEdit";
  230. export default {
  231. name: "Account",
  232. props: ["showModel", "sitem", "id", "type", "newTime"],
  233. mixins: [resToken],
  234. components: { costFormAddEdit },
  235. watch: {
  236. newTime: function (val) {
  237. if (val) {
  238. this.initForm();
  239. }
  240. },
  241. },
  242. data() {
  243. const validate_sale_price = (rule, value, callback) => {
  244. if (value === "") {
  245. callback(new Error("项目总预算不能为空!"));
  246. } else if (
  247. value === "0" ||
  248. value === "0." ||
  249. value === "0.0" ||
  250. value === "0.00"
  251. ) {
  252. callback(new Error("项目总预算不能为零!"));
  253. } else {
  254. callback();
  255. }
  256. };
  257. return {
  258. loading: false,
  259. tableData: [],
  260. costshowModel: false,
  261. costmodelIndex: "",
  262. costsitem: {},
  263. statusOptions: [
  264. { value: "1", label: "竞品" },
  265. { value: "2", label: "竞聘" },
  266. ],
  267. pickerOptions: {
  268. disabledDate(time) {
  269. return time.getTime() < Date.now() - 1000 * 60 * 60 * 24;
  270. },
  271. },
  272. company: "",
  273. platform_name: "",
  274. ruleForm: {
  275. name: "",
  276. platform: "",
  277. companyNo: "",
  278. khNo: [],
  279. customer_name: "",
  280. budget_total: "0",
  281. arrtime: "",
  282. endtime: "",
  283. use_desc: "",
  284. ladder: [],
  285. },
  286. rulesThis: this.rules,
  287. rules: {
  288. name: [
  289. {
  290. required: true,
  291. message: "项目名称不能为空!",
  292. trigger: "blur",
  293. },
  294. ],
  295. platform: [
  296. {
  297. required: true,
  298. message: "请选择所属平台",
  299. trigger: "change",
  300. },
  301. ],
  302. companyNo: [
  303. {
  304. required: true,
  305. message: "请选择销售方公司",
  306. trigger: "change",
  307. },
  308. ],
  309. khNo: [
  310. {
  311. type: "array",
  312. required: true,
  313. message: "请选择购买方公司",
  314. trigger: "change",
  315. },
  316. ],
  317. budget_total: [
  318. {
  319. required: true,
  320. validator: validate_sale_price,
  321. trigger: "blur",
  322. },
  323. ],
  324. arrtime: [
  325. {
  326. required: true,
  327. message: "要求到货时间不能为空!",
  328. trigger: "change",
  329. },
  330. ],
  331. endtime: [
  332. {
  333. required: true,
  334. message: "咨询截止时间不能为空!",
  335. trigger: "change",
  336. },
  337. ],
  338. use_desc: [
  339. {
  340. required: true,
  341. message: "项目用途不能为空",
  342. trigger: "blur",
  343. },
  344. ],
  345. ladder: [
  346. {
  347. type: "array",
  348. required: true,
  349. message: "至少添加两个商品要求",
  350. trigger: "change",
  351. },
  352. ],
  353. },
  354. };
  355. },
  356. mounted() {
  357. this.initForm();
  358. },
  359. methods: {
  360. //商品要求阶梯修改
  361. costrefreshEdit(e) {
  362. let item = JSON.parse(JSON.stringify(e));
  363. const {
  364. index,
  365. id,
  366. budget_price,
  367. num,
  368. cat_name,
  369. good_img,
  370. good_name,
  371. good_type,
  372. cat_id,
  373. } = item;
  374. if (index + "" === "-1") {
  375. this.ruleForm.ladder.push(item);
  376. } else {
  377. console.log(item);
  378. this.ruleForm.ladder.forEach((i, findex) => {
  379. if (findex === parseInt(index)) {
  380. this.ruleForm.ladder[findex].id = id;
  381. this.ruleForm.ladder[findex].budget_price = budget_price;
  382. this.ruleForm.ladder[findex].num = num;
  383. this.ruleForm.ladder[findex].good_type = good_type;
  384. this.ruleForm.ladder[findex].cat_id = JSON.parse(
  385. JSON.stringify(cat_id)
  386. );
  387. this.ruleForm.ladder[findex].cat_name = JSON.parse(
  388. JSON.stringify(cat_name)
  389. );
  390. this.ruleForm.ladder[findex].good_name = good_name;
  391. this.ruleForm.ladder[findex].good_img = good_img;
  392. }
  393. });
  394. }
  395. this.showModel = false;
  396. this.$refs.ruleForm.validateField("ladder");
  397. },
  398. time_change(e, type) {
  399. const { arrtime, endtime } = this.ruleForm;
  400. if (
  401. arrtime &&
  402. endtime &&
  403. new Date(endtime).getTime() >= new Date(arrtime).getTime()
  404. ) {
  405. this.$message.warning("咨询截止时间不能大于要求到货时间!");
  406. if (type === 1) {
  407. this.ruleForm.arrtime = "";
  408. } else if (type === 2) {
  409. this.ruleForm.endtime = "";
  410. }
  411. }
  412. this.$refs.ruleForm.validateField("arrtime");
  413. this.$refs.ruleForm.validateField("endtime");
  414. },
  415. //平台选择
  416. platform_codesearchChange(e) {
  417. const { id, code, label } = e;
  418. this.ruleForm.platform = id || "";
  419. this.$refs.ruleForm.validateField("platform");
  420. },
  421. //销售方公司选择
  422. company_idsearchChange(e) {
  423. if (e) {
  424. const { id, code, label } = e;
  425. this.ruleForm.companyNo = code || "";
  426. }
  427. this.$refs.ruleForm.validateField("companyNo");
  428. },
  429. //购买方公司选择
  430. customerChange(e) {
  431. if (e && e.id) {
  432. this.ruleForm.khNo = [e.code];
  433. this.ruleForm.customer_name = e.label;
  434. } else {
  435. this.ruleForm.khNo = [];
  436. this.ruleForm.customer_name = "";
  437. }
  438. this.$refs.ruleForm.validateField("khNo");
  439. },
  440. //项目总预算编辑
  441. budget_total_change(e) {
  442. this.ruleForm.budget_total = e + "";
  443. this.$refs.ruleForm.validateField("budget_total");
  444. },
  445. //商品要求阶梯弹窗打开
  446. openCostEdit(index, sitem) {
  447. this.costmodelIndex = index;
  448. this.costsitem = sitem;
  449. this.costshowModel = true;
  450. },
  451. //删除某一商品要求
  452. openCostEditDelete(index) {
  453. this.ruleForm.ladder.splice(index, 1);
  454. this.$refs.ruleForm.validateField("ladder");
  455. },
  456. //初始化整个组件
  457. async initForm() {
  458. this.loading = true;
  459. this.company = "";
  460. this.ruleForm = {
  461. name: "",
  462. platform: "",
  463. companyNo: "",
  464. khNo: [],
  465. customer_name: "",
  466. budget_total: "0",
  467. arrtime: "",
  468. endtime: "",
  469. use_desc: "",
  470. ladder: [],
  471. };
  472. this.rulesThis = this.rules;
  473. await this.resetForm();
  474. this.loading = false;
  475. },
  476. //初始化整个表单
  477. async resetForm() {
  478. // 重置
  479. await this.$nextTick(() => {
  480. if (this.$refs.ruleForm) {
  481. this.$refs.ruleForm.resetFields();
  482. this.$refs.ruleForm.clearValidate();
  483. console.log(this.sitem);
  484. const {
  485. project_name,
  486. budget_total,
  487. ladder,
  488. use_desc,
  489. arrtime,
  490. endtime,
  491. khName,
  492. company,
  493. khNo,
  494. companyNo,
  495. platform_id,
  496. platform_name,
  497. } = this.sitem;
  498. this.company = company || "";
  499. this.platform_name = platform_name || "";
  500. this.ruleForm = {
  501. name: project_name || "",
  502. platform: platform_id || "",
  503. companyNo: companyNo || "",
  504. khNo: khNo ? [khNo] : [],
  505. customer_name: khName || "",
  506. budget_total: budget_total || "0",
  507. arrtime: arrtime || "",
  508. endtime: endtime || "",
  509. use_desc: use_desc || "",
  510. ladder: ladder && ladder.length > 0 ? ladder : [],
  511. };
  512. this.ruleForm.ladder.forEach((e) => {
  513. e.cat_name = "";
  514. const { cat_info } = e;
  515. if (cat_info && cat_info.length > 0) {
  516. cat_info.forEach((b, bi) => {
  517. e.cat_name += bi !== 0 ? "_" + b.name : b.name;
  518. });
  519. }
  520. });
  521. }
  522. });
  523. },
  524. async submitForm() {
  525. await this.$refs.ruleForm.validate(async (valid) => {
  526. if (valid) {
  527. this.loading = true;
  528. let model = JSON.parse(JSON.stringify(this.ruleForm));
  529. console.log(model);
  530. const { budget_total, ladder } = model;
  531. let ztotal = Math.floor(budget_total * 100) / 100;
  532. // model.platform = model.platform.toString();
  533. model.khNo = model.khNo.toString();
  534. delete model["customer_name"];
  535. if (ladder && ladder.length < 2) {
  536. this.$message.warning("至少添加两个商品要求!");
  537. this.loading = false;
  538. return;
  539. }
  540. let total = 0;
  541. let list = [];
  542. ladder.forEach((e) => {
  543. let item = JSON.parse(JSON.stringify(e));
  544. delete item["id"];
  545. delete item["index"];
  546. delete item["is_del"];
  547. delete item["cat_name"];
  548. item.cat_id =
  549. item.cat_id && item.cat_id.length > 0
  550. ? item.cat_id[item.cat_id.length - 1]
  551. : "";
  552. list.push(item);
  553. let a1 = Math.floor(e.budget_price * 100);
  554. let a2 = parseInt(e.num);
  555. let a3 = (a1 * a2) / 100;
  556. total = Math.floor((a3 + total) * 100) / 100;
  557. });
  558. console.log(`项目总预算为${ztotal}---商品要求预算总和为${total}`);
  559. if (ztotal < total) {
  560. this.$message.warning("项目总预算不能低于所以商品要求预算总和!");
  561. this.loading = false;
  562. return;
  563. }
  564. model.ladder = JSON.parse(JSON.stringify(list));
  565. let res = await asyncRequest.add(model);
  566. this.loading = false;
  567. if (res && res.code === 0) {
  568. this.$notify.success({
  569. title: "添加成功",
  570. message: "",
  571. });
  572. this.showModelThis = false;
  573. // 刷新
  574. this.$emit("refresh", res.data);
  575. } else if (res && res.code >= 100 && res.code <= 104) {
  576. await this.logout();
  577. } else {
  578. this.$message.warning(res.message);
  579. }
  580. } else {
  581. console.log("error submit!!");
  582. return false;
  583. }
  584. });
  585. },
  586. },
  587. };
  588. </script>
  589. <style lang="scss" scoped>
  590. .account {
  591. }
  592. </style>