addEditGoodModal.vue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910
  1. <template>
  2. <el-dialog
  3. v-loading="loading"
  4. :title="title"
  5. :center="true"
  6. align="left"
  7. top="8vh"
  8. width="1040px"
  9. :close-on-click-modal="false"
  10. :visible.sync="showModelThis"
  11. element-loading-text="拼命加载中"
  12. element-loading-spinner="el-icon-loading"
  13. element-loading-background="rgba(0, 0, 0, 0.8)"
  14. @close="showModelThis = false"
  15. append-to-body
  16. >
  17. <el-card style="margin: -20px 0 0 0">
  18. <el-row :gutter="10">
  19. <el-col :span="24">
  20. <el-form
  21. ref="ruleForm"
  22. :model="ruleForm"
  23. status-icon
  24. :size="'mini'"
  25. :rules="rulesThis"
  26. label-width="90px"
  27. class="demo-ruleForm"
  28. >
  29. <el-row>
  30. <el-col :span="8">
  31. <el-form-item label="到货日期" prop="arrival_time">
  32. <el-date-picker
  33. v-model="ruleForm.arrival_time"
  34. type="date"
  35. style="width: 100%"
  36. :disabled="ruleForm.p_arrtime"
  37. value-format="yyyy-MM-dd"
  38. :picker-options="pickerOptions"
  39. placeholder="到货日期"
  40. >
  41. </el-date-picker>
  42. </el-form-item>
  43. </el-col>
  44. <el-col :span="6">
  45. <el-form-item label="是否多地" prop="is_addrs">
  46. <el-select
  47. v-model="ruleForm.is_addrs"
  48. placeholder="是否多地"
  49. style="width: 100%"
  50. >
  51. <el-option
  52. v-for="item in is_addrs_options"
  53. :key="item.value"
  54. :label="item.label"
  55. :value="item.value"
  56. >
  57. </el-option>
  58. </el-select>
  59. </el-form-item>
  60. </el-col>
  61. <el-col :span="6">
  62. <el-form-item label="预算单价" prop="budget_price">
  63. <digital-input
  64. :values="ruleForm.budget_price"
  65. :placeholder="'预算单价'"
  66. :min="0"
  67. :max="100000000000"
  68. :position="'right'"
  69. :precision="2"
  70. :size="'mini'"
  71. :disabled="ruleForm.p_budget_price"
  72. :controls="false"
  73. :append="'元'"
  74. @reschange="num_change($event, 'budget_price')"
  75. />
  76. </el-form-item>
  77. </el-col>
  78. <el-col :span="4">
  79. <el-form-item label="数量" prop="num" label-width="60px">
  80. <digital-input
  81. :values="ruleForm.num"
  82. :placeholder="'数量'"
  83. :min="0"
  84. :max="100000000000"
  85. :position="'right'"
  86. :precision="0"
  87. :size="'mini'"
  88. :disabled="ruleForm.p_num"
  89. :controls="false"
  90. :append="''"
  91. @reschange="num_change($event, 'num')"
  92. />
  93. </el-form-item>
  94. </el-col>
  95. <el-col :span="8">
  96. <el-form-item label="品牌" prop="brand_id">
  97. <search-brand
  98. :value="ruleForm.brand_id"
  99. :size="'mini'"
  100. :isDetail="listindex !== '-1'"
  101. :names="ruleForm.brand_name"
  102. :placeholder="'品牌'"
  103. @searchChange="brand_id_searchChange"
  104. />
  105. </el-form-item>
  106. </el-col>
  107. <el-col :span="6">
  108. <el-form-item label="是否定制" prop="is_custom">
  109. <el-select
  110. v-model="ruleForm.is_custom"
  111. placeholder="是否定制"
  112. style="width: 100%"
  113. >
  114. <el-option
  115. v-for="item in is_custom_options"
  116. :key="item.value"
  117. :label="item.label"
  118. :value="item.value"
  119. >
  120. </el-option>
  121. </el-select>
  122. </el-form-item>
  123. </el-col>
  124. <el-col :span="6">
  125. <el-form-item label="重量" prop="total_weight">
  126. <digital-input
  127. :values="ruleForm.total_weight"
  128. :placeholder="'重量'"
  129. :min="0"
  130. :max="100000000000"
  131. :position="'right'"
  132. :precision="3"
  133. :controls="false"
  134. :size="'mini'"
  135. :append="'g'"
  136. @reschange="num_change($event, 'total_weight')"
  137. />
  138. </el-form-item>
  139. </el-col>
  140. <el-col :span="4">
  141. <el-form-item label="单位" prop="unit" label-width="60px">
  142. <search-unit
  143. :value="ruleForm.unit"
  144. :size="'mini'"
  145. :isDetail="listindex !== '-1'"
  146. :names="ruleForm.unit_name"
  147. :placeholder="'单位'"
  148. @searchChange="unitsearchChange"
  149. />
  150. </el-form-item>
  151. </el-col>
  152. <el-col :span="12">
  153. <el-form-item label="商品分类" prop="cat_id">
  154. <search-sort
  155. :value="ruleForm.cat_id"
  156. :placeholder="'商品分类'"
  157. :disabled="false"
  158. :size="'mini'"
  159. :names="ruleForm.cat_id_name"
  160. :isDetail="listindex !== '-1'"
  161. @searchChange="goods_class_change"
  162. />
  163. </el-form-item>
  164. </el-col>
  165. <el-col :span="12">
  166. <el-form-item label="商品名称" prop="good_name">
  167. <el-input
  168. v-model="ruleForm.good_name"
  169. :disabled="false"
  170. placeholder="商品名称"
  171. maxlength="100"
  172. />
  173. </el-form-item>
  174. </el-col>
  175. <el-col :span="12">
  176. <el-form-item label="工艺说明" prop="cost_desc">
  177. <el-input
  178. v-model="ruleForm.cost_desc"
  179. placeholder="工艺说明"
  180. maxlength="500"
  181. />
  182. </el-form-item>
  183. <el-form-item label="产品用途" prop="use_desc">
  184. <el-input
  185. v-model="ruleForm.use_desc"
  186. placeholder="产品用途"
  187. maxlength="500"
  188. />
  189. </el-form-item>
  190. <el-form-item label="商品备注" prop="remark">
  191. <el-input
  192. v-model="ruleForm.remark"
  193. placeholder="商品备注"
  194. maxlength="500"
  195. />
  196. </el-form-item>
  197. </el-col>
  198. <el-col :span="12" style="padding: 0 0 0 15px">
  199. <el-table
  200. :data="spec_tableData"
  201. :size="'mini'"
  202. border
  203. style="width: 100%"
  204. height="120px"
  205. >
  206. <el-table-column prop="spec_name" label="规格类型" />
  207. <el-table-column prop="spec_value_name" label="规格值" />
  208. <el-table-column fixed="right" width="88px">
  209. <template slot="header" slot-scope="scope">
  210. <span>操作</span>
  211. <el-tooltip
  212. class="item"
  213. effect="dark"
  214. content="添加规格类型"
  215. placement="top"
  216. >
  217. <i
  218. class="el-icon-circle-plus-outline fr"
  219. style="font-size: 18px; margin-top: 2px"
  220. @click="openEdit('-1', {})"
  221. />
  222. </el-tooltip>
  223. </template>
  224. <template slot-scope="scope">
  225. <el-tooltip effect="dark" content="修改" placement="top">
  226. <i
  227. class="el-icon-edit tb-icon"
  228. @click="openEdit(scope.$index, scope.row)"
  229. ></i>
  230. </el-tooltip>
  231. <el-tooltip effect="dark" content="删除" placement="top">
  232. <i
  233. class="el-icon-delete tb-icon"
  234. @click="openDelete(scope.$index)"
  235. ></i>
  236. </el-tooltip>
  237. </template>
  238. </el-table-column>
  239. </el-table>
  240. <!-- 弹窗 新增/修改 -->
  241. <base-form-add-edit
  242. :index="modelIndex"
  243. :show-model="showOtherModel"
  244. :sitem="modelSitem"
  245. @refresh="refreshEdit"
  246. @cancel="showOtherModel = false"
  247. />
  248. </el-col>
  249. <el-col :span="24">
  250. <el-row>
  251. <el-col :span="12" v-if="is_noble">
  252. <el-form-item label="配置要求" prop="config">
  253. <el-select
  254. v-model="ruleForm.config"
  255. multiple
  256. style="width: 100%"
  257. placeholder="配置要求"
  258. >
  259. <el-option
  260. v-for="(item, index) in config_options"
  261. :key="item + index"
  262. :label="item"
  263. :value="item"
  264. >
  265. </el-option>
  266. </el-select>
  267. </el-form-item>
  268. </el-col>
  269. <el-col :span="6" v-if="is_noble">
  270. <el-form-item label="金属克重" prop="specs_weight">
  271. <digital-input
  272. :values="ruleForm.specs_weight"
  273. :placeholder="'金属克重'"
  274. :min="0"
  275. :max="100000000000"
  276. :position="'right'"
  277. :precision="3"
  278. :controls="false"
  279. :size="'mini'"
  280. :append="'g'"
  281. @reschange="num_change($event, 'specs_weight')"
  282. />
  283. </el-form-item>
  284. </el-col>
  285. <el-col :span="6" v-if="is_noble">
  286. <el-form-item label="启用金价" prop="is_gold_price">
  287. <el-select
  288. v-model="ruleForm.is_gold_price"
  289. placeholder="启用金价"
  290. style="width: 100%"
  291. >
  292. <el-option
  293. v-for="item in is_gold_price_options"
  294. :key="item.value"
  295. :label="item.label"
  296. :value="item.value"
  297. >
  298. </el-option>
  299. </el-select>
  300. </el-form-item>
  301. </el-col>
  302. </el-row>
  303. </el-col>
  304. <el-col :span="24" style="text-align: right">
  305. <el-row>
  306. <el-col :span="8" class="clear">
  307. <el-form-item
  308. label="商品图片"
  309. prop="good_img"
  310. class="activity-upload"
  311. >
  312. <div class="btnupload" style="position: relative">
  313. <img
  314. v-if="ruleForm.good_img"
  315. :src="ruleForm.good_img"
  316. class="avatar"
  317. />
  318. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  319. <file-upload
  320. class="Upload"
  321. :disabled="false"
  322. :accept="'.jpg,.png,.jpeg'"
  323. :multiple="true"
  324. :uploadcondition="beforeAvatarUpload"
  325. @UploadErrorEvent="UploadErrorEvent"
  326. @UploadSuccessEvent="UploadSuccessEvent"
  327. ></file-upload>
  328. </div>
  329. <div class="txt-tips fl">
  330. <p>小于1Mb</p>
  331. </div>
  332. </el-form-item>
  333. </el-col>
  334. <el-col :span="8" class="clear">
  335. <el-form-item
  336. label="附件"
  337. prop="enclosure_file"
  338. class="activity-upload"
  339. >
  340. <div
  341. v-if="ruleForm && ruleForm.enclosure_file"
  342. class="clearfix tl"
  343. >
  344. <a
  345. :href="ruleForm.enclosure_file"
  346. download="附件"
  347. class="fl"
  348. >点击下载</a
  349. >
  350. <el-link
  351. :underline="false"
  352. @click="deleteUrl()"
  353. type="warning"
  354. style="margin: 0 0 0 16px"
  355. class="fr"
  356. >删除</el-link
  357. >
  358. </div>
  359. <div class="activity-upload" v-else>
  360. <div class="btnupload" style="position: relative">
  361. <i class="el-icon-plus avatar-uploader-icon"></i>
  362. <file-upload-pdf
  363. class="Upload"
  364. :accept="'.zip,.rar,.7z,.doc,.docx,.xlsx,.xls,.pdf'"
  365. :multiple="false"
  366. :uploadcondition="beforeOtherUpload"
  367. @UploadErrorEvent="UploadErrorOtherenclosure_file"
  368. @UploadSuccessEvent="
  369. UploadSuccessOtherenclosure_file
  370. "
  371. />
  372. </div>
  373. <div class="txt-tips fl">
  374. <p>建议大小:小于5MB</p>
  375. <p>文件格式:.zip,.rar,.7z</p>
  376. <p>.doc,.docx,.xlsx,.xls,.pdf</p>
  377. </div>
  378. </div>
  379. </el-form-item>
  380. </el-col>
  381. <el-col :span="8" v-if="is_noble">
  382. <el-form-item label="金属种类" prop="metal_id">
  383. <search-metal-kind
  384. :value="ruleForm.metal_id"
  385. :size="'mini'"
  386. :isDetail="listindex !== '-1'"
  387. :placeholder="'贵金属种类'"
  388. @searchChange="noble_metalsearchChange"
  389. />
  390. </el-form-item>
  391. <el-form-item
  392. v-if="ruleForm.is_gold_price === '1'"
  393. label="当前金价"
  394. prop="gold_price"
  395. style="margin: 0 0 0 0"
  396. >
  397. <el-input
  398. v-model="ruleForm.gold_price"
  399. disabled
  400. placeholder="当前金价"
  401. maxlength="500"
  402. >
  403. <template slot="append">元</template></el-input
  404. >
  405. </el-form-item>
  406. </el-col>
  407. <el-col :span="16" v-if="is_noble">
  408. <el-form-item
  409. label="其他配置要求"
  410. prop="other_config"
  411. label-width="120px"
  412. >
  413. <el-input
  414. v-model="ruleForm.other_config"
  415. type="textarea"
  416. :rows="2"
  417. placeholder="其他配置要求"
  418. maxlength="250"
  419. show-word-limit
  420. />
  421. </el-form-item>
  422. </el-col>
  423. <el-col :span="8" class="fr" style="padding: 18px 0 0 0">
  424. <el-button
  425. v-if="id !== '007'"
  426. type="primary"
  427. :size="'mini'"
  428. @click="submitForm"
  429. >保 存
  430. </el-button>
  431. <el-button :size="'mini'" @click="showModelThis = false">{{
  432. id == "007" ? "关 闭" : "取 消"
  433. }}</el-button></el-col
  434. >
  435. </el-row>
  436. </el-col>
  437. </el-row>
  438. </el-form>
  439. </el-col>
  440. </el-row>
  441. </el-card>
  442. </el-dialog>
  443. </template>
  444. <script>
  445. import asyncRequest from "@/apis/service/sellOut/zixunOrder";
  446. import resToken from "@/mixins/resToken";
  447. import { rules } from "../columns";
  448. import baseFormAddEdit from "./baseFormAddEdit";
  449. export default {
  450. name: "brand",
  451. props: ["showModel", "id", "sitem"],
  452. mixins: [resToken],
  453. components: {
  454. baseFormAddEdit,
  455. },
  456. data() {
  457. return {
  458. modelIndex: "",
  459. modelSitem: {},
  460. showOtherModel: false,
  461. spec_tableData: [],
  462. loading: false,
  463. is_noble: false,
  464. is_addrs_options: [
  465. { value: "0", label: "一地" },
  466. { value: "1", label: "多地" },
  467. ],
  468. is_custom_options: [
  469. { value: "0", label: "非定制" },
  470. { value: "1", label: "定制" },
  471. ],
  472. is_gold_price_options: [
  473. { value: "0", label: "不启用" },
  474. { value: "1", label: "启用" },
  475. ],
  476. config_options: ["证书", "包装盒", "绒布袋", "标签", "其他"],
  477. title: "添加咨询商品",
  478. showModelThis: this.showModel,
  479. pickerOptions: {
  480. disabledDate(time) {
  481. return time.getTime() <= Date.now();
  482. },
  483. },
  484. ruleForm: {
  485. p_cat_info: [],
  486. p_cat_id: "",
  487. p_budget_price: "",
  488. p_pgNo: "",
  489. p_num: "",
  490. p_good_type: "",
  491. p_good_name: "",
  492. p_good_img: "",
  493. pgNo: "",
  494. arrival_time: "",
  495. budget_price: "0.00",
  496. num: "0",
  497. brand_id: [],
  498. cat_id: [],
  499. unit: [],
  500. good_img: "",
  501. good_name: "",
  502. total_weight: "0.000",
  503. is_addrs: "",
  504. is_custom: "",
  505. is_gold_price: "",
  506. config: [],
  507. specs_weight: "0.000",
  508. other_config: "",
  509. cost_desc: "",
  510. use_desc: "",
  511. remark: "",
  512. metal_id: "",
  513. gold_price: "0",
  514. enclosure_file: "",
  515. },
  516. rulesThis: this.rules,
  517. rules: rules,
  518. listindex: "-1",
  519. };
  520. },
  521. watch: {
  522. showModel: function (val) {
  523. this.showModelThis = val;
  524. if (val) {
  525. this.initForm();
  526. }
  527. },
  528. showModelThis(val) {
  529. if (!val) {
  530. this.$emit("cancel");
  531. }
  532. },
  533. },
  534. methods: {
  535. async initForm() {
  536. this.loading = true;
  537. const { index } = this.sitem;
  538. this.listindex = index + "";
  539. if (this.listindex === "-1") {
  540. this.title = "添加咨询商品";
  541. } else {
  542. this.title = "修改咨询商品";
  543. }
  544. this.rulesThis = this.rules;
  545. await this.resetForm();
  546. this.loading = false;
  547. },
  548. openEdit(index, sitem) {
  549. this.modelIndex = index;
  550. this.modelSitem = sitem;
  551. this.showOtherModel = true;
  552. },
  553. openDelete(index) {
  554. this.spec_tableData.splice(index, 1);
  555. },
  556. //规格编辑修改结果
  557. refreshEdit(e) {
  558. let item = JSON.parse(JSON.stringify(e));
  559. const { index, id, specid, spec_name, spec_value_id, spec_value_name } =
  560. item;
  561. if (index + "" === "-1") {
  562. this.spec_tableData.push(item);
  563. } else {
  564. this.spec_tableData.forEach((i, findex) => {
  565. if (i.spec_id === spec_id) {
  566. this.spec_tableData[findex].id = id;
  567. this.spec_tableData[findex].specid = specid;
  568. this.spec_tableData[findex].spec_name = spec_name;
  569. this.spec_tableData[findex].spec_value_id = spec_value_id;
  570. this.spec_tableData[findex].spec_value_name = spec_value_name;
  571. }
  572. });
  573. }
  574. this.showOtherModel = false;
  575. },
  576. async resetForm() {
  577. this.spec_tableData = [];
  578. // 重置
  579. await this.$nextTick(() => {
  580. if (this.$refs.ruleForm) {
  581. this.$refs.ruleForm.resetFields();
  582. this.$refs.ruleForm.clearValidate();
  583. const { index } = this.sitem;
  584. let fi = index ? index + "" : "";
  585. const {
  586. pgNo,
  587. arrival_time,
  588. budget_price,
  589. num,
  590. brand_id,
  591. cat_id,
  592. good_img,
  593. good_name,
  594. total_weight,
  595. is_addrs,
  596. is_custom,
  597. is_gold_price,
  598. config,
  599. specs_weight,
  600. other_config,
  601. cost_desc,
  602. use_desc,
  603. remark,
  604. metal_id,
  605. gold_price,
  606. unit,
  607. unit_name,
  608. p_cat_info,
  609. p_cat_id,
  610. p_budget_price,
  611. p_pgNo,
  612. p_num,
  613. p_good_type,
  614. p_good_name,
  615. p_good_img,
  616. p_arrtime,
  617. brand_name,
  618. specinfo,
  619. cat_id_name,
  620. cat_arr_id,
  621. enclosure_file,
  622. } = this.sitem;
  623. console.log(this.sitem);
  624. // console.log(p_cat_info);
  625. let asd = [];
  626. if (p_cat_info && p_cat_info.length > 0) {
  627. p_cat_info.forEach((sd) => {
  628. asd.push(sd.id);
  629. });
  630. }
  631. if (specinfo && specinfo.length > 0) {
  632. this.spec_tableData = JSON.parse(JSON.stringify(specinfo));
  633. } else {
  634. this.spec_tableData = [];
  635. }
  636. this.ruleForm = {
  637. p_cat_info: p_cat_info,
  638. p_cat_id: p_cat_id,
  639. p_cat_arr_id: asd,
  640. p_budget_price: p_budget_price,
  641. p_pgNo: p_pgNo,
  642. p_num: p_num,
  643. p_good_type: p_good_type,
  644. p_good_name: p_good_name,
  645. p_good_img: p_good_img,
  646. p_arrtime: p_arrtime,
  647. pgNo: fi === "-1" && p_pgNo ? p_pgNo : pgNo || "",
  648. arrival_time:
  649. fi === "-1" && p_pgNo ? p_arrtime : arrival_time || "",
  650. budget_price:
  651. fi === "-1" && p_pgNo ? p_budget_price : budget_price || "0.00",
  652. num: fi === "-1" && p_pgNo ? p_num : num || "0",
  653. brand_id: brand_id ? brand_id : [],
  654. brand_name: brand_name ? brand_name : "",
  655. cat_id: cat_id ? cat_id : [],
  656. cat_arr_id: cat_arr_id ? cat_arr_id : [],
  657. cat_id_name: cat_id_name ? cat_id_name : "",
  658. good_img: fi === "-1" && p_pgNo ? p_good_img : good_img || "",
  659. good_name: fi === "-1" && p_pgNo ? p_good_name : good_name || "",
  660. total_weight: total_weight || "0",
  661. is_addrs: is_addrs || "0",
  662. is_custom: is_custom || "0",
  663. is_gold_price: is_gold_price || "0",
  664. config: config ? config : [],
  665. specs_weight: specs_weight || "0.000",
  666. other_config: other_config || "",
  667. cost_desc: cost_desc || "",
  668. use_desc: use_desc || "",
  669. remark: remark || "",
  670. metal_id: metal_id || "",
  671. gold_price: gold_price || "0",
  672. unit: unit ? unit : [],
  673. unit_name: unit_name ? unit_name : "",
  674. enclosure_file: enclosure_file || "",
  675. };
  676. this.is_noble = false;
  677. if (cat_arr_id && cat_arr_id.length > 0) {
  678. cat_arr_id.forEach((e) => {
  679. if (e === "6") {
  680. this.is_noble = true;
  681. }
  682. });
  683. }
  684. }
  685. });
  686. },
  687. //商品分类选择
  688. async goods_class_change(e) {
  689. const { code, pid, id, label, item } = e;
  690. this.ruleForm.cat_id = id ? [id] : [];
  691. this.ruleForm.cat_id_name = label ? label : "";
  692. this.ruleForm.cat_arr_id = item;
  693. this.$refs.ruleForm.validateField("cat_id");
  694. this.is_noble = pid === "6";
  695. },
  696. //单位选择
  697. unitsearchChange(e) {
  698. const { code, label } = e;
  699. this.ruleForm.unit = code ? [code] : [];
  700. this.ruleForm.unit_name = label ? label : "";
  701. this.$refs.ruleForm.validateField("unit");
  702. },
  703. //购买数量
  704. num_change(e, key) {
  705. this.ruleForm[key] = e + "";
  706. this.$refs.ruleForm.validateField(key);
  707. },
  708. //品牌选择
  709. brand_id_searchChange(e) {
  710. const { id, label } = e;
  711. this.ruleForm.brand_id = id ? [id] : [];
  712. this.ruleForm.brand_name = label ? label : "";
  713. this.$refs.ruleForm.validateField("brand_id");
  714. },
  715. //贵金属种类选择
  716. async noble_metalsearchChange(e) {
  717. const { id, price } = e;
  718. this.ruleForm.metal_id = id ? id : "";
  719. this.$refs.ruleForm.validateField("metal_id");
  720. console.log("change_metal_id");
  721. await this.get_golpricelast();
  722. // this.ruleForm.gold_price = price ? price : "0";
  723. },
  724. async get_golpricelast() {
  725. const { metal_id } = this.ruleForm;
  726. if (metal_id) {
  727. let model = {
  728. type: metal_id,
  729. };
  730. const { code, data, message } = await asyncRequest.golpricelast(model);
  731. if (code === 0) {
  732. data.forEach((e) => {
  733. if (e.type) {
  734. this.ruleForm.gold_price = e.price;
  735. }
  736. });
  737. } else if (code >= 100 && code <= 104) {
  738. await this.logout();
  739. } else {
  740. this.$message.warning(message);
  741. }
  742. } else {
  743. this.ruleForm.gold_price = "0";
  744. }
  745. this.$refs.ruleForm.validateField("gold_price");
  746. },
  747. async submitForm() {
  748. await this.$refs.ruleForm.validate(async (valid) => {
  749. if (valid) {
  750. this.loading = true;
  751. if (this.spec_tableData.length === 0) {
  752. this.$message.warning("请选择商品规格!");
  753. this.loading = false;
  754. return;
  755. }
  756. let model = JSON.parse(JSON.stringify(this.ruleForm));
  757. console.log(model.cat_arr_id);
  758. const { cat_arr_id } = model;
  759. const { total_weight, specs_weight, p_cat_info } = model;
  760. if (p_cat_info && p_cat_info.length > 0) {
  761. let length = p_cat_info.length;
  762. let car_name = "";
  763. p_cat_info.forEach((e, ei) => {
  764. car_name += `${ei !== 0 ? "_" : ""}${e.name}`;
  765. });
  766. let isok = true;
  767. for (let i = 0; i < length; i++) {
  768. if (p_cat_info[i].id !== cat_arr_id[i]) {
  769. isok = false;
  770. }
  771. }
  772. if (!isok) {
  773. this.$message.warning(
  774. `商品分类不符合项目商品要求,商品要求中的分类为:${car_name}!`
  775. );
  776. this.loading = false;
  777. return;
  778. }
  779. }
  780. console.log(p_cat_info);
  781. if (total_weight * 1000 < specs_weight * 1000 && this.is_noble) {
  782. this.$message.warning("商品总重量不能小于贵金属重量!");
  783. this.loading = false;
  784. return;
  785. }
  786. model.index = this.listindex;
  787. model.specinfo = JSON.parse(JSON.stringify(this.spec_tableData));
  788. this.loading = false;
  789. this.showModelThis = false;
  790. // 刷新
  791. this.$emit("refresh", model);
  792. } else {
  793. console.log("error submit!!");
  794. return false;
  795. }
  796. });
  797. },
  798. //判断图片规格
  799. beforeAvatarUpload(file) {
  800. let isJPG = false,
  801. isLt2M = false;
  802. if (file) {
  803. if (
  804. file.type === "image/jpg" ||
  805. file.type === "image/png" ||
  806. file.type === "image/jpeg"
  807. ) {
  808. isJPG = true;
  809. }
  810. isLt2M = file.size / 1024 / 1024 < 1;
  811. if (!isJPG) {
  812. this.$message.error("图片格式不正确!");
  813. }
  814. if (!isLt2M) {
  815. this.$message.error("图片大小不能超过 1MB!");
  816. }
  817. }
  818. return isJPG && isLt2M;
  819. },
  820. //图片上传失败
  821. UploadErrorEvent(res) {
  822. if (res !== "break") {
  823. this.$message.error("图片上传失败!");
  824. this.ruleForm.good_img = "";
  825. this.$refs.ruleForm.validateField("good_img");
  826. }
  827. },
  828. //图片上传成功
  829. async UploadSuccessEvent(data) {
  830. const { url } = data;
  831. if (url === "noToken") {
  832. await this.logout();
  833. } else {
  834. this.ruleForm.good_img = url;
  835. this.$message.success("图片上传成功!");
  836. this.$refs.ruleForm.validateField("good_img");
  837. }
  838. },
  839. //其他文件上传失败
  840. UploadErrorOtherenclosure_file(res) {
  841. if (res !== "break") {
  842. this.$refs.ruleForm.validateField("enclosure_file");
  843. }
  844. },
  845. //判断其他文件规格
  846. beforeOtherUpload(file) {
  847. console.log(file.type);
  848. let isJPG = false;
  849. if (
  850. file.type === "application/msword" ||
  851. file.type ===
  852. "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ||
  853. file.type === "application/vnd.ms-excel" ||
  854. file.type ===
  855. "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ||
  856. file.type === "application/pdf" ||
  857. file.type === "application/x-zip-compressed"
  858. ) {
  859. isJPG = true;
  860. }
  861. let name = file.name;
  862. let list = name.split(".");
  863. if (list[list.length - 1] === "rar" || list[list.length - 1] === "7z") {
  864. isJPG = true;
  865. }
  866. const isLt2M = file.size / 1024 / 1024 < 5;
  867. if (!isJPG) {
  868. this.$message.error("文件格式不正确!");
  869. }
  870. if (!isLt2M) {
  871. this.$message.error("文件大小不能超过 5MB!");
  872. }
  873. return isJPG && isLt2M;
  874. },
  875. deleteUrl() {
  876. this.ruleForm.enclosure_file = "";
  877. this.$refs.ruleForm.validateField("enclosure_file");
  878. },
  879. // 其他文件上传成功
  880. async UploadSuccessOtherenclosure_file(data) {
  881. const { url } = data;
  882. console.log(url);
  883. if (url === "noToken") {
  884. await this.logout();
  885. } else {
  886. this.ruleForm.enclosure_file = url;
  887. this.$message.success("附件上传成功!");
  888. }
  889. },
  890. },
  891. };
  892. </script>
  893. <style lang="scss" scoped>
  894. .brand {
  895. }
  896. </style>