add.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <div class="goodsOnlineAdd">
  3. <div class="goodsOnlineAdd-main" v-if="powers.some((i) => i == '007')">
  4. <el-form
  5. status-icon
  6. :model="ruleForm"
  7. :rules="rulesThis"
  8. ref="ruleForm"
  9. :size="'mini'"
  10. v-loading="loading"
  11. label-width="110px"
  12. class="demo-ruleForm"
  13. >
  14. <el-row>
  15. <el-col :span="8">
  16. <el-form-item label="所属平台" prop="platform">
  17. <search-terrace
  18. :value="ruleForm.platform"
  19. :disabled="false"
  20. :size="'mini'"
  21. :is_show="'1'"
  22. :isDetail="false"
  23. :placeholder="'所属平台'"
  24. @searchChange="platform_codesearchChange"
  25. />
  26. </el-form-item>
  27. <el-form-item label="定价模式" prop="is_fixed">
  28. <el-select v-model="ruleForm.is_fixed" style="width:100%" placeholder="定价模式">
  29. <el-option
  30. v-for="f in fixedOptions"
  31. :key="f.value"
  32. :value="f.value"
  33. :label="f.label"
  34. />
  35. </el-select>
  36. </el-form-item>
  37. <el-form-item label="上线原因" prop="online_reason">
  38. <el-input
  39. :disabled="false"
  40. placeholder="上线原因"
  41. v-model="ruleForm.online_reason"
  42. maxlength="200"
  43. />
  44. </el-form-item>
  45. </el-col>
  46. <el-col :span="16">
  47. <el-form-item label="上线备注" prop="online_remark">
  48. <el-input
  49. type="textarea"
  50. :rows="3"
  51. :disabled="false"
  52. placeholder="上线备注"
  53. maxlength="250"
  54. show-word-limit
  55. v-model="ruleForm.online_remark"
  56. />
  57. </el-form-item>
  58. </el-col>
  59. <el-col :span="24">
  60. <el-table :data="tableData" stripe border :size="'mini'" style="width: 100%">
  61. <el-table-column width="50" type="index" show-overflow-tooltip />
  62. <el-table-column prop="spuCode" label="商品编号" width="180" show-overflow-tooltip />
  63. <el-table-column prop="good_thumb_img" label="图片" width="45" show-overflow-tooltip>
  64. <template slot-scope="scope">
  65. <div
  66. v-if="scope.row.good_thumb_img"
  67. style="width: 20px; height: 20px"
  68. class="hover"
  69. v-viewer
  70. >
  71. <img
  72. :src="scope.row.good_thumb_img"
  73. style="display: inline-block; width: 100%; height: 100%"
  74. alt
  75. />
  76. </div>
  77. </template>
  78. </el-table-column>
  79. <el-table-column prop="good_name" label="商品名称" min-width="160" show-overflow-tooltip />
  80. <el-table-column prop="cat_name" label="分类" min-width="110" show-overflow-tooltip />
  81. <el-table-column
  82. prop="good_name"
  83. label="品牌"
  84. min-width="brand_name"
  85. show-overflow-tooltip
  86. />
  87. <el-table-column prop="good_type" label="是否定制" min-width="70" show-overflow-tooltip>
  88. <template slot-scope="scope">
  89. <el-tag
  90. :size="'mini'"
  91. :type="scope.row.good_type == '1' ? '' : 'warning'"
  92. v-text="
  93. (options1.find((item) => item.id == scope.row.status) || {}).name ||
  94. '--'
  95. "
  96. ></el-tag>
  97. </template>
  98. </el-table-column>
  99. <el-table-column prop="supplierNo" label="供应商编号" width="110" show-overflow-tooltip />
  100. <el-table-column
  101. prop="supplier_name"
  102. label="供应商名称"
  103. width="110"
  104. show-overflow-tooltip
  105. />
  106. <el-table-column prop="companyNo" label="业务公司编号" width="110" show-overflow-tooltip />
  107. <el-table-column prop="company" label="业务公司名称" width="110" show-overflow-tooltip />
  108. <el-table-column fixed="right">
  109. <template slot="header" slot-scope="scope">
  110. <span>操作</span>
  111. <el-tooltip class="item" effect="dark" content="添加上线商品" placement="top">
  112. <i
  113. class="el-icon-circle-plus-outline fr"
  114. style="font-size: 18px; margin-top: 2px"
  115. @click="showModel = true"
  116. />
  117. </el-tooltip>
  118. </template>
  119. <template slot-scope="scope">
  120. <el-tooltip effect="dark" content="删除" placement="top">
  121. <i class="el-icon-delete tb-icon" @click="openDel(scope.$index)"></i>
  122. </el-tooltip>
  123. </template>
  124. </el-table-column>
  125. </el-table>
  126. <!--添加商品-->
  127. <search-good-modal
  128. :is-noble="isNoble"
  129. :check-type="true"
  130. :showModel="showModel"
  131. :once="false"
  132. @resultList="resultList"
  133. @cancel="showModel = false"
  134. />
  135. </el-col>
  136. <el-col :span="24" style="text-align: right; padding: 15px 0 15px 0">
  137. <el-button :size="'mini'" type="primary" @click="submitForm">保 存</el-button>
  138. </el-col>
  139. </el-row>
  140. </el-form>
  141. </div>
  142. <div v-else>
  143. <no-auth></no-auth>
  144. </div>
  145. </div>
  146. </template>
  147. <script>
  148. import asyncRequest from "@/apis/service/goodStore/goodsOnline";
  149. import resToken from "@/mixins/resToken";
  150. import { mapGetters } from "vuex";
  151. import searchGoodModal from "@/components/search-good-modal";
  152. import { rules, options1 } from "./columns";
  153. import { replaceTextWrapAndSpace } from "@/utils";
  154. export default {
  155. name: "goodsOnlineAdd",
  156. mixins: [resToken],
  157. props: ["showModel", "id", "type", "sitem"],
  158. components: {
  159. searchGoodModal
  160. },
  161. computed: {
  162. ...mapGetters(["tablebtnSize", "searchSize", "size"]),
  163. isFiexed() {
  164. return !this.isYzPlatform && this.isNoble;
  165. },
  166. powers() {
  167. const tran =
  168. this.$store.getters.btnList.find(
  169. item => item.menu_route == "goodsOnlineAdd"
  170. ) || {};
  171. const { action } = tran ?? {};
  172. return action ?? [];
  173. },
  174. fixedOptions() {
  175. return [
  176. { value: "1", label: "一口价" },
  177. ...(this.isFiexed ? [{ value: "0", label: "实时金价" }] : [])
  178. ];
  179. }
  180. },
  181. watch: {
  182. newTime: function(val) {
  183. if (val) {
  184. this.initForm();
  185. }
  186. },
  187. isFiexed() {
  188. if (this.ruleForm.is_fixed === "0") {
  189. this.ruleForm.is_fixed = "";
  190. }
  191. }
  192. },
  193. data() {
  194. return {
  195. isNoble: null,
  196. tableData: [],
  197. costshowModel: false,
  198. costmodelIndex: "",
  199. costsitem: {},
  200. showModel: false,
  201. status: "",
  202. rulesThis: this.rules,
  203. activeName: "1",
  204. isYzPlatform: false,
  205. loading: true,
  206. //是否定制
  207. options1: options1,
  208. ruleForm: {},
  209. rules: rules
  210. };
  211. },
  212. mounted() {
  213. this.initForm();
  214. },
  215. methods: {
  216. async initForm() {
  217. this.loading = true;
  218. this.resetFormData();
  219. this.rulesThis = this.rules;
  220. await this.resetForm();
  221. this.loading = false;
  222. },
  223. openDel(index) {
  224. this.tableData.splice(index, 1);
  225. if (this.tableData.length === 0) {
  226. this.isNoble = null;
  227. }
  228. },
  229. resultList(e) {
  230. this.showModel = false;
  231. let list = JSON.parse(JSON.stringify(e));
  232. let oldList = JSON.parse(JSON.stringify(this.tableData));
  233. const categoryIds = list.map(({ cat_info, is_gold_price }) => ({
  234. id: String(cat_info[0].id),
  235. isGoldPrice: String(is_gold_price)
  236. }));
  237. const nobleIds = categoryIds.filter(
  238. ({ id, isGoldPrice }) => id === "6" && isGoldPrice === "1"
  239. );
  240. console.log(nobleIds, categoryIds);
  241. this.isNoble =
  242. nobleIds.length > 0 && categoryIds.length === nobleIds.length;
  243. list.forEach((e, ei) => {
  244. let index = oldList.findIndex(a => {
  245. return e.spuCode === a.spuCode;
  246. });
  247. if (index === -1) {
  248. let item = JSON.parse(JSON.stringify(list[ei]));
  249. this.tableData.push(item);
  250. }
  251. });
  252. },
  253. async submitForm() {
  254. this.ruleForm.online_remark = replaceTextWrapAndSpace(
  255. this.ruleForm.online_remark
  256. );
  257. await this.$refs.ruleForm.validate(async valid => {
  258. if (valid) {
  259. if (!this.loading) {
  260. if (this.tableData.length === 0) {
  261. this.$message.warning("至少选择一个商品!");
  262. return;
  263. }
  264. if (this.tableData.length > 100) {
  265. this.$message.warning("商品数量不能超过100!");
  266. return;
  267. }
  268. this.loading = true;
  269. let model = JSON.parse(JSON.stringify(this.ruleForm));
  270. let list = JSON.parse(JSON.stringify(this.tableData));
  271. list.forEach(e => {
  272. model.codes.push(e.spuCode);
  273. });
  274. // model.platform = model.platform.toString();
  275. const { code, data, message } = await asyncRequest.add(model);
  276. this.loading = false;
  277. if (code === 0) {
  278. this.$notify.success({
  279. title: "新建成功",
  280. message: ""
  281. });
  282. this.showModelThis = false;
  283. // 刷新
  284. this.routeReGoto("goodsOnline", {});
  285. } else if (code >= 100 && code <= 104) {
  286. await this.logout(code <= 104);
  287. } else if (message === "一口价商品请先完善商品成本单价") {
  288. this.$message.warning(message);
  289. } else if (code === 1004) {
  290. this.open_show(
  291. data,
  292. "以下商品的业务公司和平台支付渠道中的业务公司重复,不允许上线"
  293. );
  294. } else if (code === 1009) {
  295. this.open_show(data, "以下商品已申请过商品上线");
  296. } else if (code === 1010) {
  297. this.open_show(data, "该平台要求商品必须要有一件的成本!");
  298. } else {
  299. this.$message.warning(message);
  300. }
  301. }
  302. } else {
  303. console.log("error submit!!");
  304. return false;
  305. }
  306. });
  307. },
  308. open_show(data, title) {
  309. const resList = JSON.parse(JSON.stringify(data));
  310. let htmlList = "<ul>";
  311. resList.forEach(v => {
  312. htmlList += `<li>
  313. <span>${v.good_name}</span></li>`;
  314. });
  315. htmlList += "</ul>";
  316. this.$notify({
  317. title: title,
  318. dangerouslyUseHTMLString: true,
  319. message: htmlList
  320. });
  321. },
  322. resetFormData() {
  323. this.ruleForm = {
  324. is_fixed: "",
  325. platform: "", //string 平台id
  326. codes: [], //string 无
  327. online_reason: "", //string 上线原因
  328. online_remark: "" //string 上线备注
  329. };
  330. this.tableData = [];
  331. },
  332. async resetForm() {
  333. // 重置
  334. await this.$nextTick(async () => {
  335. if (this.$refs.ruleForm) {
  336. this.$refs.ruleForm.resetFields();
  337. this.$refs.ruleForm.clearValidate();
  338. this.resetFormData();
  339. }
  340. });
  341. },
  342. platform_codesearchChange(e) {
  343. const { id, code, label, platform_type } = e;
  344. this.ruleForm.platform = id || "";
  345. this.isYzPlatform = String(platform_type) === "1";
  346. this.$refs.ruleForm.validateField("platform");
  347. }
  348. }
  349. };
  350. </script>
  351. <style lang="scss" scoped>
  352. .goodsOnlineAdd {
  353. .goodsOnlineAdd-main {
  354. padding: 30px 20px 0 20px;
  355. }
  356. }
  357. </style>