addForm.vue 18 KB

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