app-form-send.vue 4.0 KB

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