SendGoods.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template>
  2. <div>
  3. <el-dialog
  4. title="订单发货"
  5. :visible.sync="sendShow"
  6. width="1000px"
  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="订单号:">
  16. <span>{{ goodsInfo.orderId }}</span>
  17. </el-form-item>
  18. <el-form-item label="收货地址:">
  19. <span>{{
  20. `${goodsInfo.receiver},${goodsInfo.tel},${goodsInfo.province}${goodsInfo.city}${goodsInfo.area}${goodsInfo.address}`
  21. }}</span>
  22. </el-form-item>
  23. <el-form-item label="配送方式:">
  24. <!--单选框-->
  25. <el-radio @change="radioDistribution" v-model="shipForm.deliveryType" label="1">快递发货</el-radio>
  26. <el-radio @change="radioDistribution" v-model="shipForm.deliveryType" label="2">无需物流</el-radio>
  27. </el-form-item>
  28. <el-form-item v-if="shipForm.deliveryType == 1" label="快递单号:" prop="deliveryFlowId">
  29. <el-input
  30. @blur="InputBlur()"
  31. v-model="shipForm.deliveryFlowId"
  32. placeholder="输入快递单号"
  33. clearable
  34. size="small"
  35. style="width: 300px"
  36. />
  37. </el-form-item>
  38. <el-form-item v-if="shipForm.deliveryType == 1" label="快递公司:" prop="deliveryId">
  39. <el-select
  40. v-model="shipForm.deliveryId"
  41. placeholder="请选择快递公司"
  42. clearable
  43. size="small"
  44. style="width: 300px"
  45. >
  46. <el-option
  47. v-for="item in companyData"
  48. :key="item.areaId"
  49. :label="item.companyName"
  50. :value="item.deliveryId"
  51. />
  52. </el-select>
  53. </el-form-item>
  54. </el-form>
  55. <!-- 商品 -->
  56. <el-table
  57. ref="table"
  58. :data="goodsInfo.items"
  59. @selection-change="handleSelectionGoods"
  60. class="ticket-table"
  61. >
  62. <el-table-column
  63. type="selection"
  64. width="55"
  65. align="center"
  66. fixed="left"
  67. />
  68. <el-table-column label="商品名称" prop="title" />
  69. <el-table-column label="规格">
  70. <template slot-scope="{ row }">
  71. <div>{{ row.properties || "--" }}</div>
  72. </template>
  73. </el-table-column>
  74. <el-table-column label="数量">
  75. <template slot-scope="{ row }">
  76. <div>{{ row.goodsNum }}件</div>
  77. </template>
  78. </el-table-column>
  79. <el-table-column label="快递公司">
  80. <template slot-scope="{ row }">
  81. <div>{{ row.companyName || "--" }}</div>
  82. </template>
  83. </el-table-column>
  84. <el-table-column label="快递单号">
  85. <template slot-scope="{ row }">
  86. <div>{{ row.deliveryFlowId || "--" }}</div>
  87. </template>
  88. </el-table-column>
  89. <el-table-column label="发货状态">
  90. <template slot-scope="{ row }">
  91. <div>{{ row.deliveryTime ? "已发货" : "未发货" }}</div>
  92. </template>
  93. </el-table-column>
  94. </el-table>
  95. <div slot="footer" class="dialog-footer">
  96. <el-button @click="close">取 消</el-button>
  97. <el-button type="primary" :disabled="loading" @click="saveClick"
  98. >确 定</el-button
  99. >
  100. </div>
  101. </el-dialog>
  102. </div>
  103. </template>
  104. <script>
  105. import CustomFieldsMixin from "@/mixins/CustomFields";
  106. import { companyList, storeOrderShip, automaticRecognition} from "@/api/business/order";
  107. export default {
  108. mixins: [CustomFieldsMixin],
  109. props: {
  110. // 弹框显示
  111. sendShow: {
  112. type: Boolean,
  113. default: false,
  114. },
  115. // 订单详情
  116. goodsInfo: {
  117. type: Object,
  118. default: {},
  119. },
  120. },
  121. created() {
  122. this.getCompanyList();
  123. },
  124. data() {
  125. return {
  126. loading: false,
  127. shipForm: {
  128. deliveryId: "",
  129. deliveryFlowId: "",
  130. deliveryType: "1",
  131. },
  132. // 快递下拉列表
  133. companyData: [],
  134. // 选中sp
  135. goodsList: [],
  136. // 选中商品ID
  137. ids: [],
  138. rules: {
  139. deliveryId: [
  140. { required: true, message: "请选择快递公司", trigger: "change" },
  141. ],
  142. deliveryFlowId: [
  143. { required: true, message: "请输入快递单号", trigger: "blur" },
  144. ],
  145. },
  146. };
  147. },
  148. methods: {
  149. // 关闭发货弹框
  150. close() {
  151. this.shipForm.deliveryType = "1";
  152. this.$emit("close");
  153. this.loading = false;
  154. this.ids = [];
  155. this.$refs["shipForm"].resetFields();
  156. },
  157. //切换配送方式时清空另一个方式所选项
  158. radioDistribution(){
  159. if(this.shipForm.deliveryType == '2'){
  160. this.shipForm.deliveryId = '';
  161. this.shipForm.deliveryFlowId = '';
  162. }
  163. },
  164. // 快递下拉列表
  165. getCompanyList() {
  166. companyList({}).then((res) => {
  167. this.companyData = res.data;
  168. });
  169. },
  170. //快递单号失去焦点时
  171. InputBlur(){
  172. if (this.shipForm.deliveryFlowId){
  173. automaticRecognition(this.shipForm.deliveryFlowId).then((res)=>{
  174. if (res.code == 0 && res.data){
  175. this.shipForm.deliveryId = res.data.deliveryId
  176. }
  177. })
  178. }
  179. },
  180. // 选中商品
  181. handleSelectionGoods(e) {
  182. this.goodsList = e
  183. },
  184. // 确认
  185. saveClick() {
  186. this.loading = true;
  187. const subForm = this.$refs["shipForm"];
  188. subForm.validate((valid) => {
  189. if (valid) {
  190. this.submitForm(this.shipForm);
  191. } else {
  192. this.loading = false;
  193. // 提示第一个error
  194. this.getFormErrorMessage(subForm);
  195. return false;
  196. }
  197. });
  198. },
  199. // 提交
  200. submitForm(form) {
  201. if (!this.goodsList.length) {
  202. this.msgError("请选择发货的商品");
  203. this.loading = false;
  204. return;
  205. }
  206. let index = this.goodsList.findIndex(item=>{
  207. return item.deliveryTime
  208. })
  209. if(index != -1){
  210. this.msgError(`${ this.goodsList[index].title }已发货!`);
  211. this.loading = false;
  212. return
  213. }
  214. this.ids = this.goodsList.map((item) => item.itemId);
  215. let data = {
  216. ...form,
  217. orderId: this.goodsInfo.orderId,
  218. itemIds: this.ids,
  219. };
  220. storeOrderShip(data)
  221. .then((res) => {
  222. if (res.code == 0) {
  223. this.msgSuccess("发货成功");
  224. this.close();
  225. }
  226. })
  227. .catch(() => {
  228. this.loading = false;
  229. });
  230. },
  231. },
  232. };
  233. </script>
  234. <style>
  235. </style>