ExpressEdit.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <div>
  3. <el-dialog
  4. title="修改快递信息"
  5. :visible.sync="editShow"
  6. width="500px"
  7. :before-close="close"
  8. >
  9. <el-form
  10. :model="shipForm"
  11. ref="shipForm"
  12. :rules="rules"
  13. label-width="100px"
  14. >
  15. <el-form-item label="配送方式:" prop="deliveryId">
  16. <el-radio @change="radioDistribution" v-model="shipForm.deliveryType" label="1">快递发货</el-radio>
  17. <el-radio @change="radioDistribution" v-model="shipForm.deliveryType" label="2">无需物流</el-radio>
  18. </el-form-item>
  19. <el-form-item v-if="shipForm.deliveryType == 1" label="快递单号:" prop="deliveryFlowId">
  20. <el-input
  21. v-model="shipForm.deliveryFlowId"
  22. @blur="InputBlur()"
  23. placeholder="输入快递单号"
  24. clearable
  25. size="small"
  26. style="width: 300px"
  27. />
  28. </el-form-item>
  29. <el-form-item v-if="shipForm.deliveryType == 1" label="快递公司:" prop="deliveryId">
  30. <el-select
  31. v-model="shipForm.deliveryId"
  32. placeholder="请选择快递公司"
  33. clearable
  34. size="small"
  35. style="width: 300px"
  36. >
  37. <el-option
  38. v-for="item in companyData"
  39. :key="item.areaId"
  40. :label="item.companyName"
  41. :value="item.deliveryId"
  42. />
  43. </el-select>
  44. </el-form-item>
  45. </el-form>
  46. <!-- 按钮 -->
  47. <div slot="footer" class="dialog-footer">
  48. <el-button @click="close">取 消</el-button>
  49. <el-button type="primary" :disabled="loading" @click="saveClick"
  50. >确 定</el-button
  51. >
  52. </div>
  53. </el-dialog>
  54. </div>
  55. </template>
  56. <script>
  57. import CustomFieldsMixin from "@/mixins/CustomFields";
  58. import { companyList, deliverOrderShipUpdate, automaticRecognition} from "@/api/business/order";
  59. export default {
  60. mixins: [CustomFieldsMixin],
  61. props: {
  62. // 发货弹框显示
  63. editShow: {
  64. type: Boolean,
  65. default: false,
  66. },
  67. // 订单详情
  68. goodsInfo: {
  69. type: Object,
  70. default: {},
  71. },
  72. // 订单ID
  73. orderId: {
  74. type: String,
  75. default: ''
  76. }
  77. },
  78. data() {
  79. return {
  80. loading: false,
  81. shipForm: {
  82. deliveryId: "",
  83. deliveryFlowId: "",
  84. deliveryType: "1",//配送方式
  85. },
  86. // 快递下拉列表
  87. companyData: [],
  88. rules: {
  89. deliveryId: [
  90. { required: false, message: "请选择快递公司", trigger: "change" },
  91. ],
  92. deliveryFlowId: [
  93. { required: false, message: "请输入快递单号", trigger: "blur" },
  94. ],
  95. },
  96. };
  97. },
  98. created() {
  99. this.getCompanyList();
  100. this.getFormData()
  101. },
  102. methods: {
  103. getFormData(){
  104. this.shipForm.deliveryId = this.goodsInfo.deliveryId
  105. this.shipForm.deliveryFlowId = this.goodsInfo.deliveryFlowId
  106. this.shipForm.deliveryType = this.goodsInfo.deliveryFlowId?"1":"2"
  107. },
  108. // 关闭发货弹框
  109. close() {
  110. this.$emit("close");
  111. this.loading = false;
  112. this.$refs["shipForm"].resetFields();
  113. },
  114. //切换配送方式时清空另一个方式所选项
  115. radioDistribution(){
  116. if(this.shipForm.deliveryType == '2'){
  117. this.shipForm.deliveryId = '';
  118. this.shipForm.deliveryFlowId = '';
  119. }
  120. },
  121. // 快递下拉列表
  122. getCompanyList() {
  123. companyList({}).then((res) => {
  124. this.companyData = res.data;
  125. });
  126. },
  127. //快递单号失去焦点时
  128. InputBlur(){
  129. if (this.shipForm.deliveryFlowId){
  130. automaticRecognition(this.shipForm.deliveryFlowId).then((res)=>{
  131. if (res.code == 0 && res.data){
  132. this.shipForm.deliveryId = res.data.deliveryId
  133. }
  134. })
  135. }
  136. },
  137. // 确认
  138. saveClick() {
  139. this.loading = true;
  140. const subForm = this.$refs["shipForm"];
  141. subForm.validate((valid) => {
  142. if (valid) {
  143. this.submitForm(this.shipForm);
  144. } else {
  145. this.loading = false;
  146. // 提示第一个error
  147. this.getFormErrorMessage(subForm);
  148. return false;
  149. }
  150. });
  151. },
  152. // 提交
  153. submitForm(form) {
  154. let data = {
  155. ...form,
  156. orderId: this.orderId,
  157. itemIds: this.goodsInfo.items.map( item => item.itemId)
  158. };
  159. deliverOrderShipUpdate(data)
  160. .then((res) => {
  161. if (res.code == 0) {
  162. this.msgSuccess("修改成功");
  163. this.close();
  164. }
  165. })
  166. .catch(() => {
  167. this.loading = false;
  168. });
  169. },
  170. },
  171. };
  172. </script>
  173. <style scoped>
  174. </style>