distributionArea.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <view>
  3. <view class="pouponCount" :class="popup.show==true?'on':''">
  4. <view class='title'>配送区域及运费<text class='iconfont icon-guanbi' @tap='changeClose'></text></view>
  5. <view class="container">
  6. <view class="area_container">
  7. <scroll-view scroll-y="true">
  8. <view v-if="shippingAddressData.length">
  9. <view class="distribution_area" v-for="(item, index) in shippingAddressData" :key="index">
  10. <view class="distribution_area_title">
  11. <view>{{ item.title }}</view>
  12. <view class="distribution_area_title_del blackColor" v-if="item.label">
  13. <span>{{ item.label }}</span>
  14. </view>
  15. <view class="distribution_area_title_del" v-else @click="deleteAreaAndFreight(item, index)">
  16. <text class="iconfont icon-shanchu2"></text>
  17. <span>删除</span>
  18. </view>
  19. </view>
  20. <view class="distribution_area_item" @click="selectArea(item, index)" v-if="index">
  21. <view class="distribution_area_item_label">配送区域</view>
  22. <view class="distribution_area_item_value right">
  23. <text class="line1" v-if="item.city_name">
  24. <text class="select_name" v-if="Array.isArray(item.city_name)">{{item.city_name.length ? item.city_name.map(val => val.name).join(',') : '选择区域'}}</text>
  25. <text class="select_name" v-else>{{item.city_name}}</text>
  26. </text>
  27. <text v-else>选择区域</text>
  28. <text class="iconfont">&#xe617;</text>
  29. </view>
  30. </view>
  31. <view class="distribution_area_item">
  32. <view class="distribution_area_item_label">首件</view>
  33. <view class="distribution_area_item_value">
  34. <input type="number" v-model="item.first" @input="item.first = Number(item.first)" placeholder="请填写首件数量" placeholder-class="inputHolder" />
  35. </view>
  36. </view>
  37. <view class="distribution_area_item">
  38. <view class="distribution_area_item_label">运费</view>
  39. <view class="distribution_area_item_value">
  40. <input type="number" v-model="item.first_price" @input="item.first_price = Number(item.first_price)" placeholder="请填写运费金额" placeholder-class="inputHolder" />
  41. </view>
  42. </view>
  43. <view class="distribution_area_item">
  44. <view class="distribution_area_item_label">续件</view>
  45. <view class="distribution_area_item_value">
  46. <input type="number" :min="0.1" v-model="item.continue" @input="item.continue = Number(item.continue)" placeholder="请填写续件数量" placeholder-class="inputHolder" />
  47. </view>
  48. </view>
  49. <view class="distribution_area_item">
  50. <view class="distribution_area_item_label">续费</view>
  51. <view class="distribution_area_item_value">
  52. <input type="number" v-model="item.continue_price" @input="item.continue_price = Number(item.continue_price)" placeholder="请填写续费金额" placeholder-class="inputHolder" />
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <view class="add" @click="addAreaAndFreight">
  58. <span class="iconfont">&#xe70e;</span>
  59. <span>添加配送区域及运费</span>
  60. </view>
  61. </scroll-view>
  62. </view>
  63. <view class="handle"><view class="handle_button" @click="save">保存</view></view>
  64. <uni-popup ref="area_popup" type="bottom"><areas @handleGetSelectArea="handleGetSelectArea" :allReadySelect="allReadySelect" @close="close"></areas></uni-popup>
  65. </view>
  66. </view>
  67. <view class='mask' catchtouchmove="true" :hidden='popup.show==false' @tap="changeClose"></view>
  68. </view>
  69. </template>
  70. <script>
  71. // 配送区域
  72. import areas from '../components/areas.vue';
  73. export default {
  74. components: {
  75. areas
  76. },
  77. props: {
  78. freightData: {
  79. type: Array,
  80. default: () => {
  81. []
  82. }
  83. },
  84. popup: {
  85. type: Object,
  86. default: function() {
  87. return {
  88. show: false
  89. };
  90. }
  91. }
  92. },
  93. data() {
  94. return {
  95. // shippingAddressData: [
  96. // {
  97. // title: '配送区域',
  98. // label: '默认全国',
  99. // city_id: [],
  100. // first: '', //首件条件
  101. // first_price: '', //首件运费
  102. // continue: '', // 续件数量
  103. // continue_price: '' // 续件金额
  104. // }
  105. // ],
  106. shippingAddressData: this.freightData,
  107. selectIndex: '',
  108. allReadySelect: []
  109. };
  110. },
  111. watch: {
  112. },
  113. mounted() {
  114. },
  115. methods: {
  116. //初始化数据
  117. initListData(){
  118. console.log(this.freightData)
  119. let arr = [...this.freightData]
  120. if(arr.length == 0){
  121. arr = [
  122. {
  123. title: '配送区域',
  124. label: '默认全国',
  125. city_id: [],
  126. first: '', //首件条件
  127. first_price: '', //首件运费
  128. continue: '', // 续件数量
  129. continue_price: '' // 续件金额
  130. }
  131. ]
  132. }else{
  133. arr.forEach((value,i)=>{
  134. value['title'] = '配送区域'
  135. if(i == 0)value['label'] = '默认全国'
  136. })
  137. }
  138. this.shippingAddressData = arr
  139. },
  140. // 点击 添加配送区域及运费
  141. addAreaAndFreight() {
  142. this.shippingAddressData.push({
  143. title: '配送区域',
  144. city_id: [],
  145. city_name: '',
  146. selectData: [],
  147. first: '', //首件条件
  148. first_price: '', //首件运费
  149. continue: '', // 续件数量
  150. continue_price: '' // 续件金额
  151. });
  152. },
  153. // 删除配送区域和运费
  154. deleteAreaAndFreight(item, index) {
  155. this.shippingAddressData.splice(index, 1);
  156. },
  157. selectArea(item, index) {
  158. this.selectIndex = index;
  159. if(!item.selectData){
  160. item.name = this.shippingAddressData[this.selectIndex]['city_name'].map(val => val.name).join('/')
  161. this.allReadySelect = [item];
  162. }else{
  163. this.allReadySelect = item.selectData;
  164. }
  165. this.$refs.area_popup.open();
  166. },
  167. // 获取所限地址
  168. handleGetSelectArea(item) {
  169. this.shippingAddressData[this.selectIndex].selectData = item;
  170. this.shippingAddressData[this.selectIndex].city_name = item.map(val => val.name).join(',');
  171. this.shippingAddressData[this.selectIndex].city_id = item.map(val => val.id);
  172. this.$refs.area_popup.close();
  173. },
  174. // 关闭选择弹窗
  175. close() {
  176. this.$refs.area_popup.close();
  177. },
  178. changeClose(){
  179. this.$emit('changeClose')
  180. },
  181. // 点击保存
  182. save() {
  183. let that = this;
  184. let value = that.shippingAddressData
  185. for(var i=0; i<value.length; i++){
  186. if (value[i].first === "") return that.$util.Tips({
  187. title: '请填写首件数量'
  188. });
  189. if (value[i].first < 1) return that.$util.Tips({
  190. title: '首件数量不能小于1'
  191. });
  192. if (value[i].first_price === "") return that.$util.Tips({
  193. title: '请填写首件金额'
  194. });
  195. if (value[i].continue === "") return that.$util.Tips({
  196. title: '请填写续件数量'
  197. });
  198. if (value[i].continue_price === "") return that.$util.Tips({
  199. title: '请填写续费金额'
  200. });
  201. if(i != 0 && (value[i].city_id).length == 0) return that.$util.Tips({
  202. title: '请填写配送区域'
  203. });
  204. }
  205. that.$emit('getData',that.shippingAddressData);
  206. }
  207. }
  208. };
  209. </script>
  210. <style lang="scss" scoped>
  211. .pouponCount {
  212. position: fixed;
  213. bottom: 0;
  214. width: 100%;
  215. left: 0;
  216. background-color: #f5f5f5;
  217. z-index: 77;
  218. border-radius: 16rpx 16rpx 0 0;
  219. padding-bottom: 120rpx;
  220. transform: translate3d(0, 100%, 0);
  221. transition: all .3s cubic-bezier(.25, .5, .5, .9);
  222. }
  223. .pouponCount.on {
  224. transform: translate3d(0, 0, 0);
  225. }
  226. .pouponCount .title {
  227. font-size: 32rpx;
  228. font-weight: bold;
  229. text-align: center;
  230. padding: 36rpx 0;
  231. position: relative;
  232. }
  233. .pouponCount .icon-guanbi {
  234. position: absolute;
  235. right: 20rpx;
  236. color: #8a8a8a;
  237. font-size: 30rpx;
  238. top: 40rpx;
  239. line-height: 30rpx;
  240. top: 20rpx;
  241. font-weight: normal;
  242. background-color: transparent;
  243. }
  244. scroll-view{
  245. height: 70vh;
  246. }
  247. .area_container{
  248. padding: 20rpx;
  249. background-color: #f7f7f7;
  250. }
  251. .add {
  252. margin: auto;
  253. width: 710rpx;
  254. height: 106rpx;
  255. background: #ffffff;
  256. border-radius: 10px;
  257. display: flex;
  258. align-items: center;
  259. justify-content: center;
  260. color: #e93323;
  261. font-size: 30rpx;
  262. .iconfont {
  263. display: inline-block;
  264. margin-right: 10rpx;
  265. }
  266. }
  267. .distribution_area {
  268. margin: 0 auto 30rpx;
  269. width: 710rpx;
  270. padding: 36rpx 30rpx 31rpx 30rpx;
  271. box-sizing: border-box;
  272. background: #fff;
  273. border-radius: 10px;
  274. &:first-child{
  275. margin-top: 0;
  276. }
  277. &_title {
  278. display: flex;
  279. justify-content: space-between;
  280. font-size: 30rpx;
  281. margin-bottom: 36rpx;
  282. > view:nth-child(2) {
  283. color: #666666;
  284. }
  285. &_del {
  286. color: #e93323 !important;
  287. font-size: 28rpx !important;
  288. display: flex;
  289. align-items: center;
  290. .iconfont {
  291. font-size: 30rpx;
  292. margin-right: 15rpx;
  293. }
  294. }
  295. .blackColor {
  296. color: #666666 !important;
  297. }
  298. }
  299. &_item {
  300. height: 84rpx;
  301. background: #f5f5f5;
  302. display: flex;
  303. justify-content: space-between;
  304. align-items: center;
  305. padding: 0 30rpx;
  306. border-radius: 10rpx;
  307. margin-bottom: 20rpx;
  308. &_value {
  309. text-align: right;
  310. display: flex;
  311. align-items: center;
  312. }
  313. .select_name{
  314. // font-weight: bold;
  315. }
  316. .line1{
  317. max-width: 430rpx;
  318. }
  319. .right {
  320. color: #bbbbbb;
  321. > span:nth-child(1) {
  322. display: inline-block;
  323. margin-right: 14rpx;
  324. max-width: 350rpx;
  325. overflow: hidden;
  326. white-space: nowrap;
  327. text-overflow: ellipsis;
  328. }
  329. }
  330. }
  331. }
  332. .handle {
  333. width: 100%;
  334. height: 126rpx;
  335. display: flex;
  336. align-items: center;
  337. justify-content: center;
  338. position: fixed;
  339. left: 0;
  340. bottom: 0;
  341. }
  342. .handle_button {
  343. background: #e93323;
  344. border-radius: 43rpx;
  345. display: flex;
  346. align-items: center;
  347. justify-content: center;
  348. font-size: 32rpx;
  349. color: #ffffff;
  350. width: 690rpx;
  351. padding: 21rpx 0;
  352. box-sizing: border-box;
  353. }
  354. .inputHolder {
  355. color: #bbbbbb;
  356. font-size: 30rpx;
  357. }
  358. </style>