app-form-send1.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view>
  3. <tui-list-cell class="line-cell" :hover="false" :arrow="true" >
  4. <view class="tui-title">配送方</view>
  5. <picker mode="selector" :value="sendSideIndex" :range="deliveryList" :range-key="'name'" @change="selectSideEvent" class="tui-input">
  6. <view v-if="formData.sendSide" class="tui-input">
  7. {{ deliveryList[sendSideIndex].name }}
  8. </view>
  9. <view v-else class="tui-placeholder">请选择快递公司</view>
  10. <input name="sendSide" hidden />
  11. </picker>
  12. </tui-list-cell>
  13. <!-- 门店送或快递送需要设置地址 -->
  14. <appAddressGroup :customId="customId" cityTitle="配送城市" @selectAdress="selectAdress" ></appAddressGroup>
  15. <appSendTime @alterTime="selectAdress('')" :sendDate.sync="formData.sendDate" :sendTime.sync="formData.sendTime"></appSendTime>
  16. <tui-list-cell class="line-cell" :hover="false" :arrow="false">
  17. <view class="tui-title">运费</view>
  18. <view v-if="formData.sendCost" class="tui-input">
  19. {{ formData.sendCost }}
  20. </view>
  21. <view v-else class="tui-placeholder">留空表示免运费</view>
  22. <input name="sendCost" hidden />
  23. </tui-list-cell>
  24. </view>
  25. </template>
  26. <script>
  27. import TuiListCell from "@/components/plugin/list-cell";
  28. import { freight } from "@/api/order";
  29. import appFormRadioBtn from "@/components/app-formRadio-btn";
  30. import appAddressGroup from "@/components/app-address-group";
  31. import appSendTime from "@/components/app-send-time";
  32. import {mapGetters} from "vuex";
  33. export default {
  34. components: {
  35. TuiListCell,
  36. appFormRadioBtn,
  37. appAddressGroup,
  38. appSendTime
  39. },
  40. props: {
  41. customId:'',
  42. orderid:'',
  43. form: {
  44. type: Object
  45. }
  46. },
  47. data() {
  48. return {
  49. formData: {
  50. sendCost: "",
  51. receiveProvince: "",
  52. receiveCity: "",
  53. receiveFloor: "",
  54. receiveAddress: "",
  55. receiveLong: "",
  56. receiveLat: "",
  57. sendSide: "",
  58. sendType: "3", //1自取 2本店送 3快递送
  59. sendDate: "",
  60. sendTime: ""
  61. },
  62. userLong:'',
  63. userLat:'',
  64. sendSideIndex:0,
  65. deliveryList: []
  66. };
  67. },
  68. created() {
  69. this.initData();
  70. },
  71. computed: {
  72. ...mapGetters(["getDictionariesInfo"]),
  73. getCurSideName() {
  74. let name = "";
  75. if (this.formData.sendSide) {
  76. const curItem = this.deliveryList.find(ele => {
  77. return ele.value == this.formData.sendSide;
  78. });
  79. if (curItem) {
  80. name = curItem.name;
  81. }
  82. }
  83. return name;
  84. }
  85. },
  86. methods: {
  87. initData() {
  88. for (const key in this.formData) {
  89. if (Object.hasOwnProperty.call(this.formData, key)) {
  90. const element = this.form[key];
  91. this.formData[key] = element;
  92. }
  93. }
  94. //配送方-列表
  95. let list = this.getDictionariesInfo.expressList;
  96. for (let i=0;i<list.length;i++){
  97. this.deliveryList.push({name:list[i].deliveryName,value:list[i].deliveryId,id:list[i].id})
  98. }
  99. console.log(list);
  100. this.formData.sendSide = list[0].id;
  101. },
  102. selectAdress(info) {
  103. if(info){
  104. this.formData.receiveProvince = info.province;
  105. this.formData.receiveCity = info.city;
  106. this.formData.receiveFloor = info.floor;
  107. this.formData.receiveAddress = info.address;
  108. this.formData.receiveLong = info.longitude;
  109. this.formData.receiveLat = info.latitude;
  110. }
  111. console.log('this.formData',this.formData)
  112. this.$nextTick(() => {
  113. let params = {
  114. id: this.orderid,
  115. province: this.formData.receiveProvince,
  116. city:this.formData.receiveCity,
  117. address:this.formData.receiveAddress,
  118. floor:this.formData.receiveFloor,
  119. expressId: this.formData.sendSide,
  120. // orderId: this.orderid,
  121. long: this.formData.receiveLong,
  122. lat: this.formData.receiveLat,
  123. sendTime: this.formData.sendTime,
  124. };
  125. this.freightCount(params);
  126. });
  127. },
  128. // 计算运费
  129. freightCount(option) {
  130. freight(option).then(res => {
  131. this.formData.sendCost = res.data.sedCost;
  132. });
  133. },
  134. selectSideEvent(event) {
  135. // console.log(event);
  136. // console.log(event.detail.value);
  137. const {detail: { value }} = event;
  138. this.sendSideIndex = value;
  139. this.formData.sendSide = this.deliveryList[value].id;
  140. console.log(this.formData.sendSide);
  141. }
  142. },
  143. watch: {
  144. formData: {
  145. handler(val) {
  146. if (val) {
  147. let info = { ...this.form, ...val };
  148. if (this.formData.sendTime) {
  149. // info.sendTime = `${this.formData.sendDate} ${this.formData.sendTime}`;
  150. info.sendTime = this.formData.sendTime;
  151. }
  152. this.$emit("update:form", info);
  153. }
  154. },
  155. deep: true
  156. },
  157. ["formData.sendType"](val) {
  158. if (val != "3") {
  159. //不是快递配送不包含运费
  160. this.formData.sendCost = "";
  161. }
  162. }
  163. }
  164. };
  165. </script>
  166. <style></style>