addEditBargain.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <el-dialog
  3. v-loading="loading"
  4. :title="'申请议价'"
  5. :center="true"
  6. align="left"
  7. top="10vh"
  8. width="900px"
  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. >
  16. <el-card style="margin-top: -20px">
  17. <el-form
  18. ref="ruleForm"
  19. :model="ruleForm"
  20. status-icon
  21. :size="'mini'"
  22. :rules="rulesThis"
  23. label-width="102px"
  24. class="demo-ruleForm"
  25. >
  26. <el-row>
  27. <el-col :span="20">
  28. <el-form-item label="商品名称">
  29. <el-input
  30. v-if="show_sitem"
  31. v-model="show_sitem.good_name"
  32. maxlength="100"
  33. disabled
  34. />
  35. </el-form-item>
  36. </el-col>
  37. <!-- <el-col :span="4">
  38. <el-form-item label="图片" style="margin: 0" label-width="44px">
  39. <img
  40. class="hover"
  41. v-viewer
  42. :src="show_sitem.good_img"
  43. alt=""
  44. v-if="show_sitem && show_sitem.good_img"
  45. style="width: 35px; height: 35px"
  46. />
  47. </el-form-item>
  48. </el-col> -->
  49. <el-col :span="4">
  50. <el-form-item label="单位" label-width="50px">
  51. <el-input
  52. v-if="show_sitem"
  53. maxlength="10"
  54. v-model="show_sitem.unit"
  55. disabled
  56. />
  57. </el-form-item>
  58. </el-col>
  59. <el-col :span="8">
  60. <el-form-item label="议价前售价">
  61. <el-input
  62. v-if="show_sitem"
  63. v-model="show_sitem.origin_price"
  64. maxlength="20"
  65. disabled
  66. />
  67. </el-form-item>
  68. </el-col>
  69. <el-col :span="8">
  70. <el-form-item label="当前售价">
  71. <el-input
  72. v-if="show_sitem"
  73. v-model="show_sitem.sale_price"
  74. maxlength="20"
  75. disabled
  76. />
  77. </el-form-item>
  78. </el-col>
  79. <el-col :span="8">
  80. <el-form-item label="期望售价" prop="bargain_price">
  81. <digital-input
  82. :values="ruleForm.bargain_price"
  83. :name="'ruleForm.bargain_price'"
  84. :placeholder="'期望售价'"
  85. :min="0"
  86. :disabled="sitem.is_gold_price == 1 && sitem.can[0].id == 6"
  87. :max="
  88. show_sitem && show_sitem.origin_price ? show_sitem.origin_price : '0'
  89. "
  90. :position="'right'"
  91. :precision="2"
  92. :size="'mini'"
  93. :controls="false"
  94. :append="'元'"
  95. @reschange="number_change($event, 'bargain_price')"
  96. />
  97. </el-form-item>
  98. </el-col>
  99. <el-col :span="8">
  100. <el-form-item label="议价前工艺费">
  101. <el-input
  102. v-if="show_sitem"
  103. v-model="show_sitem.cost_fee"
  104. maxlength="20"
  105. disabled
  106. />
  107. </el-form-item>
  108. </el-col>
  109. <el-col :span="8">
  110. <el-form-item label="议价前工艺费">
  111. <el-input
  112. v-if="show_sitem"
  113. v-model="show_sitem.sale_cost_fee"
  114. maxlength="20"
  115. disabled
  116. />
  117. </el-form-item>
  118. </el-col>
  119. <el-col :span="8">
  120. <el-form-item label="期望工艺费" prop="cost_price">
  121. <digital-input
  122. :values="ruleForm.cost_price"
  123. :name="'ruleForm.cost_price'"
  124. :placeholder="'期望工艺费'"
  125. :min="0"
  126. :disabled="!(sitem.is_gold_price == 1 && sitem.can[0].id == 6)"
  127. :max="show_sitem && show_sitem.cost_fee ? show_sitem.cost_fee : '0'"
  128. :position="'right'"
  129. :precision="2"
  130. :size="'mini'"
  131. :controls="false"
  132. :append="'元'"
  133. @reschange="number_change($event, 'cost_price')"
  134. />
  135. </el-form-item>
  136. </el-col>
  137. <el-col :span="8">
  138. <el-form-item label="议价原因" prop="result_info_id">
  139. <abnormal-cause
  140. :value="ruleForm.result_info_id"
  141. :placeholder="'议价原因'"
  142. :type="'7'"
  143. :disabled="false"
  144. :size="'mini'"
  145. @searchChange="select_change"
  146. />
  147. </el-form-item>
  148. </el-col>
  149. <el-col :span="16">
  150. <el-form-item label="议价备注:" prop="bargain_remark" label-width="88px">
  151. <el-input
  152. type="textarea"
  153. :rows="2"
  154. maxlength="250"
  155. show-word-limit
  156. placeholder="议价备注"
  157. v-model="ruleForm.bargain_remark"
  158. >
  159. </el-input>
  160. </el-form-item>
  161. </el-col>
  162. <el-col :span="24" style="text-align: right">
  163. <el-button @click="showModelThis = false" :size="'mini'">{{
  164. isDetail ? "关 闭" : "取 消"
  165. }}</el-button>
  166. <el-button v-if="!isDetail" type="primary" :size="'mini'" @click="submitForm"
  167. >保 存
  168. </el-button>
  169. </el-col>
  170. </el-row>
  171. </el-form>
  172. </el-card>
  173. </el-dialog>
  174. </template>
  175. <script>
  176. import asyncRequest from "@/apis/service/sellOut/bargainList";
  177. import resToken from "@/mixins/resToken";
  178. import { add_sum } from "@/utils/validate";
  179. export default {
  180. name: "Account",
  181. props: ["showModel", "sitem"],
  182. mixins: [resToken],
  183. data() {
  184. return {
  185. roleList: [],
  186. loading: false,
  187. title: "添加账号",
  188. organizeList: [],
  189. showModelThis: this.showModel,
  190. ruleForm: {
  191. result_info_id: "",
  192. bargain_price: "0",
  193. result_info_id_name: "",
  194. bargain_remark: "",
  195. cost_price: "0",
  196. },
  197. show_sitem: null,
  198. rulesThis: this.rules,
  199. rules: {
  200. result_info_id: [
  201. {
  202. required: true,
  203. message: "请选择议价原因!",
  204. trigger: "change",
  205. },
  206. ],
  207. bargain_price: [
  208. {
  209. required: true,
  210. message: "期望售价不能为空!",
  211. trigger: "blur",
  212. },
  213. ],
  214. cost_price: [
  215. {
  216. required: true,
  217. message: "期望工艺费不能为空!",
  218. trigger: "blur",
  219. },
  220. ],
  221. bargain_remark: [
  222. {
  223. required: true,
  224. message: "议价备注不能为空!",
  225. trigger: "blur",
  226. },
  227. ],
  228. },
  229. };
  230. },
  231. watch: {
  232. showModel: function (val) {
  233. this.showModelThis = val;
  234. if (val) {
  235. this.initForm();
  236. }
  237. },
  238. showModelThis(val) {
  239. if (!val) {
  240. this.$emit("cancel");
  241. }
  242. },
  243. },
  244. methods: {
  245. async initForm() {
  246. this.loading = true;
  247. this.rulesThis = this.rules;
  248. await this.resetForm();
  249. this.loading = false;
  250. },
  251. number_change(e, key) {
  252. this.ruleForm[key] = e + "" || "0";
  253. this.$refs.ruleForm.validateField(key);
  254. },
  255. async resetForm() {
  256. // 重置
  257. await this.$nextTick(() => {
  258. this.show_sitem = JSON.parse(JSON.stringify(this.sitem));
  259. const { origin_price, specinfo, cost_fee, bidNo } = this.sitem;
  260. if (specinfo && specinfo.length > 0) {
  261. specinfo.forEach((a, ai) => {
  262. this.show_sitem.good_name += `${ai === 0 ? "_" : "-"}${a.spec_name}[${
  263. a.spec_value_name
  264. }]`;
  265. });
  266. }
  267. if (this.$refs.ruleForm) {
  268. this.$refs.ruleForm.resetFields();
  269. this.$refs.ruleForm.clearValidate();
  270. this.ruleForm = {
  271. bargain_price: origin_price || "0",
  272. bidNo: bidNo || "",
  273. bargain_remark: "",
  274. cost_price: cost_fee || "0",
  275. result_info_id: "",
  276. result_info_id_name: "",
  277. };
  278. }
  279. });
  280. },
  281. select_change(e) {
  282. const { code, label } = e;
  283. this.ruleForm.result_info_id = code || "";
  284. this.ruleForm.result_info_id_name = label || "";
  285. this.$refs.ruleForm.validateField("result_info_id");
  286. },
  287. async submitForm() {
  288. await this.$refs.ruleForm.validate(async (valid) => {
  289. if (valid) {
  290. if (this.loading) {
  291. return;
  292. }
  293. this.loading = true;
  294. const { bidNo, origin_price, is_gold_price, can, cost_fee } = this.sitem;
  295. const { bargain_price, cost_price } = this.ruleForm;
  296. let a = add_sum(origin_price + "", "0");
  297. let b = add_sum(bargain_price + "", "0");
  298. if (b > a) {
  299. this.$message.warning("期望售价不能高于当前售价");
  300. this.loading = false;
  301. return;
  302. }
  303. let c = add_sum(cost_fee + "", "0");
  304. let d = add_sum(cost_price + "", "0");
  305. if (d > c) {
  306. this.$message.warning("期望工艺费不能高于当前工艺费");
  307. this.loading = false;
  308. return;
  309. }
  310. let model = JSON.parse(JSON.stringify(this.ruleForm));
  311. console.log(model);
  312. delete model["result_info_id_name"];
  313. //根据实时金价对接口进行不同传参
  314. if (is_gold_price == "1" && can && can.length > 0 && can[0].id + "" == "6") {
  315. if (c === d) {
  316. this.$message.warning("期望工艺费不能等于当前工艺费!");
  317. this.loading = false;
  318. return;
  319. }
  320. model.bargain_price = "0";
  321. } else {
  322. if (a === b) {
  323. this.$message.warning("期望售价不能等于当前售价!");
  324. this.loading = false;
  325. return;
  326. }
  327. model.cost_price = "0";
  328. }
  329. let res = await asyncRequest.bargain_add(model);
  330. this.loading = false;
  331. if (res && res.code === 0) {
  332. this.$notify.success({
  333. title: "议价流程创建成功!",
  334. message: "",
  335. });
  336. this.showModelThis = false;
  337. // 刷新
  338. this.$emit("refresh");
  339. } else if (res && res.code >= 100 && res.code <= 104) {
  340. await this.logout();
  341. } else {
  342. this.$message.warning(res.message);
  343. }
  344. } else {
  345. console.log("error submit!!");
  346. return false;
  347. }
  348. });
  349. },
  350. },
  351. };
  352. </script>
  353. <style lang="scss" scoped>
  354. .account {
  355. }
  356. </style>