index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <view>
  3. <u-modal :show="showModal" ref="uModal" :title="editOrAdd === 'edit' ? '编辑' : '新增'" :asyncClose="false" showCancelButton @cancel="closeDialog" cancelColor="#909399" :confirmText="'确定'" confirmColor="#2979ff" @confirm="confirm" @close="closeDialog" :closeOnClickOverlay="false">
  4. <view class="modal_wrap">
  5. <text @click="handleBrandClick" class="item" :class="info.dictLabel ? 'brand' : 'brand placeholder'">{{ info.dictLabel || '品牌' }}</text>
  6. <text class="divider">|</text>
  7. <u--input placeholder="型号" class="item" border="none" v-model="info.model" clearable @blur="handleModelBlur"></u--input>
  8. <text class="divider">|</text>
  9. <u--input class="code-input item" placeholder="编码" border="none" v-model="info.code" clearable></u--input>
  10. </view>
  11. <view class="img_wrap">
  12. <imgs-row-scroll v-if="info.imgsUrl.length > 0" :isShowDeleteIcon="true" @deleteImgInfo="getDeleteImgInfo" imgMode="aspectFill" :totalWidth="400" :images="info.imgsUrl" :previewEnabled="true" :imageWidth="150" :imageHeight="150"></imgs-row-scroll>
  13. <u-upload
  14. @afterRead="afterRead"
  15. name="3"
  16. multiple
  17. :maxCount="10"
  18. ></u-upload>
  19. </view>
  20. <u--input v-if="editOrAdd === 'edit'" class="price" placeholder="价格" border="bottom" v-model="info.price" clearable></u--input>
  21. <view class="charts_box" v-show="chartShow">
  22. <qiun-data-charts type="line" :chartData="chartData" canvasId="trendChart" :opts="opts" :ontouch="true"
  23. width="700rpx" height="200rpx" backgroundColor="#ffffff" />
  24. </view>
  25. </u-modal>
  26. <brandList ref="brandListRef" @selectedBrand="handleSelectedBrand"></brandList>
  27. </view>
  28. </template>
  29. <script>
  30. import imgsRowScroll from '@/components/imgs-row-scroll/index.vue'
  31. import brandList from '@/components/brand-list/index.vue'
  32. export default {
  33. name: 'AddInquiryDialog',
  34. components: {
  35. imgsRowScroll,
  36. brandList
  37. },
  38. props: {
  39. clueId: {
  40. type: String,
  41. default: ''
  42. },
  43. show: {
  44. type: Boolean,
  45. default: false
  46. },
  47. editOrAdd: {
  48. type: String,
  49. default: ''
  50. },
  51. editInfo: {
  52. type: Object,
  53. default: () => {}
  54. },
  55. type: {
  56. type: Number,
  57. default: 1
  58. },
  59. },
  60. emits: ['submitSuccess'],
  61. data() {
  62. return {
  63. showModal: false,
  64. info: {
  65. model:'',
  66. code:'',
  67. id:'',
  68. price:'',
  69. dictLabel:'',
  70. dictValue:'',
  71. imgsUrl:[]
  72. },
  73. rules: {
  74. brand: [
  75. { required: true, message: '请输入品牌', trigger: 'blur' }
  76. ]
  77. },
  78. chartData:{},
  79. opts: {
  80. color: ["#f9ae3d"],
  81. padding: [10, 10, 0, 0],
  82. dataLabel: false,
  83. dataPointShape: false,
  84. enableScroll: true,
  85. legend: {
  86. show: false
  87. },
  88. xAxis: {
  89. disableGrid: true,
  90. scrollShow: true,
  91. itemCount: 7
  92. },
  93. yAxis: {
  94. gridType: "dash",
  95. dashLength: 7,
  96. axisLabel:{
  97. show: false
  98. }
  99. },
  100. extra: {
  101. line: {
  102. type: "curve",
  103. width: 3,
  104. activeType: "hollow",
  105. linearType: "custom",
  106. onShadow: true,
  107. animation: "horizontal"
  108. }
  109. }
  110. },
  111. chartShow: false
  112. }
  113. },
  114. watch: {
  115. show: {
  116. handler(newVal) {
  117. this.showModal = newVal;
  118. },
  119. immediate: true
  120. }
  121. },
  122. methods: {
  123. // 编辑回显
  124. initData() {
  125. this.$nextTick(()=>{
  126. if (this.editOrAdd === 'edit') {
  127. this.info = JSON.parse(JSON.stringify(this.editInfo))
  128. this.showModal = true;
  129. if(this.info.model && this.info.dictValue){
  130. this.getChartData()
  131. }
  132. }
  133. })
  134. },
  135. // 获取删除图片信息
  136. getDeleteImgInfo(info) {
  137. this.info.imgsUrl = info.newImages
  138. },
  139. handleBrandClick() {
  140. this.$refs.brandListRef.showBrandList();
  141. },
  142. handleSelectedBrand(info) {
  143. this.info.dictLabel = info.dictLabel
  144. this.info.dictValue = info.dictValue
  145. },
  146. // 上传图片
  147. afterRead(info) {
  148. info.file.forEach(item=>{
  149. uni.$u.api.uploadFile(item.url).then((res) => {
  150. this.info.imgsUrl.push(res.data.url);
  151. uni.$u.toast("文件上传成功");
  152. }).catch(() => {
  153. uni.$u.toast("上传文件失败");
  154. })
  155. })
  156. },
  157. // 确认添加
  158. confirm() {
  159. if (!this.info.dictLabel || !this.info.dictValue) {
  160. uni.showToast({
  161. title: '请选择品牌',
  162. icon: 'none'
  163. })
  164. return
  165. }
  166. if (!this.info.model) {
  167. uni.showToast({
  168. title: '请输入型号',
  169. icon: 'none'
  170. })
  171. return
  172. }
  173. if (!this.info.code) {
  174. uni.showToast({
  175. title: '请输入编码',
  176. icon: 'none'
  177. })
  178. return
  179. }
  180. // if(this.info.imgsUrl.length == 0){
  181. // uni.showToast({
  182. // title: '请上传图片',
  183. // icon: 'none'
  184. // })
  185. // return
  186. // }
  187. const data = {
  188. clueId: this.clueId,
  189. dictValue: this.info.dictValue,
  190. dictLabel: this.info.dictLabel,
  191. model: this.info.model,
  192. code: this.info.code,
  193. id: this.editOrAdd === 'edit' ? this.info.id : '',
  194. price: this.editOrAdd === 'edit' ? this.info.price : '',
  195. imgsUrl:this.info.imgsUrl,
  196. status: this.editOrAdd === 'edit' ? '2' : '1',
  197. type: this.type
  198. }
  199. uni.$u.api.addInquiry(data).then(res => {
  200. if (res.code == 200) {
  201. uni.showToast({
  202. title: '添加成功',
  203. icon: 'success'
  204. })
  205. this.closeDialog()
  206. this.$emit('submitSuccess')
  207. }
  208. })
  209. },
  210. showDialog() {
  211. if (this.editOrAdd === 'edit') {
  212. this.initData();
  213. }else{
  214. this.clearForm()
  215. this.showModal = true;
  216. }
  217. },
  218. clearForm() {
  219. this.info = {
  220. dictLabel:'',
  221. dictValue:'',
  222. model:'',
  223. code:'',
  224. id:'',
  225. price:'',
  226. imgsUrl:[]
  227. }
  228. },
  229. closeDialog() {
  230. this.showModal = false;
  231. this.chartShow = false
  232. this.chartData = {}
  233. },
  234. handleModelBlur() {
  235. if (this.info.model !== ''){
  236. this.getChartData()
  237. }
  238. },
  239. getChartData() {
  240. uni.$u.api.inquiryChart({
  241. dictValue: this.info.dictValue,
  242. model: this.info.model,
  243. }).then(res => {
  244. if (res.code == 200) {
  245. let data = {
  246. categories: res.data.map(item=>item.recycleTime),
  247. series: [
  248. {
  249. name: this.info.model+'价格趋势',
  250. data: res.data.map(item=>item.costPrice),
  251. setShadow: [
  252. 3,
  253. 8,
  254. 15,
  255. "#f9ae3d"
  256. ],
  257. }
  258. ]
  259. }
  260. this.chartData = JSON.parse(JSON.stringify(data))
  261. this.chartShow = true
  262. }
  263. })
  264. },
  265. }
  266. };
  267. </script>
  268. <style lang="scss" scoped>
  269. @import './index.scss'
  270. </style>