goStock-audit.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <el-form
  3. :model="ruleForm"
  4. :rules="rules"
  5. ref="ruleForm"
  6. :size="'mini'"
  7. label-width="90px"
  8. >
  9. <el-row>
  10. <el-col :span="12"
  11. ><el-form-item label="物流公司" prop="post_name">
  12. <search-express
  13. :value="ruleForm.post_name"
  14. :placeholder="'请输入物流公司'"
  15. :names="''"
  16. :size="'mini'"
  17. :disabled="!(status == '2' && powers.some((item) => item == '021'))"
  18. :is-detail="
  19. !(status == '2' && powers.some((item) => item == '021'))
  20. "
  21. @searchChange="handleCompany"
  22. />
  23. </el-form-item>
  24. <el-form-item label="物流费用" prop="post_fee">
  25. <digital-input
  26. :values="ruleForm.post_fee"
  27. :placeholder="'物流费用'"
  28. :min="0"
  29. :disabled="!(status == '2' && powers.some((item) => item == '021'))"
  30. :max="100000000000"
  31. :position="'right'"
  32. :precision="2"
  33. :size="'mini'"
  34. :controls="false"
  35. :append="'元'"
  36. @reschange="number_change($event, 'post_fee')"
  37. />
  38. </el-form-item>
  39. </el-col>
  40. <el-col :span="12">
  41. <el-form-item label="物流单号" prop="post_code">
  42. <el-input
  43. placeholder="请输入物流单号"
  44. maxlength="100"
  45. :size="'mini'"
  46. :disabled="!(status == '2' && powers.some((item) => item == '021'))"
  47. v-model="ruleForm.post_code"
  48. clearable
  49. >
  50. </el-input>
  51. </el-form-item>
  52. <el-form-item>
  53. <el-button
  54. v-if="status == '2' && powers.some((item) => item == '021')"
  55. type="primary"
  56. class="fr"
  57. :size="'medium'"
  58. @click="submitForm"
  59. >保 存
  60. </el-button>
  61. </el-form-item>
  62. </el-col>
  63. </el-row>
  64. </el-form>
  65. </template>
  66. <script>
  67. import resToken from "@/mixins/resToken";
  68. import asyncRequest from "@/apis/service/stock/allot/detail";
  69. import { isAlphanumeric, isnumber2 } from "@/utils/validate";
  70. export default {
  71. name: "allotFlow",
  72. mixins: [resToken],
  73. props: ["id", "sitem"],
  74. computed: {
  75. powers() {
  76. let tran =
  77. this.$store.getters.btnList.find(
  78. (item) => item.menu_route == "allotDetail"
  79. ) || {};
  80. if (tran && tran.action && tran.action.length > 0) {
  81. return tran.action;
  82. } else {
  83. return [];
  84. }
  85. },
  86. },
  87. data() {
  88. const validateExpressSn = (rule, value, callback) => {
  89. if (value === "") {
  90. callback(new Error("物流单号不能为空!"));
  91. } else {
  92. if (!isAlphanumeric(value)) {
  93. callback(new Error("请输入正确的物流单号"));
  94. } else {
  95. callback();
  96. }
  97. }
  98. };
  99. const validate_post_fee = (rule, value, callback) => {
  100. const { required } = rule;
  101. if (required && value === "") {
  102. callback(new Error("不能为空!"));
  103. } else {
  104. callback();
  105. }
  106. };
  107. return {
  108. status: "",
  109. ruleForm: {
  110. post_name: [], //发货物流公司
  111. post_code: "", //物流单号
  112. post_fee: "",
  113. },
  114. rules: {
  115. post_name: [
  116. {
  117. type: "array",
  118. required: true,
  119. message: "请选择发货公司",
  120. trigger: "change",
  121. },
  122. ],
  123. post_fee: [
  124. {
  125. required: true,
  126. validator: validate_post_fee,
  127. trigger: "blur",
  128. },
  129. ],
  130. post_code: [
  131. {
  132. required: true,
  133. trigger: "blur",
  134. validator: validateExpressSn,
  135. },
  136. ],
  137. },
  138. };
  139. },
  140. mounted() {
  141. this.resetForm();
  142. },
  143. methods: {
  144. async resetForm() {
  145. // 重置
  146. await this.$nextTick(() => {
  147. if (this.$refs.ruleForm) {
  148. this.$refs.ruleForm.resetFields();
  149. this.$refs.ruleForm.clearValidate();
  150. const { post_code, post_fee, post_name, status } = this.sitem;
  151. this.status = status;
  152. this.ruleForm = {
  153. post_code,
  154. post_fee: post_fee + "",
  155. post_name: post_name ? [post_name] : [],
  156. };
  157. }
  158. });
  159. },
  160. async number_change(e, key) {
  161. this.ruleForm[key] = e + "" || "0";
  162. this.$refs.ruleForm.validateField(key);
  163. },
  164. // 商品保存提交
  165. async submitForm() {
  166. await this.$refs.ruleForm.validate(async (valid) => {
  167. if (valid) {
  168. this.loading = true;
  169. const model = JSON.parse(JSON.stringify(this.ruleForm));
  170. model.allot_code = this.sitem.allot_code;
  171. model.post_name = model.post_name.toString();
  172. let res = await asyncRequest.allotgetont(model);
  173. this.loading = false;
  174. if (res && res.code === 0) {
  175. //
  176. this.showModelThis = false;
  177. // 刷新
  178. this.$emit("refresh");
  179. } else if (res && res.code >= 100 && res.code <= 104) {
  180. await this.logout();
  181. } else {
  182. this.$message.warning(res.message);
  183. }
  184. } else {
  185. console.log("error submit!!");
  186. return false;
  187. }
  188. });
  189. },
  190. handleCompany(e) {
  191. console.log(e);
  192. this.ruleForm.post_name = e && e.code ? [e.label] : [];
  193. this.$refs.ruleForm.validateField("post_name");
  194. },
  195. },
  196. };
  197. </script>