baseForm.vue 20 KB

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