add.vue 14 KB

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