cm-freight-popup.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <template name="freight">
  2. <!-- 运费信息 -->
  3. <view>
  4. <view class="goods-pros-m">
  5. <template v-if="supplier.postageFlag === 0">
  6. <view class="freight-main">
  7. <view class="freight-left">运费</view>
  8. <view class="freight-right"> <view class="freight-text">包邮</view> </view>
  9. </view>
  10. </template>
  11. <template v-if="supplier.postageFlag === 1 && supplier.designatedFlag === 1">
  12. <view class="freight-main">
  13. <view class="freight-left">运费</view>
  14. <view class="freight-right">
  15. <view class="freight-text">¥{{ handleTotalPostage | NumFormat }}</view>
  16. </view>
  17. </view>
  18. </template>
  19. <template
  20. v-if="
  21. (supplier.postageFlag === 1 && supplier.designatedFlag === 2) ||
  22. (supplier.postageFlag === 1 && supplier.designatedFlag === 3)
  23. "
  24. >
  25. <view class="freight-main">
  26. <view class="freight-left">运费</view>
  27. <view class="freight-right" @click.stop="handlePupShow">
  28. <view class="freight-text" v-if="handlePostageFlag === 1"
  29. >¥{{ handleTotalPostage | NumFormat }}</view
  30. >
  31. <view class="freight-text" v-if="handlePostageFlag === 2">到付</view>
  32. <view class="select"><text class="iconfont icon-xiayibu"></text></view>
  33. </view>
  34. </view>
  35. </template>
  36. <template v-if="supplier.postageFlag === 2">
  37. <view class="freight-main">
  38. <view class="freight-left">运费</view>
  39. <view class="freight-right"> <view class="freight-text">到付</view> </view>
  40. </view>
  41. </template>
  42. <tui-bottom-popup :radius="true" :show="popupShow" @close="hidePopup">
  43. <view class="freight-title">运费设置</view>
  44. <view class="freight-content">
  45. <radio-group @change="radioChange">
  46. <label v-for="(item, index) in radioItems" :key="index">
  47. <radio
  48. style="transform:scale(0.7)"
  49. color="#FF5B00"
  50. :id="item.value"
  51. :value="item.value"
  52. :checked="item.checked"
  53. ></radio>
  54. <label :for="item.value" class="label">
  55. <text>{{ item.name }}</text>
  56. </label>
  57. </label>
  58. </radio-group>
  59. <template v-if="handlePostageFlag === 1">
  60. <view class="freight-form">
  61. <view class="freight-form-item" v-if="handleSupplier.coldChain > 0">
  62. <view class="label">冷链运输费</view>
  63. <view class="texts">
  64. <text>¥{{ handleSupplier.coldChain | NumFormat }}</text>
  65. <text
  66. class="iconfont"
  67. :class="[isColdChina ? 'icon-yixuanze' : 'icon-weixuanze']"
  68. @click.stop="handleChangeColdChina"
  69. >
  70. </text>
  71. </view>
  72. </view>
  73. <view class="freight-form-item">
  74. <view class="label">其他运费 </view>
  75. <view class="texts red">¥{{ handleSupplier.postage | NumFormat }} </view>
  76. </view>
  77. <view class="freight-form-item">
  78. <view class="label">总运费 </view>
  79. <view class="texts red">¥{{ handleTotalPostage | NumFormat }} </view>
  80. </view>
  81. </view>
  82. </template>
  83. <template v-if="handlePostageFlag === 2">
  84. <view class="freight-form">
  85. <view class="freight-form-item" v-if="handleSupplier.coldChain > 0">
  86. <view class="label">冷链运输费</view>
  87. <view class="texts">
  88. <text>¥{{ handleSupplier.coldChain | NumFormat }}</text>
  89. <text
  90. class="iconfont"
  91. :class="[isColdChina ? 'icon-yixuanze' : 'icon-weixuanze']"
  92. @click.stop="handleChangeColdChina"
  93. >
  94. </text>
  95. </view>
  96. </view>
  97. <view class="freight-form-item">
  98. <view class="label">其他运费 </view><view class="texts red">到付</view>
  99. </view>
  100. <view class="freight-form-item">
  101. <view class="label">总运费</view>
  102. <view class="texts red" v-if="handleSupplier.isColdChina"
  103. >¥{{ handleSupplier.coldChain | NumFormat }}</view
  104. >
  105. <view class="texts red" v-else>到付</view>
  106. </view>
  107. </view>
  108. </template>
  109. <view class="freight-btn" @click="popupShow = false"> 确定 </view>
  110. </view>
  111. </tui-bottom-popup>
  112. </view>
  113. </view>
  114. </template>
  115. <script>
  116. export default {
  117. name: 'freight',
  118. props: {
  119. supplier: {
  120. type: Object
  121. },
  122. index: {
  123. type: Number
  124. }
  125. },
  126. data() {
  127. return {
  128. popupShow: false,
  129. isColdChina: false,
  130. handlePostageFlag: 1,
  131. radioItems: [
  132. {
  133. name: '不包邮',
  134. value: 1,
  135. checked: true
  136. },
  137. {
  138. name: '到付',
  139. value: 2
  140. }
  141. ],
  142. handleSupplier: {}
  143. }
  144. },
  145. filters: {
  146. NumFormat(value) {
  147. //处理金额
  148. return Number(value).toFixed(2)
  149. }
  150. },
  151. created() {
  152. this.infoSupplier(this.supplier)
  153. },
  154. computed: {
  155. // 计算总运费
  156. handleTotalPostage() {
  157. if (this.handleSupplier.isColdChina) {
  158. return (this.handleSupplier.postage * 100 + this.handleSupplier.coldChain * 100) / 100
  159. } else {
  160. return this.handleSupplier.postage
  161. }
  162. }
  163. },
  164. watch: {
  165. supplier: {
  166. handler: function(el) {
  167. //监听对象的变换使用 function,箭头函数容易出现this指向不正确
  168. this.supplier = el
  169. },
  170. deep: true
  171. }
  172. },
  173. methods: {
  174. // 初始化
  175. infoSupplier(data) {
  176. this.handleSupplier = data
  177. this.isColdChina = data.isColdChina
  178. this.handlePostageFlag = data.handlePostageFlag
  179. },
  180. // 勾选冷链费
  181. handleChangeColdChina() {
  182. this.isColdChina = !this.isColdChina
  183. this.handleSupplier.isColdChina = this.isColdChina
  184. if (this.isColdChina) {
  185. this.handleSupplier.totalPrice = Number(
  186. (this.handleSupplier.totalPrice * 100 + this.handleSupplier.coldChain * 100) / 100
  187. )
  188. this.$emit('changeColdChina', this.handleSupplier, this.index)
  189. } else {
  190. this.handleSupplier.totalPrice = Number(
  191. this.repiceNumSub(this.handleSupplier.totalPrice, this.handleSupplier.coldChain)
  192. )
  193. this.$emit('changeColdChina', this.handleSupplier, this.index)
  194. }
  195. },
  196. // 切换运费类型 1 不包邮 2 到付
  197. radioChange($event) {
  198. // const postage = this.isColdChina ? ( this.handleSupplier.postage + this.handleSupplier.coldChain ) : this.handleSupplier.postage
  199. this.handlePostageFlag = this.handleSupplier.handlePostageFlag = $event.detail.value * 1
  200. if (this.handlePostageFlag === 1) {
  201. this.handleSupplier.totalPrice = Number(
  202. (this.handleSupplier.totalPrice * 100 + this.handleSupplier.postage * 100) / 100
  203. )
  204. this.$emit('changePostage', this.handleSupplier, this.index)
  205. } else {
  206. this.handleSupplier.totalPrice = Number(
  207. this.repiceNumSub(this.handleSupplier.totalPrice, this.handleSupplier.postage)
  208. )
  209. this.$emit('changePostage', this.handleSupplier, this.index)
  210. }
  211. },
  212. repiceNumSub(arg1, arg2) {
  213. //减法精确,arg2:被减数,arg1:减数
  214. var r1, r2, m, n
  215. try {
  216. r1 = arg1.toString().split('.')[1].length
  217. } catch (e) {
  218. r1 = 0
  219. }
  220. try {
  221. r2 = arg2.toString().split('.')[1].length
  222. } catch (e) {
  223. r2 = 0
  224. }
  225. m = Math.pow(10, Math.max(r1, r2))
  226. // last modify by deeka
  227. // 动态控制精度长度
  228. n = r1 >= r2 ? r1 : r2
  229. return ((arg1 * m - arg2 * m) / m).toFixed(n)
  230. },
  231. handlePupShow() {
  232. this.popupShow = true
  233. },
  234. hidePopup() {
  235. this.popupShow = false
  236. }
  237. }
  238. }
  239. </script>
  240. <style lang="scss">
  241. .goods-pros-m {
  242. width: 100%;
  243. box-sizing: border-box;
  244. padding: 10rpx 0;
  245. .freight-main {
  246. width: 100%;
  247. height: 78rpx;
  248. line-height: 78rpx;
  249. font-size: $font-size-28;
  250. color: $text-color;
  251. background: #ffffff;
  252. float: left;
  253. .freight-left {
  254. float: left;
  255. font-weight: bold;
  256. }
  257. .freight-right {
  258. float: right;
  259. color: #333333;
  260. position: relative;
  261. .freight-text {
  262. float: left;
  263. }
  264. .select {
  265. float: right;
  266. height: 60rpx;
  267. padding: 0 20rpx;
  268. margin-top: 14rpx;
  269. line-height: 60rpx;
  270. color: #333333;
  271. font-weight: normal;
  272. position: relative;
  273. .select-text {
  274. display: inline-block;
  275. float: left;
  276. margin-right: 30rpx;
  277. }
  278. .iconfont {
  279. width: 60rpx;
  280. height: 60rpx;
  281. line-height: 60rpx;
  282. text-align: right;
  283. position: absolute;
  284. right: 0;
  285. top: 0;
  286. font-size: $font-size-28;
  287. color: #b2b2b2;
  288. }
  289. }
  290. }
  291. }
  292. .freight-bean {
  293. width: 100%;
  294. height: 58rpx;
  295. line-height: 58rpx;
  296. float: left;
  297. .bean-le {
  298. float: left;
  299. color: #666666;
  300. font-size: $font-size-26;
  301. font-weight: normal;
  302. }
  303. .bean-ri {
  304. float: right;
  305. display: flex;
  306. align-items: center;
  307. .checkbox-box {
  308. display: flex;
  309. width: 60rpx;
  310. float: left;
  311. height: 100%;
  312. font-size: $font-size-26;
  313. margin-top: 8rpx;
  314. .checkbox {
  315. width: 40rpx;
  316. text-align: right;
  317. box-sizing: border-box;
  318. text-align: center;
  319. text-decoration: none;
  320. border-radius: 0;
  321. -webkit-tap-highlight-color: transparent;
  322. overflow: hidden;
  323. color: $color-system;
  324. }
  325. }
  326. }
  327. }
  328. }
  329. .freight-title {
  330. color: #333333;
  331. font-size: 32rpx;
  332. text-align: center;
  333. margin: 40rpx 0;
  334. }
  335. .freight-content {
  336. box-sizing: border-box;
  337. padding: 0 24rpx;
  338. font-weight: normal;
  339. radio {
  340. margin-right: 8rpx;
  341. }
  342. .label {
  343. color: #666666;
  344. font-size: 28rpx;
  345. margin-right: 102rpx;
  346. }
  347. .freight-btn {
  348. height: 90rpx;
  349. background: $btn-confirm;
  350. border-radius: 45rpx;
  351. display: flex;
  352. justify-content: center;
  353. align-items: center;
  354. color: #ffffff;
  355. width: 100%;
  356. margin: 100rpx 0 0 0;
  357. }
  358. }
  359. .freight-form {
  360. margin-top: 50rpx;
  361. width: 100%;
  362. .freight-form-item {
  363. width: 100%;
  364. height: 48rpx;
  365. line-height: 48rpx;
  366. margin-bottom: 24rpx;
  367. color: #666666;
  368. font-size: 28rpx;
  369. .label {
  370. width: 50%;
  371. float: left;
  372. margin-right: 0;
  373. }
  374. .texts {
  375. width: 50%;
  376. float: right;
  377. text-align: right;
  378. &.red {
  379. color: #f94b4b;
  380. }
  381. .iconfont {
  382. margin-left: 20rpx;
  383. color: $color-system;
  384. }
  385. }
  386. }
  387. }
  388. .freight-pay {
  389. position: absolute;
  390. right: -60%;
  391. transform: scale(0.7);
  392. }
  393. </style>