cm-freight-popup.vue 12 KB

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