add.vue 9.8 KB

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