cm-freight-popup.vue 9.8 KB

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