baseForm.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. <template>
  2. <div class="activeAdd">
  3. <el-form
  4. :model="ruleForm"
  5. status-icon
  6. :rules="rulesThis"
  7. ref="ruleForm"
  8. :size="'mini'"
  9. label-width="90px"
  10. class="demo-ruleForm"
  11. >
  12. <el-row>
  13. <el-col :span="8">
  14. <el-form-item label="业务企业" prop="company_id">
  15. <search-work-company
  16. :value="ruleForm.company_id"
  17. :disabled="status !== ''"
  18. :size="'mini'"
  19. :isDetail="false"
  20. :placeholder="'业务企业'"
  21. @searchChange="company_idsearchChange"
  22. />
  23. </el-form-item>
  24. </el-col>
  25. <el-col :span="16">
  26. <el-form-item label="活动标题" prop="activity_name">
  27. <el-input
  28. placeholder="活动标题"
  29. :disabled="status !== ''"
  30. v-model="ruleForm.activity_name"
  31. maxlength="100"
  32. />
  33. </el-form-item>
  34. </el-col>
  35. <el-col :span="8">
  36. <el-form-item label="所属平台" prop="platform_code">
  37. <search-terrace
  38. :value="ruleForm.platform_code"
  39. :disabled="status !== ''"
  40. :size="'mini'"
  41. :isDetail="false"
  42. :placeholder="'所属平台'"
  43. @searchChange="platform_codesearchChange"
  44. />
  45. </el-form-item>
  46. </el-col>
  47. <el-col :span="16">
  48. <el-form-item label="活动时间" required style="margin: 0">
  49. <el-row>
  50. <el-col :span="11">
  51. <el-form-item prop="datactivity_name">
  52. <el-date-picker
  53. type="datetime"
  54. placeholder="开始时间"
  55. :disabled="status !== ''"
  56. value-format="yyyy-MM-dd HH:mm:ss"
  57. :picker-options="pickerOptions1"
  58. v-model="ruleForm.activity_start"
  59. style="width: 100%"
  60. ></el-date-picker>
  61. </el-form-item>
  62. </el-col>
  63. <el-col class="tc" :span="2">-</el-col>
  64. <el-col :span="11">
  65. <el-form-item prop="activity_end">
  66. <el-date-picker
  67. type="datetime"
  68. value-format="yyyy-MM-dd HH:mm:ss"
  69. placeholder="结束时间"
  70. :disabled="status !== ''"
  71. :picker-options="pickerOptions2"
  72. v-model="ruleForm.activity_end"
  73. style="width: 100%"
  74. ></el-date-picker>
  75. </el-form-item>
  76. </el-col>
  77. </el-row>
  78. </el-form-item>
  79. </el-col>
  80. <el-col :span="8">
  81. <el-form-item label="库存类型" prop="is_stock">
  82. <el-select
  83. v-model="ruleForm.is_stock"
  84. style="width: 100%"
  85. :size="'mini'"
  86. :disabled="status !== ''"
  87. placeholder="库存类型"
  88. @change="is_stock_change"
  89. >
  90. <el-option
  91. v-for="item in is_stock"
  92. :key="item.id"
  93. :label="item.name"
  94. :value="item.id"
  95. >
  96. </el-option>
  97. </el-select>
  98. </el-form-item>
  99. </el-col>
  100. <el-col :span="16">
  101. <el-form-item label="活动描述" prop="activity_desc">
  102. <el-input
  103. placeholder="活动描述"
  104. type="textarea"
  105. :rows="2"
  106. :disabled="status !== ''"
  107. show-word-limit
  108. v-model="ruleForm.activity_desc"
  109. maxlength="500"
  110. />
  111. </el-form-item>
  112. </el-col>
  113. <el-col
  114. :span="24"
  115. v-if="
  116. status == '' ||
  117. status == '4' ||
  118. (status === '0' && powers.some((item) => item !== '056')) ||
  119. (status === '1' && powers.some((item) => item !== '057')) ||
  120. (status === '2' && powers.some((item) => item !== '058')) ||
  121. (status === '3' && powers.some((item) => item !== '059'))
  122. "
  123. >
  124. <el-form-item
  125. label="活动商品"
  126. :label-position="'top'"
  127. prop="good_list"
  128. >
  129. <el-table
  130. :data="ruleForm.good_list"
  131. stripe
  132. border
  133. :size="'mini'"
  134. style="width: 100%"
  135. >
  136. <el-table-column
  137. prop="skuCode"
  138. label="商品编码"
  139. show-overflow-tooltip
  140. width="170"
  141. />
  142. <el-table-column
  143. prop="good_name"
  144. label="商品名称"
  145. show-overflow-tooltip
  146. />
  147. <el-table-column
  148. v-if="!(status === '' || status === '0')"
  149. prop="activity_stock"
  150. label="活动库存"
  151. width="100"
  152. show-overflow-tooltip
  153. />
  154. <el-table-column
  155. prop="moq_num"
  156. label="起订量"
  157. width="100"
  158. v-if="!(status === '' || status === '0')"
  159. show-overflow-tooltip
  160. />
  161. <el-table-column
  162. prop="cost_price"
  163. label="成本单价(元)"
  164. width="100"
  165. v-if="!(status === '' || status === '0')"
  166. show-overflow-tooltip
  167. />
  168. <el-table-column
  169. v-if="!(status === '' || status === '0')"
  170. prop="sale_price"
  171. label="非活动价(元)"
  172. width="100"
  173. show-overflow-tooltip
  174. />
  175. <el-table-column
  176. v-if="!(status === '' || status === '0')"
  177. prop="activity_price"
  178. label="活动价(元)"
  179. width="100"
  180. show-overflow-tooltip
  181. />
  182. <el-table-column
  183. prop="status"
  184. label="审核状态"
  185. width="100"
  186. v-if="!(status === '' || status === '0')"
  187. >
  188. <template slot-scope="scope">
  189. <el-tag
  190. :size="'mini'"
  191. :type="
  192. scope.row.status == '0'
  193. ? 'warning'
  194. : scope.row.status == '2'
  195. ? 'danger'
  196. : ''
  197. "
  198. v-text="
  199. (
  200. options.find(
  201. (item) => item.value == scope.row.status
  202. ) || {}
  203. ).label || '--'
  204. "
  205. ></el-tag>
  206. </template>
  207. </el-table-column>
  208. <el-table-column
  209. v-if="!(status === '' || status === '0')"
  210. prop="remark"
  211. label="审核备注"
  212. width="100"
  213. show-overflow-tooltip
  214. />
  215. <el-table-column fixed="right" width="80">
  216. <template slot="header" slot-scope="scope">
  217. <span>操作</span>
  218. <el-tooltip
  219. class="item"
  220. effect="dark"
  221. v-if="status === ''"
  222. content="添加活动商品"
  223. placement="top"
  224. >
  225. <i
  226. class="el-icon-circle-plus-outline fr"
  227. style="font-size: 18px; margin-top: 2px"
  228. @click="openEdit('add', '0')"
  229. />
  230. </el-tooltip>
  231. </template>
  232. <template slot-scope="scope">
  233. <el-tooltip
  234. effect="dark"
  235. content="查看商品信息"
  236. placement="top"
  237. >
  238. <i
  239. class="el-icon-view tb-icon"
  240. @click="showGoodModelFun(scope.row.skuCode)"
  241. ></i>
  242. </el-tooltip>
  243. <el-tooltip
  244. v-if="status === ''"
  245. effect="dark"
  246. content="删除"
  247. placement="top"
  248. >
  249. <i
  250. class="el-icon-delete tb-icon"
  251. @click="openCostEditDelete(scope.$index)"
  252. ></i>
  253. </el-tooltip>
  254. </template>
  255. </el-table-column>
  256. </el-table>
  257. </el-form-item>
  258. </el-col>
  259. </el-row>
  260. </el-form>
  261. <search-good-online-modal
  262. :once="once"
  263. :sitem="ruleForm"
  264. :active="true"
  265. :show-model="showModel"
  266. @resultList="resultList"
  267. @cancel="showModel = false"
  268. />
  269. <show-good-data-modal
  270. :show-model="showGoodModel"
  271. :id="showGoodId"
  272. @cancel="showGoodModel = false"
  273. />
  274. <el-col
  275. :span="24"
  276. v-if="status === ''"
  277. style="
  278. text-align: right;
  279. padding: 15px 0 15px 0;
  280. border-top: 1px solid #dcdfe6;
  281. "
  282. >
  283. <el-button :size="'mini'" type="primary" @click="submitForm"
  284. >保 存
  285. </el-button>
  286. </el-col>
  287. </div>
  288. </template>
  289. <script>
  290. import asyncRequest from "@/apis/service/goodStore/active";
  291. import resToken from "@/mixins/resToken";
  292. import { mapGetters } from "vuex";
  293. import searchGoodOnlineModal from "@/components/search-good-online-modal";
  294. import showGoodDataModal from "@/components/show-good-data-modal";
  295. export default {
  296. name: "activeAdd",
  297. mixins: [resToken],
  298. props: ["showModel", "id", "type", "sitem"],
  299. components: {
  300. searchGoodOnlineModal,
  301. showGoodDataModal,
  302. },
  303. computed: {
  304. ...mapGetters(["tablebtnSize", "searchSize", "size"]),
  305. powers() {
  306. let tran =
  307. this.$store.getters.btnList.find(
  308. (item) => item.menu_route == "activeDetail"
  309. ) || {};
  310. if (tran && tran.action && tran.action.length > 0) {
  311. return tran.action;
  312. } else {
  313. return [];
  314. }
  315. },
  316. },
  317. data() {
  318. return {
  319. size: "small",
  320. activeName: "3",
  321. status: "",
  322. options: [
  323. {
  324. value: "0",
  325. label: "待审核",
  326. },
  327. {
  328. value: "1",
  329. label: "通过",
  330. },
  331. {
  332. value: "2",
  333. label: "驳回",
  334. },
  335. ],
  336. is_stock: [
  337. { id: "0", name: "非库存品" },
  338. { id: "1", name: "库存品" },
  339. ],
  340. pickerOptions1: {
  341. disabledDate: (time) => {
  342. if (
  343. this.ruleForm.activity_end != null &&
  344. this.ruleForm.activity_end != "" &&
  345. time
  346. ) {
  347. return (
  348. time.getTime() > new Date(this.ruleForm.activity_end).valueOf()
  349. );
  350. }
  351. },
  352. },
  353. pickerOptions2: {
  354. disabledDate: (time) => {
  355. if (
  356. this.ruleForm.activity_start != null &&
  357. this.ruleForm.activity_start != "" &&
  358. time
  359. ) {
  360. return (
  361. time.getTime() < new Date(this.ruleForm.activity_start).valueOf()
  362. );
  363. }
  364. },
  365. },
  366. loading: false,
  367. showModel: false,
  368. once: false,
  369. rulesThis: this.rules,
  370. showGoodModel: false,
  371. showGoodId: "",
  372. ruleForm: {},
  373. // 表格 - 数据
  374. tableData: [],
  375. rules: {
  376. activity_name: [
  377. {
  378. required: true,
  379. message: "活动标题不能为空",
  380. trigger: "blur",
  381. },
  382. ],
  383. company_id: [
  384. {
  385. required: true,
  386. message: "业务公司不能为空",
  387. trigger: "change",
  388. },
  389. ],
  390. platform_code: [
  391. {
  392. type: "array",
  393. required: true,
  394. message: "所属平台不能为空",
  395. trigger: "change",
  396. },
  397. ],
  398. activity_start: [
  399. {
  400. required: true,
  401. message: "开始时间不能为空",
  402. trigger: "change",
  403. },
  404. ],
  405. activity_end: [
  406. {
  407. required: true,
  408. message: "结束时间不能为空",
  409. trigger: "change",
  410. },
  411. ],
  412. activity_desc: [
  413. {
  414. required: true,
  415. message: "活动描述不能为空",
  416. trigger: "blur",
  417. },
  418. ],
  419. is_stock: [
  420. {
  421. required: true,
  422. message: "请选择是否库存品",
  423. trigger: "change",
  424. },
  425. ],
  426. good_list: [
  427. {
  428. type: "array",
  429. required: true,
  430. message: "至少选择一个商品!",
  431. trigger: "change,blur",
  432. },
  433. ],
  434. },
  435. };
  436. },
  437. mounted() {
  438. this.initForm();
  439. },
  440. methods: {
  441. async initForm() {
  442. this.loading = true;
  443. this.resetFormData();
  444. this.rulesThis = this.rules;
  445. await this.resetForm();
  446. this.loading = false;
  447. },
  448. async resetForm() {
  449. // 重置
  450. await this.$nextTick(async () => {
  451. if (this.$refs.ruleForm) {
  452. this.$refs.ruleForm.resetFields();
  453. this.$refs.ruleForm.clearValidate();
  454. this.resetFormData();
  455. }
  456. });
  457. },
  458. showGoodModelFun(skuCode) {
  459. this.showGoodModel = true;
  460. this.showGoodId = skuCode;
  461. },
  462. openCostEditDelete(index) {
  463. this.ruleForm.good_list.splice(index, 1);
  464. this.$refs.ruleForm.validateField("good_list");
  465. },
  466. company_idsearchChange(e) {
  467. console.log(e);
  468. let old = this.ruleForm.company_id;
  469. if (e) {
  470. const { id, code, label } = e;
  471. this.ruleForm.company_id = code || "";
  472. }
  473. this.$refs.ruleForm.validateField("company_id");
  474. if (old !== this.ruleForm.company_id) {
  475. this.ruleForm.good_list = [];
  476. }
  477. },
  478. is_stock_change(e) {
  479. const { is_stock } = this.ruleForm;
  480. console.log(is_stock, e);
  481. let hs_is_stock = "0";
  482. if (this.ruleForm.good_list && this.ruleForm.good_list.length > 0) {
  483. hs_is_stock = this.ruleForm.good_list[0].is_stock;
  484. }
  485. if (is_stock !== hs_is_stock) {
  486. this.ruleForm.good_list = [];
  487. }
  488. console.log(this.ruleForm.good_list);
  489. //
  490. },
  491. platform_codesearchChange(e) {
  492. let old = JSON.parse(JSON.stringify(this.ruleForm.platform_code));
  493. console.log(e);
  494. if (e) {
  495. const { id, code, label } = e;
  496. this.ruleForm.platform_code = id ? [id] : [];
  497. }
  498. this.$refs.ruleForm.validateField("platform_code");
  499. let newList = JSON.parse(JSON.stringify(this.ruleForm.platform_code));
  500. if (old !== this.ruleForm.platform_code) {
  501. this.ruleForm.good_list = [];
  502. }
  503. },
  504. resultList(e) {
  505. console.log(e);
  506. this.showModel = false;
  507. let list = JSON.parse(JSON.stringify(e));
  508. let oldList = JSON.parse(JSON.stringify(this.ruleForm.good_list));
  509. list.forEach((e, ei) => {
  510. let index = oldList.findIndex((a) => e.skucode === a.skucode);
  511. if (index === -1) {
  512. let item = JSON.parse(JSON.stringify(list[ei]));
  513. this.ruleForm.good_list.push(item);
  514. }
  515. });
  516. },
  517. resetFormData() {
  518. this.tableData = [];
  519. const {
  520. activity_name,
  521. activity_desc,
  522. is_stock,
  523. end,
  524. start,
  525. platform_code,
  526. company_id,
  527. info,
  528. status,
  529. } = this.sitem;
  530. this.ruleForm = {
  531. activity_name: activity_name || "",
  532. platform_code: platform_code ? [platform_code] : [],
  533. company_id: company_id || "",
  534. activity_start: start || "",
  535. activity_end: end || "",
  536. activity_desc: activity_desc || "",
  537. is_stock: is_stock || "",
  538. good_list:
  539. info && info.length > 0 ? JSON.parse(JSON.stringify(info)) : [],
  540. };
  541. this.status = status || "";
  542. this.tableData =
  543. info && info.length > 0 ? JSON.parse(JSON.stringify(info)) : [];
  544. },
  545. handleClick(row) {
  546. console.log(row);
  547. },
  548. openEdit() {
  549. const { company_id, platform_code, is_stock } = this.ruleForm;
  550. if (platform_code.length === 0) {
  551. this.$message.warning("请选择平台!");
  552. return;
  553. }
  554. if (company_id === "") {
  555. this.$message.warning("请选择业务企业!");
  556. return;
  557. }
  558. if (is_stock === "") {
  559. this.$message.warning("请选择库存类型!");
  560. return;
  561. }
  562. this.showModel = true;
  563. },
  564. async submitForm() {
  565. await this.$refs.ruleForm.validate(async (valid) => {
  566. if (valid) {
  567. this.loading = true;
  568. if (this.ruleForm.good_list.length === 0) {
  569. this.$message.warning("请选择活动商品信息!");
  570. this.loading = false;
  571. return;
  572. }
  573. let model = JSON.parse(JSON.stringify(this.ruleForm));
  574. model.platform_code = model.platform_code.toString();
  575. const { good_list } = model;
  576. let list = JSON.parse(JSON.stringify(good_list));
  577. let newList = [];
  578. model.good_list = [];
  579. list.forEach((e) => {
  580. let item = {
  581. skuCode: e.skuCode,
  582. activity_stock: 1 + "",
  583. };
  584. newList.push(item);
  585. });
  586. model.good_list = newList;
  587. let res = {};
  588. console.log(this.id, this.type);
  589. if (this.type === "add") {
  590. delete model["id"];
  591. delete model["spuCode"];
  592. res = await asyncRequest.add(model);
  593. } else {
  594. res = await asyncRequest.update(model);
  595. }
  596. console.log(res);
  597. this.loading = false;
  598. if (res && res.code === 0) {
  599. const title = this.type === "add" ? "新建成功!" : "库存修改成功!";
  600. this.$notify.success({
  601. title: title,
  602. message: "",
  603. });
  604. this.showModelThis = false;
  605. // 刷新
  606. this.$emit("refresh", true);
  607. }
  608. } else {
  609. console.log("error submit!!");
  610. return false;
  611. }
  612. });
  613. },
  614. // async initData() {
  615. // this.loading = true;
  616. // let res = await asyncRequest.detail({ id: this.id });
  617. // this.loading = false;
  618. // if (res.code === 0) {
  619. // await this.resetForm(res.data);
  620. // }
  621. // },
  622. },
  623. };
  624. </script>
  625. <style lang="scss" scoped>
  626. .activeAdd {
  627. .activeAdd-title {
  628. border-top: 1px solid #ebeef5;
  629. span {
  630. height: 50px;
  631. line-height: 50px;
  632. font-family: "微软雅黑", sans-serif;
  633. font-weight: 400;
  634. font-style: normal;
  635. font-size: 16fpx;
  636. text-align: left;
  637. }
  638. }
  639. /deep/ .ddiv {
  640. border-top: 1px solid #dcdfe6;
  641. }
  642. /deep/ .dtitle {
  643. width: 40px;
  644. text-align: center;
  645. height: 100%;
  646. min-height: 100%;
  647. ul {
  648. padding: 20px 0 0 0;
  649. }
  650. }
  651. /deep/ .dmain {
  652. padding: 20px 0 0 0;
  653. width: calc(100% - 40px);
  654. border-left: 1px solid #dcdfe6;
  655. }
  656. }
  657. </style>