manualCreate.vue 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979
  1. <template>
  2. <div class="form-wrap" v-loading="isLoading" element-loading-text="正在计算中...">
  3. <el-form label-position="left" ref="form" :model="form" label-width="110px">
  4. <div class="moudle-list">
  5. <div class="moudle">
  6. <div class="title-list">
  7. <div v-if="memberType !== 1" @click="sendType = 1" :class=" sendType ? 'title' : 'normal-title'">
  8. 门店地址发单
  9. </div>
  10. <div @click="sendType = 0" :class=" !sendType ? 'title' : 'normal-title'">
  11. 个人地址发单
  12. </div>
  13. </div>
  14. <el-form-item :label="sendType ? '发件门店' : '发件人姓名'" required>
  15. <el-input v-show="!sendType" size="small" class="input" v-model="form.sendAddress.contact" placeholder="请填写发件人姓名" clearable></el-input>
  16. <el-input v-show="sendType" disabled size="small" class="input" v-model="name" placeholder="请填写发件门店"></el-input>
  17. <el-button v-show="sendType" @click="showShop(1)" class="but1 active" type="info">选择门店</el-button>
  18. <el-button v-show="!sendType" @click="showShop(2)" class="but1 active" type="info">常用地址</el-button>
  19. </el-form-item>
  20. <el-form-item label="发件人电话" required>
  21. <el-input size="small" class="phone-before" v-model="form.sendAddress.phone" placeholder="请填写发件人电话" clearable></el-input>
  22. <div class="phone-center">~</div>
  23. <el-input size="small" class="phone-after" v-model="form.sendAddress.extension" placeholder="分机号"></el-input>
  24. </el-form-item>
  25. <el-form-item label="发件人地址" required>
  26. <el-input size="small" v-model="form.sendAddress.address" placeholder="请选择发件人地址" disabled>
  27. <img @click="showMap(1)" slot="append" class="map" src="../../static/image/icon_map.png">
  28. </el-input>
  29. </el-form-item>
  30. <el-form-item label="楼号/门牌号">
  31. <el-input size="small" v-model="form.sendAddress.street" placeholder="请填写发件人楼号/门牌号" :disabled="!!sendType" clearable>
  32. </el-input>
  33. </el-form-item>
  34. </div>
  35. <div class="moudle">
  36. <div class="title">
  37. 收件地址
  38. </div>
  39. <el-form-item label="收件人姓名" required>
  40. <el-input size="small" v-model="form.receiptAddress.contact" placeholder="请填写收件人姓名" clearable>
  41. </el-input>
  42. <el-button @click="showShop(3)" class="but1 active" type="info">常用地址</el-button>
  43. </el-form-item>
  44. <el-form-item label="收件人电话" required>
  45. <el-input size="small" class="phone-before" v-model="form.receiptAddress.phone" placeholder="请填写收件人电话" clearable></el-input>
  46. <div class="phone-center">~</div>
  47. <el-input size="small" class="phone-after" v-model="form.receiptAddress.extension" placeholder="分机号"></el-input>
  48. </el-form-item>
  49. <el-form-item label="收件人地址" required>
  50. <el-input size="small" v-model="form.receiptAddress.address" placeholder="请选择收件人地址" disabled>
  51. <img @click="showMap(2)" slot="append" class="map" src="../../static/image/icon_map.png">
  52. </el-input>
  53. </el-form-item>
  54. <el-form-item label="楼号/门牌号">
  55. <el-input size="small" v-model="form.receiptAddress.street" placeholder="请填写收件人楼号/门牌号" clearable>
  56. </el-input>
  57. </el-form-item>
  58. </div>
  59. <div class="moudle">
  60. <div class="title">
  61. 物品信息
  62. </div>
  63. <el-form-item label="物品类型" required>
  64. <!-- <div class="category_box">
  65. <div class="item" :class="form.productId === item.id ? 'active':''" v-for="(item,i) in products" :key="i" @click="$set(form,'productId',item.id)">
  66. {{item.name}}
  67. </div>
  68. </div> -->
  69. <el-radio-group class="category_box" v-model="form.productId">
  70. <el-radio class="item" v-for="(item,i) in products" :key="i" :label="item.id">{{item.name}}</el-radio>
  71. </el-radio-group>
  72. </el-form-item>
  73. <el-form-item label="物品来源" required>
  74. <el-select size="small" class="item1" v-model="form.platformType" placeholder="请选择物品来源">
  75. <el-option v-for="(v,i) in goodsSource" :key="i" :label="v.name" :value="v.type"></el-option>
  76. </el-select>
  77. <!-- <el-input v-if="form.platformType" type="number" class="item2" v-model="form.daySeq" size="small" placeholder="请输入订单流水号"></el-input> -->
  78. <el-input v-if="form.platformType" type="text" class="item2" v-model="form.daySeq" @input="checkDaySeq()" size="small" :min="1" placeholder="请输入订单流水号"></el-input>
  79. <div class="tips" v-else>系统将自动为您分配订单流水号</div>
  80. </el-form-item>
  81. <el-form-item label="物品重量" required>
  82. <div class="printer-num">
  83. <img @click="reduce()" src="../../static/image/icon_reduce.png" class="reduce" alt="" srcset="" />
  84. <el-input ref="weight" size="small" class="num" v-model="form.weight" clearable>
  85. <template slot="append">KG</template>
  86. </el-input>
  87. <img @click="add()" src="../../static/image/icon_add.png" class="add" alt="" srcset="" />
  88. </div>
  89. <!-- <el-input-number size="small" v-model="form.weight" :min="1" :max="10" label="描述文字">
  90. </el-input-number> -->
  91. </el-form-item>
  92. <el-form-item label="物品价值" required>
  93. <el-input class="product-amount" ref="productAmount" size="small" v-model="form.productAmount" placeholder="请输入物品价值!" clearable>
  94. <template slot="append">元</template>
  95. </el-input>
  96. </el-form-item>
  97. <el-form-item label="发单时间">
  98. <el-button @click="form.takeType = 0" :class="!form.takeType ? 'but active' : 'but'" type="info">立即发单</el-button>
  99. <el-button @click="form.takeType = 1" :class="form.takeType ? 'but but-r active' : 'but'" type="info">预约发单</el-button>
  100. <el-date-picker @focus="focus" @change="chooseTime" size="small" v-show="form.takeType === 1" v-model="form.takeTime" type="datetime" placeholder="选择日期时间" format="yyyy-MM-dd HH:mm" :picker-options="pickerOptions">
  101. </el-date-picker>
  102. </el-form-item>
  103. <el-form-item label="发单备注">
  104. <el-input type="text" size="small" v-model="form.takeRemark" maxlength="80" placeholder="请添加备注信息,最多输入20个字!" clearable show-word-limit>
  105. </el-input>
  106. </el-form-item>
  107. </div>
  108. <div class="moudle">
  109. <div class="title">
  110. 发票信息
  111. </div>
  112. <el-form-item label="发票抬头">
  113. <el-input size="small" v-model="form.invoiceTitle" placeholder="请输入发票抬头!" clearable>
  114. </el-input>
  115. </el-form-item>
  116. <el-form-item label="发票税号">
  117. <el-input size="small" v-model="form.taxpayerId" placeholder="请输入发票税号!" clearable>
  118. </el-input>
  119. </el-form-item>
  120. </div>
  121. </div>
  122. <!-- 选择门店 -->
  123. <el-dialog v-loading="loading" element-loading-text="拼命加载中" :title="addressType === 1 ? '选择门店' : '常用地址'" :visible.sync="showChooseShop" width="600px" center>
  124. <div class="shop-top">
  125. <div @click="showAddress = true" v-if="addressType === 3 || addressType === 2" class="management-address">地址管理</div>
  126. <el-input size="small" placeholder="请输入姓名/手机号/地址" v-model="searchKey" @keydown.enter.native="seachEnterFun" clearable>
  127. <el-button type="primary" @click.stop="getData" slot="append" icon="el-icon-search"></el-button>
  128. </el-input>
  129. </div>
  130. <div class="shop-list">
  131. <template v-if="addressList.length">
  132. <div @dblclick="chooseShop" @click="curIdx = index" :class=" curIdx === index ? 'shop-item active' : 'shop-item'" v-for="(shop,index) in addressList" :key="index">
  133. <div class="name">{{shop.name}}</div>
  134. <div class="phone">{{shop.contact + ' ' + shop.phone}}</div>
  135. <div class="address">{{shop.districtName + shop.address}}</div>
  136. </div>
  137. </template>
  138. <el-empty v-else :description="`暂无可用${addressType === 1 ? '门店' : '地址'}`"></el-empty>
  139. </div>
  140. <span slot="footer" class="dialog-footer">
  141. <el-button size="small" @click="showChooseShop = false">取 消</el-button>
  142. <el-button size="small" type="primary" @click="chooseShop">确 定</el-button>
  143. </span>
  144. </el-dialog>
  145. </el-form>
  146. <el-button class="btn" size="small" type="primary" @click="onSubmit">{{form.takeType ? '保存' : '去结算'}}</el-button>
  147. <!-- 通过地图选择地理位置 -->
  148. <order-map :key="new Date().getTime()" @getAddressDetail="getAddressDetail" ref="orderMap"></order-map>
  149. <!-- 发起配送 -->
  150. <send-order-popup ref="sendOrderPopup"></send-order-popup>
  151. <!-- 地址管理 -->
  152. <el-dialog title="常用地址" :visible.sync="showAddress" width="800px" center @close="closeAddress">
  153. <address-management></address-management>
  154. </el-dialog>
  155. </div>
  156. </template>
  157. <script>
  158. import orderMap from "./orderComponents/orderAMap.vue";
  159. import addressManagement from "./settingComponents/addressManagement.vue";
  160. import { getProductList } from "../api/shop.js";
  161. import { getConfig } from "../api/setting.js";
  162. import {
  163. sendValuation,
  164. saveOrder,
  165. getAddressList,
  166. getResource,
  167. getOrderDetail,
  168. } from "../api/order.js";
  169. import sendOrderPopup from "../components/orderComponents/sendOrderPopup.vue";
  170. export default {
  171. name: "manualCreate",
  172. data() {
  173. return {
  174. goodsSource: [],
  175. products: [],
  176. addressType: 1,
  177. name: "",
  178. sendType: this.$store.state.userInfo.memberType === 1 ? 0 : 1,
  179. memberType: this.$store.state.userInfo.memberType,
  180. form: {
  181. name: "",
  182. sendAddress: {
  183. id: "",
  184. address: "",
  185. cityCode: "",
  186. cityName: "",
  187. contact: "",
  188. lat: "",
  189. lng: "",
  190. phone: "",
  191. provinceName: "",
  192. districtName: "",
  193. extension: "",
  194. street: "",
  195. },
  196. receiptAddress: {
  197. address: "",
  198. contact: "",
  199. phone: "",
  200. street: "",
  201. },
  202. weight: 1,
  203. productId: "",
  204. takeType: 0,
  205. takeTime: "",
  206. takeRemark: "",
  207. type: this.$store.state.userInfo.memberType === 1 ? 1 : 2,
  208. isWaimai: false,
  209. createType: 1,
  210. shopId: this.$store.state.userInfo.shopId,
  211. productAmount: 50,
  212. invoiceTitle: "",
  213. taxpayerId: "",
  214. transport: "0",
  215. platformType: 0,
  216. },
  217. chooseMapAddress: 1, // 1 发件选择地址2 收件选择地址
  218. showChooseShop: false,
  219. showChooseAddress: false,
  220. loading: false,
  221. shopList: [],
  222. personalList: [],
  223. addressList: [],
  224. searchKey: "",
  225. curIdx: 0,
  226. isLoading: false,
  227. pickerOptions: {
  228. disabledDate(time) {
  229. return (
  230. time.getTime() > Date.now() + 3600 * 1000 * 24 ||
  231. time.getTime() < Date.now() - 3600 * 1000 * 24
  232. );
  233. },
  234. },
  235. min: 15,
  236. showAddress: false,
  237. personalSendAddressId: "",
  238. personalReceiptAddressId: "",
  239. orderId: "",
  240. };
  241. },
  242. components: {
  243. orderMap,
  244. sendOrderPopup,
  245. addressManagement,
  246. },
  247. // 监听属性 类似于data概念
  248. computed: {},
  249. // 监控data中的数据变化
  250. watch: {
  251. "$store.state.userInfo": {
  252. handler(newVal, oldVal) {
  253. this.sendType = newVal.memberType === 1 ? 0 : 1;
  254. this.memberType = newVal.memberType;
  255. this.form.type = newVal.memberType === 1 ? 1 : 2;
  256. this.form.shopId = newVal.shopId;
  257. },
  258. deep: true,
  259. },
  260. sendType: {
  261. handler(newVal, oldVal) {
  262. this.searchKey = "";
  263. Object.keys(this.form.sendAddress).map((v) => {
  264. this.form.sendAddress[v] = "";
  265. });
  266. if (newVal) {
  267. this.addressType = 1;
  268. this.form.shopId = this.$store.state.userInfo.shopId;
  269. } else {
  270. this.addressType = 2;
  271. this.form.shopId = "";
  272. }
  273. this.getData();
  274. },
  275. immediate: true,
  276. },
  277. },
  278. // 生命周期 - 创建完成(可以访问当前this实例)
  279. created() {
  280. this.orderId = this.$route.params.orderId;
  281. if (this.orderId) {
  282. this.sendType = 0;
  283. this.getOrderDetail();
  284. }
  285. this.getProductList();
  286. this.getData();
  287. this.getResource();
  288. },
  289. // 方法集合
  290. methods: {
  291. checkDaySeq() {
  292. console.log("checkDaySeq:", typeof this.form.daySeq);
  293. this.form.daySeq = this.form.daySeq.replace(/\D|^0/g, "");
  294. },
  295. getOrderDetail() {
  296. getOrderDetail({ orderId: this.orderId }).then((res) => {
  297. console.log("再来一单订单详情:", res);
  298. if (res.code === 200) {
  299. let data = res.data;
  300. let nowTime = new Date().getTime();
  301. let takeTime = new Date(data.takeTime).getTime();
  302. if (
  303. nowTime - takeTime >
  304. this.$store.state.userInfo.privateNumberInvalidTime *
  305. 60 *
  306. 60 *
  307. 1000 &&
  308. data.receiptPhone.length > 11
  309. ) {
  310. this.$confirm(
  311. "当前收件人手机号为隐私号,骑手可能无法联系收件人!建议填写用户真实手机号",
  312. "提醒",
  313. {
  314. confirmButtonText: "我知道了",
  315. showCancelButton: false,
  316. center: true,
  317. }
  318. );
  319. }
  320. let receiptPhone = data.receiptPhone;
  321. let receiptExtension = data.receiptExtension;
  322. let sendPhone = data.sendPhone;
  323. let sendExtension = data.sendExtension;
  324. if (data.receiptPhone.length > 11) {
  325. receiptPhone = data.receiptPhone.slice(0, 11);
  326. receiptExtension = data.receiptPhone.slice(12);
  327. }
  328. if (data.sendPhone.length > 11) {
  329. sendPhone = data.sendPhone.slice(0, 11);
  330. sendExtension = data.sendPhone.slice(12);
  331. }
  332. this.form = {
  333. createType: "",
  334. invoiceTitle: "",
  335. isWaimai: false,
  336. name: "",
  337. productAmount: data.productAmount,
  338. productId: data.productId,
  339. receiptAddress: {
  340. name: "",
  341. address: data.receiptAddress,
  342. cityCode: data.receiptCityCode,
  343. cityName: data.receiptCityName,
  344. contact: data.receiptContactName,
  345. districtName: data.receiptDistrictName,
  346. id: data.receiptAddressId,
  347. isDefault: "",
  348. lat: data.receiptLat,
  349. lng: data.receiptLng,
  350. phone: receiptPhone,
  351. extension: receiptExtension ?? "",
  352. provinceName: data.receiptProvinceName || data.sendProvinceName,
  353. street: data.receiptStreet,
  354. type: "",
  355. },
  356. sendAddress: {
  357. name: "",
  358. address: data.sendAddress,
  359. cityCode: data.sendCityCode,
  360. cityName: data.sendCityName,
  361. contact: data.sendContactName,
  362. districtName: data.sendDistrictName,
  363. id: data.sendAddressId,
  364. lat: data.sendLat,
  365. lng: data.sendLng,
  366. phone: sendPhone,
  367. extension: sendExtension ?? "",
  368. provinceName: data.sendProvinceName,
  369. street: data.sendStreet,
  370. },
  371. shopId: data.waimaiOrderId ? data.shopId : "",
  372. takeRemark: data.caution ?? "" + data.takeRemark ?? "",
  373. takeTime: "",
  374. takeType: "",
  375. taxpayerId: "",
  376. transport: 0,
  377. type: "",
  378. weight: data.weight,
  379. platformType: data.orderType ?? data.platformType,
  380. daySeq: data.daySeq,
  381. };
  382. } else {
  383. this.$message({
  384. type: "error",
  385. message: res.msg,
  386. });
  387. }
  388. });
  389. },
  390. getResource() {
  391. getResource().then((res) => {
  392. if (res.code === 200) {
  393. this.goodsSource = res.data;
  394. this.form.platformType = this.goodsSource[0].type;
  395. } else {
  396. this.$message({
  397. type: "error",
  398. message: res.msg,
  399. });
  400. }
  401. });
  402. },
  403. closeAddress() {
  404. this.getData();
  405. },
  406. seachEnterFun(e) {
  407. var keyCode = window.event ? e.keyCode : e.which;
  408. if (keyCode == 13) {
  409. this.getData();
  410. }
  411. },
  412. chooseTime(time) {
  413. let min = this.min; // 多少分钟后发起配送
  414. let now = new Date().getTime();
  415. let inputTime = new Date(time).getTime();
  416. if (inputTime < now + 60 * 1000 * (min - 1)) {
  417. this.$message({
  418. type: "error",
  419. message: `至少选择${min}分钟后发单!`,
  420. });
  421. this.form.takeTime = this.$tool.getFormatDate(now + 60 * 1000 * min);
  422. } else {
  423. this.form.takeTime = this.$tool.getFormatDate(inputTime);
  424. }
  425. },
  426. chooseShop() {
  427. this.showChooseShop = false;
  428. let sendAddress = this.addressList[this.curIdx];
  429. if (this.addressType === 1) {
  430. Object.keys(this.form.sendAddress).map((v) => {
  431. this.form.sendAddress[v] = sendAddress[v];
  432. });
  433. this.name = sendAddress.name;
  434. this.form.shopId = sendAddress.id;
  435. } else if (this.addressType === 2) {
  436. this.form.sendAddress = sendAddress;
  437. this.personalSendAddressId = sendAddress.id;
  438. } else {
  439. this.form.receiptAddress = sendAddress;
  440. this.personalReceiptAddressId = sendAddress.id;
  441. }
  442. },
  443. showShop(addressType) {
  444. // 1门店地址发单选择门店 2是个人地址发单选择常用地址 3是收件地址选择常用地址
  445. this.addressType = addressType;
  446. this.searchKey = "";
  447. this.getData();
  448. this.showChooseShop = true;
  449. },
  450. getData() {
  451. this.loading = true;
  452. getAddressList({
  453. searchKey: this.searchKey,
  454. }).then((res) => {
  455. this.loading = false;
  456. if (res.code === 200) {
  457. let sendAddress;
  458. if (this.addressType === 1) {
  459. this.addressList = res.data.shop;
  460. let shopId = this.form.shopId;
  461. sendAddress = this.addressList.filter((v) => {
  462. return v.id === shopId;
  463. })[0];
  464. this.curIdx = this.addressList.findIndex((v) => {
  465. return v.id === shopId;
  466. });
  467. Object.keys(this.form.sendAddress).map((v) => {
  468. this.form.sendAddress[v] = sendAddress ? sendAddress[v] : "";
  469. });
  470. this.name = sendAddress ? sendAddress.name : "";
  471. }
  472. if (this.addressType === 2) {
  473. this.addressList = res.data.personal;
  474. if (this.personalSendAddressId) {
  475. sendAddress = this.addressList.filter((v) => {
  476. return v.id === this.personalSendAddressId;
  477. })[0];
  478. this.curIdx = this.addressList.findIndex((v) => {
  479. return v.id === this.personalSendAddressId;
  480. });
  481. } else {
  482. sendAddress = this.addressList.filter((v) => {
  483. return v.isDefault;
  484. })[0];
  485. this.curIdx = this.addressList.findIndex((v) => {
  486. return v.isDefault;
  487. });
  488. }
  489. Object.keys(this.form.sendAddress).map((v) => {
  490. this.form.sendAddress[v] = sendAddress ? sendAddress[v] : "";
  491. });
  492. }
  493. if (this.addressType === 3) {
  494. this.addressList = res.data.personal;
  495. let receiptAddress = this.addressList.filter((v) => {
  496. return v.id === this.personalReceiptAddressId;
  497. })[0];
  498. this.curIdx = this.addressList.findIndex((v) => {
  499. return v.id === this.personalReceiptAddressId;
  500. });
  501. Object.keys(this.form.receiptAddress).map((v) => {
  502. this.form.receiptAddress[v] = receiptAddress
  503. ? receiptAddress[v]
  504. : "";
  505. });
  506. }
  507. } else {
  508. this.$message({
  509. type: "error",
  510. message: res.msg,
  511. });
  512. }
  513. });
  514. },
  515. getProductList() {
  516. getProductList().then((res) => {
  517. if (res.code === 200) {
  518. this.products = res.data;
  519. this.form.productId = this.products[0].id;
  520. } else {
  521. this.$message({
  522. type: "error",
  523. message: res.msg,
  524. });
  525. }
  526. });
  527. },
  528. onSubmit() {
  529. // 去除电话中的空格
  530. this.form.sendAddress.phone = this.form.sendAddress.phone.replace(
  531. /\s/g,
  532. ""
  533. );
  534. this.form.receiptAddress.phone = this.form.receiptAddress.phone.replace(
  535. /\s/g,
  536. ""
  537. );
  538. if (!this.form.sendAddress.phone.trim()) {
  539. return this.$message({
  540. type: "error",
  541. message: "请先输入发件人电话!",
  542. });
  543. }
  544. let reg2 = new RegExp(/^1[3456789]\d{9}$/);
  545. if (!reg2.test(this.form.sendAddress.phone)) {
  546. return this.$message({
  547. type: "error",
  548. message: "请输入正确的发件人电话!",
  549. });
  550. }
  551. // 个人发件
  552. if (!this.sendType) {
  553. if (!this.form.sendAddress.contact.trim()) {
  554. return this.$message({
  555. type: "error",
  556. message: "请先输入发件人姓名!",
  557. });
  558. }
  559. if (!this.form.sendAddress.address.trim()) {
  560. return this.$message({
  561. type: "error",
  562. message: "请先选择发件人地址!",
  563. });
  564. }
  565. }
  566. if (!this.form.receiptAddress.contact.trim()) {
  567. return this.$message({
  568. type: "error",
  569. message: "请先输入收件人姓名!",
  570. });
  571. }
  572. if (!this.form.receiptAddress.phone.trim()) {
  573. return this.$message({
  574. type: "error",
  575. message: "请先输入收件人电话!",
  576. });
  577. }
  578. if (!reg2.test(this.form.receiptAddress.phone)) {
  579. return this.$message({
  580. type: "error",
  581. message: "请输入正确的收件人电话!",
  582. });
  583. }
  584. if (!this.form.receiptAddress.address.trim()) {
  585. return this.$message({
  586. type: "error",
  587. message: "请先选择收件人地址!",
  588. });
  589. }
  590. if (this.form.platformType && !this.form.daySeq) {
  591. return this.$message({
  592. type: "error",
  593. message: "请填写平台流水号!",
  594. });
  595. }
  596. let reg = new RegExp(/^[1-9]\d*$/g);
  597. if (
  598. !reg.test(Number(this.form.weight)) ||
  599. Number(this.form.weight) > 50
  600. ) {
  601. this.$refs.weight.focus();
  602. return this.$message({
  603. type: "error",
  604. message: "物品重量为正整数且不得超过50KG!",
  605. });
  606. }
  607. let reg1 = new RegExp(/(^[1-9]{1}[0-9]*$)|(^[0-9]*\.[0-9]{2}$)/);
  608. if (!reg1.test(Number(this.form.productAmount))) {
  609. this.$refs.productAmount.focus();
  610. return this.$message({
  611. type: "error",
  612. message: "请输入正确的金额!",
  613. });
  614. }
  615. if (Number(this.form.productAmount) > 20000) {
  616. this.$refs.productAmount.focus();
  617. return this.$message({
  618. type: "error",
  619. message: "物品价值不得超过20000元!",
  620. });
  621. }
  622. // 预约发单
  623. if (this.form.takeType) {
  624. if (!this.form.takeTime.trim()) {
  625. return this.$message({
  626. type: "error",
  627. message: "请先选择预约发单时间!",
  628. });
  629. }
  630. let min = this.min; // 多少分钟后发起配送
  631. let now = new Date().getTime();
  632. let inputTime = new Date(this.form.takeTime).getTime();
  633. if (inputTime < now + 60 * 1000 * (min - 1)) {
  634. return this.$message({
  635. type: "error",
  636. message: `预约发单时间至少为${min}分钟后发单!`,
  637. });
  638. }
  639. this.form.saveFlag = 1;
  640. getConfig().then((res) => {
  641. if (res.code === 200) {
  642. let amount = res.data.amount;
  643. if (amount < 100) {
  644. this.$confirm(
  645. "您的账户余额不足100元,可能会导致预约发单失败,请及时充值!",
  646. "提示",
  647. {
  648. confirmButtonText: "去充值",
  649. cancelButtonText: "知道了!",
  650. distinguishCancelAndClose: true,
  651. center: true,
  652. type: "warning",
  653. }
  654. )
  655. .then(() => {
  656. this.$router.push({
  657. path: "/shopInfo/shopAccount",
  658. });
  659. })
  660. .catch((action) => {
  661. if (action === "close") {
  662. return;
  663. } else {
  664. this.saveOrder();
  665. }
  666. });
  667. } else {
  668. this.saveOrder();
  669. }
  670. } else {
  671. this.$message({
  672. type: "error",
  673. message: res.msg,
  674. });
  675. }
  676. });
  677. } else {
  678. this.form.takeTime = this.$tool.getFormatDate(new Date());
  679. this.sendValuation();
  680. }
  681. },
  682. saveOrder() {
  683. saveOrder(this.form).then((res) => {
  684. if (res.code === 200) {
  685. this.$message({
  686. type: "success",
  687. message: "预约单保存成功!",
  688. });
  689. this.$router.push({
  690. name: "HomeIndex",
  691. params: { tabNum: 1 },
  692. });
  693. } else {
  694. this.$message({
  695. type: "error",
  696. message: res.msg,
  697. });
  698. }
  699. });
  700. },
  701. // 计价
  702. sendValuation() {
  703. this.isLoading = true;
  704. sendValuation(this.form).then((res) => {
  705. this.isLoading = false;
  706. if (res.code == 200) {
  707. if (!res.data.optionals || !res.data.optionals.length) {
  708. return this.$message({
  709. type: "error",
  710. message: `暂无可用运力!`,
  711. });
  712. }
  713. res.data.optionals.forEach((item) => {
  714. item.optionals = item.optionals ? item.optionals : [];
  715. item.lowOptionals = item.lowOptionals ? item.lowOptionals : [];
  716. item.supports = item.supports ? item.supports : [];
  717. });
  718. this.$refs.sendOrderPopup.init(res.data, {
  719. ...this.form,
  720. });
  721. } else {
  722. this.$message({
  723. type: "error",
  724. message: res.msg,
  725. });
  726. }
  727. });
  728. },
  729. showMap(type) {
  730. this.searchKey = "";
  731. this.chooseMapAddress = type;
  732. if (this.sendType === 1 && this.chooseMapAddress === 1) return;
  733. this.$refs.orderMap.chooseLocation();
  734. },
  735. getAddressDetail(v, lng, lat) {
  736. let type = "sendAddress";
  737. if (this.chooseMapAddress === 1) {
  738. type = "sendAddress";
  739. } else {
  740. type = "receiptAddress";
  741. }
  742. this.form[type].address = v.address;
  743. this.form[type].provinceName = v.province;
  744. this.form[type].cityName = v.city;
  745. this.form[type].cityCode = v.citycode;
  746. this.form[type].districtName = v.district;
  747. this.form[type].lng = lng;
  748. this.form[type].lat = lat;
  749. },
  750. reduce() {
  751. this.form.weight = this.form.weight === 1 ? 1 : --this.form.weight;
  752. },
  753. add() {
  754. this.form.weight = ++this.form.weight;
  755. },
  756. focus() {
  757. this.$nextTick(() => {
  758. document
  759. .getElementsByClassName("el-button--text")[0]
  760. .setAttribute("style", "display:none"); // 隐藏此刻按钮
  761. });
  762. },
  763. },
  764. };
  765. </script>
  766. <style lang="scss" scoped="scoped">
  767. .form-wrap {
  768. display: flex;
  769. flex-direction: column;
  770. align-items: center;
  771. width: calc(100% - 40px);
  772. padding: 20px;
  773. background: #fff;
  774. .product-amount {
  775. width: 190px;
  776. }
  777. .moudle-list {
  778. display: flex;
  779. flex-wrap: wrap;
  780. .moudle {
  781. width: 600px;
  782. margin: 0 100px 50px 0;
  783. /deep/ .el-radio__input.is-checked .el-radio__inner {
  784. border-color: #fc7200;
  785. background: #fc7200;
  786. }
  787. /deep/ .el-radio__input.is-checked + .el-radio__label {
  788. color: #fc7200;
  789. }
  790. .category_box {
  791. display: flex;
  792. flex-wrap: wrap;
  793. width: 100%;
  794. margin-top: -10px;
  795. .item {
  796. display: flex;
  797. align-items: center;
  798. width: 92px;
  799. height: 30px;
  800. margin: 10px 10px 0 0;
  801. border-radius: 2px;
  802. cursor: pointer;
  803. &.active {
  804. color: #ffffff;
  805. background: #fc7200;
  806. border-color: #fc7200 !important;
  807. }
  808. }
  809. }
  810. .phone-before {
  811. width: 50%;
  812. }
  813. .phone-center {
  814. margin: 0 15px;
  815. }
  816. .phone-after {
  817. width: 70px;
  818. }
  819. .item1 {
  820. width: 190px;
  821. }
  822. .item2 {
  823. margin-left: 20px;
  824. width: 50%;
  825. }
  826. /deep/ .item2 .el-input__inner {
  827. text-align: center;
  828. }
  829. .tips {
  830. margin-left: 20px;
  831. color: #999999;
  832. }
  833. .map {
  834. height: 25px;
  835. width: 25px;
  836. cursor: pointer;
  837. }
  838. }
  839. }
  840. .btn {
  841. width: 200px;
  842. height: 40px;
  843. font-size: 14px;
  844. background: #fc7200;
  845. border: #fc7200;
  846. margin-top: -50px;
  847. }
  848. /deep/ .el-form {
  849. display: flex;
  850. flex-wrap: wrap;
  851. }
  852. /deep/ .el-form-item__label {
  853. color: #b1b1b1;
  854. }
  855. .title-list {
  856. display: flex;
  857. align-items: center;
  858. .normal-title {
  859. color: #999;
  860. font-weight: bold;
  861. margin: 0 30px 20px 0;
  862. cursor: pointer;
  863. }
  864. .normal-title:before {
  865. content: "";
  866. display: inline-block;
  867. width: 3px;
  868. height: 14px;
  869. background-color: #999;
  870. }
  871. }
  872. .title {
  873. font-weight: bold;
  874. color: #333;
  875. margin: 0 30px 20px 0;
  876. cursor: pointer;
  877. }
  878. .title:before {
  879. content: "";
  880. display: inline-block;
  881. width: 3px;
  882. height: 14px;
  883. background-color: #fc7200;
  884. }
  885. .but {
  886. display: flex;
  887. align-items: center;
  888. justify-content: center;
  889. margin: 0;
  890. border-radius: 0;
  891. height: 32px;
  892. background: #ebebeb;
  893. border-color: #ebebeb;
  894. color: #666;
  895. &.active {
  896. color: #ffffff;
  897. background: #fc7200;
  898. border-color: #fc7200 !important;
  899. }
  900. &.but-r {
  901. margin-right: 20px;
  902. }
  903. }
  904. .but1 {
  905. display: flex;
  906. align-items: center;
  907. justify-content: center;
  908. margin-left: 100px;
  909. height: 32px;
  910. &.active {
  911. color: #ffffff;
  912. background: #fc7200;
  913. border-color: #fc7200 !important;
  914. }
  915. }
  916. /deep/ .el-form-item__content {
  917. display: flex;
  918. align-items: center;
  919. line-height: 32px;
  920. }
  921. .printer-num {
  922. display: flex;
  923. align-items: center;
  924. .reduce {
  925. width: 32px;
  926. height: 32px;
  927. cursor: pointer;
  928. }
  929. .num {
  930. margin: 0 10px;
  931. width: 150px;
  932. }
  933. .add {
  934. width: 32px;
  935. height: 32px;
  936. cursor: pointer;
  937. }
  938. .name {
  939. margin-left: 20px;
  940. }
  941. }
  942. .shop-top {
  943. display: flex;
  944. align-items: center;
  945. margin-bottom: 10px;
  946. .management-address {
  947. flex-shrink: 0;
  948. color: #fc7200;
  949. margin-right: 15px;
  950. cursor: pointer;
  951. }
  952. }
  953. .shop-list {
  954. height: 55vh;
  955. overflow: scroll;
  956. .shop-item {
  957. border: 1px solid #999;
  958. padding: 10px;
  959. margin: 10px 0;
  960. border-radius: 5px;
  961. color: #333;
  962. cursor: pointer;
  963. }
  964. .active {
  965. border-color: #fc7200;
  966. color: #fc7200;
  967. }
  968. }
  969. }
  970. </style>