print.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <template>
  2. <view class="container" v-if="modelDatas.length">
  3. <!-- 预览按钮区域 -->
  4. <view class="title">
  5. <img class="img" src="../../static/images/my/eye.png" @click="handlePreview" />
  6. <view @click="handlePreview">预览效果</view>
  7. </view>
  8. <!-- 分段器区域 -->
  9. <view class="subsection">
  10. <u-subsection
  11. v-if="modelDatas.length"
  12. bgColor="#fff"
  13. activeColor="#0061FF"
  14. inactiveColor="#808080"
  15. :list="modelDatas"
  16. :current="currentIndex"
  17. @change="changeIndex"
  18. ></u-subsection>
  19. </view>
  20. <view class="gap"></view>
  21. <!-- 小票编辑区域 -->
  22. <view class="edit">
  23. <view class="edit_title">小票编辑</view>
  24. <view class="edit_subTitle">
  25. <view class="sub_box"></view>
  26. 基本信息
  27. </view>
  28. <view class="edit_desc">注:{{ descList[currentIndex] }}为小票必须展示的信息</view>
  29. <view class="check_box">
  30. <view class="check_box_item" v-for="item in dataObj.details" :key="item.id">
  31. <u-checkbox
  32. size="50"
  33. v-model="item.isCheck == 1 ? true : false"
  34. :disabled="
  35. item.printName == '平台名称' ||
  36. item.printName == '店铺名' ||
  37. item.printName == '订单号' ||
  38. item.printName == '送达时间' ||
  39. item.printName == '订单类型' ||
  40. item.printName == '商品名称' ||
  41. item.printName == '单价' ||
  42. item.printName == '数量' ||
  43. item.printName == '备注' ||
  44. item.printName == '打包费' ||
  45. item.printName == '商品费' ||
  46. item.printName == '优惠券' ||
  47. item.printName == '跑腿费' ||
  48. item.printName == '优惠活动' ||
  49. item.printName == '合计' ||
  50. item.printName == '姓名' ||
  51. item.printName == '电话号' ||
  52. item.printName == '地址' ||
  53. item.printName == '订餐时间'
  54. "
  55. :checked="item.isCheck == 1"
  56. @change="changeCheck(item)"
  57. >
  58. {{ item.printName }}
  59. </u-checkbox>
  60. </view>
  61. </view>
  62. </view>
  63. <!-- 自定义样式区域 -->
  64. <view class="diy">
  65. <view class="diy_title">自定义样式</view>
  66. <view class="diy_box" v-for="item in dataObj.types" :key="item.id">
  67. <view class="box_title">{{ item.printName }}</view>
  68. <view class="box_row">
  69. <view style="margin-bottom: 10rpx">打印字号:</view>
  70. <u-radio-group v-model="item.wordSize">
  71. <u-radio :customStyle="{ marginBottom: '8px' }" v-for="(item, index) in radiolist1" :key="index" :name="item.label">
  72. {{ item.name }}
  73. </u-radio>
  74. </u-radio-group>
  75. </view>
  76. <view class="box_row">
  77. <view style="margin-bottom: 10rpx">字体:</view>
  78. <u-radio-group v-model="item.isBlod">
  79. <u-radio :customStyle="{ marginBottom: '8px' }" v-for="(item, index) in radiolist2" :key="index" :name="item.label">
  80. {{ item.name }}
  81. </u-radio>
  82. </u-radio-group>
  83. </view>
  84. </view>
  85. </view>
  86. <!-- 保存按钮区域 -->
  87. <view class="btn" v-if="modelDatas.length">
  88. <view class="btn_box" @click="handleSave">保存</view>
  89. </view>
  90. </view>
  91. </template>
  92. <script>
  93. export default {
  94. data() {
  95. return {
  96. // 店铺id
  97. shopId: '',
  98. // 打印数据id
  99. printId: '',
  100. // 当前激活分段器索引
  101. currentIndex: 0,
  102. // 打印字号数组
  103. radiolist1: [
  104. {
  105. name: '正常',
  106. label: 1
  107. },
  108. {
  109. name: '放大',
  110. label: 2
  111. }
  112. ],
  113. // 打印字体数组
  114. radiolist2: [
  115. {
  116. name: '正常',
  117. label: 0
  118. },
  119. {
  120. name: '加粗',
  121. label: 1
  122. }
  123. ],
  124. // 模版数据
  125. modelDatas: [],
  126. // 每一个分段器的数据
  127. dataObj: {},
  128. descList: ['平台名称、店铺名、订单号', '商品名称、单价、数量、备注', '打包费、商品费、优惠券、跑腿费、优惠活动和合计', '姓名、电话号、地址 、订餐时间']
  129. }
  130. },
  131. onLoad() {
  132. this.shopId = uni.getStorageSync('shopId')
  133. // 根据店铺ID获取小票模板数据
  134. this.getModelDatas()
  135. },
  136. methods: {
  137. // 根据店铺ID获取小票模板数据
  138. async getModelDatas() {
  139. const res = await this.$Request.getT('/admin/printInfo/getPrintModelData', {
  140. shopId: this.shopId
  141. })
  142. console.log(res)
  143. if (res.code == 0) {
  144. this.printId = res.data.id
  145. this.modelDatas = res.data.modelDatas
  146. this.changeIndex(this.currentIndex)
  147. }
  148. },
  149. // 保存按钮回调
  150. async handleSave() {
  151. const res = await this.$Request.postJson(this.printId ? '/admin/printInfo/updatePrintModelData' : '/admin/printInfo/insertPrintModelData', {
  152. id: this.printId,
  153. modelDatas: this.modelDatas,
  154. shopId: this.shopId
  155. })
  156. if (res.code == 0) {
  157. uni.showToast({
  158. title: '保存成功',
  159. mask: true,
  160. icon: 'success'
  161. })
  162. setTimeout(() => {
  163. this.getModelDatas()
  164. }, 1500)
  165. }
  166. },
  167. // 切换分段器时的回调
  168. changeIndex(i) {
  169. this.currentIndex = i
  170. this.dataObj = this.modelDatas[this.currentIndex]
  171. uni.pageScrollTo({
  172. selector: '.gap',
  173. offsetTop: -500
  174. })
  175. },
  176. // 切换check时的回调
  177. changeCheck(item) {
  178. // console.log(item)
  179. item.isCheck = item.isCheck == 1 ? 0 : 1
  180. },
  181. handlePreview() {
  182. let data = encodeURIComponent(JSON.stringify(this.modelDatas))
  183. uni.navigateTo({
  184. url: `/my/print/preview?data=${data}`
  185. })
  186. }
  187. }
  188. }
  189. </script>
  190. <style lang="scss" scoped>
  191. .container {
  192. min-height: 100vh;
  193. overflow-y: auto;
  194. .title {
  195. position: fixed;
  196. top: 0;
  197. left: 0;
  198. right: 0;
  199. display: flex;
  200. justify-content: flex-end;
  201. align-items: center;
  202. padding: 0 20rpx;
  203. height: 80rpx;
  204. font-size: 28rpx;
  205. color: #0061ff;
  206. background-color: #fff;
  207. border-bottom: 2rpx solid #f1f1f1;
  208. .img {
  209. margin-right: 6rpx;
  210. width: 58rpx;
  211. height: 58rpx;
  212. }
  213. }
  214. .subsection {
  215. position: fixed;
  216. top: 80rpx;
  217. left: 0;
  218. right: 0;
  219. }
  220. .gap {
  221. margin-top: 150rpx;
  222. height: 20rpx;
  223. background-color: #f1f1f1;
  224. }
  225. .edit {
  226. margin: 0 0 20rpx 0;
  227. background-color: #fff;
  228. .edit_title {
  229. display: flex;
  230. align-items: center;
  231. padding: 0 20rpx;
  232. height: 92rpx;
  233. font-size: 32rpx;
  234. font-weight: bold;
  235. border-bottom: 2rpx solid #f1f1f1;
  236. }
  237. .edit_subTitle {
  238. display: flex;
  239. align-items: center;
  240. padding: 0 20rpx;
  241. margin-top: 32rpx;
  242. font-size: 28rpx;
  243. .sub_box {
  244. margin-right: 12rpx;
  245. width: 20rpx;
  246. height: 20rpx;
  247. background-color: #0061ff;
  248. }
  249. }
  250. .edit_desc {
  251. padding: 0 20rpx 0 50rpx;
  252. margin: 15rpx 0;
  253. font-size: 24rpx;
  254. color: #999999;
  255. line-height: 36rpx;
  256. }
  257. .check_box {
  258. padding: 0 20rpx;
  259. margin-top: 15px;
  260. display: flex;
  261. flex-wrap: wrap;
  262. .check_box_item {
  263. margin-bottom: 35rpx;
  264. width: 350rpx;
  265. }
  266. }
  267. }
  268. .diy {
  269. background-color: #fff;
  270. .diy_title {
  271. display: flex;
  272. align-items: center;
  273. padding: 0 20rpx;
  274. height: 92rpx;
  275. font-size: 32rpx;
  276. font-weight: bold;
  277. border-bottom: 2rpx solid #f1f1f1;
  278. }
  279. .diy_box {
  280. padding: 0 20rpx 20rpx;
  281. font-size: 28rpx;
  282. .box_title {
  283. height: 80rpx;
  284. line-height: 80rpx;
  285. font-weight: bold;
  286. }
  287. .box_row {
  288. margin-bottom: 20rpx;
  289. }
  290. }
  291. }
  292. .btn {
  293. display: flex;
  294. justify-content: center;
  295. padding: 0 20rpx 40rpx;
  296. background-color: #fff;
  297. .btn_box {
  298. display: flex;
  299. justify-content: center;
  300. align-items: center;
  301. width: 200rpx;
  302. height: 80rpx;
  303. color: #fff;
  304. border-radius: 10rpx;
  305. background-color: #0061ff;
  306. }
  307. }
  308. }
  309. </style>